utiliTIes.h
#ifndefUTILITIES_H_INCLUDED
#defineUTILITIES_H_INCLUDED
typedefunsignedcharuchar,BYTE,uint8;
typedefunsignedintuint,WORD,uint16;
typedefunsignedlongulong,DWORD,uint32;
typedefcharint8;
typedefintint16;
typedeflongint32;
typedefunsignedchar*uchar_p;
typedefunsignedint*uint_p;
typedefunsignedlong*ulong_p;
typedefchar*char_p;
typedefint*int_p;
typedeflong*long_p;
#endif//UTILITIES_H_INCLUDED
keyBoard.c
#include
#include“utilities.h”
sbitKEY_OUT_3=P2^0;
sbitKEY_OUT_2=P2^1;
sbitKEY_OUT_1=P2^2;
sbitKEY_OUT_0=P2^3;
sbitKEY_IN_0=P2^4;
sbitKEY_IN_1=P2^5;
sbitKEY_IN_2=P2^6;
sbitKEY_IN_3=P2^7;
ucharcodekeyCodeMap[4][4]={//矩阵按键编号到标准键盘键码的映射表
{0x31,0x32,0x33,0x26},//数字键1、数字键2、数字键3、向上键
{0x34,0x35,0x36,0x25},//数字键4、数字键5、数字键6、向左键
{0x37,0x38,0x39,0x28},//数字键7、数字键8、数字键9、向下键
{0x30,0x1B,0x0D,0x27}//数字键0、ESC键、回车键、向右键
};
ucharpdatakeyState[4][4]={//全部矩阵按键的当前状态
{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}
};
externvoidkeyAction(ucharkeyCode);
voidkeyDriver(){
uchari,j;
staticucharbackup[4][4]={
{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}
};
for(i=0;i《4;i++)
for(j=0;j《4;j++)
if(keyState[i][j]!=backup[i][j]){
if(keyState[i][j]==0)
keyAction(keyCodeMap[i][j]);
backup[i][j]=keyState[i][j];
}
}
voidkeyScan(){
staticuchari=0;
staticucharkeyBuf[4][4]={
{0xFF,0xFF,0xFF,0xFF},{0xFF,0xFF,0xFF,0xFF},
{0xFF,0xFF,0xFF,0xFF},{0xFF,0xFF,0xFF,0xFF}
};
ucharj;
keyBuf[i][0]=(keyBuf[i][0]《《1)|KEY_IN_0;
keyBuf[i][1]=(keyBuf[i][1]《《1)|KEY_IN_1;
keyBuf[i][2]=(keyBuf[i][2]《《1)|KEY_IN_2;
keyBuf[i][3]=(keyBuf[i][3]《《1)|KEY_IN_3;
for(j=0;j《4;j++){
if(keyBuf[i][j]==0x00)
keyState[i][j]=0;
elseif(keyBuf[i][j]==0xFF)
keyState[i][j]=1;
}
switch(i){
case0:KEY_OUT_0=1;KEY_OUT_1=0;break;
case1:KEY_OUT_1=1;KEY_OUT_2=0;break;
case2:KEY_OUT_2=1;KEY_OUT_3=0;break;
case3:KEY_OUT_3=1;KEY_OUT_0=0;break;
default:break;
}
i=++i&0x03;
}
digitalTube.c
#include
#include“utilities.h”
ucharcodeLEDChar[]={//数码管显示字符转换表
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E
};
ucharLEDBuff[6]={//数码管显示缓冲区
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
voidshowNumber(ulongnum){
chari;
ucharbuf[6];
for(i=0;i《6;i++){
buf[i]=num%10;
num/=10;
}
for(i=5;i》0;i--){
if(buf[i]==0)
LEDBuff[i]=0xFF;
else
break;
}
for(;i》=0;i--)
LEDBuff[i]=LEDChar[buf[i]];
}
voidLEDScan(){
staticuchari=0;
P0=0xFF;
P1=(P1&0xF8)|i;
P0=LEDBuff[i];
if(i《5)
i++;
else
i=0;
}
timer.c
#include
#include“utilities.h”
#defineTIMER0
#defineTIMER0_MOD1
#ifdefined(TIMER0)
ucharT0RH=0;
ucharT0RL=0;
#ifdefined(TIMER0_MOD1)
voidsetTmr0(uintms){
ulongtmp;
tmp=11059326/12;
tmp=tmp*ms/1000;
tmp=65536-tmp;
tmp+=28;
T0RL=tmp;
T0RH=tmp》》8;
}
#endif//defined
#endif//defined
calculator.c
/**********************************************************
加减乘除计算器,能实现连续的运算,并且提供修改功能:
对于算符来说,以最后输入的算符为准。
测试样例:
12+256*9-53/2
3 + - * 5
上一篇:51单片机中的定时计数器的主体结构及功能解析
下一篇:如何采用51单片机连接24C02-C语言测试代码
推荐阅读最新更新时间:2024-11-10 20:26
设计资源 培训 开发板 精华推荐
- 永不过时的物联网解决方案 Intel带你6的飞起来!
- 西门子EDA直播:多板产品互联规划方案,为破局而来!
- 让是德科技带我们一起 了解汽车电子车载系统解决方案 看视频答题赢好礼!
- 有奖问答:解锁智能变送器方案
- 【楼层接力】电阻你问我答!
- Keysight感恩月:每天送出一台示波器,一次注册即可参与
- Microchip直播:单片机编程不再难, 利用MPLAB®代码配置器(MCC)实现快速开发
- NI白皮书下载《如何克服复杂待测设备的生产测试挑战》
- ADI & WT ·世健 MCU 痛点问题探索季 ——第一站:征集 | 使用 MCU ,哪些问题最令你头大?
- 创通联达高通 IOT 平台解决方案及成功案例|报名直播赢【蓝牙耳机、音箱、京东卡】等好礼