本人在项目中用到了,实际测试OK
typedef struct//位操作 { unsigned char bit0 : 1; unsigned char bit1 : 1; unsigned char bit2 : 1; unsigned char bit3 : 1; unsigned char bit4 : 1; unsigned char bit5 : 1; unsigned char bit6 : 1; unsigned char bit7 : 1; }iar_bits; DEFINE_SFR(iar_bits,iar1,0x02); #define iar1_3 iar1.bit3 #define iar1_2 iar1.bit2 #define iar1_1 iar1.bit1 #define iar1_0 iar1.bit0 unsigned short eepromread(unsigned char addr) { _emi = 0; unsigned short backup; _eea = addr; _mp1l = 0x40; backup = _mp1h;//这个有些单片机可能会不一样,可能是_bp _mp1h = 1; iar1_1 = 1; iar1_0 = 1; while(iar1_0); _iar1 = 0; _mp1h = backup; _emi = 1; return _eed; } void eepromwrite(unsigned char eeaddr,unsigned short eedata) { _emi = 0; unsigned short backup; _eed = eedata; _eea = eeaddr; _mp1l = 0x40; backup = _mp1h; _mp1h = 1; iar1_3 = 1; iar1_2 = 1; while(iar1_2); _iar1 = 0; _mp1h = backup; _emi = 1; _mp1h=0; _mp1l=0; }来源链接: