#include <htc.h>
#define BUTTON_INPUT GP0
//Sleep command
void Sleep(void)
{
#asm
sleep
#endasm
}
//main function
void main()
{
while(1) //do forever
{
CLRWDT(); //clear the watchdog timer
CheckButton(); //check button
WDTCON = 1; //enable the watchdog timer
Sleep(); //go to sleep for 18 ms
WDTCON = 0; //disable the watchdog timer
CheckButton(); //check button again
}
}
//Function: CheckButton
//Description: Check the state of RC2
//if active low, increment COUNTER. Check COUNTER to see if it is over 3 seconds. If so, provide power
//to main computer. If active high, reset COUNTER to 0
void CheckButton(void)
{
unsigned int COUNTER = 0;
if (BUTTON_INPUT == 0) //if an active low, increment the COUNTER
{
COUNTER++;
if (COUNTER >= 10000) //3
{
//SEND POWER TO HOST, IN TESTING, LIGHT AN LED
}
}
else //else - reset the COUNTER value back to 0 because button is not pressed
{
COUNTER = 0;
}
}