-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.c
54 lines (50 loc) · 1.77 KB
/
delay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Program: Multitherm - A multiple DS18x20 thermometer control and logging device
* File Name: delay.c
* Purpose: Precise AVR delay functions without the avr/delay overhead
*
* Description:
* Precise Delay Functions
* V 0.5, Martin Thomas, 9/2004
*
* In the original Code from Peter Dannegger a timer-interrupt
* driven "timebase" has been used for precise One-Wire-Delays.
* My loop-approach is less elegant but may be more usable
* as library-function. Since it's not "timer-dependent"
* See also delay.h.
*
* Inspired by the avr-libc's loop-code
*
* RTB - 09/20 - added 1us delay timed for ATMega running at 8MHz
*
*
* Programmer: Tom Blough
* Host System: ATMega16L tested with both internal RC osc at 8MHz
* and external 8MHz crystal
* Date Created: 2007/09/20
* Revision: $WCREV$ $WCDATE$
* Modifications:
*/
#include <avr/io.h>
#include <avr/io.h>
#include <inttypes.h>
#include "delay.h"
void delayloop32(uint32_t loops)
{
__asm__ volatile ( "cp %A0,__zero_reg__ \n\t" \
"cpc %B0,__zero_reg__ \n\t" \
"cpc %C0,__zero_reg__ \n\t" \
"cpc %D0,__zero_reg__ \n\t" \
"breq L_Exit_%= \n\t" \
"L_LOOP_%=: \n\t" \
"subi %A0,1 \n\t" \
"sbci %B0,0 \n\t" \
"sbci %C0,0 \n\t" \
"sbci %D0,0 \n\t" \
"brne L_LOOP_%= \n\t" \
"L_Exit_%=: \n\t" \
: "=w" (loops) \
: "0" (loops) \
); \
return;
}