;PC0 RS 
;PC1 RW
;PC2 E_CLOCK
;PC3
;PC4 D4
;PC5 D5
;PC6 D6
;PC7 D7
	.DATA
Alamat_LCD	Ds	1
Data_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:
Send_Loop:
	Mov	A,#00H
	Movc	A,@A+Dptr
	Cjne	A,#0FH,Send
	Ret
	
Send:
	Acall	Kirim_Karakter
	Inc	Dptr
	Ajmp	Send_Loop


Init_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,#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	Data_LCD,A
	Push	DPH
	Push	DPL
	Mov	DPTR,#4002H		;RS, RW = 0
	Mov	A,#04H			;
	Movx	@DPTR,A			;

	Mov	A,Data_LCD
	Anl	A,#0F0H			;
	Mov	B,A
	Setb	A.2
	Movx	@DPTR,A			;

	Acall	RS0PulseE_Clock
	Mov	A,Data_LCD
	Anl	a,#0FH
	Swap	A
	Mov	B,A
	Setb	A.2
	Movx	@Dptr,A
	Acall	RS0PulseE_Clock
	Pop	DPL
	Pop	DPH
	Ret


RS0PulseE_Clock:
	Mov	A,#00000100b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Mov	A,#00000000b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Mov	A,#00000100b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Ret

Kirim_Karakter:
	Push	DPH
	Push	DPL
	Mov	Data_LCD,A
	Mov	A,#00000101b			;RS = 1, RW = 0
	Mov	DPTR,#4002H			;
	Movx	@Dptr,A				;
	Mov	A,Data_LCD
	Anl	A,#0F0H
	Mov	B,A
	Setb	A.2
	Movx	@DPTR,A
	Acall	RS1PulseE_Clock
	Mov	A,Data_LCD
	Anl	A,#0FH
	Swap	A
	Mov	B,A
	Setb	A.2
	Movx	@DPTR,A
	Acall	RS1PulseE_Clock
	Pop	DPL
	Pop	DPH
	Ret		

Baca_AddresCounter:
	Push	DPH
	Push	DPL

	Mov	DPTR,#4002H		;RS = 0, RW = 1, E = 1
	Mov	A,#00000011b		;
	Movx	@DPTR,A			;

	Acall	RS0PulseRead_EClock	;
	Movx	A,@DPTR
	Anl	A,#0F0H
	Push	A
	Mov	A,#00000011b
	Movx	@DPTR,A
	Acall	RS0PulseRead_EClock
	Movx	A,@DPTR
	Anl	A,#0F0H
	Swap	A
	Pop	B
	Clr	C
	Add	A,B
	Pop	DPL
	Pop	DPH
	Ret


RS0PulseRead_EClock
	Clr	A.2
	Movx	@DPTR,A
	Setb	A.2
	Movx	@DPTR,A
	Acall	Delay_LCD
	Ret


RS1PulseE_Clock:
	Mov	A,#00000101b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Mov	A,#00000001b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Mov	A,#00000101b
	Clr	C
	Add	A,B
	Movx	@Dptr,A
	Ret


Baris2:
	Mov	A,#0C0H
	Acall	Kirim_Perintah
	Ret

Baris1:
	Mov	A,#02H
	Acall	Kirim_Perintah
	Acall	Delay_LCD2
	Ret

Hapus_LCD:
	Push	A
	Push	DPH
	Push	DPL
	Push	07H
	Mov	R7,#16
	Acall	Baris1
HapusBaris1_Loop:
	Mov	A,#' '
	Acall	Kirim_Karakter
	Djnz	R7,HapusBaris1_Loop
	Acall	Baris2

	Mov	R7,#19
HapusBaris2_Loop:
	Mov	A,#' '
	Acall	Kirim_Karakter
	Djnz	R7,HapusBaris2_Loop
	Acall	Baris1
	Pop	07H
	Pop	DPL
	Pop	DPH
	Pop	A
	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


out
	push	a
	lcall	36ah
	pop	a
	ret