//****************************************************************************************** // PIC18F14K50 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H21.12.20 // History : // Laungage : MPLAB C18 //****************************************************************************************** // (1)Description // //****************************************************************************************** #include #include #include #include #include #include #include #include // //Define configration // #pragma config CPUDIV=NOCLKDIV //CPU System Clock Selection bit(No CPU System Clock divide) #pragma config USBDIV = OFF //USB Clock Selection bit(USB Clock comes directly from the OSC1/OSC2 oscillator block; no divide) #pragma config FOSC = HS //Oscillator Selection bits(HS oscillator) #pragma config PLLEN = ON //X PLL Enable bit(Oscillator multiplied by 4) #pragma config PCLKEN = OFF //Primary Clock Enable Bit(Primary clock is under software control) #pragma config FCMEN = OFF #pragma config IESO = OFF //Internal/External Oscillator Switchover bit(Oscillator Switchover mode disabled) #pragma config PWRTEN = OFF,BOREN = OFF,BORV = 19 #pragma config WDTEN = OFF,WDTPS = 1 #pragma config MCLRE = OFF //MCLR Pin Enable bit(RE3 input pin enabled; MCLR disabled) #pragma config HFOFST = OFF,STVREN = OFF,LVP = OFF,BBSIZ = OFF,XINST = OFF #pragma config CP0 = OFF,CP1 = OFF,CPB = OFF,CPD = OFF,WRT0 = OFF,WRT1 = OFF,WRTB = OFF,WRTC = OFF,WRTD = OFF,EBTR0 = OFF,EBTR1 = OFF,EBTRB = OFF // //Define function // void mvLED(unsigned char *); void wat(unsigned int); //****************************************************************************************** // Program : // Title : // Input : // Output : //****************************************************************************************** void main(void) { unsigned char LEDlst = 0x01; // ***************************** // 1.Initialized Segment // ***************************** TRISA = 0xFF; TRISB = 0xFF; TRISC = 0x00; LATC = 0x00; PORTC = 0x00; // ***************************** // 2.Program main // ***************************** while(1){ mvLED(&LEDlst); PORTC = LEDlst; wat(1000); }; } //****************************************************************************************** // Function Name : mvLED // Title : Move LED function // Input : // Output : //****************************************************************************************** void mvLED(unsigned char *LEDlst) { if(*LEDlst == 1){ *LEDlst = 2; }else if(*LEDlst > 127){ *LEDlst = 1; }else{ *LEDlst = *LEDlst * 2; } PORTB = *LEDlst; return; } //****************************************************************************************** // Function Name : wat // Title : wait function // Input : // Output : //****************************************************************************************** void wat(unsigned int tim) { unsigned int lp,lp1 ; for(lp=0 ; lp < tim ; lp++ ) for(lp1=0 ; lp1 < 100 ; lp1++ ) ; return; }