	.DATA
	Org	*
Slave_AddrSEE	Ds	1
DataSEE	Ds	1

	.Code
	Org	*
***********
Tulis_SEE16b:
	Lcall	Siapkan16bAlamatSEE
	Jc	Wrong_Write
	Mov	A,DataSEE		
	Lcall	KirimDataSEE
	Jc	Wrong_Write
	Lcall	Buat_StopBit
	Ret


Wrong_Write:
	Lcall	Buat_StopBit
	Clr	C
	Ljmp	Tulis_SEE16b

Tulis_SEE8b:
	Lcall	Siapkan8bAlamatSEE
	Jc	Wrong_Write8b
	Mov	A,DataSEE		
	Lcall	KirimDataSEE
	Jc	Wrong_Write8b
	Lcall	Buat_StopBit
	Ret


Wrong_Write8b:
	Lcall	Buat_StopBit
	Clr	C
	Ljmp	Tulis_SEE8b

**********
Baca_SEE16b:
	Lcall	Siapkan16bAlamatSEE
	Jc	Wrong_Read
	Lcall	Buat_StartBit		;Kirim Device Address dengan
	Lcall	ModeBacaSEE
	Jc	Wrong_read
	Lcall	BacaDataSEE
	Ret


Wrong_Read
	Lcall	Buat_StopBit
	Clr	C
	Ajmp	Baca_SEE16b

Baca_SEE8b:
	Clr	C
	Lcall	Siapkan8bAlamatSEE
	Jc	Wrong_Read8b
	Lcall	Buat_StartBit		;Kirim Device Address dengan
	Lcall	ModeBacaSEE
	Jc	Wrong_read8b
	Lcall	BacaDataSEE
	Ret


Wrong_Read8b:
	Lcall	Buat_StopBit
	Clr	C
	Ljmp	Baca_SEE8b


Ambil_Ack:
	Clr	C
	Setb	SDA
	Setb	SCL
	Mov	C,SDA
	Clr	SCL
	Ret

KirimDeviceAddress:
	Lcall	Buat_StartBit
	Push	A
	Mov	A,R7			;Device Address
	Lcall	KirimDataSEE		;
	Pop	A			;
	Ret

Kirim1WordAddress:
	Push	A			;
	Mov	A,B			;First Word Address
	Lcall	KirimDataSEE		;
	Pop	A			;
	Ret

Kirim2WordAddress:
	Push	A
	Mov	A,R6			;Second Address
	Lcall	KirimDataSEE		;
	Pop	A
	Ret

BacaDataSEE:
	Push	B
	Mov	B,#08H
	Clr	A
LoopBacaSEE16b:
	Push	B
	Rl	A
	Setb	SDA
	Setb	SCL
	Clr	C
	Mov	C,SDA
	Mov	A.0,C
	Clr	SCL
	Pop	B
	Djnz	B,LoopBacaSEE16b
	Lcall	Ambil_Ack
	Lcall	Ambil_Ack
	Lcall	Buat_StopBit
	Pop	B
	Ret

KirimDataSEE:
	Push	B
	Mov	B,#8
Send8_bitloop
	Rlc	A
	Mov	SDA,C
	Lcall	Pulse_SEE
	Djnz	B,Send8_bitloop
	Pop	B
	Clr	C
	Lcall	Ambil_Ack
	Ret


Pulse_SEE:
	Push	b
	Setb	SCL
	Clr	SCL
	Pop	B
	Ret


Buat_StartBit:
	Setb	SDA
	Setb	SCL
	Clr	SDA
	Clr	SCL
	Ret

Buat_StopBit:
	Clr	SDA
	Setb	SCL
	Setb	SDA
	Clr	SCL
	Ret
PageSEE8bWrite
	Clr	F0
	Push	05H
	Lcall	Siapkan8bAlamatSEE
	Ajmp	PageSEEWrite

PageSEE16bWrite:
	Setb	F0
	Push	05H
Loop2PageSEE16bWrite:
	Lcall	Siapkan16bAlamatSEE

PageSEEWrite:
	Mov	A,DataSEE
	Lcall	KirimDataSEE
	
	Jc	WrongPWrite
	Mov	R5,#031
LoopPageSEE16bWrite:
	Mov	A,DataSEE
	Lcall	KirimDataSEE
	Jc	Loop2PageSEE16bWrite
	Djnz	R5,LoopPageSEE16bWrite
	Pop	05H
	Lcall	Buat_StopBit
	Ret

WrongPWrite:
	Pop	05H
	Lcall	Buat_StopBit
	Jb	F0,PageSEE16bWrite
	Ljmp	PageSEE8bWrite



Siapkan16bAlamatSEE:
	Lcall	KirimDeviceAddress
	Jc	SalahTulisAlamat		
	Lcall	Kirim1WordAddress
	Jc	SalahTulisAlamat		
	Lcall	Kirim2WordAddress

SalahTulisAlamat:
	Ret

Siapkan8bAlamatSEE:
	Lcall	KirimDeviceAddress
	Jc	SalahTulisAlamat		
	Lcall	Kirim1WordAddress
	Ajmp	SalahTulisAlamat

ModeBacaSEE:
	Push	A			;
	Mov	A,R7
	Setb	A.0
	Mov	Slave_AddrSEE,A
	Pop	A
	Mov	A,Slave_AddrSEE
	Lcall	KirimDataSEE
	Ret

DPHSEE8bit:
	Mov	R7,#0A0H
	MOv	A,DPH
	Anl	A,#00000011b		;Ambil bit 0 dan 1 DPH
	Rl	A			;Geser kiri 1x

	Orl	A,R7			;Copy bit 1 dan 2 ke R7
	Mov	R7,A			;
	Mov	B,DPL		
	Ret

DPTRSEE8bit:
	Acall	DPHSEE8bit
	Acall	Baca_SEE8b
	Ret

DPTRSEE16bit:
	Mov	R7,#0A0H
	Mov	B,DPH
	Mov	R6,DPL
	Acall	Baca_SEE16b
	Ret

TulisDPTRSEE8b:
	Acall	DPHSEE8bit
	Acall	Tulis_SEE8b
	Ret

TulisDPTRSEE16b:
	Mov	R7,#0A0H
	Mov	B,DPH
	Mov	R6,DPL
	Lcall	Tulis_SEE16b
	Ret