APORT EQU 0FF00H BPORT EQU 0FF01H CPORT EQU 0FF02H CNTPORT EQU 0FF03H RARROW EQU 7EH ; right arrow LARROW EQU 7FH ; left arrow BLANK EQU 0A0H ; whitespace MITEM_SEP EQU 0F0h ; menu item separator MENU_SEP EQU 0F1h ; menu separator org 2000H ;***************************************************** ; Pin assignment ;***************************************************** ; APORT.7 - APORT.0 : DB7 - DB0 ; CPORT.3 -> E2 ; CPORT.2 -> E1 ; CPORT.1 -> RS ; CPORT.0 -> R/W ;****************************************************** mov sp,#40h call lcd_init set_8255_mode1: ; Initialising 8255 push a mov a,#88h ;A:OUT, B:OUT, C_u:IN C_l:OUT mov dptr,#CNTPORT movx @dptr,a pop a ret set_8255_mode2: ; Initialising 8255 push a mov a,#98h ;A:IN, B:OUT, C_u:IN C_l:OUT mov dptr,#CNTPORT movx @dptr,a pop a ret display_menu: ; address in DPTR push psw ; save contents of psw,a,b push a push b setb psw.4 clr psw.3 mov b,#00h mov a,b mov r5,dph mov r6,dpl call clear_lcd1 call clear_lcd2 mov dph,r5 mov dpl,r6 display_next_line: call display_line mov a,#00h movc a,@a+dptr inc b jb b.2,display_menu_done ;end if b=4 cjne a,#MENU_SEP,display_next_line ;end if reached menu separator display_menu_done: pop b ; restore pop a pop psw ret ;***THIS FUNC STARTS DISPLAYING A LINE IN PROG MEMORY UPTO MITEM_SEP FROM POSITION 1(not 0) ON THE GIVEN LINE ;*** AND LEAVES IN DPTR THE ADDRESS OF THE FOLLOWING BYTE display_line: ; line number in B, address in DPTR push psw setb psw.4 clr psw.3 mov r2,dph ; save dptr mov r3,dpl mov a,#01h call move_cursor mov dpl,r3 ; restore dptr mov dph,r2 mov a,#00h movc a,@a+dptr ; get first character display_line_loop: mov r3,dpl mov r2,dph jb b.1,w2c2 w2c1: call write_char_1 jmp written w2c2: call write_char_2 written: mov dpl,r3 ; restore dptr mov dph,r2 inc dptr mov a,#00h movc a,@a+dptr cjne a,#MITEM_SEP,display_line_loop display_line_done: pop psw ret del_character1: push psw push a setb psw.4 clr psw.3 mov a,#10h ; shift cursor left call write_comm_1 mov a,#BLANK call write_char_1 ; write a BLANK mov a,#10h ; shift cursor left call write_comm_1 pop a pop psw ret del_character2: push psw push a setb psw.4 clr psw.3 mov a,#10h ; shift cursor left call write_comm_2 mov a,#BLANK call write_char_2 ; write a BLANK mov a,#10h ; shift cursor left call write_comm_2 pop a pop psw ret write_char_1: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov r1,a mov a,#11110101b ; e2=0,e1=1,rw=0(write),rs=1(text) mov dptr,#CPORT movx @dptr,a mov a,r1 ; copy charcode mov dptr,#APORT movx @dptr,a mov a,#11110001b ;execute mov dptr,#CPORT movx @dptr,a call wait4lcd1 ; wait till busy pop psw pop a ; restore context ret write_char_2: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov r1,a mov a,#11111001b ; e2=1,e1=0,rw=0(write),rs=1(text) mov dptr,#CPORT movx @dptr,a mov a,r1 ; copy charcode mov dptr,#APORT movx @dptr,a mov a,#11110001b ;execute mov dptr,#CPORT movx @dptr,a call wait4lcd2 ; wait till busy pop psw pop a ; restore context ret move_cursor: ; row in b, col in a push a push psw setb psw.4 clr psw.3 jnb b.0,even_row add a,#40h ; add 40h for odd row even_row: add a,#80h ; command code added to DDRAM address ; new cursor position in a jb b.1,controller_2 controller_1: call write_comm_1 jmp moved controller_2: call write_comm_2 moved: pop psw pop a ret clear_lcd1: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov a,#1h ; clear lcd command call write_comm_1 pop psw pop a ; restore context ret clear_lcd2: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov a,#1h ; clear lcd command call write_comm_2 pop psw pop a ; restore context ret write_comm_1: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov r1,a mov a,#11110100b ; e2=0,e1=1,rw=0(write),rs=0(comm) mov dptr,#CPORT movx @dptr,a mov a,r1 ; copy command mov dptr,#APORT movx @dptr,a mov a,#11110000b ;execute mov dptr,#CPORT movx @dptr,a call wait4lcd1 ; wait till busy pop psw pop a ; restore context ret write_comm_2: push a push psw ; saving context setb psw.4 ; set register bank 10 clr psw.3 mov r1,a mov a,#11111000b ; e2=1,e1=0,rw=0(write),rs=0(comm) mov dptr,#CPORT movx @dptr,a mov a,r1 ; copy the command mov dptr,#APORT movx @dptr,a mov a,#11110000b ; execute mov dptr,#CPORT movx @dptr,a call wait4lcd2 ; wait till busy pop psw pop a ; restore context ret wait4lcd1: push a ; save context call set_8255_mode2 ; set APORT to IN mov a,#11110110b ; e2=0,e1=1,rw=1(read),rs=0(comm) mov dptr,#CPORT movx @dptr,a mov dptr,#APORT readytest1: call lcd_delay movx a,@dptr jb acc.7,readytest1 mov a,#11110010b mov dptr,#CPORT movx @dptr,a call set_8255_mode1 ; reset APORT to OUT pop a ret wait4lcd2: push a call set_8255_mode2 mov a,#11111010b mov dptr,#CPORT movx @dptr,a mov dptr,#APORT readytest2: call lcd_delay movx a,@dptr jb acc.7,readytest2 mov a,#11110010b mov dptr,#CPORT movx @dptr,a call set_8255_mode1 pop a ret lcd_init: push a mov a,#38H call write_comm_1 call write_comm_2 mov a,#0ch call write_comm_1 call write_comm_2 mov a,#01h call write_comm_1 call write_comm_2 mov a,#06 call write_comm_1 call write_comm_2 pop a ret lcd_delay: mov r4,#0FFH loop4lcd: djnz r4,loop4lcd ret