added ports/uart test code for atmega32
authorhackbard <hackbard>
Sat, 17 Jun 2006 12:53:06 +0000 (12:53 +0000)
committerhackbard <hackbard>
Sat, 17 Jun 2006 12:53:06 +0000 (12:53 +0000)
beginners/test_ports_uart.asm [new file with mode: 0644]

diff --git a/beginners/test_ports_uart.asm b/beginners/test_ports_uart.asm
new file mode 100644 (file)
index 0000000..f870a3e
--- /dev/null
@@ -0,0 +1,94 @@
+;
+; test all ports and uart
+;
+
+.include "../include/m32def.inc"
+
+INIT:
+
+       ; all ports outputs
+       ldi r16,0xff
+       out DDRA,r16
+       out DDRB,r16
+       out DDRC,r16
+       out DDRD,r16
+
+       ; uart baudrate (8mhz -> 38.4k) + enable
+       ldi r16,0
+       out UBRRH,r16
+       ldi r16,12
+       out UBRRL,r16
+       sbi UCSRB,TXEN
+
+       ; led counter
+       ldi r17,0
+       ; loop counter
+       ldi r18,0
+
+MAINLOOP:
+
+       ; reset loop counter
+       ldi r18,0
+
+       ; the delay loop
+       LOOP:
+       
+               ; the dely loop in the delay loop
+               ldi r22,0
+               INNERLOOP:
+
+                       inc r22
+                       cpi r22,0xff
+                       brne INNERLOOP
+       
+               ; increase loop counter
+               inc r18
+
+               ; check loop counter
+               cpi r18,0xff
+
+               ; continue if loop counter = 0xff
+               ; else do loop again
+               brne LOOP
+               
+       ; shift the led counter
+       lsl r17
+       
+       ; set first bit if led counter is equal zero
+       cpi r17,0
+       brne LEDOUT
+       ldi r17,1
+
+       ; drive the leds
+       LEDOUT:
+       ldi r21,0xff
+       sub r21,r17
+       out PORTA,r21
+       out PORTB,r21
+       out PORTC,r21
+       out PORTD,r21
+
+       ; get the number we want to transmit
+       mov r19,r17
+       ldi r20,0x30 ; ascii 0
+       GETNUMBER:
+
+               lsr r19
+               inc r20
+               cpi r19,0
+               brne GETNUMBER
+
+       ; uart transmit
+       UARTOUT:
+
+               ; try again if uart not ready
+               sbis UCSRA,UDRE
+               rjmp UARTOUT
+
+       ; transmit the number
+       out UDR,r20
+               
+       ; loop forever
+       rjmp LOOP
+
+; eof