
EN equ P3.3	
RW equ P3.4	
RS equ P3.5	
DAT equ P1	

lcall init_lcd		;initialize lcd
lcall clear_lcd
	
mov A, #'H'		;send text data to lcd
lcall write_lcd_text	
mov A, #'e'	
lcall write_lcd_text	
mov A, #'l'	
lcall write_lcd_text	
mov A, #'l'	
lcall write_lcd_text	
mov A, #'o'	
lcall write_lcd_text

wait_lcd:
	clr RS			;command
	setb RW		;read command
	setb EN		;start lcd command
	mov P1, #0FFh	
	mov A, P1	
	jb ACC.7, wait_lcd	;if bit 7 high, lcd still busy
	clr EN			;finish command
	clr RW			;turf off RW for future commands
ret	
	
lcd_command:
	clr RS			;low to indicate command
	clr RW			;low to indicate write
	mov DAT, A	
	setb EN		;high to initiate command

	mov R0, #30h	
	loop:			;loops 48 times instead of 4
		nop			; to compensate for the Dallas' speed
		djnz R0, loop	

	clr EN
	lcall wait_lcd		;wait for command to execute
ret	

init_lcd:	
	mov A, #38h		;8-bit data bus, 5x8 font
	lcall lcd_command	
	mov A, #0Eh		;turn on lcd, turn on cursor
	lcall lcd_command	
	mov A, #06h		;turn on cursor auto advance
	lcall lcd_command	
ret	
	
clear_lcd:	
	mov A, #01h	
	lcall lcd_command	
ret
	
write_lcd_text:	
	setb RS		;RS high to indicate text
	clr RW			;RW low to indiacte write
	mov DAT, A	
	setb EN		;high to initiate command

	mov R0, #30h
	loop2:			;loops 48 times instead of 4
		nop			; to compensate for the Dallas' speed
		djnz R0, loop2	

	clr EN	
	lcall wait_lcd		;wait for command to execute
ret

end	


