📄 u08key.c
字号:
//============================================================================
// File: U08KEY.C
// Func: Key Input Functions for USB08
// Ver.: 1.01
// Auth: (C)2000,2001 by Oliver Thamm, MCT Elektronikladen GbR
// http://hc08web.de/usb08
// Rem.: View/Edit this File with TAB-Size=4
// Jan 02 : Adapted for CodeWarrior by Isabelle GIRAUD, Metrowerks Europe
//============================================================================
#include "hc08jb8.h"
#include "u08key.h"
//-- Definitions -------------------------------------------------------------
// Specification of *active* Key Inputs:
// PTA[4,5,6] = %01110000 = 0x70
// First Key connected to Port Bit 4
#define KEY_MASK 0x70
#define KEY_FIRST 4
//-- Variables ---------------------------------------------------------------
// Var used to track the Key Status
#pragma DATA_SEG SHORT MY_ZEROPAGE
unsigned char KeyState;
#pragma DATA_SEG DEFAULT
//----------------------------------------------------------------------------
void initKey() {
POCR |= 0x01; // enable PTA Pullups
PTA |= KEY_MASK; // write 1 to Output Latches
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 Status 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 Status Bit
return 1;
return 0;
}
//----------------------------------------------------------------------------
interrupt void isrKey() {
KeyState ^= ~(PTA | ~KEY_MASK);
KBSCR = 0x04; // reset ACKK (for noise safety only)
}
//============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -