您的位置 首页 汽车

自己用单片机数码管做的秒表

基于51hei单片机开发板电路图可从官网去下载,p1为位选p0为段选*实现功能,数码管前五位计数,显示时间的变化,误差11000s*includer

根据51hei单片机开发板电路图可从官网去下载,p1为位选 p0为段选

/*
完成功用,数码管前五位计数,显现时刻的改变,差错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;
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/255108.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部