
Designer Reference Manual USB08 Evaluation Board
116 Source Code Files MOTOROLA
Source Code Files
U08KEY.C//===================== ======================== ======================= ========
// File: U08KEY.C
// Func: Key Input Func tions for USB08
// Ver.: 1.00
// Auth: (C)2000,2001 b y Oliver Thamm, MCT Elek tronikladen GbR
// http://hc08web .de/usb08
// Rem.: View/Edit this File with TAB-Size=4
//===================== ======================== ======================= ========
#include "hc08jb8.h"
#include "u08key.h"
//-- Definitions ------ ------------------------ ----------------------- --------
// Specification of *ac tive* Key Inputs:
// PTA[4,5,6] = %011100 00 = 0x70
// First Key connected to Port Bit 4
#define KEY_MASK 0x70
#define KEY_FIRST 4
//-- Variables -------- ------------------------ ----------------------- --------
// Var used to track the Key Status
unsigned char KeyState;
//--------------------- ------------------------ ----------------------- --------
void initKey() {
POCR |= 0x01; // enable PTA Pullups
PTA |= KEY_MASK; // write 1 to Output La tches
DDRA |= KEY_MASK; // output H-Level Pulse
DDRA &= ~KEY_MASK; // back to Input
KBIER = KEY_MASK; // enable Interrupts
KBSCR = 0x04; // reset ACKK (just in case)
KeyState = 0; // reset internal Statu s Var
}
//--------------------- ------------------------ ----------------------- --------
char getKey(unsigned char x) {
x += KEY_FIRST-1; // calculate Bit Position
x = 1 << x; // create Bit Mask
if(KeyState & x) // test the relevant St atus Bit
return 1;
return 0;
}
//--------------------- ------------------------ ----------------------- --------
@interrupt void isrKey( ) {
KeyState ^= ~(PTA | ~KE Y_MASK);
KBSCR = 0x04; // reset ACKK (fo r noi se safety only)
}
//===================== ======================== ======================= ========