编辑代码

#include <stdio.h>
#include <stdint.h>

typedef enum 
{
  RESET = 0U, 
  SET = !RESET
} FlagStatus, ITStatus;

#define I2C_FLAG_OVR                    0x00010800U
#define I2C_FLAG_AF                     0x00010400U
#define I2C_FLAG_ARLO                   0x00010200U
#define I2C_FLAG_BERR                   0x00010100U
#define I2C_FLAG_TXE                    0x00010080U
#define I2C_FLAG_RXNE                   0x00010040U
#define I2C_FLAG_STOPF                  0x00010010U
#define I2C_FLAG_ADD10                  0x00010008U
#define I2C_FLAG_BTF                    0x00010004U
#define I2C_FLAG_ADDR                   0x00010002U
#define I2C_FLAG_SB                     0x00010001U
#define I2C_FLAG_DUALF                  0x00100080U
#define I2C_FLAG_GENCALL                0x00100010U
#define I2C_FLAG_TRA                    0x00100004U
#define I2C_FLAG_BUSY                   0x00100002U
#define I2C_FLAG_MSL                    0x00100001U

#define I2C_FLAG_MASK                    0x0000FFFFU

#define SR1 0x00000080U
#define SR2 0x00000007U

#define _EEPROM_ADDRESS 0xA0


#define __HAL_I2C_GET_FLAG(__FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U) ? \
                                                  ((((SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET) : \
                                                  ((((SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)) ? SET : RESET))

int main () {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    printf("%d\n", __HAL_I2C_GET_FLAG(I2C_FLAG_ADDR));
    printf("%d\n", __HAL_I2C_GET_FLAG(I2C_FLAG_AF));

    int address = 0;
    printf("%d, %d\n", _EEPROM_ADDRESS | address, (address & 0xff));
    printf("%d, %d\n", _EEPROM_ADDRESS | ((address & 0x0100) >> 7), (address & 0xff));
    printf("%d, %d\n", _EEPROM_ADDRESS | ((address & 0x0300) >> 7), (address & 0xff));
    printf("%d, %d\n", _EEPROM_ADDRESS | ((address & 0x0700) >> 7), (address & 0xff));

    return 0;
}