#include<reg52.h>
#define uint unsigned int
unsigned int count=0;
sbit L1=P0^0;
sbit L2=P0^1;
void SelectHC573(unsigned char n)
{
switch(n)
{
case 4:
P2=(P2 & 0x1f) | 0x80;
break;
case 5:
P2=(P2 & 0x1f) | 0xa0;
break;
case 6:
P2=(P2 & 0x1f) | 0xc0;
break;
case 7:
P2=(P2 & 0x1f) | 0xe0;
break;
}
}
void Init()
{
SelectHC573(5);
P0=0x00;
SelectHC573(4);
P0=0xff;
}
/*============初始化定时器0==============*/
void Init_Timer0()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
/*=========定时器0中断服务函数===========*/
void Service_Timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;//忘记计数
if(count%10==0 )
{
L1=~L1;
}
if(count==20)
{
L2=~L2;
count=0;
}
}
/*===============主函数==================*/
void main()
{
Init();
Init_Timer0();
while(1);
}
定时器的基本原理与应用
最新推荐文章于 2022-10-17 15:52:00 发布