自己用单片机数码管做的秒表
/*
实现功能,数码管前五位计数,显示时间的变化,误差1/1000s
*/
#include
#include
#define uint unsigned int
#define uchar unsigned char
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 closedu,closewe;
uint ge,shi,bai,num;
uchar wenum,count;
uchar doucount,dounum,doufirst,dousecond;
uchar decimal;
void delay(uint z);
void init();
void display(uint bai,uint shi,uint ge,uint doufrist,uint dousecond);
void main()
{
init();
while(1)
{
display(bai,shi,ge,doufirst,dousecond);
}
}
void init()
{
num=0;
dounum=0;
doucount=0;
decimal=0x80;
count=0;
wenum=0;
closedu=0xff;
closewe=0xff;
P1=closewe;//关闭位选
P0=closedu;//关闭段选
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(uint z)//延时1ms
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<11;y++)
{
}
}
}
void display(uint bai,uint shi,uint ge,uint doufrist,uint dousecond)
{
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;
P1=wetable[wenum];
P0=decimal;
delay(1);
P1=closewe;
P0=closedu;
wenum++;
P1=wetable[wenum];
P0=dutable[doufirst];
delay(1);
wenum++;
P1=wetable[wenum];
P0=dutable[dousecond];
delay(1);
wenum=0;
}
void time0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
count++;
doucount++;
if(count==100)
{
count=0;
num++;
if(num==1000)
{
num=0;
}
bai=num/100;
shi=num%100/10;
ge=num%10;
}
if(doucount==1)
{
doucount=0;
dounum++;
if(dounum==100)
{
dounum=0;
}
doufirst=dounum/10;
dousecond=dounum%10;
}
}
单片机数码管秒 相关文章:
- 单片机+数码管简单秒表程序,带停止启动复位(11-30)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)