#include #define DATA_EEMEM_PROTECT_DISABLE 0x0100 #define XT_OSC 0x0001 #define DISABLE_DEBUG 0x0800 #define CP0 0x1010 #define CP1 0x2020 /* CP0,CP1 code protect off*/ /* other bits zero which means WDT disabled Low Voltage prm disabled, brownout disabled power up timer enabled */ __CONFIG((CP1 | CP0) | DATA_EEMEM_PROTECT_DISABLE | XT_OSC | DISABLE_DEBUG); #define bitset(var,bitno) ((var) |= (1 << (bitno))) #define bitclr(var,bitno) ((var) &= ~(1 << (bitno))) #define bittst(var,bitno) (var & (1 << (bitno))) /* a subroutine that implements a delay via loops Note that the compile option used will alter this delay! Always use -O compile option */ a_delay() { unsigned int i,k; /* change count values to alter delay */ for (k=1800; --k;) { for(i = 200 ; --i ;); } } /* just flash LED on port PB1 */ /* use this to test if PIC board is alive */ main(void) { TRISB = 0; /* all bits output */ PORTB = 0x00; /* turn all off */ /* use PB1 for output */ for(;;) { /* note infinite loop, all PIC programs should be an infinite loop of some kind. Why? If the loop exited, what would the PIC do? */ a_delay(); /* a subroutine that implements a delay via loops */ bitset(PORTB,1); /* turn on PB1 */ a_delay(); bitclr(PORTB,1); /* turn off PB1 */ } }