slowed down state change
[my-code/atmel.git] / beginners / test_ports_uart.asm
1 ;
2 ; test all ports and uart
3 ;
4
5 .include "../include/m32def.inc"
6
7 INIT:
8
9         ; all ports outputs
10         ldi r16,0xff
11         out DDRA,r16
12         out DDRB,r16
13         out DDRC,r16
14         out DDRD,r16
15
16         ; uart baudrate (8mhz -> 38.4k) + enable
17         ldi r16,0
18         out UBRRH,r16
19         ldi r16,12
20         out UBRRL,r16
21         sbi UCSRB,TXEN
22
23         ; led counter
24         ldi r17,0
25         ; loop counter
26         ldi r18,0
27
28 MAINLOOP:
29
30         ; reset loop counter
31         ldi r18,0
32
33         ; the delay loop
34         LOOP:
35         
36                 ; the dely loop in the delay loop
37                 ldi r22,0
38                 INNERLOOP:
39
40                         ldi r23,0
41                         IILOOP:
42                                 inc r23
43                                 cpi r23,0x40
44                                 brne IILOOP
45
46                         inc r22
47                         cpi r22,0xff
48                         brne INNERLOOP
49         
50                 ; increase loop counter
51                 inc r18
52
53                 ; check loop counter
54                 cpi r18,0xff
55
56                 ; continue if loop counter = 0xff
57                 ; else do loop again
58                 brne LOOP
59                 
60         ; shift the led counter
61         lsl r17
62         
63         ; set first bit if led counter is equal zero
64         cpi r17,0
65         brne LEDOUT
66         ldi r17,1
67
68         ; drive the leds
69         LEDOUT:
70         ldi r21,0xff
71         sub r21,r17
72         out PORTA,r21
73         out PORTB,r21
74         out PORTC,r21
75         out PORTD,r21
76
77         ; get the number we want to transmit
78         mov r19,r17
79         ldi r20,0x30 ; ascii 0
80         GETNUMBER:
81
82                 lsr r19
83                 inc r20
84                 cpi r19,0
85                 brne GETNUMBER
86
87         ; uart transmit
88         UARTOUT:
89
90                 ; try again if uart not ready
91                 sbis UCSRA,UDRE
92                 rjmp UARTOUT
93
94         ; transmit the number
95         out UDR,r20
96                 
97         ; loop forever
98         rjmp LOOP
99
100 ; eof