English
Language : 

MG82FG5B32 Datasheet, PDF (203/273 Pages) Megawin Technology Co., Ltd – Flexible IAP size by software configured
MOV
RL
MOV
RLC
MOV
CLR
JB
JNB
A,IICByte
A
IICByte,A
A
SDA,C
IE1
IE1, $+6
DisableTWSI, $-3
; transfer IICByte.1
JNB
LJMP
MOV
RL
MOV
RLC
MOV
CLR
JB
JNB
StartTWSI,$+6
EXIT_SCL_DETECT_ISR
A,IICByte
A
IICByte,A
A
SDA,C
IE1
IE1, $+6
DisableTWSI, $-3
; transfer IICByte.0
JNB
StartTWSI,$+6
LJMP EXIT_SCL_DETECT_ISR
SETB
CLR
JB
JNB
SDA
IE1
IE1, $+6
DisableTWSI, $-3
; for 9th bit - ACK / NAK
JNB
MOV
JMP
SDA,SET_I2C_SLAVE_READ_ACK
Stage,#I2C_SL_R_NAK
COMPLETE_READ_ONE_BYTE
SET_I2C_SLAVE_READ_ACK:
MOV
Stage,#I2C_SL_R_ACK
COMPLETE_READ_ONE_BYTE:
CLR
IE1
SETB
completeAByte
; set '1' when it tranfer a byte
JMP
EXIT_SCL_DETECT_ISR
;-----------------------------------------------------------------------------------
END
C Code Example:
#include <REG_MG82FG5B32.H>
#include <intrins.h>
#define SLAVE_DEV_ADDR
#define DATA_LENGTH 32
0x20
// declare buffer size
// declare slave device address
//-----------------------------------------------------------------------------
// declare I2C stage
//-----------------------------------------------------------------------------
#define I2C_SlaveStandby 0x00
#define I2C_SLA_with_W 0x01
#define I2C_SLA_with_R 0x02
#define I2C_Disable
0x03
#define I2C_SL_W_ACK 0x04
// SLA_W with data ACK
#define I2C_SL_R_ACK 0x05
// SLA_R with data ACK
#define I2C_SL_R_NAK 0x06
// SLA_R with data NAK
//-----------------------------------------------------------------------------
// declare global variable
//-----------------------------------------------------------------------------
typedef struct {
unsigned char ADDR;
unsigned char IICByte;
unsigned char Stage:8;
MEGAWIN
MG82FG5BXX Data Sheet
203