51單片機(jī)(AT89C52)定時(shí)器
#include
#define uchar unsigned char
#define uint unsigned int
uchar i,temp;
void init()
{
TMOD=0x01;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
ET0=1;
EA=1;
TR0=1;
}
void main()
{
i=0;
temp=0x01;
init();
while(1);
}
void timer0() interrupt 1
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
if(i<8)
{
P2=temp;
i++;
temp<<=1;
}
else
{
i=0;
temp=0x01;
}
}
編輯:admin 最后修改時(shí)間:2018-05-18