动态扫描方法和定时器1在数码管的前三位显示出秒表
用动态扫描方法和定时器1在数码管的前三位显示出秒表
*/
#include
#include
#define uint unsigned int
#define uchar unsigned char
uint closedu,closewe;
uchar code wetable[]={
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
uchar code dutable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//段选
uint ge,shi,bai,num;
uchar wenum,count;
void delay(uint z);
void init();
void display(uint bai,uint shi,uint ge);
void main()
{
init();
while(1)
{
display(bai,shi,ge);
}
}
void init()
{
num=0;
count=0;
wenum=0;
closedu=0xff;
closewe=0xff;
P1=closewe;//关闭位选
P0=closedu;//关闭段选
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<110;y++)
{
}
}
}
void display(uint bai,uint shi,uint ge)
{
closedu=0xff;
closewe=0xff;
wenum=0;
P1=wetable[wenum];
P0=dutable[bai];
delay(1);
P1=closewe;
P0=closedu;
wenum++;
P1=wetable[wenum];
P0=dutable[shi];
delay(1);
P1=closewe;
P0=closedu;
wenum++;
P1=wetable[wenum];
P0=dutable[ge];
delay(1);
P1=closewe;
P0=closedu;
wenum=0;
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
num++;
if(num==1000)
{
num=0;
}
bai=num/100;
shi=num%100/10;
ge=num%10;
}
}
动态扫描定时器数码 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)