Using the Keyboard Interrupt (KBI) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
Freescale Semiconductor
4-5
Figure 4-1
, shows hardware connections used for the KBI project. For
detailed information about the MCU supply voltages needed, please refer to
the Pins and Connections chapter in the Reference Manual (MC9S08QE128
or MCF51QE128). It can also be found at www.freescale.com.
4.3
KBI project for Demo board
4.3.1
Code example and explanation
This example code is available from the Freescale Web site www.freescale.com.
This section explains the differences of the codes used in EVB and the Demo board. The codes are the
same.
The functions for KBI.mcp project are:
•
main – Endless loop waiting for a KBI interrupt.
•
MCU_Init – MCU initialization, watchdog disable and the KBI clock module enabled.
•
GPIO_Init – Enables internal pull-ups. Configures PTC0 pin as output.
•
KBI_Init – KBI module configuration.
•
KBI_ISR – routine that toggles a LED every time an interrupt is generated.
This is the General Purpose Input/Output configuration These code lines configure the direction for the
PTC port. Only six LEDs from the demo board are connected to the PTC port. The other two LEDs are
connected to the E port. In this example only PTC0 is configured as output in order to drive a LED. The
demo board does not count with any pull-ups; therefore the internal pull-up is enabled for the PTA2 and
PTA3 pins.
void GPIO_Init(void) {
PTAPE = 0x0C; // Enable PTA2 and PTA3 pins Internal Pullups
PTCDD = 0x01; // Configure PTC0 pin as output
PTCD = 0x01; // Put 0's in PTC0 pin
}
This is the initialization code for the keyboard interrupt using the QE128 MCU. For this example, both
KBI registers (KBIxSC and KBIxPE) are used to configure the module to detect only falling edges and
enable PTA2 and PTA3 as KBI. During the initialization phase, the interrupts are masked. It takes time for
the internal pull up to reach a ‘1’ logic value. After the false interrupts are cleared, the keyboard interrupt
is unmasked.
void KBI_Init(void) {
KBI1SC = 0x06; // KBI interrupt request enabled. Detects edges only
KBI1PE = 0x0C; // PTA2 and PTA3 enabled as Keyboard interrupts
KBI1ES = 0x00; // Pins detects falling edge
}