m820250324001rs232transmit.asm


;; (C) David Vajda
;; 2025-03-24
;; rs-232-transmit, and digital recording

.include "m8def.inc"

ldi r16, HIGH (RAMEND)
out SPH, r16
ldi r16, LOW (RAMEND)
out SPL, r16

ldi r16, 0x00
out DDRC, r16

ldi r16, HIGH (25)
out UBRRH, r16
ldi r16, LOW (25)
out UBRRL, r16

ldi r16, (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0)
out UCSRC, r16

ldi r16, (1 << TXEN)
out UCSRB, r16
loop1:
in r16, PORTC
andi r16, 0b00001111
swap r16
;rcall sleep
;in r17, PORTC
;andi r17, 0x0f
;or r16, r17
rcall rs232transmitrec
rcall sleep
ldi r16, 'd'
rcall rs232transmitrec
rjmp loop1

sleep:
push r16
push r17
ldi r16, 0x0f
sleep_loop1:
ldi r17, 0x0f
sleep_loop2:
dec r17
brne sleep_loop2
dec r16
brne sleep_loop1
pop r17
pop r16
ret

rs232transmitrec:
sbis UCSRA, UDRE
rjmp rs232transmitrec
out UDR, r16
ret