下面是我做的数码管
电子表,我觉得程序没任何问题,可是定时器好像没跑起来,不知道什么原因,忘大神指教
#include <reg52.h>
#define uchar unsigned char ;
uchar shi=0,fen=0,miao=0;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uchar code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(unsigned long z)
{
while(z--);
}
void init_T0()
{
TMOD = 0x01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void T0_
time() interrupt 1
{
unsigned char num = 0;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
num++;
if(num == 20)
{
num = 0;
miao++;
if(miao == 60)
{
miao = 0;
fen++;
if(fen == 60)
{
fen = 0;
shi++;
if(shi == 25)
shi = 0;
}
}
}
}
void display()
{
// P2 =0xff;
P2 = weima[0];
P0 = table[(miao % 10)];
delay(100);
P2 = weima[1];
P0 = table[(miao / 10)];
delay(100);
P2 = weima[2];
P0 = 0xbf;
delay(100);
P2 = weima[3];
P0 = table[(fen % 10)];
delay(70);
P2 = weima[4];
P0 = table[(fen / 10)];
delay(70);
P2 = weima[5];
P0 = 0xbf;
delay(70);
P2 = weima[6];
P0 = table[(shi % 10)];
delay(70);
P2 = weima[7];
P0 = table[(shi / 10)];
delay(70);
}
void main()
{
init_T0();
while(1)
{
display();
}
}
-
-
-
数码管做的电子表带有闹钟.zip
下载积分: 积分 -1 分
57.52 KB, 下载次数: 16, 下载积分: 积分 -1 分
一周热门 更多>