Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/27/00 21:08
Read: times


 
#1979 - RE: LCD in 4bit mode problem
Hi Erik,

Please find below my complete code contains, LCD initializing, LCD_data_send routine, Wait routines and a sample data sent over to LCD.

I am using a 20x2 LCD. but the addresses of 16x2 and 20x2 are the same except 20x2 has four extended character location address at the end of each row.

LCD_STRT:
ACALL WT17MS
ACALL LCD_INIT
ACALL CLEAR_LCD
MOV IE,#82h ; global and Timer0 int. enable

MESSOUT:
ACALL INIT_MESS

LCD_INIT:
CLR RS ; this is going to be a command byte not the LDATA.
MOV LDATA,#30
ACALL LCD_SNT
ACALL WT17MS

CLR RS
MOV LDATA,#30
ACALL LCD_SNT
ACALL WAIT_4MS

CLR RS
MOV LDATA,#30
ACALL LCD_SNT
ACALL WAIT_LCD

CLR RS
MOV LDATA,#28h
ACALL LCD_SNT

CLR RS
MOV LDATA,#0Eh
ACALL LCD_SNT

CLR RS
MOV LDATA,#06h
ACALL LCD_SNT
RET

CLEAR_LCD:
CLR RS
MOV LDATA,#01h
ACALL LCD_SNT
ACALL WAIT_4MS
RET

; *****************
; * WAIT ROUTINES *
; *****************

;Waiting routine for LCD to become ready for LDATA acceptance.

WAIT_LCD:
MOV 08h,#01h
WAIT_F:
MOV 07h,#0FFh
WAIT:
DJNZ 07h,WAIT
DJNZ 08h,WAIT_F
RET ; end of wait call.


WAIT_4MS:
MOV 08h,#28
W_4MS:
MOV 07h,#180
W_LOOP:
DJNZ 07h,W_LOOP
DJNZ 08h,W_4MS
RET


WT17MS:
;MOV 02,#01h ; load reg R2(02) with 01h for test purpose
MOV 02,#40d ; load reg R2(02) with 04h
FIVEMS:
;MOV 01,#21D ; load R1 of bank0 by 21 decimal value for test
MOV 01,#218D ; load R1 of bank0 by 218 decimal value
COUNTs:
DJNZ 01,COUNTs ; decrement R1 and loop until zero.
DJNZ 02,FIVEMS ; decrement R2(02) and start 5 ms again
RET ; RETURN to main KB routine.
RET

; Routine for sending LDATA to LCD panel as 4bits x 2 = 8bits.

LCD_SNT:
ACALL WAIT_LCD ; wait for LCD to free before sending any further LDATA.
SETB E ; strobe enable bit to latch first 4 bit into LCD panel.
PUSH ACC
PUSH PSW
MOV A,LDATA
SWAP A
ANL A,#00001111b
ANL POUT,#11110000b
ORL POUT,A
CLR E
NOP
NOP
NOP
SETB E
MOV A,LDATA
ANL A,#00001111b
ANL POUT,#11110000b
ORL POUT,A
CLR E ; prepare enable to send the LDATA to lcd.
POP PSW
POP ACC
RET




;***********************************************************************
;* Routine for initial message to appear on LCD screen. *
;* Message will be "TIME: 00:00" , "Switchboard" *
;***********************************************************************

INIT_MESS:

MOV LDATA,#0C4h ; #0C4 move cursor position to the next line char first.
CLR RS ; tell LCD that this is a command
ACALL LCD_SNT
ACALL WAIT_4MS

SETB RS ; inform LCD panel that char. LDATA will be sent.
MOV LDATA,#'S'
ACALL LCD_SNT
MOV LDATA,#'w'
ACALL LCD_SNT
MOV LDATA,#'i'
ACALL LCD_SNT
MOV LDATA,#'t'
ACALL LCD_SNT
MOV LDATA,#'c'
ACALL LCD_SNT
MOV LDATA,#'h'
ACALL LCD_SNT

MOV LDATA,#20h
ACALL LCD_SNT

MOV LDATA,#'b'
ACALL LCD_SNT
MOV LDATA,#'o'
ACALL LCD_SNT
MOV LDATA,#'a'
ACALL LCD_SNT
MOV LDATA,#'r'
ACALL LCD_SNT
MOV LDATA,#'d'
ACALL LCD_SNT

;CLR RS
;MOV LDATA,#05h
;ACALL LCD_SNT

;CLR RS
;MOV LDATA,#18h
;ACALL LCD_SNT


MOV LDATA,#84H ;#084h mov cursor position to the LAST CHAR.
CLR RS ; tell LCD that this is a command
ACALL LCD_SNT
ACALL WAIT_4MS

ACALL WAIT_LCD ; call lcd wait routine.
SETB RS ; inform LCD panel that char. LDATA will be sent.
MOV LDATA,#'T' ; send character 'C' to LCD
ACALL LCD_SNT ; call send to lcd routine.
MOV LDATA,#'I' ; send char 'o' to LCD
ACALL LCD_SNT
MOV LDATA,#'M' ; send char 'm' to LCD
ACALL LCD_SNT
MOV LDATA,#'E' ; send char 'p' to LCD
ACALL LCD_SNT
MOV LDATA,#':' ; send char ':' to LCD
ACALL LCD_SNT
MOV LDATA,#20h ; send char 'space' to LCD
ACALL LCD_SNT

SETB RS ; inform LCD panel that char. LDATA will be sent.
MOV A,HBCD ; send hour high digit in bcd format
ANL A,#11110000b ; mast lower 4 bits
SWAP A
ADD A,#30h ; add ascii value factor
DA A
MOV LDATA,A
ACALL LCD_SNT

MOV A,HBCD ; send hour low digit in bcd format
ANL A,#00001111b ; mask upper 4 bits
ADD A,#30h ; add ascii value factor
DA A
MOV LDATA,A
ACALL LCD_SNT

MOV LDATA,COLON ; send middle colon
ACALL LCD_SNT

MOV A,MBCD ; send minute high digit in bcd format
ANL A,#11110000b ; mask lower 4 bits
SWAP A
ADD A,#30h ; add ascii value factor
DA A
MOV LDATA,A
ACALL LCD_SNT

MOV A,MBCD ; send minute low digit in bcd format
ANL A,#00001111b ; mask lower 4 bits
ADD A,#30h ; add ascii value factor
DA A
MOV LDATA,A
ACALL LCD_SNT

RET

LDATA is a temporary ram location, where I keep the character to be sent.


List of 8 messages in thread
TopicAuthorDate
LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      
RE: LCD in 4bit mode problem            01/01/70 00:00      

Back to Subject List