| ??? 10/09/02 04:40 Read: times |
#30448 - RE: LCD still doesn\\\\\\\'t work |
Try the code below. I am using an 80c31 Mc, so check its data book from Phillips and the one you are using to see the similarities. The LCD I am using is a 20 by 4 lines.
;==constants=============================== LCD_DATA equ 090h LCD_RS equ 0B5h LCD_RW equ 0B6h LCD_E equ 0B7h ;==system instructions================ Config equ 38h entryMode equ 6 ;increment curser ;to the right, ; do not shift display ;==curser control instructions============= offCur equ 0Ch lineCur equ 0Eh blinkCur equ 0Dh combnCur equ 0Fh homeCur equ 02h shLfCur equ 10h shRtCur equ 14h blank bit 16h AM_PM equ 45h ;==display control instructions============ clrDsp equ 01h offDsp equ 0Ah onDsp equ 0Eh shLfDsp equ 18h shRtDsp equ 1Ch ;******************************************** lcall resetLCD ; duplicate power on reset lcall initLCD ; initialize fonts, #lines, Entry Mode rep_scr: mov r0,#01h ;clear LCD lcall wrLCDcom lcall prtLCD ; db 'Osman Kargbo',0 ; display ;for first line ;******************************************* ; Subroutine wrLCDdata ; ; Write a data word to the LCD ; input: r0 = data word ;******************************************* wrLCDdata: clr LCD_E setb LCD_RS ; Select send Data clr LCD_RW ; Select ;write operation mov LCD_DATA,r0 ; Load command ;into port lcall pulseEwait ; Pulse the ;enable line ret ;return ;******************************************* ; Subroutine wrLCDcom ; ; Write a command word to the LCD ; input: r0 = command word ;******************************************* wrLCDcom: clr LCD_E clr LCD_RS ; Select ;send command clr LCD_RW ; Select ;Write operation mov LCD_DATA,r0 ; Load command ;into port call pulseEwait ; Pulse the ;enable line ret ;return ;*************************************************************** ; Subroutine pulseEwait ; ; Generates a positive pulse on the LCD enable line. ; Waits 5.5 ms ; ; input: none ; output: none ; destroys: LCD_RW, LCD_RS, LCD_DATA ;*************************************************************** pulseEwait: ;clr LCD_E setb LCD_E ; Pulse the ;Enable line. clr LCD_E mov LCD_DATA,#0FFh ; Prepare port ;for input ;setb LCD_RW ; Prepare R/W ;for read operation setb LCD_E ; Start the ;Enable pulse clr LCD_E ; stop the ;enabling pulse LCALL Delay_5_5ms ret ;******************************************* ; Subroutine initLCD ; ; Initialize the LCD ;****************************************** initLCD: clr LCD_RS ;LCD Register Select line clr LCD_RW ; Read/Write line clr LCD_E ; Enable line mov r0,#38h ; Function set - 4 lines 5x7 fonts lcall wrLCDcom mov r0,#00001010b ; Display OFF lcall wrLCDcom MOV r0,#01h ;clear display lcall wrLCDcom mov r0,#06h ;Set Entry Mode lcall wrLCDcom ; Increment ;cursor to right, no display shift mov r0,#0Eh ; display on lcall wrLCDcom ret ;****************************************** ; Subroutine resetLCD ; ; Reset the LCD. ; software version of the power on ; reset operation ;***************************************** resetLCD: clr LCD_RS ; LCD Register Select line clr LCD_RW ; Read/Write line clr LCD_E ; Enable line mov LCD_DATA,#30h ; Step 1 setb LCD_E ; Start Enable pulse clr LCD_E ; End Enable pulse lcall Delay_5_5ms mov LCD_DATA,#30h ; Step 2 setb LCD_E ; Start Enable pulse clr LCD_E ; End Enable pulse lcall Delay_5_5ms mov LCD_DATA,#30h ; Step 3 setb LCD_E ; Start Enable pulse clr LCD_E ; End Enable pulse lcall Delay_5_5ms mov r0,#Config ; Function Set lcall wrLCDcom mov r0,#08h ; Set Entry Mode lcall wrLCDcom ; Increment ;cursor, do not shift display ret ;****************************************** ; Subroutine prtLCD ; ; Takes the string immediately ; following the call and ; displays on the LCD. String must ; be terminated with a ; null (0). Upon termination this ; routine jumps to the ; instruction immediately following ; the string. ; ; input: none ; output: none ; destroys: acc, dptr ;***************************************** prtLCD: pop dph ; pop return address into dptr pop dpl prtNext: clr a ; set offset=0 movc a,@a+dptr ; get chr from code memory cjne a,#0,chrOK ; if chr=0 ;then return sjmp retPrtLCD chrOK: mov r0,a lcall wrLCDdata ; send character inc dptr ; point at next character ajmp prtNext ; loop till end of string retPrtLCD: jmp @a+dptr ; return with a ;jump instruction end thanks Osman |



