boyguitar1
Member level 1
Hi ..
I want to write program for check button pressing (Counter)
In case of Press button has 5V
In case of Not Press button has 0V
I can use ADC for detect it but the problem is when I press hold button my program will increase 1 (by non stopping.)
SO How can I do even I press hold the button the must count only 1
please help
thank you!!
I want to write program for check button pressing (Counter)
In case of Press button has 5V
In case of Not Press button has 0V
I can use ADC for detect it but the problem is when I press hold button my program will increase 1 (by non stopping.)
SO How can I do even I press hold the button the must count only 1
Code:
int i=0;
char txt1[4];
long adcVal;
void main ()
{
portc=0;
TRISC = 0b00000001;
trisa = 0xFF;
trisb = 0x00;
ADCON1 = 0x87;
Lcd_config(&portb,1,2,3,7,6,5,4);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"Test Counter");
i=0;
IntToStr(i,txt1);
Lcd_Out(2,1,"Count:");
Lcd_Out(2,8,txt1);
while(1){
adcval = adc_read(0);
if(adcval >512) [I]// ~ 2.5V[/I]
{
Delay_ms(500);
i = i++;
IntToStr(i,txt1);
Lcd_Out(2,1,"Count:");
Lcd_Out(2,8,txt1);
}
}
}
please help
thank you!!
Last edited: