微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机制作简易定时器

单片机制作简易定时器

时间:11-18 来源:互联网 点击:

系统图:

程序:

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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top