用定时器和独立按键来控制时钟,程序哪里错了啊,求大神帮助啊。
51单片机吧
全部回复
仅看楼主
level 1
叶北玄º 楼主
RT
2016年12月01日 06点12分 1
level 1
叶北玄º 楼主
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
sbit weibiao=P2^7;
sbit duan=P2^6;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar weizhi[8];
void delay(uint);
uchar h,m,s;
uint num;
void display()
{
weizhi[0]=table[h/10];
weizhi[1]=table[h%10];
weizhi[2]=0x40;
weizhi[3]=table[m/10];
weizhi[4]=table[m%10];
weizhi[5]=0x40;
weizhi[6]=table[s/10];
weizhi[7]=table[s%10];
}
void main()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET1=1;
TR1=1;
ET0=1;
TR0=1;
while(1)
{
display();
if(!key1)
{
delay(100);
if(!key1)
{
h++;
if(h==24)
h=0;
}
}
if(!key2)
{
delay(100);
if(!key2)
{
h--;
if(h==255)
h=23;
}
}
if(!key3)
{
delay(100);
if(!key3)
{
m++;
if(m==60)
m=0;
}
}
if(!key4)
{
delay(100);
if(!key4)
{
m--;
if(m==255)
m=59;
}
}
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
switch(num)
{
case 0:P2=0;
P0=weizhi[num];
break;
case 1:P2=1;
P0=weizhi[num];
break;
case 2:P2=1;
P0=weizhi[num];
break;
case 3:P2=1;
P0=weizhi[num];
break;
case 4:P2=1;
P0=weizhi[num];
break;
case 5:P2=1;
P0=weizhi[num];
break;
case 6:P2=1;
P0=weizhi[num];
break;
case 7:P2=1;
P0=weizhi[num];
break;
default:break;
}
num++;
if(num==8)
num=0;
}
void T1_time() interrupt 3
{
uchar count;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++;
if(count==100)
{
count=0;
s++;
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
{
h=0;
}
}
}
}
}
void delay(uint xms)
{
uint i, j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
2016年12月01日 06点12分 2
level 1
叶北玄º 楼主
求大神帮助啊,在线等,挺急的。。。。
2016年12月01日 06点12分 3
1