//INTERRUPT1 //Program to tests interrupts //Interrupts the flashing of an LED by 'simultaneously' mirroring RX port to ESC when RX changes state //Written for PIC12F683 to be compiled with the CC5X compiler //Clock frequency not changed from 4MHz default //Copyright David Theunissen 2007 www.flyelectric.ukgateway.net //----------------------------------------------------------------------------- #include "12F683.H" //PIC chip file #include "INT16CXX.H" //Interrupt header file from CC5X #pragma origin 4 //Locates interrupt location at address 4 as required by CC5X #pragma config = 0b.11.1100.0100//Normal device configuration //11. Brown-out Detect enabled //11 Code Protect off //0 MCLR/GP3 set to digital input //0. Powerup timer enabled //0 Watchdog timer disabled //100 Oscillator set to INTRCIO #define ESC GPIO.1 //GP1 (Pin6) is ESC #define RX GPIO.3 //GP3 (Pin4) is RX #define LED1 GPIO.5 //GP5 (Pin2) is LED1 //----------------------------------------------------------------------------- //Position of interrupt function and some #include files have to be juggled around //This is to avoid 'overlapping code' compile errors //These seem to be caused by taking up too much memory before the #pragma origin 4 statement interrupt esc_rx() //Interrupt function for ESC to mirror RX when RX changes state { int_save_registers //Standard registers saved ESC=RX; //Mirror RX pulse to ESC on each change of state GPIF=0; //Clear the GPIO interrupt flag after each change of state int_restore_registers //Pre-interrupt register settings restored } //----------------------------------------------------------------------------- #include "delay_ms.h" //Delay function used below //Placed here to avoid compile errors (see above) //FUNCTIONS section (ie: programs) ============================================ void main() { // TRISIO0 = 0; //Sets GP0/AN0 (pin7) to Output TRISIO1 = 0; //Sets GP1/AN1 (pin6) to Output (ESC) // TRISIO2 = 1; //sets GP2/AN2 (pin5) to Input TRISIO3 = 1; //sets GP3 (pin4) to Input (RX) // TRISIO4 = 1; //sets GP4/AN3 (pin3) to Input TRISIO5 = 0; //Sets GP5 (pin2) to Output (LED1) // ANS0 = 0; //Sets AN0 (pin7) to digital ANS1 = 0; //Sets AN1 (pin6) to digital // ANS2 = 1; //Sets AN2 (pin5) to analogue // ANS3 = 1; //Sets AN3 (pin3) to analogue CMCON0 = 0b.111; //Switches all 3 comparator ports off GIE = 1; //Enable interrupts GPIE = 1; //Enable GPIO interrupts IOC = 0b.0.1000; //Only GP3 enabled //----------------------------------------------------------------------------- while (1) { LED1 = 0; delay_ms(500); LED1 = 1; delay_ms(500); } //end while } //end main