背景图片
基于BS86D20的EEPROM读写源码 - 啊和的博客

基于BS86D20的EEPROM读写源码 - 啊和的博客 基于BS86D20的EEPROM读写源码 - 啊和的博客

基于BS86D20的EEPROM读写源码

本人在项目中用到了,实际测试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;	
}


来源链接:

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论