prescaler and timer0 counter initialization value, along
with the crystal frequency, determine the interrupt interval,
chosen to be four milliseconds (but not particularly critical
for this application). Comments in the code further explain
how these values have been derived.
The main activity is to call debounce_switch, the
function that polls each input pin and performs the input
debouncing. There are no parameters, since global
variables in memory are used to manage the debouncing
states. If any input level changes, an event flag is set for
the main code to deal with.
The secondary activity is to
look for the beeper being on, and
count down to zero and turn the
I hope you found the rotary encoder as interesting as
I have. It is easier to design a project to use one in place of
a number of other input devices. It is also easier to build a
project with one input device instead of many, and the
project may be simpler for the user to operate, as well. NV
Contact the Author
The author can be contacted at email@example.com.
3) Function debounce_switch polls
each input (two encoder and one
pushbutton) and keeps track of the
state, returning the current state in
global variable ucDebouncedState.
4) Function analyze_switch is called
by the main code in response to an
input changed event. This function
determines if the button was pressed
or the encoder shaft turned clockwise or counter-clockwise. A
corresponding event bit is turned
on for the mainline to process.
For the encoder, the method
used is to isolate Output A and
Output B as the lowest two bits in
a byte as described above and see
how it compares to the previous
Button presses are detected but
not button releases. An event for
button release could be added if
necessary, or a global variable set to
1 when the button was down.
Exclusively at Jameco…
The Lowest Prices…
Save 15%-25% Save 30% or more!
Save more when a Looking for killer deals?
specific manufacturer is Jameco buyers often find
not required. Major Brand Factory Overruns from
semi’s are sourced some of the industry’s
from 5-6 specific major biggest names. That
manufacturers, plus we means savings of 30%
also offer Jameco Brand and more to you!
and Generic passives for
even greater savings.
Save 3% to 5%
Looking to save on
thousands of Name Brand
offers these popular
products for 3% to 5%
below market price, and
we guarantee it!
3 Levels of Choice
3 Levels of Savings
5) The main function looks for the
various event flags and performs the
Other Jameco Advantages:
We offer over 300 Major Manufacturers
99% of catalog products ship the same day.
Lowest prices guaranteed, or we pay 10%.
Order 24 hours a day, 7 days a week
Or call 800-831-4242 anytime
SEMICONDUCTORS • PASSIVES • INTERCONNECTS • ELECTROMECHANICAL • POWER
August 2008 55