	Org	*


******* INIT LCD ********
* - Contains:
*	- Init LCD1
*	- Init LCD2
*	- Init All LCD
*************************


Init_LCD:
	LCALL Reset_LCD1
	LCALL Two_LineLCD1
	LCALL ClearLCD1
	LCALL Line_OneLCD1
	LCALL Under_LineLCD1
	LCALL Cursor_OnLCD1
	LCALL Blink_OnLCD1
	LCALL Display_OnLCD1
	RET   

Init_LCD2:
	LCALL Reset_LCD2
	LCALL Two_LineLCD2
	LCALL ClearLCD2
	LCALL Line_OneLCD2
	LCALL Under_LineLCD2
	LCALL Cursor_OnLCD2
	LCALL Blink_OnLCD2
	LCALL Display_OnLCD2
	RET   

************ LCD COMMAND **********
* - Contains of:
*	- Cursor On
*	- Cursor OFF
*	- Blink On
*	- Blink OFF
*	- Display On
*	- Reset LCD
*	- One Line (One Line Active)
*	- Two Line (Two Line Active)
*	- Line One (Line One Active)
*	- Line Two (Line Two Active)
*	- Under Line (Under Line Cursor)
* 	- Cursor Dot (Dot Cursor)
*	- Cursor Left
*	- Cursor Right
* - Used Registers:
*	- R7 (LCD Number)
***********************************

****** CURSOR ON ********
AllCursor_On:
	LCALL	Cursor_OnLCD1
	LCALL	Cursor_OnLCD2
	Ret

Cursor_OnLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0FH
	LCALL Outcommand
	Pop	07H
	RET   

Cursor_OnLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0FH
	LCALL Outcommand
	Pop	07H
	RET   

****** CURSOR OFF ********
AllCursor_OFF:
	LCALL	Cursor_OFFLCD1
	LCALL	Cursor_OFFLCD2
	Ret

Cursor_OFFLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0EH
	LCALL Outcommand
	Pop	07H
	RET   

Cursor_OFFLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0EH
	LCALL Outcommand
	Pop	07H
	RET   

******* BLINK ON ********

AllBlink_On:
	LCALL	Blink_OnLCD1
	LCALL	Blink_OnLCD2
	Ret

Blink_OnLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0BH
	LCALL Outcommand
	Pop	07H	
	RET   

Blink_OnLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0BH
	LCALL Outcommand
	Pop	07H	
	RET   

******* BLINK OFF ********
AllBlink_OFF:
	LCALL	Blink_OFFLCD1
	LCALL	Blink_OFFLCD2
	Ret

Blink_OFFLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0AH
	LCALL Outcommand
	Pop	07H	
	RET   

Blink_OFFLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0AH
	LCALL Outcommand
	Pop	07H	
	RET   


*******	DISPLAY ON ******
AllDisplay_ON:
	Push	07H
	LCALL	Display_OnLCD1
	LCALL	Display_OnLCD2
	Pop	07H
	Ret

Display_OnLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0DH
	LCALL Outcommand
	Pop	07H
	RET   

Display_OnLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0DH
	LCALL Outcommand
	Pop	07H
	RET   

******** DISPLAY OFF *******

AllDisplay_OFF:
	Push	07H
	LCALL	Display_OFFLCD1
	LCALL	Display_OFFLCD2
	Pop	07H
	Ret

Display_OFFLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#0CH
	LCALL Outcommand
	Pop	07H
	RET   


Display_OFFLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#0CH
	LCALL Outcommand
	Pop	07H
	RET   

******* RESET LCD ******
ResetAll_LCD:
	LCALL	Reset_LCD1
	LCALL	Reset_LCD2
	Ret

Reset_LCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#10H
	LCALL Outcommand
	Pop	07H
	RET   

Reset_LCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#10H
	LCALL Outcommand
	Pop	07H
	RET   

******* ONE LINE ******
One_LineAllLCD:
	LCALL	One_LineLCD1
	LCALL	One_LineLCD2
	Ret

One_LineLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#12H
	LCALL Outcommand
	Pop	07H
	RET   

One_LineLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#12H
	LCALL Outcommand
	Pop	07H
	RET   


****** TWO LINE ******

Two_LineAllLCD:
	LCALL	Two_LineLCD1
	LCALL	Two_LineLCD2
	Ret

Two_LineLCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#13H
	LCALL Outcommand
	Pop	07H
	RET   

Two_LineLCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#13H
	LCALL Outcommand
	Pop	07H
	RET   


**** CURSOR LEFT ******
CursorLeft_AllLCD:
	LCALL	CursorLeft_LCD1
	LCALL	CursorLeft_LCD2
	Ret

CursorLeft_LCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#07H
	LCALL Outcommand
	Pop	07H
	RET   


CursorLeft_LCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#07H
	LCALL Outcommand
	Pop	07H
	RET   

CursorRight_AllLCD:
	LCALL	CursorRight_LCD1
	LCALL	CursorRight_LCD2
	Ret

CursorRight_LCD1:
	Push	07H
	Mov	R7,#00H
	MOV   a,#06H
	LCALL Outcommand
	Pop	07H
	RET   


CursorRight_LCD2:
	Push	07H
	Mov	R7,#01H
	MOV   a,#06H
	LCALL Outcommand
	Pop	07H
	RET   


****** END OF LCD COMMAND *******

******* OUT LCD *******
* - Contains:
*	- Out Command (Send LCD Command)
*	- Out Char (Send Character)
* - Used Registers:
*	- DPTR
*	- Acc
*	- R2 (Clock Counter)
*	- R7 (LCD Number)
***********************
Outcommand:
	Push	02H
	Push	DPH
	Push	DPL
	Push	A
	MOV   Dptr,#0E000H
	AJMP  Outbyte

Outchar:
	Push	02H
	Push	DPH
	Push	DPL
	Push	A
	MOV   Dptr,#0E001H
Outbyte:
	Cjne	R7,#01H,Out_LCD1
	Clr	P1.3
	LCALL	Outbyte2
	Setb	P1.3
	Ajmp	Clocking

Out_LCD1:
	Clr	P1.2
	LCALL	Outbyte2
	SETB  	P1.2
	
	MOV   r2,#16
Clocking:
	DJNZ  r2,clocking
	Pop	A
	Pop	DPL
	Pop	DPH
	Pop	02H
	RET   

Outnibble:
	ANL   A,#0FH
	NOP   
	MOVX  @Dptr,A
	RET   

Outbyte2:
	PUSH  a
	SWAP  a
	LCALL Outnibble
	POP   a
	LCALL Outnibble
	Ret

Kirim_Karakter:
	Push	07H
	Mov	R7,#00H
	LCALL	Outchar
	Pop	07H
	Ret

Out_Char2:
	Push	07H
	Mov	R7,#01H
	LCALL	Outchar
	Pop	07H
	Ret

KirimPesan_LCD
Send_Loop:
	Mov	A,#00H
	Movc	A,@A+Dptr
	Cjne	A,#0FH,Send
	Ret
	
Send:
	Acall	Kirim_Karakter
	Inc	Dptr
	Ajmp	Send_Loop
