winnie 发表于 2009-4-25 15:43:10

关于C语言下EEPROM的读写问题

我用的是PIC16F877A单片机,仿真器是高奇的picmate2002,现在欲验证下写进去的数据和读出来的数据是不一样,特意编写如下程序,可是程序编译成功了,但不论写入何数据,读出来的数据都是00,这是什么原因啊?难道没写进去?程序如下,望大虾们帮忙看看,多谢,急啊!
#include   <pic.h>
unsigned char eeprom_read(unsigned char addr);
void eeprom_write(unsigned char addr,unsigned char value);
void eeprom_write(unsigned char addr,unsigned char value)
{
EEADR=addr;
EEDATA=value;
EEPGD=0;
WREN=1;
EECON2=0x55;
EECON2=0xaa;
WR=1;
do {;}
while(WR==1);
WREN=0;//写保护
}
unsigned char eeprom_read(unsigned char addr)//片内EEPROM的读取
{
unsigned char rd_data;
EEADR=addr;
EEPGD=0;
RD=1;
rd_data=EEDATA;//读取EEDATA的内容
return(rd_data);
}
main()
{
   unsignedchardata1,data2;
   unsignedcharaddress;
   address=0x80;
   data1=0x50;
   eeprom_write(address,data1);
   data2=eeprom_read(address);
NOP();
}

winnie 发表于 2009-4-25 15:43:24

内存调用是这样的!
#include   <pic.h>


void eeprom_write(unsigned char address,unsigned char datavalue)
{
asm("CLRWDT");
eeprom_write(address,datavalue);
while(WR == 1)
{
asm("CLRWDT");
}
}

unsigned char eeprom_read(unsigned char address)
{
return EEPROM_READ(address);
}

main()
{
   unsignedchardata1,data2;
   unsignedcharaddress;
   address=0x80;
   data1=0x50;
   eeprom_write(address,data1);
   data2=eeprom_read(address);
}
页: [1]
查看完整版本: 关于C语言下EEPROM的读写问题