
; PC-LCD operator
; X-tal op 11.0952 MHz
;-----Controller declaration------------------------

;	PORTS
;	P0	LCD Data bus
;	P1	
;	P2	Control Port
;		P2.0	LCD EN
;		P2.1	LCD R/W
;		P2.2	LCD RS
;		P2.3	230 V~ Output
;		P2.4
;		P2.5	N/A
;		P2.6	N/A
;		P2.7	N/A
;	P3	Communication port
;		P3.0	RXD
;		P3.1	TXD
;		P3.5	LED

;	REGISTERS
;	R0	
;	R1		
;	R2
;	R3
;	R4
;	R5
;	R6
;	R7

;	MEMORY
;	TIMERS
;	T1	Serial Baudrate generator	





#include 8051.H


;-------Main routine----------------------------
	.org	0000H
	ajmp	Main

	.org	0010H
Main	acall	Init	
run	aCALL	CLEAR_LCD
	acall	TXT		; call send
;	sjmp	run

	.end


;-------SUB routines--------------------------------


Init	mov	R1,	#00H	; reset car. index
	acall	INIT_LCD
	ret			; return



WAIT_LCD:
	CLR	P2.0		;Start LCD command
	CLR	P2.2		;It's a command
	SETB	P2.1		;It's a read command
	MOV	P0,	#0FFh	;Set all pins to FF initially
	SETB	P2.0		;Clock out command to LCD
	MOV	A,	P0	;Read the return value
	JB	ACC.7		,WAIT_LCD ;If bit 7 high, LCD still busy
	CLR	P2.0		;Finish the command
	CLR	P2.1		;Turn off RW for future commands
	RET

INIT_LCD:			;COPPIED FROM TUTORIAL
	CLR	P2.2
	MOV	P0,	#38h
	SETB	P2.0
	CLR	P2.0
	aCALL	WAIT_LCD
	CLR	P2.2
	MOV	P0,	#0Eh
	SETB	P2.0
	CLR	P2.0
	aCALL	WAIT_LCD
	CLR	P2.2
	MOV	P0,	#06h
	SETB	P2.0
	CLR	P2.0
	aCALL	WAIT_LCD
	RET

CLEAR_LCD:			;COPPIED FROM TUTORIAL
	CLR	P2.2
	MOV	P0,	#01h
	SETB	P2.0
	CLR	P2.0
	aCALL	WAIT_LCD
	RET

WRITE_TEXT:			;COPPIED FROM TUTORIAL
	SETB	P2.2
	MOV	P0,	A
	SETB	P2.0
	CLR	P2.0
	aCALL	WAIT_LCD
	RET

TXT	acall	MOVE_LINE
TXT2	mov	A,	R1	; caracter index
	mov	DPTR,	#STRING	; get string info
	movc	A,	@A+DPTR	; get caracter
	jnz	SND		; ckeck wether or not a caracter
	mov 	R1,	#00h
	ret
SND	acall	WRITE_TEXT
	inc	R1		; inc car. pointer
	ajmp	TXT2


MOVE_LINE
	PUSH	ACC
	CLR	P2.2
	MOV	P0,	#082h	; first line 3rd place
	SETB	P2.0
	CLR	P2.0
	LCALL	WAIT_LCD
	POP	ACC
	RET


:-------Caracter TABLE-------------------------------------
STRING

	.DB	'H','E','L','L','O',' ','W','O','R','L','D'
	.DB	00H 			;END CODE
	.END
