; ;**************************************************************************** ; ; Purpose: ; Provides An Interface To A LCD Display That Uses A Hitachi HD44100/ ; HD44780 Display Controller ; ; Date: ; 07/21/92 ; ; Author: ; John C. Wren ; ; Modications: ; 02/04/97 - Added Description Fields For Archive ; ; Processor: ; Generic 8031 ; ; Assembler: ; Avocet AVA51 ; ; Dependencies: ; LCD_IO.ASM, MACROS.INC ; ; Files: ; None ; ; Comments: ; While The LCD Display Supports LCD On/Off And Blink On/Off, There Are ; No Calls In Place To Support This. The Bits Are Present In Internal ; Bit Memory, If One Wished To Implement Functions To Support These. ; ; These Drivers Were Written With 1x16 And 2x16 Displays In Mind, But ; Should Not Require Much Alternation For Larger Displays. ; ; The Display Needs To Be Connected Such That The Status May Be Read ; Back. ; ; Philosophic: ; The Routines Starting With IO_ Should Be In IO.ASM, ETX Equate Should ; Be In The System EQUATES.INC File. ; ; Some Labels Are Shorted From A Truly Readable Form, Since This Code ; Was Originally Written Under An Assembler That Had An 8 Character ; Limitation On Labels. ; ; ;******************************************************************************* ; ; Include Files Go Here ; ; %include "equates.inc" %include "macros.inc" seg code ; ;******************************************************************************* ; ; Publics ; public LCD_INIT public LCD_MCT public LCD_MCT_CLEAR public LCD_MDT public LCD_MDT_CLEAR public LCD_OUT public LCD_CLEAR public LCD_CPOS public LCD_DMOD public LCD_CURSOR_ON public LCD_CURSOR_OFF ; extrn IO_LCD_RD extrn IO_LCD_WR extrn IO_LCDRS_LO extrn IO_LCDRS_HI extrn IO_LCDRW_LO extrn IO_LCDRW_HI extrn IO_LCDEN_LO extrn IO_LCDEN_HI ; ;**************************************************************************** ; ; Equates ; ETX equ 3 ; ASCII ETX Character ; E_LCDCOLUMNS equ 12 ; Number Of Columns E_LCDLINES equ 1 ; Number Of Lines ; ;**************************************************************************** ; ; Description: ; Initializes LCD Controller, Clears Display, Homes Cursor, Sets ; No Blinking, No Display Shift, 5 x 7 Font, 8 Bit Bus. ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY, PSW.Z, PSW.P, Acc, R2, R3 ; ; Stack: ; 4 Bytes, Not Including Called Routines ; ; Comments: ; Initialized Values: ; S=0 - No Display Shift ; I/D=1 - Cursor Moves To Right After Writing A Character ; D=1 - Display On ; C=0 - No Cursor Displayed ; B=0 - No Cursor Character Blink ; DL=1 - 8 Bit Data Bus ; N=0 - 1 Display Lines ; F=0 - 5 x 7 Dots ; ; The Display Is Cleared, And An Address Is Written Into DD Ram (To ; Establish That All Subsequent Writes Are Into DD Ram). ; LCD_INIT proc setb B_LCDONOFF ; LCD Display On clr B_LCDCURSOR ; Cursor Off clr B_LCDBLINK ; No Blinking ; call IO_LCDEN_LO ; Clear LCD Enable call l?p1 ; Send Init Byte call l?p1 ; Send Init Byte, Again call l?p1 ; Send Init Byte, Again call l?p1 ; Send Init Byte, Again call LCD_DMOD ; Set Display Mode call LCD_CLEAR ; Clear Display call LCD_WAIT ; Wait For Display To Finish mov a,#00000110b ; Entry Mode, Increase With No Shifting call LCD_IOC ; Strobe Data To Display mov D_LCDPOS,#000h ; Set Initial Cursor To 0 ret ; Return To Caller ; l?p1 mov a,#00110000b ; Function Set, 8 Bits, 1 Lines, 5 x 7 Dots call LCD_IOC ; Strobe Data To LCD Display mov r3,#0ffh ; R3 = ff mov r2,#0ffh ; R2 = ff l?p2 djnz r3,l?p2 ; Loop djnz r2,l?p2 ; Waste More Than 4.1 Ms ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Displays An ETX Terminated String In Code Space To The LCD. Does ; Not Check For A Messages That Are Longer Than The Display. ; ; Entry Requirements: ; DPTR Points To ETX Terminated String In Code Space ; ; On Exit: ; DPTR Remains Pointing To Start Of String ; ; Affected: ; PSW.CY, PSW.Z, PSW.P ; ; Stack: ; 5 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_MCT proc push acc ; Save Users Acc push dpl ; Save DPL push dph ; Save DPH ; l?p1 clr a ; A = 0, So DPTR + A Gives Correct Data movc a,@a+dptr ; Fetch Character To Output inc dptr ; Increment Data Pointer cjeq a,#ETX,l?p2 ; If ETX Character, Exit jz l?p2 ; If A 0x00, Exit call LCD_OUT ; Output Character jmp l?p1 ; Loop Until ETX ; l?p2 pop dph ; Recover DPH pop dpl ; Recover DPL pop acc ; Recover Acc ret ; Return If ETX endproc ; ;**************************************************************************** ; ; Description: ; Same As LCD_MCT, Only Clears Display First ; ; Entry Requirements: ; DPTR Points To ETX Terminated String In Code Space ; ; On Exit: ; DPTR Remains Pointing To Start Of String ; ; Affected: ; PSW.CY, PSW.Z, PSW.P ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_MCT_CLEAR proc call LCD_CLEAR ; Clear Display call LCD_MCT ; Display Message ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Displays An ETX Terminated String In External Data Space To The LCD. ; Does Not Check For A Messages That Are Longer Than The Display. ; ; Entry Requirements: ; DPTR Points To ETX Terminated String In External Data Space ; ; On Exit: ; DPTR Remains Pointing To Start Of String ; ; Affected: ; PSW.CY, PSW.Z, PSW.P ; ; Stack: ; 5 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_MDT proc push acc ; Save Users Acc push dpl ; Save DPL push dph ; Save DPH ; l?p1 movx a,@dptr ; Fetch Character To Output inc dptr ; Increment Data Pointer cjeq a,#ETX,l?p2 ; If ETX Character, Exit jz l?p2 ; If A 0x00, Exit call LCD_OUT ; Output Character jmp l?p1 ; Loop Until ETX ; l?p2 pop dph ; Recover DPH pop dpl ; Recover DPL pop acc ; Recover Acc ret ; Return If ETX endproc ; ;**************************************************************************** ; ; Description: ; Same As LCD_MDT, Only Clears Display First ; ; Entry Requirements: ; DPTR Points To ETX Terminated String In External Data Space ; ; On Exit: ; DPTR Remains Pointing To Start Of String ; ; Affected: ; PSW.CY, PSW.Z, PSW.P ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_MDT_CLEAR proc call LCD_CLEAR ; Clear Display call LCD_MDT ; Display Message ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Output Character To LCD Display ; ; Entry Requirements: ; Acc Has Character To Display ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; Increments Cursor Position, But Does Not Check If Running Off Of ; Display. ; LCD_OUT proc call LCD_WAIT ; Make Sure Display Not Busy call LCD_IOD ; Strobe Character To LCD Display inc D_LCDPOS ; Advance Character By One ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Clear LCD Display To Blanks ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 3 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_CLEAR proc push acc ; Save Acc call LCD_WAIT ; Make Sure Display Not Busy mov a,#001h ; LCD Clear Display Code call LCD_IOC ; Output Command mov D_LCDPOS,#00h ; LCD Cursor To Position 0, 0 pop acc ; Recover Acc ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Set LCD Cursor Position ; ; Entry Requirements: ; Acc Contains The Character Position. To Position To Line 2, Acc ; Would Contain 17. ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 3 Bytes, Not Including Called Routines ; ; Comments: ; Tailored To 1x16 Or 2x16 Displays. Needs Work For Larger Displays. ; LCD_CPOS proc push acc ; Don't Let User Know We Modified It call LCD_WAIT ; Make Sure LCD Not Busy anl a,#01fh ; Keep Only Low 5 Bits jb acc.4,l?p1 ; 0 <= Acc <= F, Fall Through mov D_LCDPOS,a ; Store New Cursor Position orl a,#080h ; OR In Set DD Ram Address Function call LCD_IOC ; Strobe Data To Display jmp l?p2 ; Skip To Routine End ; l?p1 anl a,#00fh ; Keep Low Character Position Bits orl a,#040h ; OR In Line 2 Address mov D_LCDPOS,a ; Store New Cursor Position orl a,#080h ; OR In Set DD Ram Address Command call LCD_IOC ; Strobe Data To Display ; l?p2 pop acc ; Recover Acc ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Set LCD Display Mode ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 3 Bytes, Not Including Called Routines ; ; Comments: ; Sets LCD On/Off, Cursor On/Off And Blink/No Blink Mode Based On Bits ; In Internal Memory. ; LCD_DMOD proc push acc ; Save Acc call LCD_WAIT ; Make Sure Display Not Busy mov a,#008h ; Set Mode Control Bit mov c,B_LCDONOFF ; Get On/Off Control mov acc.2,c ; Set It mov c,B_LCDCURSOR ; Get Cursor Mode mov acc.1,c ; Set It mov c,B_LCDBLINK ; Get Blink Mode mov acc.0,c ; Set It call LCD_IOC ; Strobe Bits To Display pop acc ; Recover Acc ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Enable LCD Cursor ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_CURSOR_ON proc setb B_LCDCURSOR ; Enable Cursor call LCD_DMOD ; Do It ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Disable LCD Cursor ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_CURSOR_OFF proc clr B_LCDCURSOR ; Disable Cursor call LCD_DMOD ; Do It ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Strobe Data In Latch To LCD Command Register ; ; Entry Requirements: ; Acc Contains Value To Send To LCD Command Register ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 4 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_IOC proc push dpl ; Save DPL push dph ; Save DPH call IO_LCDRS_LO ; Clear LCD Register Select call LCD_IO ; Load Command Register pop dph ; Recover DPH pop dpl ; Recover DPL ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Strobe Data In Latch To LCD Data Register ; ; Entry Requirements: ; Acc Contains Value To Send To LCD Data Register ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 4 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_IOD proc push dpl ; Save DPL push dph ; Save DPH call IO_LCDRS_HI ; Set LCD Register Select call LCD_IO ; Load Data Register pop dph ; Recover DPH pop dpl ; Recover DPL ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Strobe Data In Latch To LCD ; ; Entry Requirements: ; Register Select Is Presumed To Be Pointing To Either The Command ; Or Data Register. Acc Contains The Value To Write To The Selected ; Register. ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 2 Bytes, Not Including Called Routines ; ; Comments: ; None ; LCD_IO proc call IO_LCD_WR ; Write To LCD call IO_LCDRW_LO ; Set Write Mode call IO_LCDEN_HI ; Set LCD Enable call IO_LCDEN_LO ; Clear LCD Enable ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Description: ; Delay Until LCD Display Ready ; ; Entry Requirements: ; None ; ; On Exit: ; None ; ; Affected: ; PSW.CY ; ; Stack: ; 5 Bytes, Not Including Called Routines ; ; Comments: ; Requires That The LCD Be Connected Such That Read Operations Can ; Be Performed On The Display. ; LCD_WAIT proc push acc ; Save Acc push dpl ; Save DPL push dph ; Save DPH call IO_LCDRS_LO ; Set Command Register call IO_LCDRW_HI ; Set Read Mode call IO_LCDEN_HI ; Set LCD Enable Line ; l?p1 call IO_LCD_RD ; Read LCD jb acc.7,l?p1 ; Loop While Not Ready ; call IO_LCDEN_LO ; Clear LCD Enable Line call IO_LCDRW_LO ; Set LCD Back To Write Mode pop dph ; Recover DPH pop dpl ; Recover DPL pop acc ; Recover Acc ret ; Return To Caller endproc ; ;**************************************************************************** ; ; Data Area ; seg bit B_LCDONOFF ds 1 ; OnDisplay /Off Control B_LCDCURSOR ds 1 ; Cursor Control B_LCDBLINK ds 1 ; Blink Control ; seg data D_LCDPOS ds 1 ; LCD Cursor Position Storage ; ;**************************************************************************** ; end