#include<reg51.h>//矩阵键盘 从下往上 从左往右依次为1 2 3……号 14号为复位加减 15号++ 16号--
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define DIG P0
#define KEY P1
sbit seg1=P2^0;
//sbit seg2=P2^2;
uchar code shuzi[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7C,0x39,0x5E};
uchar xianshi,a=0,b,c;
void delay(uint t)
{
while(t--);
}
void keydown()
{
KEY=0xf0;
if(KEY!=0xf0)
{
delay(15);
if(KEY!=0xf0)
{
switch(KEY)
{
case(0x70):xianshi=0;break;
case(0xb0):xianshi=1;break;
case(0xd0):xianshi=2;c--;break;
case(0xe0):xianshi=3;c++;break;
}
KEY=0x0f;
switch(KEY)
{
case(0x07):xianshi=xianshi;break;
case(0x0b):xianshi=xianshi+4;break;
case(0x0d):xianshi=xianshi+8;break;
case(0x0e):xianshi=xianshi+12;break;
}
while((a<50)&&(KEY!=0XF0))
{
delay(1000);
a++;
}
}
}
}
void main()
{
seg1=0;
while(1)
{
keydown();
if ((xianshi>=0)&&(xianshi<=12))
DIG=shuzi[xianshi];
if(xianshi==13)
{
c=5;
DIG=shuzi[c];
}
if(xianshi==14)
{
DIG=shuzi[c];
delay(50000);
}
if(xianshi==15)
{
DIG=shuzi[c];
delay(50000);
}
}
}
|