;; (C) David Vajda ;; 2024-12-20 ;; LCD - RS232 .include "m8def.inc" ldi r16, HIGH (RAMEND) out SPH, r16 ldi r16, LOW (RAMEND) out SPL, r16 ldi r16, 0xff out DDRB, r16 rcall lcd_init 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 << RXEN) out UCSRB, r16 urecieve: sbis UCSRA, RXC rjmp urecieve in r16, UDR rcall lcd_data rjmp urecieve sleep: push r16 ldi r16, 0xff sleep_loop1: dec r16 brne sleep_loop1 pop r16 ret lcd_enable: sbi PORTB, 5 nop nop nop cbi PORTB, 5 ret lcd_init: push r16 rcall sleep ldi r16, 0x03 out PORTB, r16 rcall sleep ldi r16, 0x03 out PORTB, r16 rcall sleep ldi r16, 0x03 out PORTB, r16 ldi r16, 0x02 rcall lcd_cmd ldi r16, 0x20 rcall lcd_cmd ldi r16, 0x01 rcall lcd_cmd ldi r16, 0x02 rcall lcd_cmd pop r16 ret lcd_data: push r17 push r16 mov r17, r16 swap r16 andi r16, 0x0f andi r17, 0x0f ori r16, 0b00010000 ori r17, 0b00010000 out PORTB, r16 rcall lcd_enable out PORTB, r17 rcall lcd_enable rcall sleep pop r16 pop r17 ret lcd_cmd: push r17 push r16 mov r17, r16 swap r16 andi r16, 0x0f andi r17, 0x0f out PORTB, r16 rcall lcd_enable out PORTB, r17 rcall lcd_enable rcall sleep pop r16 pop r17 ret |