#include "dt_inc.s" .text .org 0x0 start: br+ main br+ main ret main: call+ u_init call+ u_recv_byte call u_send_newline ldis r1, 0x41 ; 'A' call u_send_byte call lcd_init ldis r1, 0x42 ; 'B' call u_send_byte call lcd_clear ldis r1, 0x43 ; 'C' call u_send_byte call lcd_home ldis r1, 0x44 ; 'D' call u_send_byte call+ u_send_newline ldis r0, 0x00 ; init line var (we begin at line 0 ofc) push r0 loop: call+ u_recv_byte ; print received Char on LCD cmpi r0, 0x0d ; change line on '\r' breq l_nl addi r1, r0, 0 call+ lcd_data br loop l_nl: pop r1 cmpi r1, 0 brnq l_ln1 l_ln0: ldis r1, 1 push r1 ldis r1, 0xc0 ; jump to second line call+ lcd_command call delay5ms br+ loop l_ln1: ldis r1, 0 push r1 ldis r1, 0x80 ; jump to first line call+ lcd_command br+ loop hang: br+ hang .define LCD_BASE, 0x2050 ; http://www.mikrocontroller.net/articles/AVR-Tutorial:_LCD#Routinen_zur_LCD-Ansteuerung lcd_data: lrs r2, r1, 4 andx r2, 0xf orx r2, 0x10 stw r2, 0(r12) call+ lcd_enable andx r1, 0xf orx r1, 0x10 stw r1, 0(r12) call+ lcd_enable call+ delay50us ret lcd_command: lrs r2, r1, 4 andx r2, 0xf stw r2, 0(r12) call+ lcd_enable andx r1, 0xf stw r1, 0(r12) call+ lcd_enable call+ delay50us ret lcd_enable: addinv r0, r0, 0 addinv r0, r0, 0 addinv r0, r0, 0 ldw r0, 0(r12) orx r0, 0x20 stw r0, 0(r12) addinv r0, r0, 0 addinv r0, r0, 0 addinv r0, r0, 0 addinv r0, r0, 0 addinv r0, r0, 0 ldw r0, 0(r12) ldis r5, 0xffdf and r0, r0, r5 stw r0, 0(r12) ret delay50us: ; @ 50 MHz ldis r0, 2500/2 ;ldis r0, 4000/2 delay50us_: subi r0, r0, 1 brnz+ delay50us_ ; not zero ret delay5ms: ; @ 50 MHz ldis r0, 5 ;ldis r0, 7 delay5ms_1: ldis r1, 50000/2 delay5ms_2: subi r1, r1, 1 brnz+ delay5ms_2 ; not zero subi r0, r0, 1 brnz+ delay5ms_1 ; not zero ret lcd_init: ldis r12, LCD_BASE@lo ldih r12, LCD_BASE@hi ldis r3, 50 powerupwait: call+ delay5ms subi r3, r3, 1 brnz+ powerupwait ldis r3, 0x3 stw r3, 0(r12) call+ lcd_enable call+ delay5ms call+ lcd_enable call+ delay5ms call+ lcd_enable call+ delay5ms ldis r3, 0x2 stw r3, 0(r12) call+ lcd_enable call+ delay5ms ; ldis r1, 0x24 ldis r1, 0x2c ; 4bit interface, 2/4zeiliges display, 5x10 font call+ lcd_command ldis r1, 0xf ; display an, cursor an, cursor blinkt call+ lcd_command ldis r1, 0x4 ; display fest call+ lcd_command ret lcd_clear: ldis r1, 0x1 call lcd_command call delay5ms ret lcd_home: ldis r1, 0x2 call lcd_command call delay5ms ret