#include //包含文件
#define uchar unsigned char
#define uint unsigned int
char b[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,
0xa1,0x86,0x8e,0x8c,0xc1,0xce,0x91,0x89,0xc7,0xff}; // 共阴极字符码
//延时函数,用于实现程序中的短暂延时,表示延时cnt个毫秒
void delay(unsigned int cnt)
{
unsigned char i;
while(cnt--)
{
for(i=220;i>0;i--)
;
}
}
//键盘扫描程序
uchar keyboardscan(void)
{
uchar sccode,recode;
P1=0xf0; //P1口附初值
if((P1&0xf0)!=0xf0)//如果P1口电平不等于0xf0,表示有按键按下
{
delay(20); //延时20毫秒后再判断,看是否还有按键按下,次步为软件防抖
if((P1&0xf0)!=0xf0)//继续判断是否有按键按下
{
sccode=0xfe; //进行逐行判断
while((sccode&0x10)!=0)
{
P1=sccode;