$NOMOD51
$include (c8051f020.inc)               ; Include register definition file.


				ORG	0H

				MOV   XBR2, #0x40 ; Enable the Port I/O Crossbar

				MOV	A,#38H			;Display initialisation routine LCD 2 lines 5*7 matrix
				ACALL	COMNWRT   ;Call commad subroutine
				ACALL	DELAY			;Give LCD some time
				MOV	A,#0EH			;Display on, cursor on
				ACALL	COMNWRT		
				ACALL	DELAY
				MOV	A,#01				; clear LCD
				ACALL	COMNWRT
				ACALL	DELAY
				MOV	A,#06H			;shift cursor right
				ACALL	COMNWRT
				ACALL	DELAY
				MOV	A,#80H			; cursor at line 1, pos 0
				ACALL	COMNWRT
				ACALL	DELAY



				MOV A,#'H'			;display letter 'H'
				ACALL	DATAWRT		
				ACALL	DELAY

				MOV A,#'E'			;display letter 'E'
				ACALL	DATAWRT
				ACALL	DELAY

				MOV A,#'L'			;display letter 'L'
				ACALL	DATAWRT
				ACALL	DELAY

				MOV A,#'L'			;display letter 'L'
				ACALL	DATAWRT
				ACALL	DELAY

				MOV A,#'O'			;display letter 'O'
				ACALL	DATAWRT
				ACALL	DELAY

				;MOV A,#3CH 			;Activate second line
				;ACALL	COMNWRT
				;ACALL	DELAY

				;MOV A,#0C1H 		;Jump to second line, position 1
				;ACALL	COMNWRT
				;ACALL	DELAY

				;MOV A,#'H'			;display letter 'H'
				;ACALL	DATAWRT		
				;ACALL	DELAY


AGAIN:  SJMP AGAIN		;Stay here
		
COMNWRT:							;send command to LCD
				MOV	P1,A			;copy reg A to Port 1
				CLR	P2.0			;RS= 0 for command
				CLR	P2.1			;R/W/= 0 for write
				SETB	P2.2		;E=1 for high pulse
				ACALL	DELAY		;give LCD some time
				CLR	P2.2			;E=0 for H-to-L pulse
				RET

DATAWRT:							; write data to LCD
				MOV	P1,A			;copy reg A to Port 1
				SETB	P2.0		;RS= 1 for data
				CLR	P2.1			;R/W/= 0 for write
				SETB	P2.2		;E=1 for high pulse
				ACALL	DELAY
				CLR	P2.2			;E=0 for H-to-L pulse
				RET

		
DELAY:								;extra long delay
				MOV	R3,#50		; 50 or highr for fast CPUs 		 
HERE2:
				MOV	R4,#255		; R4=255
HERE:
	 			DJNZ	R4,HERE	;stay until R4 becomes 0
				DJNZ	R3,HERE2
				RET


				END