| ??? 02/21/04 07:44 Read: times |
#65246 - Here is the full code Responding to: ???'s previous message |
Dear Eric,
Instead of reading your code and trying to debug, I have provided a full code which has been fully checked and found OK. You can use it as is by changing the port and bit defenitions or use it as a guide. (I have a doubt on the LCD init routines in the code posted by you)
; PROGRAM TO TEST THE HD44780 LCD MODULE INTERFACE.
; Using 89c51RD2 with 6 MHz crsytal in 6 clock mode. Each machine cycle = 1us.
; 10 Jan 2003 : Checked out OK with Elnix-0803 PCB
;===========================================
;LCD hardware interface:
;( Change as required based on your hardware interface )
;P0 is used for LCD data bus
REGISBIT EQU P1.0 ; Data !Command register bit of LCD
MODEBIT EQU P1.1 ; Read !Write mode bit of LCD
ENABIT EQU P1.2 ; Enable bit of LCD
;==========================================
; LCD command bytes
FSET EQU 38H ; L=1(8 BITS),N=1(2LINE) ; 001L N000
DCB EQU 0CH ; DIS.ON=1,CUR.OFF=0,BLINK OFF=0; 0000 1DCB
CLEAR EQU 01H ; Clear display; 0000 0001
RH EQU 02H ; Return Home ; 0000 0010
SDD1 EQU 80H ; Set DDRAM address line1; 1000 0000
SEM EQU 06H ; Entry mode; INC=1, SHIFT=0; 0000 01IS
DCON EQU 18H ; DIS & CUR Control ; DIS SHIFT=1,LEFTWISE=0; 0001 SL00
;=========================================
ORG 0000H
JMP BEGIN
ORG 100H
BEGIN: NOP
INITLCD: CALL LCDSET
MAIN: MOV DPTR, #TXT ; Display the Message
CALL DISPLAY
WAIT: SJMP $ ; Wait here for reset .
;==========================================
; DISPLAY routine arranges to display the 32 characters that are pointed at by the DPTR.
; Call with DPTR pointing to the message to be displayed.
DISPLAY: MOV A, #80H ; Init display first line
CALL LCDCOM
MOV A, #CLEAR ; To clear the old message
CALL LCDCOM
CALL DLY10ms ; Delay to complete the clear
CALL SHOW ; Display the first line now
NXTLIN: MOV A, #0C0H ; Set address for 2nd line
CALL LCDCOM ; Write to LCD
CALL SHOW ; Display the second line.
RET
; SHOW routine arranges to move 16 charaters to the LCD one by one.
SHOW: MOV R2, #16 ; Counter for 16 Characters
NXT_C: MOV A, #0
MOVC A, @A+DPTR
CALL LCDCHR
INC DPTR
DJNZ R2, NXT_C
RET ; DPTR now at next line beginning
; LCDSET is a routine to initialize the Hitachi HD44780 type LCD modules
LCDSET: CALL DLY15ms ; Give some time for Vcc to stabilize
MOV A, #FSET ; Send FSET thrice in varying intervals
CALL LCDCOM
CALL DLY5ms
MOV A, #FSET
CALL LCDCOM
CALL DLY500us
MOV A, #FSET
CALL LCDCOM
MOV A, #DCB ; Set Display, Cursor and Blink options
CALL LCDCOM
DISPCLR: MOV A, #CLEAR
CALL LCDCOM
CALL DLY10ms ; Init at times does not happen without this delay
RET
; LCDCOM is for sending a command byte to the LCD.
LCDCOM: CLR REGISBIT ; Select command register
CLR MODEBIT ; So that you can Write
SETB ENABIT ; Enable LCD
MOV P0, A ; Move the data to LCD port
DELAY: MOV R3, #50 ; 100us Delay for each write. Works from 20us onwards
DJNZ R3, $
CLR ENABIT ; Disable LCD
RET
; LCDCHR is for sending one data byte to the LCD.
LCDCHR: SETB REGISBIT ; Select Data register
CLR MODEBIT ; So that you can Write
SETB ENABIT ; Enable LCD
MOV P0, A ; Move the data to LCD port
CALL DELAY
CLR ENABIT ; Disable LCD
RET
; Fixed duration delay routines.
DLY15ms: MOV R6, #30
CALL DLY500us
RET
DLY10ms: MOV R6, #20
CALL DLY500us
RET
DLY5ms: MOV R6, #10
CALL DLY500us
RET
; DLY500us causes a delay of 500us x R6 value when called. Call after loading R6 suitably
DLY500us: MOV R7,#250
DJNZ R7,$
DJNZ R6,DLY500us
RET
TXT: DB 'ABCDEFGHIJKLMNOP' ; First line message
TXT1: DB 'QRSTUVWYZ1234567' ; Second line message
END
Hope that helps. Raghu |
| Topic | Author | Date |
| keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| Here is the full code | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
| RE: keil evaluation board & lcd | 01/01/70 00:00 | |
RE: keil evaluation board & lcd | 01/01/70 00:00 |



