hawk1943
Member level 3
- Joined
- Jun 14, 2010
- Messages
- 62
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- United Kingdom
- Activity points
- 1,859
Hi there,
I'm getting myself confused here...
Basically i'm trying to detect multiple pushes from a Push Button, as I wish to use it to change the message displayed on an LCD...
But I am finding that either the push buttons are not that sensitive or I am not reading them correctly...
Basically I am trying to turn on & off an LED on a 16F877 to make sure the code works before I attempt to use it for the LCD...
But I cannot work out how to do it...
But do I now need to test to see if the button has returned to the 5v rail so is therefore "Hi" before I can re-press the push button?
Only I just cannot fathom out how to do it...
At the moment this is how I am doing it...
As you can see one push-button turns the LED on, the other turns it off
All I wish to do is initially toggle the LED on & off from a single Push Button...
At the moment the push button has a 10K pull up resistor on it, pulling it "Hi" so that when I push a button the input is pulled low...
Added after 43 minutes:
Ok... I've resolved the push button problem
How can I use this to move on the LCD display?
I'm getting myself confused here...
Basically i'm trying to detect multiple pushes from a Push Button, as I wish to use it to change the message displayed on an LCD...
But I am finding that either the push buttons are not that sensitive or I am not reading them correctly...
Basically I am trying to turn on & off an LED on a 16F877 to make sure the code works before I attempt to use it for the LCD...
But I cannot work out how to do it...
Code:
int Debounce_SW1(void)
{
if (SW1 == 0) // test for keypress
DelayMs(5); // wait for switch to stop bouncing
if (SW1 == 0) // if button still held down
RB5 = TRUE; // Turn on LED
}
But do I now need to test to see if the button has returned to the 5v rail so is therefore "Hi" before I can re-press the push button?
Only I just cannot fathom out how to do it...
At the moment this is how I am doing it...
Code:
int Debounce_SW1(void)
{
if (SW1 == 0) // test for keypress
DelayMs(5); // wait for switch to stop bouncing
if (SW1 == 0) // if button still held down
RB5 = TRUE; // Turn on LED
}
int Debounce_SW2 (void)
{
if (SW2 == 0) // test for keypress
DelayMs(5); // wait for switch to stop bouncing
if (SW2 == 0) // if button still held down
RB5 = FALSE; // Turn LED off
}
As you can see one push-button turns the LED on, the other turns it off
All I wish to do is initially toggle the LED on & off from a single Push Button...
At the moment the push button has a 10K pull up resistor on it, pulling it "Hi" so that when I push a button the input is pulled low...
Added after 43 minutes:
Ok... I've resolved the push button problem
Code:
while(1)
{
if (SW1 == 0) // test the switch twice to eliminate *short* glitches
if(SW1 == 0)
{
shadowB^=1<<5; PORTB=shadowB; // Toggle RB5 cleanly
DelayMs(50); // 1/20 s key down debounce time
while(SW1 == 0); // Wait for key up
DelayMs(50); // 1/20 s key up debounce time
}
How can I use this to move on the LCD display?