
RS EQU P2.0
RW EQU P2.1
EN EQU P2.2
LCD_DATA BIT P2.4
LCD_CLK BIT P2.5
LCD_STB BIT P2.6
LCD_OE BIT P2.7
;main program
ORG 0000H
CLR LCD_STB
CLR LCD_OE
CLR RW ;because we are writing to lcd
ACALL LCD_CLR ;clear display
ACALL LCD_INIT ;initialize the lcd
ACALL LCD_CLR ;clear display
MOV A, #'D' ;here we sending a single character at a time and then call lcd_data to tell
ACALL LCD_DATA ;lcd that we sending some thing to display on lcd
MOV A, #'E'
ACALL LCD_DATA
MOV A, #'B'
ACALL LCD_DATA
MOV A, #'A'
ACALL LCD_DATA
MOV A, #'S'
ACALL LCD_DATA
MOV A, #'H'
ACALL LCD_DATA
MOV A, #'I'
ACALL LCD_DATA
MOV A, #'S'
ACALL LCD_DATA
MOV A, #'H'
ACALL LCD_DATA
MOV A, #'.'
ACALL LCD_DATA
MOV A, #'.'
ACALL LCD_DATA
MOV A, #' '
ACALL LCD_DATA
SJMP $
;......................
;all the subroutine goes here
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LCD_CLR:
MOV A, #01H ;clear lcd
ACALL LCD_CMD ;sending command to lcd
RET
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LCD_INIT:
ACALL DELAY ;some delay to lcd after power on
ACALL DELAY
MOV A, #38H ;telling the lcd that we use 8 bit mode,
;2 line display and 5x7 font
;#38h because here dl=1,n=1 and f=0
;in "set interface length"
ACALL LCD_CMD ;sending command to lcd
MOV A, #0EH ;we use display on,cursor on and cursor blinking off
;#0ch to display on,cursor off and cursor blinking off
ACALL LCD_CMD ;sending command to lcd
MOV A, #06H ; cursor position auto increment and move cursor to
;right #04 cursor moved to left
ACALL LCD_CMD ;sending command to lcd
RET
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;......................
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LCD_CMD:
CLR RS ;telling the lcd that the data is a command
;mov p1,a ; command is send to the port
ACALL SEND_DATA
SETB EN ; make en high
ACALL DELAY ;a short delay
CLR EN ;en is low to make a higt-low pulse
RET ;return
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LCD_DATA:
SETB RS ;telling the lcd that the data which is being send is to be displayed
;mov p1, a ;data to displayed is stored in a and now send to port p1
ACALL SEND_DATA
SETB EN ;en is high
ACALL DELAY ;a short delay
CLR EN ;en is low to make a high-low pulse
RET ; return to main
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++
;serial bit send
SEND_DATA: MOV R2, #08H
SEND_BIT: RLC A
MOV LCD_DATA, C
CLR LCD_CLK
NOP
SETB LCD_CLK
DJNZ R2, SEND_BIT
SETB LCD_OE
SETB LCD_STB
NOP
CLR LCD_STB
RET
DELAY:
MOV R0, #5H
L2: MOV R1, #0FFH
L1: DJNZ R1, L1
DJNZ R0, L2
RET
;+++++++++++++++++++++++++++++++++++++++
END ; end of code
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Download Code and Model