兄弟姐妹们:请教个 问题,PIC18F4580片内EEPROM的读写问题
我是看着单片机的DATASHEET上面的汇编写的读写程序,把它改成C就不行了,。。。。
程序如下:
#include <P18CXXX.H>
#pragma config OSC = HS
#pragma config WDT = OFF
unsigned char EEPROM_Read(unsigned char Add_H, unsigned char Add_L)
{
unsigned char uc_data;
// EEADRH = Add_H;
EEADR = Add_L;
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.RD = 1;
uc_data = EEDATA;
return uc_data;
}
void EEPROM_Write(unsigned char data, unsigned char Add_H, unsigned char Add_L)
{
// EEADRH = Add_H;
EEADR = Add_L;
EEDATA = data;
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xaa;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
}
void delay(int i)
{
int j;
for(j=i;j>0;j--)
{
}
}
void main(void)
{
while(1)
{
EEPROM_Write(0x56,0x00,0x00);
delay(100);
EEPROM_Read(0x00,0x00);
}
}
编译器用的是MC18 ,单片机PIC18F4580,大家帮忙看下,数据写不进去,但是能读出FF来 。。。。
此帖出自
小平头技术问答
一周热门 更多>