单片机制作简易定时器
系统图:
程序:
#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;}
}
}
单片机简易定时 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)