PIC18F4550 is an enhanced Flash micro-controller with USB 2.0 feature. This device can operate up to 48MHz that yield the executing speed up to 12MIPS.
PIC18F4550 Family Data Summary |
- MPLABX XC8
- MikroC Pro for PIC
- IAR for PIC18
- CCS PICC, and etc.
MPLABX XC8 is a free compiler from this device manufacturer. We can buy a paid version for a higher code generation quality.
In this example I use the MPLABX IDE to get start with this device programming. I use the latest version of MPLABX of 6.0, and the XC8 compiler of 2.40.
The program will chase the output LED(s) connect to PORTD.
/* * File: main.c * Author: aki-technical * * Created on August 1, 2022, 6:22 PM */ #include <xc.h> #include "config18f4550.h" #define _XTAL_FREQ 20000000 void main(void) { PORTD=0x00; LATD=0x00; TRISD=0x00; LATD=0x01; while(1){ LATD=0x01; while(LATD!=0){ LATD<<=1; __delay_ms(50); } } return; }
Configuration File:
// CONFIG1L #pragma config PLLDIV = 1 #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 1 // CONFIG1H #pragma config FOSC = HS #pragma config FCMEN = OFF #pragma config IESO = OFF // CONFIG2L #pragma config PWRT = OFF #pragma config BOR = OFF #pragma config BORV = 3 #pragma config VREGEN = OFF // CONFIG2H #pragma config WDT = OFF #pragma config WDTPS = 32768 // CONFIG3H #pragma config CCP2MX = OFF #pragma config PBADEN = OFF #pragma config LPT1OSC = OFF #pragma config MCLRE = ON // CONFIG4L #pragma config STVREN = OFF #pragma config LVP = OFF #pragma config ICPRT = OFF #pragma config XINST = OFF // CONFIG5L #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CP2 = OFF #pragma config CP3 = OFF // CONFIG5H #pragma config CPB = OFF #pragma config CPD = OFF // CONFIG6L #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRT2 = OFF #pragma config WRT3 = OFF // CONFIG6H #pragma config WRTC = OFF #pragma config WRTB = OFF #pragma config WRTD = OFF // CONFIG7L #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTR2 = OFF #pragma config EBTR3 = OFF // CONFIG7H #pragma config EBTRB = OFF
Click here to download its source file. I use Protues 8.10 SP3 to simulate this program. Now let try an random LED output on PORTD.
/* * File: main.c * Author: aki-technical * * Created on August 1, 2022, 6:22 PM */ #include <xc.h> #include "config18f4550.h" #define _XTAL_FREQ 20000000 void main(void) { PORTD=0x00; LATD=0x00; TRISD=0x00; LATD=0x01; while(1){ LATD=rand(); __delay_ms(50); } return; }
The schematic diagram remains the same as the previous one's.
No comments:
Post a Comment