English
Language : 

MG82FG5B32 Datasheet, PDF (198/273 Pages) Megawin Technology Co., Ltd – Flexible IAP size by software configured
MOV
MOV
MOV
RLC
MOV
CLR
JMP
R1,#ReceiveString
A,@R1
IICByte,A
A
SDA,C
completeAByte
MAIN_LOOP
; initial for transfer
; it must transfer MSB to SDA
; clear event flag
SUBROUTINE_I2C_SL_W_ACK:
CJNE
A,#I2C_SL_W_ACK,SUBROUTINE_I2C_SL_R_ACK
MOV
@R1,IICByte
; save data
to "ReceiveString"
INC
CJNE
MOV
R1
R1,#ReceiveString+DATA_LENGTH,$+3+2
R1,#ReceiveString
; limit buffer index
CLR
JMP
completeAByte
MAIN_LOOP
; clear event flag
SUBROUTINE_I2C_SL_R_ACK:
CJNE
A,#I2C_SL_R_ACK,SUBROUTINE_I2C_SL_R_NAK
INC
CJNE
MOV
R1
R1,#ReceiveString+DATA_LENGTH,$+3+2
R1,#ReceiveString
; limit buffer index
MOV
MOV
RLC
MOV
IICByte,@R1
ACC,@R1
A
SDA,C
; prepare data form data buffer
; SDA = MSB
CLR
JMP
completeAByte
MAIN_LOOP
; clear event flag
SUBROUTINE_I2C_SL_R_NAK:
CJNE
A,#I2C_SL_R_NAK,MAIN_LOOP
SETB
CLR
JMP
SDA
completeAByte
MAIN_LOOP
; NAK-event
;-------------------------------------------------------------------------
; initial TWSI interrupt (priority) & trigger mode
;-------------------------------------------------------------------------
INITIAL_TWSI:
; System Flag have the highest priority
ORL
EIP1H,#08H
ORL
EIP1L,#08H
; the EX1 priority
ORL
IP0H,#00000100B
ANL
IP0L,#11111011B
; enable ETWSI
ORL
ORL
SETB EA
EIE1,#ESF
SFIE,#SDIFIE
; P33 & P32 is open drain mode for TWSI
MOV
P3M0,#0CH
MOV
P3M1,#0CH
; edge detect
SETB
ORL
IT1
AUXR0,#INT1H
198
MG82FG5BXX Data Sheet
MEGAWIN