APPLICATION NOTE
ST7 KEYPAD DECODING TECHNIQUES, IMPLEMENTING
WAKE-UP ON KEYSTROKE
by Microcontroller Division Application Team
INTRODUCTION
The goal of this application note is to present an example of the use of the HALT mode.
In this application, the MCU (here a ST72251) is waked up by an external interrupt caused by
someone pressed a key on the 4x4 matrixed keypad.
1 ST7 / KEYBOARD INTERFACE
Rows are connected to inputs with pull-up and interrupts (Port C). Columns are connected to
Port A configured as output. The result of the interrupt (the value of the pressed key) is sent on
LEDS (Port B) and stored into the X register. In our configuration, we have to add 4 pull-up re-
sistors on Port A (from PA0 to PA3) to be able to apply a high level on the corresponding pads.
Figure 1. ST7 / keypad interface set-up
4x100k
8x560
V
DD
PC0
PC1
PC2
PC3
ST7
PA0
PA1
PA2
GND
PA3
AN980/1098
1/10
1
ST72251 CONFIGURATION
2 ST72251 CONFIGURATION
The application has been validated with a ST72251. Its configuration is described in this part.
Refer to your datasheet for more details.
2.1 I/O CONTROL
Rows are connected to pins configured as inputs (Port C as input with pull up and interrupts).
Columns are connected to pins configured as outputs (Port A).
External interrupts are caused by a low level applied to a pin of Port C (caused by a key
pressed), they wake up the MCU which was in HALT mode.
Port B is configured as outputs to send the value of the pressed key on LEDS.
Please, refer to the Data Book to configure pins properly.
2.2 MISCELLANEOUS REGISTER
Bits 7 and 6 have to be set to configure events correctly: the external interrupt (EI1) has here
to be caused by a falling edge only.
Please, refer to the datasheet for more details.
2.3 HALT MODE
The HALT instruction places the ST72251 in its lowest power consumption mode. The core
and all peripherals are frozen. In this mode, the internal oscillator is turned off, causing all in-
ternal processing to be halted. The data remain unchanged. During the HALT mode, external
interrupts are still enabled. The MCU stays in this state until an external interrupt or a reset oc-
curs. Then the internal oscillator is restarted and the core waits for 4096 CPU clock cycles
(512 µs for a f
CPU
= 8MHz) before running the external interrupt subroutine. Then the MCU
comes back to the main program (in our application to the HALT state).
Please, refer to the datasheet for more details.
3 EXTERNAL INTERRUPTS
The MCU is in HALT mode. When a key is pressed, a low level is applied to the pin corre-
sponding to the row the key belongs (pins configured as inputs with pull-up). It’s a falling edge
applied to a pin of Port C which creates an external interrupt (EI1) and wakes up the MCU. The
MCU executes then the external interrupt subroutine (decoding the pressed key) and comes
back to its previous state (HALT state in the main program).
2/10
KEYPAD
4 KEYPAD
The keypad used is a 4x4 matrixed keypad. Rows are connected to pins configured as inputs
with pull-up. So the initial state of these pins are a high level (1). When a key is pressed, a low
level is applied to the corresponding pin. For this reason, the keypad is coded as follows:
Table 1. Key values
row
KEY
value
1
2
3
F
4
5
6
E
0x0E
0x0E
0x0E
0x0E
0x0D
0x0D
0x0D
0x0D
value
0x0E
0x0D
0x0B
0x07
0x0E
0x0D
0x0B
0x07
7
8
9
D
A
0
B
C
column
KEY
value
0x0B
0x0B
0x0B
0x0B
0x07
0x07
0x07
0x07
value
0x0E
0x0D
0x0B
0x07
0x0E
0x0D
0x0B
0x07
row
column
1
4
7
A
2
5
8
0
3
6
9
B
F
E
D
C
PC0
PC1
PC2
PC3
PA0
PA1
PA2
PA3
You have to press the chosen key at least 0.5 to 1 second depending on which key you
choose (table read from keypad_top to keypad). The faster the key is read into the table, the
faster it will be decoded and the faster the result will be sent on LEDS.
3/10
FLOWCHARTS
5 FLOWCHARTS
Figure 2. Flowchart: Main program
Initializations
infinite
loop
HALT
Figure 3. Flowchart: external interrupt (EI1)
X = 48 (3x16 coded values)
one column activated
(PA0...PA3)
Is there a low level on the
intersection of the stored
row and column?
no
yes
corresponding value of the pressed key
stored into A, X and sent on LEDS
store into X
next column
value
EXIT
5/10