LCD_EN equ P1.1 ;LCD Enable LCD_RS equ P1.0 ;LCD Register Select LCD_D7 equ P2.7 ;LCD Data port LCD_D6 equ P2.6 ;LCD Data port LCD_D5 equ P2.5 ;LCD Data port LCD_D4 equ P2.4 ;LCD Data port LED equ P2.0 dataflag equ 01h wordflag equ 02h ORG 0000H JMP init ORG 0060H init: ;configure all pins for push-pull output clr wordflag clr dataflag lcall LCD_init LCD_sendstring: jb wordflag, 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 wordflag clr dataflag mov A, #80H ;Display on, Curson blinking command acall send_byte 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 character in accumulator jz here ;go to exit if zero setb dataflag ;set flag to show that this is data acall send_byte ;send char inc dptr ;increment data pointer sjmp loop1 ;jump back to send the next character nextadr: mov A, #0C0H ;Display on, Curson blinking command clr dataflag acall send_byte loop2: clr a ;clear Accumulator for any previous data movc a,@a+dptr ;load the character in accumulator jz here ;go to exit if zero setb dataflag ;set flag to show that this is data acall send_byte ;send char inc dptr ;increment data pointer sjmp loop2 ;jump back to send the next character here: acall long_delay cpl LED ljmp LCD_sendstring string1: DB '0123456789abcdef',0h string2: DB ' LCD Test OK ',0h LCD_init: acall long_delay setb LCD_D4 setb LCD_D5 setb LCD_D6 setb LCD_D7 setb LCD_RS setb LCD_EN acall long_delay clr LCD_RS ;Selected command register clr LCD_EN ;Enable H->L acall long_delay mov A, #20H ;Set 4-bit mode clr dataflag ;set flag for control reg acall send_nibble acall long_delay mov A, #28H ;Set 4-bit mode clr dataflag ;set flag for control reg acall send_byte acall long_delay mov A, #28H ;Set 4-bit mode clr dataflag ;set flag for control reg acall send_byte acall delay mov A, #0FH ;Display on, Curson blinking command clr dataflag ;set flag for control reg acall send_byte ret send_byte: ;assumes the data to be sent is in the accumulator clr LCD_D4 clr LCD_D5 clr LCD_D6 clr LCD_D7 clr LCD_EN mov C, dataflag mov LCD_RS, C acall delay ;Write the data (high nibble) rlc A mov LCD_D7, C rlc A mov LCD_D6, C rlc A mov LCD_D5, C rlc A mov LCD_D4, C acall delay setb LCD_EN acall delay clr LCD_EN acall delay send_nibble: clr LCD_D4 clr LCD_D5 clr LCD_D6 clr LCD_D7 clr LCD_EN mov C, dataflag mov LCD_RS, C acall delay ;Write the data (low nibble) rlc A mov LCD_D7, C rlc A mov LCD_D6, C rlc A mov LCD_D5, C rlc A mov LCD_D4, C acall delay setb LCD_EN acall delay clr LCD_EN acall delay ret delay: mov r2, #05h wait_0: mov r3, #0FFh ;reg2 and reg3 wait_1: djnz r3, wait_1 djnz r2, wait_0 ret long_delay: mov r2, #70h ;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