Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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:

klystron

Advanced Member level 4
Joined
Jul 11, 2002
Messages
1,014
Helped
192
Reputation
384
Reaction score
180
Trophy points
1,343
Location
South Africa
Activity points
4,515
Why dont you use a GPIO input line of the micro instead of the analogue input?
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
232
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.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top