/*******************************************************************/
/*向单片机内部EEPROM空间读出一字节数据*/
/*******************************************************************/
//11F04E 共2个扇区,起始地址0000H
uchar read_51flash_data(uint eeprom_addr)
{
uchar temp;
IAP_CONTR=0X83;
IAP_CMD =read_cmd;//字节读命令,,
IAP_ADDRL=eeprom_addr&0xff;
IAP_ADDRH=eeprom_addr>>8;
IAP_TRIG=0X5a;
IAP_TRIG=0Xa5;//
//delay_nus(2);
Nop();
temp=IAP_DATA;
IAP_CONTR=0X00;
IAP_CMD =0X00;
IAP_TRIG=0X00;
IAP_ADDRH=0Xff;
IAP_ADDRL=0Xff;
return temp ;
}
/*******************************************************************/
/*******************************************************************/
void write_51eeprom_1byte(uint eeprom_addr,uchar w_data)
{
IAP_CMD =program_cmd;//字节编程命令,,
IAP_ADDRL=eeprom_addr&0xff;
IAP_ADDRH=eeprom_addr>>8;
IAP_CONTR=0X03;
IAP_CONTR|=0X80;
IAP_DATA =w_data;
IAP_TRIG=0X5a;
IAP_TRIG=0Xa5;//
Nop();
IAP_CONTR=0X00;
IAP_CMD =0X00;
IAP_TRIG =0X00;
IAP_ADDRH=0Xff;
IAP_ADDRL=0Xff;
}
/*******************************************************************/
/*******************************************************************/
/*擦除单片机内部EEPROM空间一个数据的扇区*/
void earse_one_sector_in51(uint eeprom_page_addr)
{
EA=0;
IAP_CONTR=0X83;
IAP_CMD =erase_cmd;//字节擦除命令,, IAP_CMD
IAP_ADDRH=eeprom_page_addr>>8;
IAP_ADDRL=eeprom_page_addr;
IAP_TRIG=0X5a;
IAP_TRIG=0Xa5;//
delay_nus(10);
Nop();
IAP_CONTR=0X00;
IAP_CMD =0X00;
IAP_TRIG=0X00;
IAP_ADDRH=0Xff;
IAP_ADDRL=0Xff;
EA=1;
}
|