View previous topic :: View next topic |
Author |
Message |
eason_terrorist
Joined: 11 Dec 2010 Posts: 1
|
help for push button coding |
Posted: Sat Dec 11, 2010 9:21 am |
|
|
Hi,
Can anyone tell me how to program two push button with function increase and decrease value?
What I mean is for example like my output is 100, when I press decrease button 1 times, it will decrease my output to 90 and press the 2nd times will become 80. Then when I press 1 times increase button again the output will increase back to 90.
How to do programming like what I say?
Can anyone give some example?
thank you very much |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 11, 2010 3:37 pm |
|
|
You could use the push-button code here:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
There is a sample program that shows how to call the button() routine.
Instead of the printf() statements, you could put in code to increment
or decrement a variable, based on which button was pushed. Make sure
you initialize the variable to some value at the beginning of the program.
Also put in code to check if the variable goes below or above some limit,
and prevent it from doing so (for safety).
This code expects the following circuit to be connected to your PIC pins
for each button. The circuit consists of a pull-up resistor and
a switch. Normally the pin is held at a logic "1" by the pull-up. When
you push the button it will go to a logic "0", until you release it:
Code: |
+5v
|
<
> 4.7K
< ___ Push button switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
If you have questions, ask them in this thread (not in the button.c thread). |
|
|
|