17 Keypad Interrupt
The Keypad Interrupt function is intended primarily to allow a single interrupt to be generated when Port 2 is
equal to or not equal to a certain pattern. This function can be used for bus address recognition or keypad
recognition.
There are three SFRs used for this function. The Keypad Interrupt Mask Register (KBMASK) is used to define
which input pins connected to Port 2 are enabled to trigger the interrupt. The Keypad Pattern Register (KBPATN)
is used to define a pattern that is compared to the value of Port 2. The Keypad Interrupt Flag (KBIF) in the
Keypad Interrupt Control Register (KBCON) is set by hardware when the condition is matched. An interrupt will
be generated if it has been enabled by setting the EKBI bit in AUXIE register and EA=1. The PATN_SEL bit in the
Keypad Interrupt Control Register (KBCON) is used to define “equal” or “not-equal” for the comparison.
In order to use the Keypad Interrupt as the “Keyboard” Interrupt, the user needs to set KBPATN=0xFF and
PATN_SEL=0 (not equal), then any key connected to Port 2 which is enabled by KBMASK register will cause the
hardware to set the interrupt flag KBIF and generate an interrupt if it has been enabled. The interrupt may wake
up the CPU from Idle mode or Power-Down mode. This feature is particularly useful in handheld, battery powered
systems that need to carefully manage power consumption but also need to be convenient to use.
The following special function registers are related to the KBI operation:
KBPATN (Address=D5H, Keypad Pattern Register, Reset Value=1111,1111B)
7
6
5
4
3
2
1
0
KBPATN.7 KBPATN.6 KBPATN.5 KBPATN.4 KBPATN.3 KBPATN.2 KBPATN.1 KBPATN.0
KBPATN.7~0: The keypad pattern, reset value is 0xFF.
KBCON (Address=D6H, Keypad Control Register, Reset Value=xxxx,xx00B)
7
6
5
4
3
2
1
0
PATN_SEL
KBIF
-
-
-
-
-
-
PATN_SEL: Pattern Matching Polarity selection.
1: The keypad input has to be equal to the user-defined keypad pattern in KBPATN to generate the interrupt.
0: The keypad input has to be not equal to user-defined keypad pattern in KBPATN to generate the interrupt.
KBIF:
Keypad Interrupt Flag. Set when Port 2 matches user defined conditions specified in KBPATN, KBMASK, and
PATN_SEL. Needs to be cleared by software by writing “0”.
KBMASK (Address=D7H, Keypad Interrupt Mask Register, Reset Value=0000,0000B)
7
6
5
4
3
2
1
0
KBMASK.7 KBMASK.6 KBMASK.5 KBMASK.4 KBMASK.3 KBMASK.2 KBMASK.1 KBMASK.0
KBMASK.7: When set, enables P2.7 as a cause of a Keypad Interrupt (KBI7).
KBMASK.6: When set, enables P2.6 as a cause of a Keypad Interrupt (KBI6).
KBMASK.5: When set, enables P2.5 as a cause of a Keypad Interrupt (KBI5).
KBMASK.4: When set, enables P2.4 as a cause of a Keypad Interrupt (KBI4).
KBMASK.3: When set, enables P2.3 as a cause of a Keypad Interrupt (KBI3).
KBMASK.2: When set, enables P2.2 as a cause of a Keypad Interrupt (KBI2).
KBMASK.1: When set, enables P2.1 as a cause of a Keypad Interrupt (KBI1).
KBMASK.0: When set, enables P2.0 as a cause of a Keypad Interrupt (KBI0).
85
MPC82G516A Data Sheet
MEGAWIN