mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
No longer disabling interrupts in delayMicroseconds(): http://code.google.com/p/arduino/issues/detail?id=67
This commit is contained in:
parent
07a5160f3b
commit
ba5935e273
@ -103,13 +103,9 @@ void delay(unsigned long ms)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock.
|
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
|
||||||
* Disables interrupts, which will disrupt the millis() function if used
|
|
||||||
* too frequently. */
|
|
||||||
void delayMicroseconds(unsigned int us)
|
void delayMicroseconds(unsigned int us)
|
||||||
{
|
{
|
||||||
uint8_t oldSREG;
|
|
||||||
|
|
||||||
// calling avrlib's delay_us() function with low values (e.g. 1 or
|
// calling avrlib's delay_us() function with low values (e.g. 1 or
|
||||||
// 2 microseconds) gives delays longer than desired.
|
// 2 microseconds) gives delays longer than desired.
|
||||||
//delay_us(us);
|
//delay_us(us);
|
||||||
@ -150,19 +146,11 @@ void delayMicroseconds(unsigned int us)
|
|||||||
us--;
|
us--;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// disable interrupts, otherwise the timer 0 overflow interrupt that
|
|
||||||
// tracks milliseconds will make us delay longer than we want.
|
|
||||||
oldSREG = SREG;
|
|
||||||
cli();
|
|
||||||
|
|
||||||
// busy wait
|
// busy wait
|
||||||
__asm__ __volatile__ (
|
__asm__ __volatile__ (
|
||||||
"1: sbiw %0,1" "\n\t" // 2 cycles
|
"1: sbiw %0,1" "\n\t" // 2 cycles
|
||||||
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
||||||
);
|
);
|
||||||
|
|
||||||
// reenable interrupts.
|
|
||||||
SREG = oldSREG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user