void main()
{
cnt=0;
Int0Ini
tial();
Initpwm();
AUXR = 0x80;
CCAP0H = 0x57;
EA =1;
TMOD = 0x01;
TH0 = 0x44;
TL0 = 0x80;
ET0 = 1;
TR0 = 1;
while(1)
{
sensor();
}
}
void Int0Initial()
{
IN1 = 0;
IN2 = 0;
IN3 = 0;
IN4 = 0;
IN5 = 0;
IN6 = 0;
}
void tm0_isr() interrupt 1 using 1
{
TH0 = 0x44;
TL0 = 0x80;
if (cnt == 1500)
{
cnt = 0;
if (CCAP0H < 0x7A)
{
CCAP0H = CCAP0H + 0x05;
}
else if(CCAP0H >= 0X7A)
{
CCAP0H = 0x7A;
}
}
cnt++;
}
void Initpwm()
{
CCON = 0; //
CL = 0;//
CH = 0;//
CMOD = 0x01;//
CCAP0H = CCAP0L=0x57;/256*(1-Duty)
CCAPM0 = 0x42;//
CR =1;
}
单片机输出的pwm的占空比一直不变。。。但我在中断里设置了每三秒加2%。。。说明一直没进中断。。。大神们求解释。。。CCAP0H是用来改变占空比的
一周热门 更多>