|
#include <reg51.h>
#define uchar unsigned char
uchar time;
uchar period=250;
uchar high=50;
//-----------定时器0中断处理程序-------------
timer0 (void) interrupt 1 using 1
{
TH0= -8333/256; //重载计数初值
TL0= -8333%256;
if (++time= =high) P1=0; //高电平时间到变低
else if (time= =period) //周期时间到变高
{
time=0;
P1=1;
}
}
//-------------------主函数------------------------------------------------------------
main ( )
{
TMOD=0x01; //定时器0方式1
TH0= -8333/256; //预置计数初值
TL0= -8333%256;
EA=1;
ET0=1;
TR0=1;
do { } while (1);
}
|
|