//****************************************************************************************** // PIC18F4550 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H22.08.20 // History : // Laungage : MPLAB C18 //****************************************************************************************** // (1)Description // //****************************************************************************************** #include #include #include #include #include #include #include #include // //Define configration // #pragma config PLLDIV = 4 // Divide by 4 (16 MHz oscillator input) #pragma config CPUDIV = OSC1_PLL2 // [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2] #pragma config USBDIV = 2 // USB clock source comes from the 96 MHz PLL divided by 2 #pragma config FOSC = HSPLL_HS // HS oscillator, PLL enabled, HS used by USB #pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled #pragma config IESO = OFF // Oscillator Switchover mode disabled #pragma config PWRT = OFF // PWRT disabled #pragma config BOR = OFF // Brown-out Reset disabled in hardware and software #pragma config BORV = 0 // Maximum setting #pragma config VREGEN = OFF // USB voltage regulator disabled //#pragma config VREGEN = ON // USB voltage regulator enabled #pragma config WDT = OFF // HW Disabled - SW Controlled #pragma config WDTPS = 1 // Watchdog Timer Postscale Select bits: 1:1 //#pragma config MCLRE = OFF // RE3 input pin enabled; MCLR disabled #pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled #pragma config LPT1OSC = OFF // Timer1 configured for higher power operation #pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset //#pragma config PBADEN = ON // PORTB<4:0> pins are configured as analog input channels on Reset //#pragma config CCP2MX = OFF // CCP2 input/output is multiplexed with RB3 #pragma config CCP2MX = ON // CCP2 input/output is multiplexed with RC1 #pragma config STVREN = OFF // Stack full/underflow will not cause Reset #pragma config LVP = OFF // Single-Supply ICSP disabled #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit : ICPORT disabled #pragma config XINST = OFF // Instruction set extension and Indexed Addressing mode disabled (Legacy mode) #pragma config DEBUG = OFF // Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins #pragma config CP0 = OFF // Block 0 (000800-001FFFh) not code-protected #pragma config CP1 = OFF // Block 1 (002000-003FFFh) not code-protected #pragma config CP2 = OFF // Block 2 (004000-005FFFh) not code-protected #pragma config CP3 = OFF // Block 3 (006000-007FFFh) not code-protected #pragma config CPB = OFF // Boot block (000000-0007FFh) not code-protected #pragma config CPD = OFF // Data EEPROM not code-protected #pragma config WRT0 = OFF // Block 0 (000800-001FFFh) not write-protected #pragma config WRT1 = OFF // Block 1 (002000-003FFFh) not write-protected #pragma config WRT2 = OFF // Block 2 (004000-005FFFh) not write-protected #pragma config WRT3 = OFF // Block 3 (006000-007FFFh) not write-protected #pragma config WRTB = OFF // Boot block (000000-0007FFh) not write-protected #pragma config WRTC = OFF // Configuration registers (300000-3000FFh) not write-protected #pragma config WRTD = OFF // Data EEPROM not write-protected #pragma config EBTR0 = OFF // Block 0 (000800-001FFFh) not protected from table reads executed in other blocks #pragma config EBTR1 = OFF // Block 1 (002000-003FFFh) not protected from table reads executed in other blocks #pragma config EBTR2 = OFF // Block 2 (004000-005FFFh) not protected from table reads executed in other blocks #pragma config EBTR3 = OFF // Block 3 (006000-007FFFh) not protected from table reads executed in other blocks #pragma config EBTRB = OFF // Boot block (000000-0007FFh) not protected from table reads executed in other blocks // //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 = 0xFF; TRISD = 0x00; LATD = 0x00; PORTD = 0x00; // ***************************** // 2.Program main // ***************************** while(1){ mvLED(&LEDlst); PORTD = 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; }