各位大佬好。我采用高、低電平delay的方式 用IO輸出方波。但調(diào)delay值,不能改變占空比,是什么原因?同樣的代碼。在51中是可以的。謝謝!
代碼如下:
void pwmout()
{
unsigned char i=0;
switch(i)
{
case 0:
DDRB = 0x0F;
PORTB = 0x01; //輸出高
delay(2000);
i=1;
case 1:
DDRB = 0x0F;
PORTB = 0x00; //輸出高
delay(1000);
i=0;
}
}
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
請大佬們,指點一下原因。謝謝!
|