#include //Ms級延時函數(shù),參數(shù)i:延時時間 void main(void) PORTB = 0xFF; while (1) i 定義為無符號字符數(shù),取值范圍為0-255,當(dāng)增加到255再加1時,就又回到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 ++;
}
}
}