3.8 實例
3.8.1 XC8 under Windows 10
#include "mcc_generated_files/mcc.h" //already in MCC generated main.c#include "mcc_generated_files/device_config.h" //watch include files and add these two#include "mcc_generated_files/pin_manager.h" void main(void){ SYSTEM_Initialize(); while (1) { IO_RA2_Toggle(); //already defined in MCC generated pin_manager.c __delay_ms(500); //also generated code, add this line for 1 sec circle //go device_config.h, check freq is 4MHz }}
3.8.2 SDCC under Linux
https://hackaday.io/project/8559-microchip-pic-arduino-based-programmer/log/35064-goals-slightly-revisited-pic18f25k50-support? #include "pic18f25k50.h"#pragma config XINST=OFF //good old instruction set, don't change this#pragma config WDTEN = OFF //we don't need WDT here#pragma config FOSC = INTOSCIO //internal oscillator, IO on RA6,7volatile int i,j; //we don't want the compiler to optimize out the delay
void main(void) OSCCON = 0x70; //switch the internal oscillator to 16MHz ANSELC = 0; TRISC = 0x00; //and make them IO outputs while (1) { LATC = ~ LATC; //flip all C pins to opposite state for (i=0;i<20000;i++) j++; //and burn some time
}}