#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define key P1
sbit dula=P2^6;
sbit wela=P2^7;
sbit SCL=P1^0;
sbit SDA=P1^1;
code uchar disptab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x48};
code uchar bittab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar disnum,key_1_num,keyB;
uchar dispbuf[6];//显存
uchar shuxian[3]={0x11,0x02,0x0a};//临时放数据,放时BCD码
uchar dis_num;
void init()
{
TMOD=0x01;
TR0=1;
ET0=1;
EX0=1;
TI0=1;
TH0=63266/256;
TL0=63266%256;
EA=1;
dula=0;
wela=0;
dis_num=0;
}
//**************键盘部分*************************
void delay(int n)
{
int z;
for(z=n;z>0;z--);
}
void key_fun()
{
shuxian[1]++;
EA=1;
}
void key_() //如果直接调用 菜用扫描的方法 能正常的用着个程序 但是用中断就不 行 了不。。
{
uchar key_value=0;
key_value=key&0xf0;
delay(1000);
if((key_value&key)!=0)
{
while((key_value&key)!=0);
delay(1000);
switch(key_value)
{
case 0x10:key_fun();break;
case 0x20:key_fun();break;
case 0x40:key_fun();break;
case 0x80:key_fun();break;
}
}
}
//**************显示部分*************************
void dis_0()
{
static uchar mun;
uchar temp;
TH0=63266/256;
TL0=63266%256;
dispbuf[0]=shuxian[0]>>4&0x7;
dispbuf[1]=shuxian[0]&0x0f;
dispbuf[2]=shuxian[1]>>4&0x7;
dispbuf[3]=shuxian[1]&0x0f;
dispbuf[4]=shuxian[2]>>4&0x7;
dispbuf[5]=shuxian[2]&0x0f;
P0=0xff;
wela=1;
P0=P0&bittab[mun];
wela=0;
temp=dispbuf[mun];
dula=1;
P0=disptab[temp];
dula=0;
mun++;
if(mun==6)
mun=0;
}
void dis_1()
{
}
void display()
{
switch(dis_num)
{
case 0:dis_0();break;//正常显示时间模式
case 1:dis_1();break;//显示故障模式
// case 2:dis_2();break;
}
}
//**************中断部分*************************
void time_int0() interrupt 1
{
TH0=63266/256;
TL0=63266%256;
display();
}
void int0() interrupt() 0
{
key_()
}
//**************MAIN*************************
void main()
{
init();
while(1)
{
//guzhang();
}
}
键盘部分有问题 |