Apr 27, 2011 #1 B boyguitar1 Member level 1 Joined Nov 8, 2010 Messages 33 Helped 12 Reputation 24 Reaction score 12 Trophy points 1,288 Activity points 1,486 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 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: Apr 27, 2011
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 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!!
Apr 27, 2011 #2 klystron Advanced Member level 4 Joined Jul 11, 2002 Messages 1,011 Helped 193 Reputation 386 Reaction score 179 Trophy points 1,353 Location South Africa Activity points 4,518 Why dont you use a GPIO input line of the micro instead of the analogue input?
Apr 27, 2011 #3 qwertyuiop415263 Full Member level 4 Joined Mar 26, 2010 Messages 231 Helped 50 Reputation 102 Reaction score 39 Trophy points 1,308 Location Pakistan Activity points 2,414 why you are using ADC for this purpose. this can be easily done without using ADC.