硬件平台:C8051F314
包括键盘扫描程序
源代码在线查看: define.h.bak
// 宏定义文件
//------------------------------------------------------------------------------------
//
// FILE NAME : DEFINE.H
// TARGET DEVICE : C8051F314
// CREATED ON : 07/14/06
// CREATED BY : Jzp
//
// 文件说明:宏定义文件
typedef unsigned char UCHAR;
typedef signed char SCHAR;
typedef unsigned int UINT;
typedef unsigned char BOOLEAN;
#define FALSE1 0
#define TRUE1 1
#define SYSCLK 24500000 // System clock frequency
#define SMB_FREQUENCY 50000 // Target SMBus frequency
#define BAUD_RATE 9600 // UART0 波特率
#define KEY_COL0 P1^0
#define KEY_COL1 P1^1
#define KEY_COL2 P1^2
#define KEY_COL3 P1^3
#define KEY_ROW0 P1^4
#define KEY_ROW1 P1^5
#define KEY_ROW2 P1^6
#define KEY_ROW3 P1^7
#define KEY_ROW4 P2^0
#define KEY_ROW5 P2^1
#define KEY_ROW6 P2^2
#define KEY_ROW7 P2^3
#define KEY_ROW8 P2^4
#define KEY_ROW9 P2^5
#define KEY_ROW10 P2^6
#define LED_ALPHA_ON() P2^7 = 0
#define LED_ALPHA_OFF() P2^7 = 1
// sfr定义
sfr16 TMR3RL = 0x92; // Timer2 reload registers
sfr16 TMR3 = 0x94; // Timer3 counter registers
//sfr16 TMR0 = 0X8A; // Timer0
sfr16 TMR2RL = 0xca; // Timer2 reload registers
sfr16 TMR2 = 0xcc; // Timer2 counter registers
//sfr16 TMR0 = 0xcc; // Timer2 counter registers
sbit KbIrqOut = P0^6; //键盘中断请求
sbit BatIrqOut = P0^7; //电池电量低中断请求
sbit KbBlCtl = P3^2; //键盘有动作,键盘灯点亮,否则经过延时后,熄灭
sbit AlphaLed = P2^7;
sbit DQ = P3^1;
//#define KEY_ROW_LOW(0) P1 = 0xef
//#define KEY_ROW_LOW(1) P1 = 0xdf
//#define KEY_ROW_LOW(2) P1 = 0xbf
//#define KEY_ROW_LOW(3) P1 = 0x7f
//#define KEY_ROW_LOW(4) P2 &= 0x80; P2 |= 0x7e
//#define KEY_ROW_LOW(5) P2 &= 0x80; P2 |= 0x7d
//#define KEY_ROW_LOW(6) P2 &= 0x80; P2 |= 0x7b
//#define KEY_ROW_LOW(7) P2 &= 0x80; P2 |= 0x77
//#define KEY_ROW_LOW(8) P2 &= 0x80; P2 |= 0x6f
//#define KEY_ROW_LOW(9) P2 &= 0x80; P2 |= 0x5f
//#define KEY_ROW_LOW(10) P2 &= 0x80; P2 |= 0x3f
//#define KEY_ROW_HIGH P1 = 0xff; P2 &= 0x80; P2 |= 0x7f
#define KEY_ROW_ALL_LOW P1 = 0X0F; P2 &= 0X80