#include //Use this to include the device header for your PIC. //In our case, this will include pic16f690.h. //Do not directly include pic16f690.h to avoid issues if you //change your device later on. Always use . //set the configuration bits: internal OSC, everything off except MCLR #pragma config FOSC=INTRCIO, WDTE=OFF, PWRTE=OFF, MCLRE=ON, CP=OFF, \ CPD=OFF, BOREN=OFF, IESO=OFF, FCMEN=OFF #define _XTAL_FREQ 4000000 //4MHz, which is default //This is used by the compiler to calculate how many //instructions to delay in the calls to __delay_ms(). #define LED1 PORTBbits.RB7 //Create meaningful names for our pins #define LED1_TRIS TRISBbits.TRISB7 #define LED2 PORTCbits.RC7 #define LED2_TRIS TRISCbits.TRISC7 void interrupt isr() { //reset the interrupt flag INTCONbits.INTF = 0; LED2 = ~LED2; //flip the bit //The ~ (tilde) is the complement operator } int main() { TRISA = 0xFF; //set all digital I/O to inputs TRISB = 0xFF; TRISC = 0xFF; ANSEL = 0x00; //disable all analog ports ANSELH = 0x00; LED1_TRIS = 0; //LED1 is an output LED2_TRIS = 0; //LED2 is an output INTCONbits.INTF = 0; //reset the external interrupt flag OPTION_REGbits.INTEDG = 1; //interrupt on the rising edge INTCONbits.INTE = 1; //enable the external interrupt INTCONbits.GIE = 1; //set the Global Interrupt Enable /////////////////////// // Main Program Loop // /////////////////////// while(1) { LED1 = 1; //Flash LED1 __delay_ms(500); LED1 = 0; __delay_ms(500); } return 0; }