您的位置 首页 IC

单片机制造简易定时器

系统图:程序:#includeat89x51.h>unsignedcharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x

体系图:

程序:

#include
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90};
unsigned char count;
unsigned char second,temp;
bit alarmflag;
void delay(unsigned int i)
{ unsigned char j;
while(i–)for(j=248;j>0;j–);
}
void main()
{
TMOD=0x22;
TH0=0x06;
TL0=0x06;
TH1=0x06;
TL1=0x06;
TR1=1;
ET1=1;
EA=1;
ET0=1;
P1=table[count/10];
P0=table[count%10];
while(1)
{
if(P3_2==0)
{
delay(20);
if(P3_2==0)
{
count++;
if(count==60){count=0;}
P1=table[count/10];
P0=table[count%10];
}
while(P3_2==0);temp=count;
}
else if(P3_3==0)
{
delay(20);
if(P3_3==0)
{
TR0=1;
}
}
}
}
void time0() interrupt 1
{
static unsigned int nn;
nn++;
if(nn==4000)
{
second=count–;
P0=table[second%10];P1=table[second/10];
if(second<=0){second=0;}
}
}
void time1() interrupt 3
{
static unsigned int kk,ll,pp;
kk++;
if(kk==4000)
{temp=count;
ll++;
if(ll==temp)
{ll=0;P2_1=0;
}
pp++;
if(pp==6)
{P0=table[0xc0];P1=table[0xc0];P2_1=1;pp=0;}
}
}

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

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

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

微信扫一扫关注我们

返回顶部