Edge Trigger Code

qaisarpk1

qaisarpk1

@qaisarpk1-6Lfp0G Oct 26, 2024
hi every one..

i want to make a up-down counter using 8051..
two switches are connected with UC.
one for up counting and one for down counting..
now the problem is that if i press one switch only at once it count correctly but if
switch is not released then it will not count only for once.....it count continuosly untill the switch is released.
i want to make it edge triger mean if a switch is pressed it will count when switch is released. if switch is hold for long time ,it must have to count only once...

i need c code or any algorithem ..

i m using keil c compiler..

thnx

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww Jun 21, 2011

    qaisarpk1
    hi every one..

    i want to make a up-down counter using 8051..
    two switches are connected with UC.
    one for up counting and one for down counting..
    now the problem is that if i press one switch only at once it count correctly but if
    switch is not released then it will not count only for once.....it count continuosly untill the switch is released.
    i want to make it edge triger mean if a switch is pressed it will count when switch is released. if switch is hold for long time ,it must have to count only once...

    i need c code or any algorithem ..

    i m using keil c compiler..

    thnx

    That is called KEY DEBOUNCE.

    what have you written? something like that? this is only if your switch is connected with Ground and you detect 0 at controller side.

    if(!SWITCH1)
    {
    count++;
    }

    Right?

    you can write
    while(!SWITCH) // in this case your execution waits untill you release the Key.
    {
    count++
    }