User manual

Table Of Contents
General Purpose Input/Output Labs
© 2009 Microchip Technology Inc. DS41369A-page 41
A new function called Get_Inputs() is used to check the RA2 pin voltage. Referring
to Figure 3-12, the RA2 pin connected to the push button (SW1) is pulled to V
DD using
a 10 KΩ
resistor. This pull-up resistor eliminates noise on the pin that could trigger
“false” push button presses. The second terminal of the push button is connected to
V
SS. In this way, when a user presses the push button the voltage present on RA2 will
transition from V
DD
(high or ‘1’) to VSS (low or ‘0’). The software flowchart for the
Get_Inputs() is shown in Figure 3-20.
FIGURE 3-20: GET_INPUTS() SOFTWARE FLOWCHART FOR LAB 5
Referring to the flowchart in Figure 3-20, the Get_Inputs() first checks the voltage
level on the RA2 pin. If the voltage is logic low (= 0 or V
SS), a 5mS delay is implemented
using a new support routine called Delay_5mS() to allow any switch bouncing to set-
tle. The Delay_5mS() is based off of the Timer0 peripheral as discussed in Lab 3. The
software flowchart for Delay_5mS() is shown in Figure 3-21.
Get_Inputs()
RA0 = 0
?
END
Contents of direction
remain unchanged
YES
NO
Delay_5mS()
RA0 = 0
?
Toggle contents of
direction
YES
NO
Debounces signal
on RA2