//picl -16f627 -o -Zg -C main.c sci.c sci.h constants.h //picl -16f627 main.obj sci.obj //-------------------------------------------------------------- // libraries //-------------------------------------------------------------- #include #include "sci.h" #include "constants.h" __CONFIG(WDTEN); //-------------------------------------------------------------- // function declarations //-------------------------------------------------------------- void interrupt button_isr(void); unsigned char state; //-------------------------------------------------------------- // main //-------------------------------------------------------------- main(void) { // ----------------------------------------------------------- // configure processor // ----------------------------------------------------------- PORTA = 0xff; // set output data latches to default value CMCON = 0x07; // disable comparators to allow I/O TRISA = 0x00; // all bits output TRISB = 0xF0; // low 4 bits output, high 4 bits input PORTB = 0xFE; // clear PortB OPTION = 0x7F; // Set internal pull-up on portB // Asign Postscalar to WDT // Set ratio to 1:128 INTCON = 0x88; // setup interrupt control state = NO; // ----------------------------------------------------------- // USART setup // ----------------------------------------------------------- sci_Init(); // setup USART protocol // ----------------------------------------------------------- // main code // ----------------------------------------------------------- for(;;) { sci_PutByte(state); SLEEP(); } } void interrupt button_isr(void) { GIE = 0; // disables all interrupts if(RBIF == 1){ state = ((~state) & 0x0F); if(state == YES){ RB3 = 1; }else if (state == NO){ RB3 = 0; } RBIF = 0; } GIE = 1; // enable all interrupts }