#include <htc.h>
#define _XTAL_FREQ 4000000
/***** CONFIGURATION *****/
// ext reset, no code or data protect, no brownout detect,
// no watchdog, power-up timer enabled, 4MHz int clock
__CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);
#define nB_LED 1 // indicator LED on GP1
#define nBUTTON 2 // switch on GP2
unsigned char sGPIO; // shadow copy of GPIO
void main()
{
TRISIO = ~(1<<nB_LED); // configure LED pin (only) as an output
IOCB |= 1<<nBUTTON; // Enable IOC nBUTTON intput
GPIO = 0; // start with LED off
sGPIO = 0; // update shadow
GPIE = 1; // enable port change interrupt
ei(); // enable global interrupts
while(1)
{
GPIO = sGPIO;
SLEEP();
}
}
void interrupt isr(void)
{
GPIO;
GPIF = 0;
if(GPIO & 1<<nBUTTON)
{
sGPIO = 0x02;
_delay(100000);
sGPIO = 0x00;
_delay(100000);
}
}