【文件属性】:
文件名称:4×4键盘仿真、程序及pcb
文件大小:84KB
文件格式:RAR
更新时间:2013-06-15 11:51:05
51单片机 键盘 数码管
#include
#define uchar unsigned char
#define uint unsigned int
uchar buff,times,j;
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f, //0,1,2,3
0x66,0x6d,0x7d,0x07, //4,5,6,7
0x7f,0x6f,0x77,0x7c, //8,9,A,B
0x39,0x5e,0x79,0x71,0x00}; //C,D,E,F,null
unsigned char idata value[8];
void delay1ms(void) //消抖动
{ uchar i;
for(i=200;i>0;i--);
}
void delay5ms(void) //延时5ms
{
unsigned char i,j;
for(i=5;i>0;i--)
for(j=248;j>0;j--);
}
void key_scan(void) //键盘输入扫描函数
{ uchar hang,lie,key;
P3=0xf0;
if((P3&0xf0)!=0xf0) //行码为0,列码为1
{ delay1ms();
if((P3&0xf0)!=0xf0) //有键按下,列码变为0
{ hang=0xfe; //逐行扫描
times++;
if(times==2)
times=1;
while((hang&0x10)!=0) //扫描完4行后跳出
{ P3=hang;
if((P3&0xf0)!=0xf0) //本行有键按下
{ lie=(P3&0xf0)|0x0f;
buff=((~hang)+(~lie));
switch(buff)
{ case 0x11: key=0;break;
case 0x21: key=1;break;
case 0x41: key=2;break;
case 0x81: key=3;break;
case 0x12: key=4;break;
case 0x22: key=5;break;
case 0x42: key=6;break;
case 0x82: key=7;break;
case 0x14: key=8;break;
case 0x24: key=9;break;
case 0x44: key=10;break;
case 0x84: key=11;break;
case 0x18: key=12;break;
case 0x28: key=13;break;
case 0x48: key=14;break;
case 0x88: key=15;break;
}
value[times-1]=key; //按下的键值
}
else hang=(hang<<1)|0x01; //下一行扫描
}
}
}
}
void main(void)
{ uchar key;
while(1)
{ key_scan();
P0=0;
for(j=times;j>0;j--)
{
P2=j-1; //数码管列扫描
P0=dispcode[value[times-j]]; //A-G数据
delay5ms();
}
}
}
【文件预览】:
51单片机4X4键盘仿真程序和pcb
----key.c(2KB)
----key_scan_Opt.Bak(1KB)
----KEY.PWI(832B)
----key_scan.hex(1KB)
----key_scan.Opt(1KB)
----key.LST(4KB)
----键盘.ddb(342KB)
----Last Loaded KEY.DBK(163KB)
----key_scan.plg(0B)
----中国最专业的专注于大学生电子设计竞赛的论坛.url(236B)
----key_scan_Uv2.Bak(2KB)
----KEY.DSN(163KB)
----key_scan.h(698B)
----key_scan(4KB)
----key_scan.lnp(28B)
----key_scan.M51(8KB)
----key.OBJ(5KB)
----key_scan.Uv2(2KB)