yourdreamz
Junior Member level 1
- Joined
- Oct 23, 2008
- Messages
- 17
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,465
I'm trying to implement a simple toggle flip-flop in a microcontroller. One pin as an input Pin 'TOGGLE_IN' and another as output 'TOGGLE_OUT'. What is expected is that the output should toggle its state every rising edge of Input pin. The following code that I wrote is not working as expected. What actually happen is that it toggles only once from Low to high and stays there. Doesn't work anymore. Could anybody please help find what am I doing wrong.
Thanks for the help in advance.
Code:
while(1)
{
if(lastToggleInStatus != TOGGLE_IN)
{
if((lastToggleInStatus == OFF) && (TOGGLE_IN == ON))
{
Delay(DEBOUNCING_TIME);
if((lastToggleInStatus == OFF) && (TOGGLE_IN == ON))
{
temp = TOGGLE_OUT;
TOGGLE_OUT = ~temp ;
}
}
lastToggleInStatus = TOGGLE_IN;
}
}
Last edited by a moderator: