Studyhard/AVR2009. 4. 3. 14:22

void delay_us(unsigned int us)
{
     unsigned int i;
     for(i = 0; i < us; i++) // 4 cycle <- 함수의 들어감과 나감에 있어 4Cyclye 소요
     {
        asm("PUSH R0"); // 2 cycle 
        asm("POP R0");  // 2 cycle 
        asm("PUSH R0"); // 2 cycle 
        asm("POP R0");  // 2 cycle 
        asm("PUSH R0"); // 2 cycle 
        asm("POP R0");  // 2 cycle   => 4+2+2+2+2+2+2 = 16cycle = 1us for 16Mhz


    }

}


void delay_ms(unsigned int ms)
{
    unsigned int i;
    for(i = 0; i < ms; i++)
        delay_us(1000);

}




* 1초를 delay_ms(1000) 을 이용하여 사용하였을 때,  언뜻 보기에도 1초가 아닌 경우에는 

  퓨즈비트 설정이 잘 못 되어 있는 경우가 있으므로, PonyProg 에서 퓨즈비트 체크를 확인하고 하면 된다.

  

Posted by 리얼한놈