
;___________________________________________________________________________
;--------------------command and data write subroutines---------------------
;___________________________________________________________________________


cmdw:        acall write_4bit
             clr rs
             setb en
             clr en
	     acall delay_100us
	     acall write_4bit
	     clr rs
             setb en
             clr en
             ret

datw:        acall write_4bit
             setb rs
             setb en
             clr en
  	     acall delay_100us
             acall write_4bit
             setb rs
             setb en
             clr en
             ret

 ;--------------------4bit write sequence---------------------

write_4bit: push 00h
            ;mov r0,a

            rlc a
	    mov p0.0, c
	    rlc a
	    mov p0.1, c
	    rlc a
	    mov p0.2, c
	    rlc a
	    mov p0.3, c

	    ;mov a,r0
 	    pop 00h
	    ret
;___________________________________________________________________________
;--------------------------line select subroutines--------------------------
;___________________________________________________________________________


line1:       mov a,#80h	          ;initial position of cursor
             acall cmdw
	     acall delay_100us
	     ret

line2:       mov a,#0c0h		 ;initial position of cursor
             acall cmdw
	     acall delay_100us
  	     ret


;___________________________________________________________________________
;----------------------lcd initialisation subroutine------------------------
;___________________________________________________________________________


lcd4_initialise: acall delay_16ms   ;wait more than 15ms after vdd reaches 4.5v

                 mov a,#28h         ;2line 5x7 matrix
                 acall cmdw
                 acall delay_100us
	 
	         mov a,#0fh	        ;display on, cursor on, cursor blinking
		 acall cmdw
                 acall delay_100us
			 
		 mov a,#01h	        ;clear screen
		 acall cmdw
                 acall delay_100us
			 
		 mov a,#06h	        ;cursor and display shifts(right/left)
		 acall cmdw
                 acall delay_100us

		ret

;___________________________________________________________________________
;-------------------------------lcd main code-------------------------------
;___________________________________________________________________________


lcd4_main:   mov p0,#00h
             clr RS              ;make out pins
             clr EN              ;make out pins
              
	     acall lcd4_initialise  		 
;---------------------------------------------------------------------------
	     acall line1         ;select first or second line of display
			 
  	     mov a,# 'a'
             acall datw
             acall delay_half_second
 	     acall delay_half_second

             mov a,# 'b'
             acall datw
             acall delay_half_second
	     acall delay_half_second

 	     acall line2
             mov dptr,#disp_ashwin
 	     acall disp_message

	     sjmp $


end

