用三位数码管的动态扫描实现999计时显示
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数字钟源程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void display(uchar hshi,uchar hge,uchar minshi,uchar minge,uchar secshi,uchar secge); uint aa,xiaoshi,fenzhong,miao;
uchar hshi,hge,minshi,minge,secshi,secge;
void delay();
void main()
{
TMOD=0x01;
TH0=0x3C;
TL0=0xB0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(aa==1)
{aa=0;miao++;
if(miao==60)
{miao=0;fenzhong++;
if(fenzhong==60)
{fenzhong=0;xiaoshi++;
if(xiaoshi==24)
{xiaoshi=0;}
}
}
hshi=xiaoshi/10;
hge=xiaoshi%10;
minshi=fenzhong/10;
minge=fenzhong%10;
secshi=miao/10;
secge=miao%10;
}
display(hshi,hge,minshi,minge,secshi,secge);
}
}
void delay()
{
uchar i,j;
for(i=0;i<100;i++)
for(j=0;j<20;j++);
}
void display(uchar hshi,uchar hge,uchar minshi,uchar minge,uchar secshi,uchar secge) {
P1=0x01; // 小时的十位
P2=num[hshi];
delay();
P1=0x02; //小时的个位
P2=num[hge];
delay();
P1=0x04; // 分钟的十位
P2=num[minshi];
delay();
P1=0x08; //分钟的个位
P2=num[minge];
delay();
P1=0x10; // 秒的十位
P2=num[secshi];
delay();
P1=0x20; //秒的个位
P2=num[secge];
delay();
}
void timer0() interrupt 1
{
TH0=0x3C;
TL0=0xB0;
aa++;
}
00000 000
00000 001 00000010 00000100
P3 0x01 0x02 0x04
任务
用三位数码管的动态扫描实现999倒计时显示
1、用定时器中断秒可以精确
2、动态扫描
3、数位分解
582582/100=5
582%100/10=8
582%100%10=2
V oid main()
{ 初始值TH0=
TL0=
While(1)
{}
}
V oid timer0() interrupt 1
{
工作方式TMOD=0x
初始值TH0=
TL0=
开总中断EA=
起动定时器允许定时器中断
Miao++;
}
V oid display()
{
}
V oid delay()
{
}
有参函数bai shi ge 形式参数实际参数
无参函数
void display(uint bai,uint shi,uint ge)
{
P3=0x01;
P2=num[bai];
delay();
P3=0x02;
P2=num[shi];
delay();
P3=0x04;
P2=num[ge];
delay();
}
999秒倒计时
1、数码管显示技术动态扫描轮流导通
2、定时器中断1s 精确
3、数位分解
P3
00000 001 0000 0 010 00000 100 0x01 0x02 0x04
P3=0x01;
P1=num[]
Delay();
Unsigned int unsigned char
Jishu= 269
269/100=2 bai= jishu/100
269%100/10=6 shi=jishu%100/10
269%100%10=0 ge=jishu%100%10
If( )
{if()
{}
}
#include<reg51.h>
#define uint unsigned int //宏定义
#define uchar unsigned char
uchar code num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; void delay();
//void xianshi(uint bai,uint shi,uint ge);
//uint bai,shi,ge;
uint a,jishu=0;
void main()
{
TMOD=0x01;
TH0=0x3c; //50ms 重置
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(a==1)
{ a=0;jishu++;
if(jishu==999)
jishu=0; }
P3=0x01;
P2=num[jishu/100];
delay();
P3=0x02; //十位
P2=num[jishu%100/10];
delay();
P3=0x04; //个位
P2=num[jishu%100%10];
delay();
}
}
void delay()
{
uchar i,j;
for(i=0;i<100;i++)
for(j=0;j<50;j++);
}
//void xianshi(uint bai,uint shi,uint ge)
//{
// P3=0x01; //百位
// P2=num[bai];
// delay();
// P3=0x02; //十位
// P2=num[shi];
// delay();
// P3=0x04; //个位
// P2=num[ge];
// delay();
//}
void timer0() interrupt 1
{
TH0=0x3c; //50ms TL0=0xb0;
a++;
}。