新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)制作簡(jiǎn)易定時(shí)器

單片機(jī)制作簡(jiǎn)易定時(shí)器

作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏

系統(tǒng)圖:

本文引用地址:http://m.butianyuan.cn/article/201611/315683.htm

程序:

#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;}
}
}



評(píng)論


技術(shù)專區(qū)

關(guān)閉