我想写一个能产生1kHZ 可调的PWM信号,但是没有现象。
#include"stc12c5a60s2.h"
#define uint unsigned int
#define uchar unsigned char
uchar t,zhankongbi;
sbit pwm1=P2^0;
sbit pwm2=P2^1;
sbit jia=P0^0;
sbit jian=P0^1;
void delayms(uint);
void main()
{
TMOD = 0x01;
TH0 = 0x0FF;
TL0 = 0x0F7;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void jianpan()
{
if(jia==0)
{
delayms(2);
if(jia==0)
{
zhankongbi+=30;
if(zhankongbi>=100)
zhankongbi=0;
}
while(!jia);
}
if(jian==0)
{
delayms(2);
if(jian==0)
{
zhankongbi-=30;
if(zhankongbi>=100)
zhankongbi=0;
}
while(!jian);
}
}
void Timer0() interrupt 1
{
TR0=0;
TH0 = 0x0FF;
TL0 = 0x0F7;
TR0=1;
t++;
if(t>=100)
t=0;
if(t<=zhankongbi)
pwm1=1;
else
pwm1=0;
pwm2=0;
}
|