学前班
最后登录1970-1-1
在线时间 小时
注册时间2017-11-21
|
用动态扫描方法和定时器1在数码管的前三位显示出秒表,精确到1%秒,即后两位显示1%秒,一直循环下去。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
void delayms(uint);
void display(uchar,uchar,uchar);
uchar ge,gefen,shifen;
uint num;
void main()
{
wela=0;
dula=0;
EA=1;
ET1=1;
TMOD=0x10;
TH1=(65536-9174)/256,TL1=(65536-9174)%256;
TR1=1;
while(1)
{
display(ge,gefen,shifen);
}
}
void T1_time() interrupt 3
{
TH1=(65536-9174)/256,TL1=(65536-9174)%256;
num++;
if(num==1000) num=0;
ge=num/100;
gefen=num/10%10;
shifen=num%100;
}
void display(uchar ge,uchar gefen,uchar shifen)
{
wela=1;
P0=0xfe;
wela=0;
P0=0xff;
dula=1;
P0=table[ge];
dula=0;
delayms(1);
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
P0=0xff;
dula=1;
P0=table[gefen];
dula=0;
delayms(1);
P0=0xff;
wela=1;
P0=0xfc;
wela=0;
P0=0xff;
dula=1;
P0=table[shifen];
dula=0;
delayms(1);
P0=0xff;
}
|
|