stc89c58 flash eepROM读写 无反应
这是flash eepROM程序读写时只需传递扇区号
#include<stc89.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define IAP_READ 0x01 //eeprom 读
#define IAP_WRITE 0x02 //eeprom 写
#define IAP_ERASE 0x03 //eeprom 擦除
#define ENABLE_IAP 0x82 //时间
#define base_address(ba) 0x8000+(512*ba) //求eepROM基地址
#define base_32_address(ba) 0x8000+(32*ba)
void iap_disable(void);
void f_delay(uchar fd);
/*读一个扇区*/
void read_block_eeprom(unsigned char *read_eeprom_data,unsigned char read_eeprom_address)//read section
{
uint bi,eepr_address;
ISP_CONTR=ENABLE_IAP;
ISP_CMD=IAP_READ;
eepr_address=base_address(read_eeprom_address);
ISP_ADDRH= eepr_address/256;
ISP_ADDRL= eepr_address%256;
EA=0;
for(bi=0;bi<512;bi++)
{
ISP_TRIG=ISP_TRIG0;
ISP_TRIG=ISP_TRIG1;
_nop_();_nop_();
*read_eeprom_data++=ISP_DATA;
eepr_address++;
ISP_ADDRH= eepr_address/256;
ISP_ADDRL= eepr_address%256;
}
EA=1;
iap_disable();
}
/*写一个扇区*/
void write_block_eeprom(unsigned char *write_eeprom_data,unsigned char write_eeprom_address) //write section
{
uint bii,eepw_address;
ISP_CONTR=ENABLE_IAP;
ISP_CMD=IAP_WRITE;
eepw_address=base_address(write_eeprom_address);
ISP_ADDRH= eepw_address/256;
ISP_ADDRL= eepw_address%256;
EA=0;
for(bii=0;bii<512;bii++)
{
ISP_DATA=*write_eeprom_data++;
ISP_TRIG=ISP_TRIG0;
ISP_TRIG=ISP_TRIG1;
_nop_();_nop_();
eepw_address++;
ISP_ADDRH= eepw_address/256;
ISP_ADDRL= eepw_address%256;
}
EA=1;
iap_disable();
}
/*擦除一个扇区*/
void erasure_block_eeprom(unsigned char erasure_eeprom_address) //erasure section
{
ISP_CONTR=ENABLE_IAP;
ISP_CMD=IAP_ERASE;
ISP_ADDRH=( base_address(erasure_eeprom_address)/256 );
ISP_ADDRL=( base_address(erasure_eeprom_address)%256 );
EA=0;
ISP_TRIG=ISP_TRIG0;
ISP_TRIG=ISP_TRIG1;
iap_disable();
EA=1;
f_delay(1);
}
/*读32byte*/
void read_32byte_eeprom(unsigned char *read_eeprom_32byte,unsigned int read_32byte_address) //read_32byte
{
uchar bir;
uint eepr32_address;
ISP_CONTR=ENABLE_IAP;
ISP_CMD=IAP_READ;
eepr32_address=base_32_address(read_32byte_address);
ISP_ADDRH= eepr32_address/256;
ISP_ADDRL= eepr32_address%256;
EA=0;
for(bir=0;bir<32;bir++)
{
ISP_TRIG=ISP_TRIG0;
ISP_TRIG=ISP_TRIG1;
_nop_();_nop_();
*read_eeprom_32byte++=ISP_DATA;
eepr32_address++;
ISP_ADDRH= eepr32_address/256;
ISP_ADDRL= eepr32_address%256;
}
EA=1;
iap_disable();
}
/*关闭isp*/
void iap_disable(void)
{
ISP_CONTR = 0; //关闭IAP 功能
ISP_CMD = 0; //清命令寄存器,使命令寄存器无命令,此句可不用
ISP_TRIG = 0; //清命令触发寄存器,使命令触发寄存器无触发,此句可不用
ISP_ADDRH = 0;
ISP_ADDRL = 0;
}
/*延时*/
void f_delay(uchar fd)
{
uchar fdt;
while(fd)
{
for(fdt=0;fdt<200;fdt++)
{
_nop_();_nop_();_nop_();_nop_();
}
fd--;
}
} 写之前记得要搽除! 回复【1楼】zqy517 燎原星火
-----------------------------------------------------------------------
在主程序里有 这只是一个模块的程序 参考手册啊,手册的例程很详细啦
页:
[1]