User manual

GPIO Expander Keypad and LCD Demo Board User’s Guide
DS51636A-page 10 © 2006 Microchip Technology Inc.
2.5 FIRMWARE DESCRIPTION
See Figure 2-3 for the main firmware flow diagram.
Main Function:
1. The firmware first configures the PIC MCU.
2. The MCP23X08 and MCP23X17 devices are configured. I
2
C Devices are
selected first by default. The SPI devices I/O are held in reset.
3. The LCD splash screen is shown.
4. Wait for an interrupt from the MCP23X08. An interrupt will occur when a button
is pressed. Four (4) inputs are configured to interrupt on falling edge. These
inputs are for the “columns” of the keypad matrix.
5. After the interrupt occurs, the firmware calls the Scan_Buttons routine.
6. Then the Update_LCD routine.
Scan_Buttons Function:
1. Read INTCAP register. This register contains a snapshot of the port condition
when the interrupt occurred.
2. Swap inputs and outputs so the rows can be read.
3. Read GPIO register and merge with variable containing INTCAP value.
4. The pressed key is determined by looking up the result in a lookup table.
Update_LCD Function:
1. The LCD is updated based on which button was pressed.