/******************************************************************************/ /* Files to Include */ /******************************************************************************/ #if defined(__XC) #include /* XC8 General Include File */ #elif defined(HI_TECH_C) #include /* HiTech General Include File */ #endif ` #include /* For uint8_t definition */ #include /* For true/false definition */ #include "system.h" /* System funct/params, like osc/peripheral config */ #include "user.h" /* User funct/params, such as InitApp */ /******************************************************************************/ /* User Global Variable Declaration */ /******************************************************************************/ /* i.e. uint8_t ; */ /******************************************************************************/ /* Main Program */ /******************************************************************************/ int loop; void main(void) { /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); TRISAbits.TRISA2 = 0; // setting RA2 as an output TRISAbits.TRISA4 = 1; // setting RA4 as an input ANSELAbits.ANSA4 = 0; // setting RA4 as a digital pin while(1) { if (PORTAbits.RA4 == 1) // Is switch open? { for (loop = 0; loop <= 5; loop = loop + 1) { LATAbits.LATA2 = 0; // turn LED on wait_ms(3); // wait 100 ms LATAbits.LATA2 = 1; // turn it back off wait_ms(3); // wait 100 ms } wait_ms(50); loop = 0; } else { LATAbits.LATA2 = 0; // turn LED on } } }