#include <a.h>
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
int buttonState=0;
int lastbuttonState=0;
int buttoncounter=3;
void init()
{
set_tris_a( 0b11011101 ); // set GP1 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
init();
while ( TRUE ) // blink LED
{
buttonState=input(GP0);
delay_ms(10);
if(buttonState!=lastbuttonState)
{
if(buttonState==1)
{
buttoncounter=buttoncounter+1;
}
}
lastbuttonState=buttonState;
if(buttoncounter % 2 == 0)
{
output_high( GP5 ); // turn LED on
}
else
{
output_low( GP5 ); // turn LED off
}
}// end while
}//end main
Tuesday, 19 August 2014
Mantain keep push switch state CODE using a microcontroller
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment