;------------------------------------------------- ;Program: Bioslcd.ASM ;Update: 13 November 2003 ;Initial: 17 October 1991 ; ;By: Dr. Marcus O. Durham, PhD, PE ; Tulsa, OK, USA ; mod@superb.org ; www.ThewayCorp.com ;Copyright (c)1991, 2002. All rights reserved ; ;Purpose: ; A set of routines are provided to initialize ; and operate a liquid crystal display. ; ;Processor: 8031 family ;PROM: 8k (2000H) onboard ;Crystal: 11.059 MHz ;Baud: 9600 ;Handshake: not used at this speed ;Assembler: Intel ASM51 ; ;################################################# ; ; ASSIGNMENTS ; ;################################################# ;CONSTANTS ;------------------------------------------------- ; ;CHARACTERS, HOLD, COUNT CharL EQU 0EH ;character to LCD & Serial LoopC EQU 07H ;loop counter ;R2 EQU 02H ;loop, destination size,mat Pio EQU 0A0h ;Port 2 LcdRS EQU 0B2h ;port 3.2 LcdRW EQU 0B6h ;port 3.6, write not line LcdEn EQU 0B4h ;port 3.4 ;################################################# ; ; PROGRAM ; ;################################################# ORG 00H START: ;------------------------------------------------- LJMP INITIAL ORG 0080H ;Addres past reserve ;------------------------------------------------- INITIAL: ;------------------------------------------------- ; ; The procedure initializes all common routines. ; It directs traffic for initiation messages. ;LCD INITIALIZE LCALL SCRINIT ;initialize screen ;------------------------------------------------- MAIN: ;------------------------------------------------- ; ; The main procedure directs traffic. ; The main orchestrates execution of the ; subroutines. ;PROCESS MOV DPTR,#SerGreet ;get address LCALL BIOSLCD ;message headr RS232 LCALL BIOSLCD ;second line MAN9: LJMP MAN9 ;Halt ;------------------------------------------------- BIOSLCD: ;------------------------------------------------- ; ; Send LCD message ; The first byte is the # of characters to send. MOV A,#0 ;read initial byte MOVC A,@A+DPTR ;input byte MOV LoopC,A ;set up loop MOV A,#1 ;length of message MOVC A,@A+DPTR MOV CharL,A LCALL SCRINST LCALL DLYMIL BIOL2: MOV A,#2 ;get 1st message MOVC A,@A+DPTR ;input byte MOV CharL,A ;character lcd ;LCD DATA LCALL DLYMIC ;wait for next byte LCALL SCRDATA ;send out byte INC DPTR ;restore offset DJNZ LoopC,BIOL2 ;go thru loop INC DPTR INC DPTR RET ;************************************************* ; ; LCD SETUP ; ;************************************************* ; ; Because of the control sequence, the LCD ; appears somewhat tedious. ; ; There are three groups of routines. ; 1. LCD control lines ; 2. LCD initialize, instruction, data, & busy ; 3. Message to display info. ; ; The LCD has 14 pins. ; 1 = Vss, ground ; 2 = Vdd, 5 V ; 3 = Vo, power for liquid crystal drive ; 4 = RS, 0= instruction, 1= data Reg. Select ; 5 = RW, 0= Write, 1= Read ; 6 = Enable ; 7-14 = DB0-DB7 data bits ; ; The LCD control lines are connected thru a ; register. ; The LCD control lines are programmed as bits ; RS = bit ; RW'= bit ; EN = bit ; ;------------------------------------------------- ;SCREEN INSTRUCTION CODES ;------------------------------------------------- ; The following codes are required by the LCD ; display. The LCD can receive instructions for ; set-up, send status, receive display data, or ; send the data currently in the display back to ; the microcontroller. ; Two address lines (XX)select the function. ; ; Instruction Codes ; 01 ;clear and home ; 02 ;home ; 04 ;cursor increment w/ data display ; 06 ;cursor decrement w/ data display ; 0A ;cursor on, flash off ; 0B ;cursor on, flash on ; 10 ;move cursor left ; 14 ;move cursor right ; 38 ;function set -8bit, 2line, 5x7dot ; 8X ;cursor position= DDRAM address ; 81 ;each line has 40 chars, 1=home ; C1 ;41=2nd line home, 80+41=C1 ; ; Status Response ; 8X ;busy flag, X=current address ; 0X ;clear, ready to accept data ; ; Write Data ; ;8 bits of data to display ; ; Read Data ; ;8 bits of data from display ; ; All instructions have a TYPICAL execution time ; of "40us" in the LCD module except instructions ; Clear Diplay and Return Home. These two ; have a TYPICAL execution time of 1.64ms. ; ; The LCD busy flag (BF) is clear when the LCD ; module is ready to accept another instruction. ; ; The LCD busy flag (BF) cannot be read until ; the first 3 LCD initialization bytes have been ; processed by the LCD module. Thus BF is not ; tested in this subroutine. ; ; Interfacing the LCD to port 1 allows the uC to ; use any crystal frequency available. A ; memory-mapped interface limits uC frequency to ; values less than about 9 MHz. ; ; Installation of different crystal frequencies ; dictates changing the software counter used to ; create a 1ms delay. Insertion of NOPs may be ; necessary crystal frequencies above 40MHz. ; See subroutines for control line values. ;------------------------------------------------- SCRINIT: ;------------------------------------------------- ;--SUBS CALL - ; The routine initializes the Liquid Crystal ; Display. The busy flag stays busy until ; initialization is complete. The time is 15ms. ; Therefore delays must be built into the init ; routine before Busy can be used. ; ; Allow 15ms for Hitachi 44780 internal initial ; to complete after Vcc is applied. ; (Re: Standish document A93531B p. 2 & ; Hitachi document CD-E613P 0591 p. 90). ; ; The series of instructions are as required by ; Philips mfg data sheet. ; ; Instruction mode is used for all initializing. ; ; 232 must be on for LCD contrast control ; to get 10 volts. ; ; Delay is used rather than test for Busy line. ; If LCD is not plugged-in, then there is only ; a small delay. If Busy were checked, the ; process would hang. ;POWER ON RESET MOV LoopC,#20 ;20ms delay SCRNI1: LCALL DLYMIL ;1 ms routine DJNZ LoopC,SCRNI1 ;loop ;CLEAR REGISTERS MOV CharL,#30H ;#1 function set=8bit LCALL SCRINST ;send command MOV LoopC,#5 ;5ms delay SCRNI2: LCALL DLYMIL ;1 ms routine DJNZ LoopC,SCRNI2 ;loop MOV CharL,#30H ;#2 function set=8bit LCALL SCRINST ;send command LCALL DLYMIC ;>100 microsec MOV CharL,#30H ;#3 function set=8bit LCALL SCRINST ;send command LCALL DLYMIC ;>100 microsec ;SET CURSOR MOV CharL,#38H ;#4 funct set=8bit,2line LCALL SCRINST ;send command LCALL DLYMIC ;>100 microsec MOV CharL,#0FH ;cursor on, blink ; MOV CharL,#0CH ;cursor on,no blink LCALL SCRINST ;send command LCALL DLYMIC ;>100 microsec MOV CharL,#01H ;display clear LCALL SCRINST ;send command LCALL DLYMIL LCALL DLYMIL LCALL DLYMIL ;CHANGE MODE MOV CharL,#06H ;entry mode set LCALL SCRINST ;send command RET ;------------------------------------------------- DLYMIL: ;------------------------------------------------- ; Delays shorter than the interrupt cycle are ; required. Since this is outside the normal ; program polling, hard calculated delays are ; used. ; ; The delay is based on clock cycles. ; MOV=1, NOP=1, DJNZ=2. ; ; The cycles in the loop are calculated. ; (1) for MOV ; (2* count ) for both NOP's ; (2* count-1) for DJNZ ; (2) for last jump ; = Total cycles ; ; Old crystal frequency was 7.3728Mhz ; ; Time = #states(12) * Total cycles/crys freq ; 11.059 MHz = 1.085 microsecond ; ; The inside loop has 925 cycles. ; At 11.059MHz this represents 1.003 ms MOV R2,#231 ;max loop=0 DLYM1: NOP NOP DJNZ R2,DLYM1 ;inside loop RET ;------------------------------------------------- DLYMIC: ;------------------------------------------------- ; Delay = 50 microsecond ; ; Delays shorter than the interrupt cycle are ; required. Since this is outside the normal ; program polling, hard calculated delays are ; used. ; ; The inside loop has 49 cycles. ; At 11.059Mhz, ; 1.085 microsec * this represents 53 microsec MOV R2,#12 ;max loop=0 DLYC1: NOP NOP DJNZ R2,DLYC1 ;inside loop RET ;------------------------------------------------- SCRINST: ;------------------------------------------------- ; The routine writes instructions to LCD. ; Write an instruction to the LCD requires ; control line RS= 0 ; control line RW= 0 ; Enable must be low before change R/W' or RS. ; ; CAUTION: A delay after data, before deselect ; can be interrupted and cause erratic data. ; disable interrupts until complete. ;CONTRL INSTRUCTION CLR LcdEn ;clr enable lo CLR LcdRW ;instruction& write CLR LcdRS SETB LcdEn ;set enable ;DISABLE INTERRUPTS ; ANL IE,#7Fh ;disable main inter ;SEND INSTRUCTION MOV A,CharL ;select LCD data MOV Pio,A ;send out ;CONTROL INSTRUCTION CLR LcdEn ;clr enable lo LCALL DLYMIL ;longer delay ;ENABLE INTERRUPTS ; ORL IE,#80h ;enable all RET ;------------------------------------------------- SCRDATA: ;------------------------------------------------- ; The routine writes output data to LCD. ; ; Write data to the LCD requires ; control line RS= 1, data display on HD44780 ; control line RW= 0, to write ; Enable must be low before change R/W' or RS. ; ; CAUTION: A delay after data, before deselect ; can be interrupted and cause erratic data. ;CONTRL INSTRUCTION CLR LcdRW ;instruction& write SETB LcdRS SETB LcdEn ;set enable ;DISABLE INTERRUPTS ; ANL IE,#7Fh ;disable main inter ;SEND INSTRUCTION MOV A,CharL ;select LCD data MOV Pio,A ;send out ;CONTROL INSTRUCTION CLR LcdEn ;clr enable lo LCALL DLYMIC ;short delay ;ENABLE INTERRUPTS ; ORL IE,#80h ;enable all RET ;################################################# ; ; TABLES ; ;################################################# ; ; Tables are used to convert between formats. ; These include kepad & ASCII. ; ; Tables are also used to carry display messages. ; ; ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;TABLE SETUP - MESSAGES ;------------------------------------------------- ; Predefined messages are in code memory. ; These are used in BIOSSER. ; Place at end of program code or ORG out of way ; ; The first byte is the number of characters. ; The second byte is the cursor location for LCD. ; The next bytes are the ASCII message. ; ; The format for intel assembler is illustrated. ;SerGreet: DB 14, 0, 'uC BIOS 11V3- ';intel ; ; The format for Tasm is illustrated. ;SerGreet .BYTE 14 ; .BYTE 0 ; .TEXT "uC BIOS 11V3- "; ;------------------------------------------------- TABMESSG: ;------------------------------------------------- SerGreet: DB 8, 80h ,'uC Lcd--' DB 2,0C0h ,'hi' ;************************************************* END