/*如下为键盘驱动的头文档*/#ifndef _KEY_H_ //防重复引用,如果没有定义过_KEY_H_,则编译下句#define _KEY_H_ //此符号唯一, 表示只要引用过一次,即#i nclude,则定义符号_KEY_H_/////////////////////////////////////////////////////////////////char keyhit( void ); //击键否unsigned char Keyscan( void ); //取键值////////////////////////////////////////////////////////////////#endif
二、尽量使用宏定义#define
#define KEYNUM 65//按键数量,用于Keycode[KEYNUM]#define LINENUM 8//键盘行数#define ROWNUM 8//键盘列数
static unsigned char sts;//按键状态变量static unsigned char Nowkeycode;//此时的键码static unsigned char Prekeycode;//上一次的键码static unsigned char Keydowntime;//矩形键盘按下去抖时间变量static unsigned char Keyuptime;//矩形键盘释放去抖时间变量static unsigned char Onoffdowntime;//关机键按下去抖时间变量static unsigned char Onoffuptime;//关机键释放去抖时间变量static unsigned char onoff_10ms; //判断关机键中断次数变量,累计150次大约为3S,因为前后进了两个10ms中断
const unsigned char a=1;//定义a=1,编译器不允许修改a的值作用:保护不希望被修改的参数const unsigned char Key_code[KEYNUM]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41};//键码const unsigned char Line_out[LINENUM]={0xFE,0xFD,0xFB,0xf7,0xEF,0xDF,0xBF,0x7F};//行输出编码const unsigned char Row_in[ROWNUM]={0xFE,0xFD,0xFB,0xf7,0xEF,0xDF,0xBF,0x7F};//列输入编码
static int i=0;int main(void){...while (1){if (i)dosomething();}}/* Interrupt service routine. */void ISR_2(void){i=1;}
【1】沙子的逆袭——从二氧化硅到芯片
【2】大佬故事:初中开始学编程,大学毕业后直接进微软…
【3】漫画科普:芯片是如何设计出来的
【4】你常用哪种软件画原理图和PCB
【5】PCB大神的那些专属技巧和风骚走位
免责声明:本文内容由21ic获得授权后发布,版权归原作者所有,本平台仅提供信息存储服务。文章仅代表作者个人观点,不代表本平台立场,如有问题,请联系我们,谢谢!