; ------------------------------------------------- ; lcd.inc.jsm ; ------------------------------------------------- ; needs xmem-address definition for ; - lcd_port (LCD-Base) ; needs delay.inc.jsm ; ------------------------------------------------- lcd_cmd: equ 0x00 lcd_rd: equ 0x20 lcd_data: equ 0x40 lcd_enable: equ 0x80 LCD_CMD_Z1: equ 0x80 LCD_CMD_Z2: equ 0xC0 LCD_CMD_CLEAR: equ 0x01 ; ------------------------------------------------- ; Init LCD ; ------------------------------------------------- LCD_init: mov R2, 0x00 mov R0, 0x03 call _write_lcd call delay10ms mov R2, 0x00 mov R0, 0x03 call _write_lcd call delay10ms mov R2, 0x00 mov R0, 0x02 call _write_lcd call delay1ms ; 1. Function set: 4-Bit mode, two display lines mov R0, 0x28 call LCD_writecmd ; 2. Display on, no cursor mov R0, 0x0C call LCD_writecmd ; 3. Cursor shift during write mov R0, 0x06 call LCD_writecmd ; 4. Display clear mov R0, 0x01 call LCD_writecmd ret ; ------------------------------------------------- ; LCD_waitbsy ; ------------------------------------------------- LCD_waitbsy: push R0 bsy_loop: call LCD_readstat and R0, 0x80 jz ex_bsy call delay1us jmp bsy_loop ex_bsy: pop R0 ret ; ------------------------------------------------- ; LCD_writecmd ; ------------------------------------------------- ; R0 = cmd LCD_writeaddr: LCD_writecmd: push R2 mov R2, lcd_cmd call LCD_write pop R2 ret ; ------------------------------------------------- ; LCD_putsx ; ------------------------------------------------- ; R1 = address of null-terminated string in XMEM LCD_putsx: push R0 putsx_loop: movx R0, (R1) inc R1 tst R0 jz putsx_ex call LCD_writechar jmp putsx_loop putsx_ex: pop R0 ret ; ------------------------------------------------- ; LCD_putsc ; ------------------------------------------------- ; R1 = address of null-terminated string in CMEM LCD_putsc: push R0 putsc_loop: movc R0, (R1) inc R1 tst R0 jz putsc_ex call LCD_writechar jmp putsc_loop putsc_ex: pop R0 ret ; ------------------------------------------------- ; LCD_writechar ; ------------------------------------------------- ; R0 = char LCD_writedata: LCD_writechar: push R2 mov R2, lcd_data call LCD_write pop R2 ret ; ------------------------------------------------- ; LCD_write ; ------------------------------------------------- ; R0 = input ; R2 = register LCD_write: call LCD_waitbsy push R0 swap R0 call _write_lcd pop R0 call _write_lcd ret ; ------------------------------------------------- ; LCD_readstat ; ------------------------------------------------- ; R0 = status LCD_readstat: push R2 mov R2, lcd_cmd call LCD_read pop R2 ret ; ------------------------------------------------- ; LCD_read ; ------------------------------------------------- ; R0 = output ; R2 = register LCD_read: call _read_lcd swap R0 push R0 call _read_lcd pop R2 or R0, R2 ret ; ------------------------------------------------- ; _write ; ------------------------------------------------- ; R0 = input _write_lcd: push R1 and R0, 0x0F mov R1, R0 or R1, R2 xout (lcd_port), R1 call delay1us mov R1, R0 or R1, R2 or R1, lcd_enable xout (lcd_port), R1 call delay1us mov R1, R0 or R1, R2 xout (lcd_port), R1 call delay1us or R1, lcd_rd xout (lcd_port), R1 pop R1 ret ; ------------------------------------------------- ; _read ; ------------------------------------------------- ; R0 = output _read_lcd: push R1 mov R1, lcd_rd or R1, R2 xout (lcd_port), R1 call delay1us mov R1, lcd_rd or R1, R2 or R1, lcd_enable xout (lcd_port), R1 call delay1us xin R0, (lcd_port) and R0, 0x0F mov R1, lcd_rd or R1, R2 xout (lcd_port), R1 call delay1us pop R1 ret