	.DATA
Alamat_LCD	Ds	1
	.CODE
	Org	*
;----------------------
;Geser Display ke kanan

GeserDisplay_Kanan:
	Mov	A,#1FH
	Acall	Kirim_Perintah
	Acall	Delay_LCD
	Ret

;----------------------
;Geser Display ke kiri

GeserDisplay_Kiri:
	Mov	A,#18H
	Acall	Kirim_Perintah
	Acall	Delay_LCD
	Ret

;----------------------
;Kembali ke posisi awal

Posisi_Awal:
	Mov	A,#02H
	Acall	Kirim_Perintah
	Acall	Delay_LCD
	Ret

;----------------------
;Geser Cursor ke kiri

GeserCursor_Kiri:
	Mov	A,#10H
	Acall	Kirim_Perintah
	Acall	Delay_LCD
	Ret

;----------------------
;Geser Cursor ke kanan

GeserCursor_Kanan:
	Mov	A,#14H
	Acall	Kirim_Perintah
	Acall	Delay_LCD
	Ret

KirimPesan_LCD:
LoopKirimPesan_LCD:
	Mov	A,#00H			;Ambil data dari memori yg ditunjuk
	Movc	A,@A+Dptr		;
	Cjne	A,#0FH,Kirim_LCD	;Kirim ke LCD selama belum ditemukan
	Ret				;0FH
	
Kirim_LCD:
	Acall	Kirim_Karakter
	Inc	Dptr			;Tunjuk ke memori selanjutnya
	Ajmp	LoopKirimPesan_LCD

********* SUBROUTINE INISIAL LCD **********
Init_LCD:
	Setb	RS

	Mov	A,#30H			;Kirim 30H
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD

	Mov	A,#30H			;Kirim 30H
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD

	Mov	A,#30H			;Kirim 30H
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD
	
	Mov	A,#20H			;Send Init
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD

	Mov	A,#2FH			;8x5 2lines
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD
	
	Mov	A,#08H			;
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD
	
	Mov	A,#01H			;
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD

	Mov	A,#07H			;
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD		;

	Mov	A,#0EH			;Display ON
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD		;

	Mov	A,#06H			;Mode Increment Address
	Acall	Kirim_Perintah		;
	Acall	Delay_LCD		;
	Ret

Kirim_Perintah:
	Mov	P2,#00H			;Mode Interface 4 bit, kirim data
	Acall	Kirim_DataLCD		;4 bit sebanyak 2 x
	Swap	A
	Acall	Kirim_DataLCD		;
	Ret				;

Kirim_DataLCD
	Swap	A
	Mov	P0,A			;Kirim ke Port 0
	Nop				;
	Acall	PulseE_Clock		;Beri 1 pulsa E Clock
	ret

PulseE_Clock:
	Push	A
	Mov	A,#0A0H
	Orl	A,P2
	Mov	P2,A
	Anl	A,#0FH
	Mov	P2,A
	Pop	A
	Ret

Kirim_Karakter:
	Mov	P2,#02H			;Mode Interface 4 bit, kirim data
	Acall	Kirim_DataLCD		;ke LCD 2x
	Acall	Kirim_DataLCD		;
	Acall	Delay_LCD		;Delay LCD
	Ret

Baris2:
	Mov	A,#0C0H
	Acall	Kirim_Perintah
	Ret

Baris1:
	Mov	A,#02H
	Acall	Kirim_Perintah
	Acall	Delay_LCD2
	Ret

Delay_LCD:
	Push	B
	Mov	B,#06H
Delay_LCD_Loop:
	Push	B
	Acall	Delay_LCD2
	Pop	B
	Djnz	B,Delay_LCD_Loop
	Pop	B
	Ret

Delay_LCD2:
	Mov	B,#0FFH
	Djnz	B,*
	Ret

