Platform MPLAB X
CPU PIC18F2520
Compiler XC8 v1.38我们正在将一个项目从旧的(htc)编译器转移到MPLAB X平台,但无法访问EEPROM。
旧的编译器支持eeprom_read和eeprom_write,但是XC8不支持,好吧,有定义定义它们,但是它们是“空的”。(xc.h包括htc.h,其中包括pic18.h) pic.h中的行
#if _EEPROMSIZE > 0 && defined(_PLIB)没有触发,而是相应的#else似乎既没有定义_EEPROMSIZE也没有定义_PLIB。
为什么xc8不支持旧版本(eeprom_read和eeprom_write)?
我们应该怎么做才能访问EEPROM?
我们试着看看微芯片代码配置会做什么,但中央处理器PIC18F2520不支持MCC。
The chip do have 256 byte eeprom according tohttp://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf
问候
发布于 2016-07-19 14:09:40
是的,正如您所发现的,Microchip已经在MPLAB X IDE中删除了PIC18系列微控制器的EEPROM读/写功能。它将宏保留为空外壳(EEPROM_READ()、eeprom_read()、e.t.c),这些外壳不会抛出编译器错误/警告,但实际上不会做任何事情!
pic18.h建议,如果#if _EEPROMSIZE > 0 && defined(_PLIB)为真,则将填充宏,但是通过手动添加PLIB宏定义,编译器随后会抱怨无法找到plib.h。我找不到合适的地方下载"plib“。
一种选择是返回到直接寄存器操作,以执行EEPROM读/写(有关一个特定PIC18 micro的EEPROM寄存器定义,请参见http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf的第75页)。我已经写了下面的函数,这些函数抽象了它,并提供了与Microchip移除的功能类似的功能:
//! @brief Reads a single byte of data from the EEPROM.
//! @param address The EEPROM address to write the data to (note that not all
//! 16-bits of this variable may be supported).
//! @returns The byte of data read from EEPROM.
//! @warning This function does not return until read operation is complete.
uint8_t Eeprom_ReadByte(uint16_t address)
{
// Set address registers
EEADRH = (uint8_t)(address >> 8);
EEADR = (uint8_t)address;
EECON1bits.EEPGD = 0; // Select EEPROM Data Memory
EECON1bits.CFGS = 0; // Access flash/EEPROM NOT config. registers
EECON1bits.RD = 1; // Start a read cycle
// A read should only take one cycle, and then the hardware will clear
// the RD bit
while(EECON1bits.RD == 1);
return EEDATA; // Return data
}
//! @brief Writes a single byte of data to the EEPROM.
//! @param address The EEPROM address to write the data to (note that not all
//! 16-bits of this variable may be supported).
//! @param data The data to write to EEPROM.
//! @warning This function does not return until write operation is complete.
void Eeprom_WriteByte(uint16_t address, uint8_t data)
{
// Set address registers
EEADRH = (uint8_t)(address >> 8);
EEADR = (uint8_t)address;
EEDATA = data; // Write data we want to write to SFR
EECON1bits.EEPGD = 0; // Select EEPROM data memory
EECON1bits.CFGS = 0; // Access flash/EEPROM NOT config. registers
EECON1bits.WREN = 1; // Enable writing of EEPROM (this is disabled again after the write completes)
// The next three lines of code perform the required operations to
// initiate a EEPROM write
EECON2 = 0x55; // Part of required sequence for write to internal EEPROM
EECON2 = 0xAA; // Part of required sequence for write to internal EEPROM
EECON1bits.WR = 1; // Part of required sequence for write to internal EEPROM
// Loop until write operation is complete
while(PIR2bits.EEIF == 0)
{
continue; // Do nothing, are just waiting
}
PIR2bits.EEIF = 0; //Clearing EEIF bit (this MUST be cleared in software after each write)
EECON1bits.WREN = 0; // Disable write (for safety, it is re-enabled next time a EEPROM write is performed)
}发布于 2017-04-01 09:20:17
使用MCC选择内存模块,它将创建具有所有所需功能的Memory y.c。
https://stackoverflow.com/questions/38436675
复制相似问题