void writeByteEeprom(unsigned char add, unsigned char data)
{
EEADR = add;
EEDATA = data;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;//关闭所有中断
EECON2 = 0x55;
EECON2 = 0xaa;
EECON1bits.WR = 1;
while(1 == EECON1bits.WR);//等待写入完毕
INTCONbits.GIE = 1;//打开所有中断
EECON1bits.WREN = 0;
}
写单个字节的E2,我写进去之后,比如我写00地址,结果04地址也写进去相同的了.
哪位大虾帮我看看什么问题?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
真崩溃了~
-----------------------------------------------------------------------
uchar Rd_EeProm(uchar Rd_EeAddr)
{
EEADR = Rd_EeAddr;
RD=1;
return EEDATA;
}
void Wr_EeProm(uchar Wr_EeAdd,uchar Wr_EeData)
{
do
;
while(WR == 1); //等待上次数据写完
EEADR = Wr_EeAdd;
EEDATA = Wr_EeData;
EEPGD = 0; //指向数据区
WREN = 1;
GIE = 0;
EECON2 = 0x55;
EECON2 = 0xaa;
WR = 1;
WREN = 0;
GIE = 1;
}
记得写完最后一个字节如果马上读的话,加上:
do
;
while(WR == 1); //等待上次数据写完
一周热门 更多>