Monday April 12 2004 09:13, you (2:5020/400) wrote to me:
AG>> ÷ gcc libc ÅÓÔØ ÔÏÖÅ: AG>> delay (uint8_t mS); // × ÍÉÌÌÉÓÅËÕÎÄÁÈ
HZ> ï! á ËÁË ÜÔÏ ÏÎÏ Ë ÍÉÌÌÉÓÅËÕÎÄÁÍ ÐÒÉ×ÑÚÙ×ÁÅÔÓÑ? ïÔËÕÄÁ ËÏÍÐÉÌÑÔÏÒ HZ> ÚÎÁÅÔ ÓËÏÌØËÏ ÔÁËÔÏ× ÍÉÌÌÉÓÅËÕÎÄÁ?
õ×Ù ÍÎÅ! ñ ÎÅÓËÏÌØËÏ ÐpÏÇÎÁÌ. ÷ ÚÁÇÏÌÏ×ÏÞÎÙÈ ÆÁÊÌÁÈ ÅÓÔØ ÔÏÌØËÏ Ä×Á ÍÁËpÏÓÁ, ËÏÔÏpÙÅ ÐpÉ×ÅÌ Alex Mogilnikov. á ÔÏ, ËÏÔÏpÙÊ × ÍÉÌÌÉÓÅËÕÎÄÁÈ, ÎÉÖÅ. ó ÐpÏÐÏÚÁÌÁÍÉ ÎÁÓÞÅÔ ÐpÅÏÄÏÌÅÎÉÑ ÔpÁÂÌÏ×. äÕÍÁÀ, ÞÔÏ ÏÆÏpÍÉÔØ ÓÉÅ ÁËÉ ÍÁËpÏÓ ÎÅ ÓÌÏÖÎÏ. ëÕÓÏÞÅË ÉÚ ÍÁÎÁ:Macro definitions will include the same assembler code whenever they are referenced. This may not be acceptable for larger routines. In this case you may define a C stub function, containing nothing other than your assembler code.
void delay(uint8_t ms) { uint16_t cnt; asm volatile ( "\n" "L_dl1%=:" "\n\t" "mov %A0, %A2" "\n\t" "mov %B0, %B2" "\n" "L_dl2%=:" "\n\t" "sbiw %A0, 1" "\n\t" "brne L_dl2%=" "\n\t" "dec %1" "\n\t" "brne L_dl1%=" "\n\t" : "=&w" (cnt) : "r" (ms), "r" (delay_count) ); }
The purpose of this function is to delay the program execution by a specified number of milliseconds using a counting loop. The global 16 bit variable delay count must contain the CPU clock frequency in Hertz divided by 4000 and must have been set before calling this routine for the first time. As described in the clobber section, the routine uses a local variable to hold a temporary value.
Alex