2016-07-18 35 views
1
Platform MPLAB X 
CPU PIC18F2520 
Compiler XC8 v1.38 

私たちは、MPLAB X プラットフォームに古い(HTC)コンパイラからプロジェクトを移動しているが、EEPROMにアクセスすることはできません。PIC18F2520のMPLAB Xのxc8のEEPROM

古いコンパイラはeeprom_readとeeprom_writeをサポートしていましたが、XC8 には定義する定義がありますが、それらは "空"です。 (xc.hがpic18.hが含まhtc.hを含ん)pic.hラインで

#if _EEPROMSIZE > 0 && defined(_PLIB) 

がトリガーではなく、対応する#elseの ないです。_EEPROMSIZEも_PLIBどちらも定義されているようです。

古い(eeprom_readとeeprom_write) がxc8でサポートされないのはなぜですか?

EEPROMにアクセスするにはどうすればよいですか?

がマイクロチップコード設定で何をしているのかを確認しようとしましたが、CPU PIC18F2520はMCCではサポートされていません。

The chip do have 256 byte eeprom according to 

http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf

よろしく

答えて

0

あなたが発見したとはい、マイクロチップは、MPLAB X IDEにマイクロコントローラのPIC18ファミリ用EEPROMの読み取り/書き込み機能を削除しました。マクロは空のシェル(EEPROM_READ()eeprom_read()、e.t.c)として残しましたが、コンパイラのエラー/警告をスローしません。ですが、実際には何もしません。

pic18.h#if _EEPROMSIZE > 0 && defined(_PLIB)が真であるならば、マクロを手動でPLIBマクロ定義を追加することで、まだ、入力されますことを示唆している、コンパイラは、plib.hを見つけることができない不満。私は "plib"をダウンロードするのに適した場所を見つけることができませんでした。

1つのオプションは、EEPROMを実行するための操作を登録ダイレクトに戻すことです(ある特定のPIC18マイクロ用EEPROMレジスタの定義についてhttp://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdfの75ページを参照してください)/はの読み書きを行います。私は離れて、以下の機能抽象的に書かれており、マイクロチップを外しものと同様の機能を提供しています

//! @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) 
} 
+0

を必要とし、それはmemory.cを作成し、I同じことをしました マイクロチップにはマクロがあります_LOAD_EEADR これは、EEADRHとEEADRの代わりに使用することができます(私はそれがCPUに依存しないと思います).PICにはレジスタがありません.EEADR – user6127660

0

MCC 選択メモリモジュールを使用して、すべての機能がはい

関連する問題