-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait.asm
46 lines (40 loc) · 1.38 KB
/
wait.asm
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
;------------------------------------------------------------------------------
; Busy-wait loops utilities module
; For F_CPU >= 4MHz
; http://avr-mcu.dxp.pl
; (c) Radoslaw Kwiecien, 2008
;------------------------------------------------------------------------------
.ifndef F_CPU
.error "F_CPU must be defined!"
.endif
.if F_CPU < 4000000
.warning "F_CPU too low, possible wrong delay"
.endif
.define CYCLES_PER_US (F_CPU/1000000)
.define C4PUS (CYCLES_PER_US/4)
;------------------------------------------------------------------------------
; Input : XH:XL - number of CPU cycles to wait (divided by four)
;------------------------------------------------------------------------------
Wait4xCycles:
sbiw XH:XL, 1
brne Wait4xCycles
ret
;------------------------------------------------------------------------------
; Input : r16 - number of miliseconds to wait
;------------------------------------------------------------------------------
WaitMiliseconds:
push r16
WaitMsLoop:
ldi XH,HIGH(500*C4PUS)
ldi XL,LOW(500*C4PUS)
rcall Wait4xCycles
ldi XH,HIGH(500*C4PUS)
ldi XL,LOW(500*C4PUS)
rcall Wait4xCycles
dec r16
brne WaitMsLoop
pop r16
ret
;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------