103 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			NASM
		
	
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			NASM
		
	
	
	
	
	
; TM404A 40x4 characters LCD display (based on SN76489 chip) driver
 | 
						||
; @author Daniele Verducci
 | 
						||
; @language: Z80 ASM
 | 
						||
;
 | 
						||
;
 | 
						||
; This file is part of Pat80 Memory Monitor.
 | 
						||
;
 | 
						||
; Pat80 Memory Monitor is free software: you can redistribute it and/or modify
 | 
						||
; it under the terms of the GNU General Public License as published by
 | 
						||
; the Free Software Foundation, either version 3 of the License, or
 | 
						||
; (at your option) any later version.
 | 
						||
;
 | 
						||
; Pat80 Memory Monitor is distributed in the hope that it will be useful,
 | 
						||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						||
; GNU General Public License for more details.
 | 
						||
;
 | 
						||
; You should have received a copy of the GNU General Public License
 | 
						||
; along with Pat80 Memory Monitor.  If not, see <http://www.gnu.org/licenses/>.
 | 
						||
;
 | 
						||
 | 
						||
; --------------------------------------------------------------------------
 | 
						||
;
 | 
						||
; This is meant to be used with a 40x4 character display (containing a dual hd44780-compatible controller) like the TM404A.
 | 
						||
; This kind of display uses two controllers to overcome the hd44780 controllers limitation of 80 addressable characters.
 | 
						||
; It is seen as two separate displays, and thus have two EN pins. A finer implementation would apply some deconding logic to
 | 
						||
; an address bit to use a single port, but here we will use two different IO ports to save an IC.
 | 
						||
;
 | 
						||
; LCD config (IO port 0)
 | 
						||
LCD4004_TOP2LINES_PORT: EQU IO_2
 | 
						||
LCD4004_BOTTOM2LINES_PORT: EQU IO_3
 | 
						||
 | 
						||
 | 
						||
; PIN CONNECTIONS
 | 
						||
;
 | 
						||
; PIN   DESCRIPTION     TO PAT80 BUS PIN                INFO
 | 
						||
; ---------------------------------------------------------------------------------------------------
 | 
						||
; 1‐8   DB7‐DB0         DATA BUS
 | 
						||
; 9     E1 (chip en 1)  IOEN on LCD_TOP2LINES_PORT      Chip enable for top 2 lines
 | 
						||
; 10    R/W             IOWR
 | 
						||
; 11    RS              A4                              0: Command, 1: Data
 | 
						||
; 12 	V0 		        -	                            Power supply for contrast (approx. +0.5V)
 | 
						||
; 13 	Vss		        -	                            Ground
 | 
						||
; 14 	VDD 		    -	                            Power Supply Supply voltage for logic (+5.0V)
 | 
						||
; 15    E2 (chip en 2)  IOEN on LCD_BOTTOM2LINES_PORT   Chip enable for bottom 2 lines
 | 
						||
; 16 	NC 		        ‐ 	                            No Connect
 | 
						||
;
 | 
						||
 | 
						||
 | 
						||
; The 40x4 LCD memory map is the following:
 | 
						||
;
 | 
						||
; LINE      CHIP EN PIN     START ADDR      END ADDR
 | 
						||
; ----------------------------------------------------
 | 
						||
; 1         9               0x00 (0)        0x27 (39)
 | 
						||
; 2         9               0x40 (64)       0x67 (103)
 | 
						||
; 3         15              0x00 (0)        0x27 (39)
 | 
						||
; 4         15              0x40 (64)       0x67 (103)
 | 
						||
;
 | 
						||
; When we reach 0x40 on the first controller, we switch to the second.
 | 
						||
; When we reach 0x40 on the second controller, we must shift
 | 
						||
; all the lines up by one and position the cursor at 0x40.
 | 
						||
 | 
						||
; variables
 | 
						||
LCD4004_VAR_SPACE: EQU DRV_IO_2_VAR_SPACE
 | 
						||
LCD4004_CURSOR_POSITION_CONTROLLER: EQU DRV_IO_2_VAR_SPACE  ; In which LCD controller is the cursor (0 or 1)
 | 
						||
LCD4004_CURSOR_POSITION_CONTROLLER_MEMORY: EQU DRV_IO_2_VAR_SPACE + 1   ; Memory position of the cursor inside the controller's memory
 | 
						||
 | 
						||
; functions
 | 
						||
 | 
						||
; Initializes the driver and the LCD screen
 | 
						||
LCD4004_Initialize:
 | 
						||
    ; The following are documented as in the datasheet: RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
 | 
						||
    ; Function set: 0 0 0 0 1 DL N F 0 0 (DL: 8-bit/4-bit, N: number of display lines 2/1, F: Font type 11dots/8dots)
 | 
						||
    ; 0000111000 (8 bit, 2 lines)
 | 
						||
    
 | 
						||
    ; Display ON/OFF Control: 0 0 0 0 0 0 1 D C B (D: display on/off, C: cursor on/off, B: blinking cursor on/off)
 | 
						||
    ; 0000001111 (display on, blinking cursor)
 | 
						||
    ; Clear display
 | 
						||
    ; 0000000001
 | 
						||
 | 
						||
 | 
						||
; Move cursor (set DDRAM address in address counter)
 | 
						||
LCD4004_MoveCursor:
 | 
						||
    ; 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 (ACx: Address)
 | 
						||
 | 
						||
 | 
						||
; Sends string
 | 
						||
; @param BC Pointer to a null-terminated string first character
 | 
						||
LCD4004_print:
 | 
						||
    ld a, (bc)  ; bc is the pointer to passed string's first char
 | 
						||
    cp 0        ; compare A content with 0 (subtract 0 from value and set zero flag Z if result is 0)
 | 
						||
    ret z       ; if prev compare is true (Z flag set), string is finished, return
 | 
						||
    out (TERM_DATA_REG),a    ; output char
 | 
						||
    inc bc ; increment bc to move to next char
 | 
						||
    jp LCD4004_print
 | 
						||
 | 
						||
; Writes a single character
 | 
						||
; @param A Value of character to print
 | 
						||
LCD4004_printc:
 | 
						||
    out (TERM_DATA_REG),a
 | 
						||
    ret
 | 
						||
 |