标题:
51单片机输出方波,周期20ms,占空比5%,p2^0串口,频率333HZ
[打印本页]
作者:
2805948843
时间:
2020-7-10 14:06
标题:
51单片机输出方波,周期20ms,占空比5%,p2^0串口,频率333HZ
这是周期为20毫秒的程序,至于你说的频率zhi333Hz,与前者冲突选用前者
#include<reg51.h>
unsigned char cnt;
sbit pwm=P2^0;
void t0isr() interrupt 1
{
cnt++;
if(cnt<5)pwm=1;
else pwm=0;
if(cnt>=100)cnt=0;
}
main()
{
TMOD=0x02;
TH0=56;
TL0=56;
TR0=1;
ET0=1;
EA=1;
while(1);
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1