bit oldstate; // Old state flag
unsigned short int i;
void main() {
CMCON = 0b00000111; // turns off the compare mod
TRISIO = 0b00000100; // set input on gp2 outputs the rest are outputs
GPIO = 0b00000000; // clears gpio
GPIO.GP0 = 1; // turns on the led to start to show the chips running
oldstate = 0; //sets oldstate to 0
i=0;
do {
if (Button(&GPIO, 2, 0, 0)) { // Detect logical lows
oldstate = 1; // Update flag
}
if (oldstate && Button(&GPIO, 2, 0, 1)) { // Detect low to high transition
// increment counter by 1
i=i+1;
// increment counter
oldstate = 0; // Update flag
}
if (i==1) // put code here to act on count
{GPIO.F1 = 1;} // when we press 1 time GPIO.F1 is ON
if (i==2) // when we press 2 times GPIO.F1,GPIO.F4 is ON
{GPIO.F1 = 1;GPIO.F4 = 1;GPIO.F5 = 0;}
if (i==3) // when we press 3 times GPIO.F1, GPIO.F4,GPIO.F5 is ON
{GPIO.F1 = 1;GPIO.F4 = 1;GPIO.F5 = 1;}
} while(1); // Endless loop
}