我想用89c52写一个1302+1602的时钟程序 5
1个回答
展开全部
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint ge,shi,bai,temp,t0,t1,x;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void yanshi(uint c)
{
uint a,b;
for(a=c;a>0;a--)
for(b=100;b>0;b--);
}
void display(uchar bai,uchar shi,uchar ge);
void init();
sbit wei=P2^7;
sbit duan=P2^6;
void main()
{
init(); //初始化
while(1)
{
if(t0==10)
{
t0=0;
temp--;
if(temp==0)
temp=300;
}
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
display(bai,shi,ge);
if(t1==10)
{
t1=0;
x=_crol_(x,1);
P1=x;
}
}
}
void display(uchar bai,uchar shi,uchar ge)
{
P0=0xff;
wei=1; //百位显示
P0=0xfe;
wei=0;
duan=1;
P0=table[bai];
duan=0;
yanshi(2);
P0=0xff;
wei=1; //十位显示
P0=0xfd;
wei=0;
duan=1;
P0=table[shi];
duan=0;
yanshi(2);
P0=0xff; //个位显示
wei=1;
P0=0xfb;
wei=0;
duan=1;
P0=table[ge];
duan=0;
yanshi(2);
}
void time0()interrupt 1
{
t0++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void time1()interrupt 3
{
t1++;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
}
void init()
{
x=0xfe;
temp=300;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
希望对你有帮助。看你的题意不是很清楚。
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint ge,shi,bai,temp,t0,t1,x;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void yanshi(uint c)
{
uint a,b;
for(a=c;a>0;a--)
for(b=100;b>0;b--);
}
void display(uchar bai,uchar shi,uchar ge);
void init();
sbit wei=P2^7;
sbit duan=P2^6;
void main()
{
init(); //初始化
while(1)
{
if(t0==10)
{
t0=0;
temp--;
if(temp==0)
temp=300;
}
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
display(bai,shi,ge);
if(t1==10)
{
t1=0;
x=_crol_(x,1);
P1=x;
}
}
}
void display(uchar bai,uchar shi,uchar ge)
{
P0=0xff;
wei=1; //百位显示
P0=0xfe;
wei=0;
duan=1;
P0=table[bai];
duan=0;
yanshi(2);
P0=0xff;
wei=1; //十位显示
P0=0xfd;
wei=0;
duan=1;
P0=table[shi];
duan=0;
yanshi(2);
P0=0xff; //个位显示
wei=1;
P0=0xfb;
wei=0;
duan=1;
P0=table[ge];
duan=0;
yanshi(2);
}
void time0()interrupt 1
{
t0++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void time1()interrupt 3
{
t1++;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
}
void init()
{
x=0xfe;
temp=300;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
希望对你有帮助。看你的题意不是很清楚。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询