標(biāo)題:
51單片機(jī)輸出方波,周期20ms,占空比5%,p2^0串口,頻率333HZ
[打印本頁(yè)]
作者:
2805948843
時(shí)間:
2020-7-10 14:06
標(biāo)題:
51單片機(jī)輸出方波,周期20ms,占空比5%,p2^0串口,頻率333HZ
這是周期為20毫秒的程序,至于你說(shuō)的頻率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.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1