Please help review the easy code on mikroC.

Status
Not open for further replies.

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:

Why dont you use a GPIO input line of the micro instead of the analogue input?
 

why you are using ADC for this purpose. this can be easily done without using ADC.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…