设8051单片机的晶振频率为6MHz,试分别用定时器T0的方式1、2编程,使在P1.0引脚上输出1ms的方波。

2025-04-13 02:37:03
推荐回答(1个)
回答(1):

#include
sbit pluse=P1^0;
void t0isr() interrupt 1
{
TH0=(65536-500);
TL0=(65536-500);
pluse=~pluse;
}
main()
{
TMOD=0x01;
TH0=(65536-500);
TL0=(65536-500);
TR0=1;
ET0=1;
while(1);
}

#include
sbit pluse=P1^0;
bit flag=0;
void t0isr() interrupt 1
{
flag=~flag;
if(!flag)pluse=~pluse;

}
main()
{
TMOD=0x02;
TH0=6;
TL0=6;
TR0=1;
ET0=1;
while(1);

}