#include <htc.h>
//__CONFIG(MCLREN & UNPROPTECT & BORDIS & WDTDIS & PWRTEN & INTIO);



unsigned char sGPIO;


#define FOSC 8000000L
/* The Delay Function */
void init(void);
#define	delay_us(x) { unsigned char us; \
		      us = (x)/(12000000/FOSC)|1; \
		      while(--us != 0) continue; }
void delay_ms(unsigned int ms)
{
  unsigned char i;
  do {
    i = 4;
    do {
      delay_us(164);
    } while(--i);
  } while(--ms);
}
void delay_s(unsigned int s)
{
  unsigned char j;
  do {
    j = 5;
    do {
      delay_ms(200);
    } while(--j);
  } while(--s);
}


void main()
	{


ANSEL=0x00;
TRISIO=0b11101111;
IOC =  0b00100000;   //IOC: INTERRUPT-ON-CHANGE GPIO REGISTER
GPIO = 0;
sGPIO =0;

GPIE =1; //Port change
GIE=0;


for(;;) {

	sGPIO =GPIO ;
		
	if(GP2=1){    // Something woke me upp, Look and see if its dark by looking at the Photoresistor
	
	GP4=1;			// It'ts Nigt time so lets light the LED
	
	delay_s(10);	// Kill some time
	
	sGPIO =GPIO ;	// Shadow register
	
	delay_s(15); 	// Kill some more time
	
	}
	
	
	
	GP4=0;		//Lights out
	GPIF = 0;
	SLEEP();



}

	
}

