//****************************************************************************************** // PIC12F683 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H24.05.20 // Replace date : // History : // Laungage : HI_TECH PICC C Laungage Version 9.70 //****************************************************************************************** // Description // (1)LED Format(P0〜P5) // (P1)  (P2)    // (P5) (P0) (P5) // (P2) (P1) // // P4:Select LED Block // P3:Input Push-SW // // (2)OSC : Internal OSC 8MHz //****************************************************************************************** #include __CONFIG( FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTDIS & WDTDIS & INTIO ); void Disp_LED(unsigned char, unsigned char); void Wait_Inter(void); void Timer(void); #define PI_LED_BLK_1 0 #define PI_LED_BLK_2 1 #define PI_LOOP_1 25 #define PI_LPT 10 #define PI_LPANS 5 void main() { unsigned char cnt1,cnt2; unsigned int lp1,lp2; // ******************************** // 1.Initialized Segment // ******************************** // (1)Define OSC (Internal OSC 8MHz) OSCCON = OSCCON | 0x70; // (2)Define ANSEL (All Degital Port) ANSEL = 0x00; // (3)Define I/O PORT GPIO = 0x00; TRISIO = 0b11001000; // (4)Clear numeric cnt1 = 0x00; cnt2 = 0x00; // ******************************** // 2.Program main // ******************************** while(1){ // (1)Release Push-Switch // Random numbers generetor 1 (upfoword octal counter) Disp_LED((unsigned char)0, PI_LED_BLK_1); while(1){ cnt1++; if(cnt1 > 5) cnt1 = 0; if((GPIO & 0b00001000) != 0)break; } // (2)Push Push-Switch // Random numbers generetor 2 (upfoword octal counter) Disp_LED((unsigned char)0, PI_LED_BLK_2); while(1){ cnt2++; if(cnt2 > 5) cnt2 = 0; if((GPIO & 0b00001000) == 0)break; } // (3)Move LED (demo) for(lp2=0;lp2 4) cnt1 = 0; else cnt1++; if(cnt2 < 1) cnt2 = 5; else cnt2--; } // (4)Stop LED (anser) for(lp2=0;lp2: Timer1 Input Clock Prescale Select bits // 11 = 1:8 Prescale Value // 10 = 1:4 Prescale Value // 01 = 1:2 Prescale Value // 00 = 1:1 Prescale Value // T1CON[3] T1OSCEN: LP Oscillator Enable Control bit // If INTOSC without CLKOUT oscillator is active: // 1 = LP oscillator is enabled for Timer1 clock // 0 = LP oscillator is off // Else: This bit is ignored. // T1CON[2] T1SYNC: Timer1 External Clock Input Synchronization Control bit // TMR1CS = 1: // 1 = Do not synchronize external clock input // 0 = Synchronize external clock input // TMR1CS = 0: // This bit is ignored. Timer1 uses the internal clock. // T1CON[1] TMR1CS: Timer1 Clock Source Select bit // 1 = External clock from T1CKI pin (on the rising edge) // 0 = Internal clock (FOSC/4) // T1CON[0] TMR1ON: Timer1 On bit // 1 = Enables Timer1 // 0 = Stops Timer1 // ************************************************* T1CON = 0b00000101; // ************************************************* // 2.Set TMR1 Value // 8000000Hz(Int_OSC)/4/8(Prescale)/10(0.1[S]) => 0d25000(0x61A8) // 0xFFFF(-)0xF424 => 0d40535(0x9E57) // 8000000Hz(Int_OSC)/4/1(Prescale)/1000(0.001[S]) => 0d2000(0x7D0) // 0xFFFF(-)0x07D0 => 0d63535(0xF82F) // ************************************************* // TMR1H = 0xF8; TMR1L = 0x2F; // ************************************************* // 3.Timer // ************************************************* PIR1 = PIR1 & 0xfe; while((PIR1 & 0x01) == 0); }