-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwait.S
185 lines (136 loc) · 4.95 KB
/
wait.S
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
; ****************************************************************************
;
; Delay loop (F_CPU = 8000000, 4000000)
;
; ****************************************************************************
#include "include.inc"
#define nop2 rjmp .+0 ; [2] shorter form of "nop nop"
.text
; ============================================================================
; 8 MHz
; ============================================================================
; Quartz 8 MHz, 1 clock = 0.125 us, 1 us = 8 clocks
#if F_CPU >= 6000000
; ----------------------------------------------------------------------------
; Delay 10 us (8 MHz: 80 clock cycles)
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
; clocks = 3 + 2 + 1 + 2 + 2 + (13-1)*5 + 4 + 2 + 4 = 80
.global Wait10us
Wait10us:
; rcall Wait10us ; [rcall 3]
push r24 ; [2] push R24
ldi r24,13 ; [1]
nop2 ; [2]
1: nop2 ; [2]
2: nop2 ; [2]
dec r24 ; [1]
brne 2b ; [1,2]
pop r24 ; [2] pop R24
ret ; [4]
; ----------------------------------------------------------------------------
; Delay 100 us (8 MHz: 800 clock cycles)
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
; clocks = 3 + 2 + 1 + 2 + 2 + (157-1)*5 + 4 + 2 + 4 = 800
.global Wait100us
Wait100us:
; rcall Wait100us ; [rcall 3]
push r24 ; [2] push R24
ldi r24,157 ; [1]
rjmp 1b ; [2]
; ============================================================================
; 4 MHz
; ============================================================================
; Quartz 4 MHz, 1 clock = 0.25 us, 1 us = 4 clocks
#else // #if F_CPU >= 6000000
; ----------------------------------------------------------------------------
; Delay 10 us (4 MHz: 40 clock cycles)
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
; clocks = 3 + 2 + 1 + 2 + 2 + (5-1)*5 + 4 + 2 + 4 = 40
.global Wait10us
Wait10us:
; rcall Wait10us ; [rcall 3]
push r24 ; [2] push R24
ldi r24,5 ; [1]
nop2 ; [2]
1: nop2 ; [2]
2: nop2 ; [2]
dec r24 ; [1]
brne 2b ; [1,2]
pop r24 ; [2] pop R24
ret ; [4]
; ----------------------------------------------------------------------------
; Delay 100 us (4 MHz: 400 clock cycles)
; ----------------------------------------------------------------------------
; DESTROYS: -
; ----------------------------------------------------------------------------
; clocks = 3 + 2 + 1 + 2 + 2 + (77-1)*5 + 4 + 2 + 4 = 400
.global Wait100us
Wait100us:
; rcall Wait100us ; [rcall 3]
push r24 ; [2] push R24
ldi r24,77 ; [1]
rjmp 1b ; [2]
#endif // #if F_CPU >= 6000000
; ----------------------------------------------------------------------------
; Delay 10 ms
; ----------------------------------------------------------------------------
; DESTROYS: R24
; ----------------------------------------------------------------------------
.global Wait10ms
Wait10ms:
ldi r24,10 ; 10 ms
rjmp Waitms
; ----------------------------------------------------------------------------
; Delay 100 ms
; ----------------------------------------------------------------------------
; DESTROYS: R24
; ----------------------------------------------------------------------------
.global Wait100ms
Wait100ms:
ldi r24,100 ; 100 ms
rjmp Waitms
; ----------------------------------------------------------------------------
; Delay 1 second
; ----------------------------------------------------------------------------
; DESTROYS: R24
; ----------------------------------------------------------------------------
.global Wait1s
Wait1s:
rcall Wait250ms
rcall Wait250ms
rcall Wait250ms
; ----------------------------------------------------------------------------
; Delay 250 ms
; ----------------------------------------------------------------------------
; DESTROYS: R24
; ----------------------------------------------------------------------------
.global Wait250ms
Wait250ms:
ldi r24,250 ; 250 ms
; Waitms must follow
; ----------------------------------------------------------------------------
; Delay 1..255 ms
; ----------------------------------------------------------------------------
; INPUT: R24 = numer of [ms]
; DESTROYS: -
; ----------------------------------------------------------------------------
.global Waitms
Waitms:
push r24
push r25
1: ldi r25,10 ; counter to 1 ms
; DESTROYS: -
2: rcall Wait100us ; wait 100 us
dec r25
brne 2b
dec r24 ; counter of ms
brne 1b
pop r25
pop r24
ret