Software Module Descriptions
Push Button Module U08KEY.C
USB08 Evaluation Board
Designer Reference Manual
MOTOROLA
Software Module Descriptions
51
The KBI module of the MC68HC908JB8 greatly simplifies the scanning
of the attached buttons. The software necessary for this takes only 20
lines of C code.
The conditions are created in the initialization function initKey(). First the
internal pullup resistors at the port A pins are activated. A short pulse of
an active H level is driven at the port A pins which accelerates the rising
of the logic levels at these pins. This prevents a false reading of the initial
low level on the lines.
The initialization function ends with the resetting of the status variable,
KeyState, and the enabling of the keyboard interrupt.
During the manipulation of a key, the interrupt service routine isrKey() is
called. At port A, the pressed key is seen as a 0 bit. The appropriate bit
location is set accordingly in the status variable KeyState. By activation
of a key the key status is inverted. This implementation simulates an
on/off push button.
If the main program wants to know the current status of a key (on/off), it
uses the access function getKey(). The number of the key (1...) will be
handed over as a function argument. The function getKey() calculates a
bit mask for access to an individual bit of the (internal) status variable
KeyState. The return value amounts to 0, if the key is off; otherwise, a 1
is returned.
This module provides an easy way to specify the desired number of
possible keys. For this purpose, two macros are used. KEY_MASK
defines the used lines of port A by setting a “one” flag at the appropriate
bit location. The macro KEY_FIRST defines at which bit location the first
key is attached. Some examples:
KEY_MASK=0x01;
KEY_FIRST=0;
/ / one key at PTA[0 ]
KEY_MASK=0x02;
KEY_FIRST=1;
/ / onea key at PTA[1 ]
KEY_MASK=0x80;
KEY_FIRST=7;
/ / one key at PTA[7 ]
KEY_MASK=0x70;
KEY_FIRST=4;
/ / three keys at PTA[4..6 ]
KEY_MASK=0xF0;
KEY_FIRST=4;
/ / four keys at PTA[4..7 ]
KEY_MASK=0xFF;
KEY_FIRST=0;
/ / eight keys at PTA[0..7 ]
The port bits included in the key scan have to follow one after another.
Содержание MC68HC908JB8
Страница 2: ...blank ...
Страница 6: ...Designer Reference Manual USB08 Evaluation Board 6 List of Sections MOTOROLA List of Sections ...
Страница 16: ...Designer Reference Manual USB08 Evaluation Board 16 List of Tables MOTOROLA List of Tables ...
Страница 42: ...Designer Reference Manual USB08 Evaluation Board 42 Hardware Description MOTOROLA Hardware Description ...
Страница 88: ...Designer Reference Manual USB08 Evaluation Board 88 USB08 Descriptors MOTOROLA USB08 Descriptors ...
Страница 243: ...blank ...