标题:
通过调节脉宽改变频率
[打印本页]
作者:
51hhcc
时间:
2017-4-7 11:47
标题:
通过调节脉宽改变频率
/*
占空比可以调整 pwm_h=20;
*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit fangbo=P1^1;
uint count=0;
uchar pwm_h=20;
int main()
{
//定时器0 初始化 工作方式1 定时50ms
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
fangbo=0;
while(1)
{
}
}
void ftimer0() interrupt 1
{
TH0=(-1000)/256;
TL0=(-1000)%256;
count++;
if(count==100)
{
count=0;
fangbo=1;
}
else if(count==pwm_h)
{
fangbo=0;
}
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1