//****************************************************************************************** // Project : // Program Name : // Programer : // Create date : Version 1.0 H23.05.20 // Replace date : // History : // Laungage : MPLAB C18 //****************************************************************************************** // Description // 1)OSC 40MHz (10MHz Crystal * PLL4) // //****************************************************************************************** #include #include #include #include #include #include #include #include // //Define configration // #pragma config OSC=HSPLL //Oscillator Selection : HS-PLL Enabled #pragma config OSCS=OFF //Osc. Switch Enable: #pragma config PWRT=OFF //Power-up Timer: #pragma config BOR=OFF //Brown-out Reset: #pragma config BORV=25 //Brown-out Voltage: 2.5V #pragma config WDT=OFF //Watchdog Timer: #pragma config WDTPS=1 //Watchdog Postscaler: 1:1 #pragma config CCP2MUX=OFF //CCP2 MUX: Disable(RB3) //#pragma config CCP2MUX = ON //CCP2 MUX: Enable(RC1) #pragma config STVR=OFF //Stack Overflow Reset: #pragma config LVP=OFF //Low Voltage ICSP: #pragma config DEBUG=OFF //Background Debugger Enable: #pragma config CP0=OFF //Code Protection Block 0: #pragma config CP1=OFF //Code Protection Block 1: #pragma config CP2=OFF //Code Protection Block 2: #pragma config CP3=OFF //Code Protection Block 3: #pragma config CPB=OFF //Boot Block Code Protection: #pragma config CPD=OFF //Data EEPROM Code Protection: #pragma config WRT0=OFF //Write Protection Block 0: #pragma config WRT1=OFF //Write Protection Block 1: #pragma config WRT2=OFF //Write Protection Block 2: #pragma config WRT3=OFF //Write Protection Block 3: #pragma config WRTB=OFF //Boot Block Write Protection: #pragma config WRTC=OFF //Configuration Register Write Protection: #pragma config WRTD=OFF //Data EEPROM Write Protection: #pragma config EBTR0=OFF //Table Read Protection Block 0: #pragma config EBTR1=OFF //Table Read Protection Block 1: #pragma config EBTR2=OFF //Table Read Protection Block 2: #pragma config EBTR3=OFF //Table Read Protection Block 3: #pragma config EBTRB=OFF //Boot Block Table Read Protection: // //Define function // #define PI_NORMAL 0 #define PI_FAILURE 1 // // //Define function // void BCF(unsigned int); void BSF(unsigned int); void Timer(void); void Wait_1mS(unsigned int); void Select_clm(unsigned int); unsigned char Set_FNT(unsigned int); unsigned char Set_FNT_no(unsigned char); void Wait_dsp(unsigned char *,unsigned int); void Wait_dsp_num(unsigned char *,unsigned int); void Demo01(void); void Demo02(void); void LED_OFF(void); volatile unsigned int G_counter=0; #define PI_7SEG_MAX 14 void main(void) { unsigned char tmp_char; unsigned char flg = 0; unsigned char lp; // ************************************* // 1.Initialize Segment // ************************************* // (1)TRIS TRISA=0b11110000; TRISB=0b10000000; TRISC=0b11000000; TRISD=0b10000000; TRISE=0b00000011; //Caution !!! (Bit[7-4]) // (2)LAT LATA=0b00000000; LATB=0b00000000; LATC=0b00000000; LATD=0b00000000; LATE=0b00000000; // (3)PORT PORTA=0b00001111; PORTB=0b01111111; PORTC=0b00000000; PORTD=0b01111111; PORTE=0b00000000; // (4)Select A/D Converter ADCON1=0b00000111; //ALL Degital Port // ************************************* // 2.Program Main // ************************************* // (1)Demo Program while(1){ Demo01(); Demo02(); } } //****************************************************************************************** // Function Name : Demo01 // Title : // Input : // Output : //****************************************************************************************** void Demo01(void) { unsigned char c_dat[PI_7SEG_MAX]; unsigned int lp; for(lp=0;lp: 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: Timer1 Oscillator Enable bit // 1 = Timer1 oscillator is enabled // 0 = Timer1 oscillator is shut off // The oscillator inverter and feedback resistor are turned off to eliminate power drain. //* T1CON(2) T1SYNC: Timer1 External Clock Input Synchronization Select bit // When TMR1CS = 1: // 1 = Do not synchronize external clock input // 0 = Synchronize external clock input // When TMR1CS = 0: // This bit is ignored. Timer1 uses the internal clock when TMR1CS = 0. //* T1CON(1) TMR1CS: Timer1 Clock Source Select bit // 1 = External clock from the T13CKI pin (on the rising edge) // 0 = Internal clock (FOSC/4) //* T1CON(0) bit 0 TMR1ON: Timer1 On bit // 1 = Enables Timer1 // 0 = Stops Timer1 // ******************************************************* T1CON = 0b10000001; // 16-bit Read/Write Mode, 1:8 Prescale value // ******************************************************* // 2.Define TMR1 Register // Caution(16-bit Read/Write Mode) !!!!: // (a)Writing to TMR1H does not directly affect Timer1. // Instead, the high byte of Timer1 is updated with the contents of TMR1H when a write occurs to TMR1L. // This allows all 16 bits of Timer1 to be updated at once. // (b)A read from TMR1L will load the contents of the high byte of Timer1 into the Timer1 high byte buffer. // This provides the user with the ability to accurately read all 16 bits of Timer1 without the need to // determine whether a read of the high byte, followed by a read of the low byte, has become invalid due // to a rollover or carry between reads. // ******************************************************* // TMR1 data ( OSC:10MHz, 4X PLLON, 1:1 Prescale value, 0.001[S];1000Hz ) // 1mS(1000Hz): 10MHz * 4(PLLON) / 4(PIC) / 1(Prescale) / 1000(1000Hz)==> 0d10,000(Count) ==> 0x2710(Count) // TMR1 = 0xFFFF - 0x2710 ==> 0xD8EF // TMR1H = 0xD8; TMR1L = 0xEF; // ******************************************************* // 3.Timer // ******************************************************* PIR1bits.TMR1IF = 0; while(1){ if(PIR1bits.TMR1IF != 0 )break; } }