void ee_xieru(unsigned char ee_dizhi,int ee_shuju) //存储器写入
{
unsigned char ee_a1,ee_a2;
ee_a1 =ee_shuju >>8;
ee_a2 =ee_shuju;
//while(GIE) //等待GIE为0
//{
//GIE = 0; //写数据必须关闭中断
//NOP();
//NOP();
//}
EEADRL =ee_dizhi; //EEPROM的地址
EEDATL =ee_a1; //EEPROM的写数据
CFGS =0; //访问EEPROM存储器
EEPGD=0;
EEIF = 0;
WREN=1; //写使能
#asm //解锁
MOVLW 0x03
MOVWF _BSREG
MOVLW 0x55
MOVWF _EECON2 & 0x7F
MOVLW 0xAA
MOVWF _EECON2 & 0x7F
BSF _EECON1& 0x7F,1 //WR=1;
NOP
NOP
#endasm
NOP();
NOP();
NOP();
NOP();
while(WR); //等待EE写入完成
EEADRL =ee_dizhi +1; //EEPROM的地址
EEDATL =ee_a2; //EEPROM的写数据
CFGS =0; //访问EEPROM存储器
EEPGD=0;
EEIF = 0;
WREN=1; //写使能
#asm //解锁
MOVLW 0x03
MOVWF _BSREG
MOVLW 0x55
MOVWF _EECON2 & 0x7F
MOVLW 0xAA
MOVWF _EECON2 & 0x7F
BSF _EECON1& 0x7F,1 //WR=1;
NOP
NOP
#endasm
NOP();
NOP();
NOP();
NOP();
while(WR); //等待EE写入完成
WREN=0;
// GIE = 1;
}
|