#include //Ms級(jí)延時(shí)函數(shù),參數(shù)i:延時(shí)時(shí)間 void main(void) PORTB = 0xFF; while (1) i 定義為無(wú)符號(hào)字符數(shù),取值范圍為0-255,當(dāng)增加到255再加1時(shí),就又回到0了,于是條件不成立,退出循環(huán)。
void DelayMs(unsigned int i)
{
unsigned char j;
for(;i;i--)
{
for(j=142;j;j--)
{;}
}
}
{
unsigned char i;
DDRB = 0xFF;
TCCR1A = 0x81;
TCCR1B = 0x09; //start Timer
{
i = 255;
while (i)
{
OCR1A = i;
DelayMs(10);
i --;
}
i = 1;
while (i)
{
OCR1A = i;
DelayMs(10);
i ++;
}
}
}





