Gast
#178242
Hallo
Ist der unten eingefügten Code für die Programmierung der verlangten
Verzögerungen beim 1-Wire Protokoll (in us Bereich) geeignet ?
Vielen Dank für die Hilfe
Toni
---------------------------------------------------------------------
Code aus lcd.c von Peter Fleury
/***********************************************************************
**
delay loop for small accurate delays: 16-bit counter, 4 cycles/loop
************************************************************************
*/
static inline void _delayFourCycles(unsigned int __count)
{
if ( __count == 0 )
_asm_ __volatile__( "rjmp 1f\n 1:" ); // 2 cycles
else
_asm__ __volatile_ (
"1: sbiw %0,1" "\n\t"
"brne 1b" // 4 cycles/loop
: "=w" (__count)
: "0" (__count)
);
}
/***********************************************************************
**
delay for a minimum of <us> microseconds
the number of loops is calculated at compile-time from MCU clock
frequency
************************************************************************
*/
#define delay(us) _delayFourCycles( ( ( 1*(XTAL/4000) )*us)/1000 )