User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 40 © 2009 Microchip Technology Inc.
of uncorrected switch bounce can range from being just annoying to catastrophic. The
classic solution involves filtering, such as through a resistor-capacitor circuit, or through
resettable shift registers. These methods are still effective but they involve additional
cost in material, installation and board real estate. Debouncing in software eliminates
these additional costs.
One of the simplest ways to switch debounce is to sample the switch until the signal is
stable or continue to sample the signal until no more bounces are detected. How long
to continue sampling requires some investigation. However, 5 mS is usually adequate,
while still reacting fast enough that the user won't notice it.
The software flowchart for this application is shown in Figure 3-19.
FIGURE 3-19: MAIN() SOFTWARE CONTROL LOOP FLOWCHART FOR
LAB 5
The Initialize() now configures the following:
•PORTC
- Configure PORTC pins as per the previous labs
•PORTA
- Clear PORTA register.
- Configure RA2 as a digital input pin
(see Registers 4-1 and 4-2 in Section 4.1 of the PIC16F690 Data Sheet).
Timer0 will be configured to implement the 5mS delay as follows:
- Use the internal instruction clock F
OSC/4 as the TMR0 clock source.
- Increment TMR0 on the low-to-high transition of F
OSC/4.
- Assign the prescaler to TMR0 and configure 1:64.
Initialize the LED_Output variable to ‘0
Initialize the direction bit variable to ‘0
- This is a global variable that will be manipulated by the new Get_Inputs()
and used to determine PORTC shift direction by the Decide().
main()
Initialize()
Do_Outputs()
Loop Forever
Timing()
Decide()
Global Variables:
8-bit variable LED_Output will be used to
light the LEDs connected to PORTC
1-bit variable direction used to deter-
mine the direction of the sequential LED
flashing
0 = shift PORTC bits right-to-left
1 = shift PORTC bits left-to-right
Get_Inputs()