Rev Author Line No. Line
4985 kaklik 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title> words/usart.asm </title>
6 <meta name="keywords" content="amforth programming language Forth ATmega ATMEL">
7 <meta name="description" content="amforth - laguage Forth for ATMEL ATmega">
8 <!-- AUTOINCLUDE START "Page/Head.en.ihtml" DO NOT REMOVE -->
9 <link rel="StyleSheet" href="../../../../Web/CSS/MLAB.css" type="text/css" title="MLAB Basic Style">
10 <link rel="StyleSheet" href="../../../../Web/CSS/MLAB_Print.css" type="text/css" media="print">
11 <link rel="shortcut icon" type="image/x-icon" href="../../../../Web/PIC/MLAB.ico">
12 <script type="text/javascript" src="../../../../Web/JS/MLAB_Menu.js"></script>
13 <!-- AUTOINCLUDE END -->
14 </head>
15  
16 <body lang="en">
17  
18 <!-- AUTOINCLUDE START "Page/Header.en.ihtml" DO NOT REMOVE -->
19 <!-- ============== HEADER ============== -->
20 <div class="Header">
21 <script type="text/javascript">
22 <!--
23 SetRelativePath("../../../../");
24 DrawHeader();
25 // -->
26 </script>
27 <noscript>
28 <p><b> JavaScript is required for including of the header </b></p>
29 </noscript>
30 </div>
31 <!-- AUTOINCLUDE END -->
32  
33 <!-- AUTOINCLUDE START "Page/Menu.en.ihtml" DO NOT REMOVE -->
34 <!-- ============== MENU ============== -->
35 <div class="Menu">
36 <script type="text/javascript">
37 <!--
38 SetRelativePath("../../../../");
39 DrawMenu();
40 // -->
41 </script>
42 <noscript>
43 <p><b> JavaScript is required for including of the menu </b><p>
44 </noscript>
45 </div>
46 <!-- AUTOINCLUDE END -->
47  
48 <!-- ============== TEXT ============== -->
49 <div class="Text">
50  
51 <h1> words/usart.asm </h1>
52  
53 <p>
54 <input type=button onClick="history.back()" value="Back">
55 <input type=button onClick="history.forward()" value="Forward">
56 <a href="../WordList.en.html">Jump to Vocabulary</a>
57 </p>
58  
59 <pre>
60 ;;; usart driver
61  
62 ;; bit definitions
63  
64  
65 .set pc_ = pc
66  
67 .org URXCaddr
68 rjmp usart0_rx_isr
69 .org UDREaddr
70 rjmp usart0_udre_isr
71 .org pc_
72  
73 ; sizes have to be powers of 2!
74 .equ usart0_tx_size = $10
75 .equ usart0_rx_size = $10
76  
77 .equ usart0_tx_mask = usart0_tx_size - 1
78 .equ usart0_rx_mask = usart0_rx_size - 1
79  
80 .set usart0_tx_in = heap
81 .set heap = heap + 1
82  
83 .set usart0_tx_out = heap
84 .set heap = heap + 1
85  
86 .set usart0_tx_data = heap
87 .set heap = heap + usart0_tx_size
88  
89 .set usart0_rx_in = heap
90 .set heap = heap + 1
91  
92 .set usart0_rx_out = heap
93 .set heap = heap + 1
94  
95 .set usart0_rx_data = heap
96 .set heap = heap + usart0_rx_size
97  
98 ; ( -- v) System Value
99 ; R( -- )
100 ; returns usart0 baudrate
101 VE_BAUD0:
102 .db 05,&quot;baud0&quot;
103 .dw VE_HEAD
104 .set VE_HEAD = VE_BAUD0
105 XT_BAUD0:
106 .dw PFA_DOVALUE
107 PFA_BAUD00: ; ( -- )
108 .dw 10
109  
110 ; ( -- ) Hardware Access
111 ; R( --)
112 ; initialize usart0
113 VE_USART0:
114 .db $06, &quot;usart0&quot;,0
115 .dw VE_HEAD
116 .set VE_HEAD = VE_USART0
117 XT_USART0:
118 .dw DO_COLON
119 PFA_USART0: ; ( -- )
120 .dw XT_ZERO
121 .dw XT_DOLITERAL
122 .dw usart0_tx_in
123 .dw XT_CSTORE
124  
125 .dw XT_ZERO
126 .dw XT_DOLITERAL
127 .dw usart0_tx_out
128 .dw XT_CSTORE
129  
130 .dw XT_ZERO
131 .dw XT_DOLITERAL
132 .dw usart0_rx_in
133 .dw XT_CSTORE
134  
135 .dw XT_ZERO
136 .dw XT_DOLITERAL
137 .dw usart0_rx_out
138 .dw XT_CSTORE
139  
140 .dw XT_F_CPU
141 .dw XT_D2SLASH
142 .dw XT_D2SLASH
143 .dw XT_D2SLASH
144 .dw XT_D2SLASH
145 .dw XT_ROT
146 .dw XT_UMSLASHMOD
147 .dw XT_SWAP
148 .dw XT_DROP
149 .dw XT_1MINUS
150  
151 .dw XT_DUP
152 .dw XT_DOLITERAL
153 .dw BAUDRATE0_LOW
154 .dw XT_CSTORE
155 .dw XT_BYTESWAP
156 .dw XT_DOLITERAL
157 .dw BAUDRATE0_HIGH
158 .dw XT_CSTORE
159 .dw XT_DOLITERAL
160 .dw (1&lt;&lt;UMSEL01)|(3&lt;&lt;UCSZ00)
161 .dw XT_DOLITERAL
162 .dw USART0_C
163 .dw XT_CSTORE
164 .dw XT_DOLITERAL
165 .dw (1&lt;&lt;TXEN0) | (1&lt;&lt;RXEN0) | (1&lt;&lt;RXCIE0)
166 .dw XT_DOLITERAL
167 .dw USART0_B
168 .dw XT_CSTORE
169 .dw XT_EXIT
170  
171 usart0_udre_isr:
172 push xl
173 in xl,SREG
174 push xl
175 push xh
176 push zl
177 push zh
178  
179 lds xl,usart0_tx_in
180 lds xh,usart0_tx_out
181  
182 cp xh,xl
183 brne usart0_udre_next
184  
185 usart0_udre_last:
186 lds xl, USART0_B
187 cbr xl,(1&lt;&lt;UDRIE0)
188 sts USART0_B,xl
189  
190 rjmp usart0_udre_done
191  
192 usart0_udre_next:
193 inc xh
194 andi xh,usart0_tx_mask
195 sts usart0_tx_out,xh
196  
197 ldi zl,low(usart0_tx_data)
198 ldi zh,high(usart0_tx_data)
199 add zl,xh
200 adc zh,zeroh
201  
202 ld xl,z
203 out_ UDR0,xl
204  
205 usart0_udre_done:
206 pop zh
207 pop zl
208 pop xh
209 pop xl
210 out SREG,xl
211 pop xl
212 reti
213 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
214 usart0_rx_isr:
215 push xl
216 in xl, SREG
217 push xl
218 push xh
219 push zl
220 push zh
221  
222 lds xl,usart0_rx_in
223 inc xl
224 andi xl,usart0_rx_mask
225  
226 ldi zl, low(usart0_rx_data)
227 ldi zh, high(usart0_rx_data)
228 add zl, xl
229 adc zh, zeroh
230 in_ xh, UDR0
231 st Z, xh
232 sts usart0_rx_in, xl
233  
234 pop zh
235 pop zl
236 pop xh
237 pop xl
238 out SREG, xl
239 pop xl
240 reti
241  
242 ; (c -- ) Hardware Access
243 ; R( --)
244 ; put 1 character into output queue, wait if needed, enable UDRIE0 interrupt
245 VE_TX0:
246 .db $03, &quot;tx0&quot;
247 .dw VE_HEAD
248 .set VE_HEAD = VE_TX0
249 XT_TX0:
250 .dw DO_COLON
251 PFA_TX0:
252 ; wait for queue
253 .dw XT_TX0Q
254 .dw XT_DOCONDBRANCH
255 .dw PFA_TX0
256 ; append to queue
257 .dw XT_DOLITERAL
258 .dw usart0_tx_in
259 .dw XT_CFETCH ; ( -- c tx_in)
260 .dw XT_1PLUS
261 .dw XT_DOLITERAL
262 .dw usart0_tx_mask
263 .dw XT_AND ; ( -- c tx_in_new)
264 .dw XT_DUP
265 .dw XT_DOLITERAL
266 .dw usart0_tx_in
267 .dw XT_CSTORE
268 .dw XT_DOLITERAL
269 .dw usart0_tx_data ; ( -- c tx_in_new data)
270 .dw XT_PLUS
271 .dw XT_CSTORE
272 ; enable interrupt
273 .dw XT_DOLITERAL
274 .dw USART0_B
275 .dw XT_DUP ;
276 .dw XT_CFETCH
277 .dw XT_DOLITERAL
278 .dw 1&lt;&lt;UDRIE0
279 .dw XT_OR
280 .dw XT_SWAP
281 .dw XT_CSTORE
282 .dw XT_EXIT
283  
284 ; ( -- f) Hardware Access
285 ; R( --)
286 ; check if a character can be appended to output queue.
287 VE_TX0Q:
288 .db $04, &quot;tx0?&quot;,0
289 .dw VE_HEAD
290 .set VE_HEAD = VE_TX0Q
291 XT_TX0Q:
292 .dw DO_COLON
293 PFA_TX0Q:
294 .dw XT_PAUSE
295 .dw XT_DOLITERAL
296 .dw usart0_tx_out
297 .dw XT_CFETCH
298 .dw XT_DOLITERAL
299 .dw usart0_tx_in
300 .dw XT_CFETCH
301 .dw XT_EQUAL
302 .dw XT_EXIT
303  
304 ; ( -- c) Hardware Access
305 ; R( --)
306 ; get 1 character from input queue, wait if needed
307 VE_RX0:
308 .db $03, &quot;rx0&quot;
309 .dw VE_HEAD
310 .set VE_HEAD = VE_RX0
311 XT_RX0:
312 .dw DO_COLON
313 PFA_RX0:
314 .dw XT_RX0Q
315 .dw XT_DOCONDBRANCH
316 .dw PFA_RX0
317 .dw XT_DOLITERAL
318 .dw usart0_rx_out
319 .dw XT_CFETCH
320 .dw XT_1PLUS
321 .dw XT_DOLITERAL
322 .dw usart0_rx_mask
323 .dw XT_AND
324 .dw XT_DUP
325 .dw XT_DOLITERAL
326 .dw usart0_rx_out
327 .dw XT_CSTORE
328 .dw XT_DOLITERAL
329 .dw usart0_rx_data
330 .dw XT_PLUS
331 .dw XT_CFETCH
332 .dw XT_EXIT
333  
334 ; ( -- f) Hardware Access
335 ; R( --)
336 ; check if unread characters are in the input queue.
337 VE_RX0Q:
338 .db $04, &quot;rx0?&quot;,0
339 .dw VE_HEAD
340 .set VE_HEAD = VE_RX0Q
341 XT_RX0Q:
342 .dw DO_COLON
343 PFA_RX0Q:
344 .dw XT_PAUSE
345 .dw XT_DOLITERAL
346 .dw usart0_rx_out
347 .dw XT_CFETCH
348 .dw XT_DOLITERAL
349 .dw usart0_rx_in
350 .dw XT_CFETCH
351 .dw XT_NOTEQUAL
352 .dw XT_EXIT
353 </pre>
354  
355 <p>
356 <input type=button onClick="history.back()" value="Back">
357 <input type=button onClick="history.forward()" value="Forward">
358 <a href="../WordList.en.html">Jump to Vocabulary</a>
359 </p>
360  
361 </div>
362  
363 <!-- AUTOINCLUDE START "Page/Footer.en.ihtml" DO NOT REMOVE -->
364 <!-- ============== FOOTER ============== -->
365 <div class="Footer">
366 <script type="text/javascript">
367 <!--
368 SetRelativePath("../../../../");
369 DrawFooter();
370 // -->
371 </script>
372 <noscript>
373 <p><b> JavaScript is required for including of the footer </b></p>
374 </noscript>
375 </div>
376 <!-- AUTOINCLUDE END -->
377  
378 </body>
379 </html>