LCD_data equ P2 ;LCD Data port LCD_rs equ P0.2 ;LCD Register Select LCD_rw equ P0.1 ;LCD Read/Write LCD_en equ P0.0 ;LCD Enable bitflag equ 1 ORG 0000H JMP init ORG 0060H init: clr bitflag setb LCD_rs ;Selected command register clr LCD_rw ;We are writing in instruction register setb LCD_en ;Enable H->L acall long_delay lcall LCD_init LCD_sendstring: mov LCD_data,#80H ;position cursor clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay jb bitflag, nextptr mov dptr, #string1 ;string1 is the label where the string is stored sjmp skip1 nextptr: mov dptr, #string2 ;string2 is the label where the string is stored skip1: cpl bitflag mov r0, #08h loop1: mov a, r0 jz nextadr dec a mov r0, a clr a ;clear Accumulator for any previous data movc a,@a+dptr ;load the first character in accumulator jz here ;go to exit if zero acall lcd_senddata ;send first char inc dptr ;increment data pointer sjmp loop1 ;jump back to send the next character acall long_delay nextadr: mov LCD_data,#0C0H ;Display on, Curson blinking command clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay loop2: clr a ;clear Accumulator for any previous data movc a,@a+dptr ;load the first character in accumulator jz here ;go to exit if zero acall lcd_senddata ;send first char inc dptr ;increment data pointer sjmp loop2 ;jump back to send the next character here: acall long_delay ljmp LCD_sendstring string1: DB '0123456789abcdef',0h string2: DB ' Sally Test LCD ',0h LCD_init: mov LCD_data,#0FH ;Display on, Curson blinking command clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay mov LCD_data,#38H ;Function Set 2-line mode (even for 16x1!) clr LCD_rs ;Selected instruction register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay ret LCD_senddata: mov LCD_data,A ;Move the command to LCD port setb LCD_rs ;Selected data register clr LCD_en acall delay setb LCD_en ;Enable H->L acall delay ret delay: mov r2, #01h wait_0: mov r3, #0FFh ;reg2 and reg3 wait_1: djnz r3, wait_1 djnz r2, wait_0 ret long_delay: mov r2, #03h ;initialise counters wait_2: mov r3, #0ffh ;reg2 and reg3 wait_3: mov r4, #0ffh ;reg2 and reg3 wait_4: djnz r4, wait_4 djnz r3, wait_3 djnz r2, wait_2 ret end