<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 治標治本,徹底解決AVR單片機EEPROM數(shù)據(jù)丟失問題

          治標治本,徹底解決AVR單片機EEPROM數(shù)據(jù)丟失問題

          作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
          編譯環(huán)境:WinAVR-20060421 + AVR Studio 4.12.498 Service Pack 4
          基本思路:每份寫到EEPRM的數(shù)據(jù),都做三個備份,每個備份的數(shù)據(jù)都做CRC16校驗,只要系統(tǒng)運行中出錯,錯誤地修改了EEPROM數(shù)據(jù),
          那么根據(jù)校驗字節(jié)就知道哪個備份的數(shù)據(jù)被修改了,然后用正確的備份覆蓋出錯的備份,達到數(shù)據(jù)恢復(fù)的目的。
          EEPROMSave.h 文件:
          /* EEPROM管理定義 */
          #define EepromPageSize 64 //頁容量定義
          #define EepromPage0Addr 0x0000 //各個頁的其始地址定義
          #define EepromPage1Addr (EepromPage0Addr + EepromPageSize)
          #define EepromPage2Addr (EepromPage1Addr + EepromPageSize)
          #define EepromPage3Addr (EepromPage2Addr + EepromPageSize)
          #define EepromPage4Addr (EepromPage3Addr + EepromPageSize)
          #define EepromPage5Addr (EepromPage4Addr + EepromPageSize)
          #define EepromPage6Addr (EepromPage5Addr + EepromPageSize)
          #define EepromPage7Addr (EepromPage6Addr + EepromPageSize)
          /*
          最后兩個字節(jié)為CRC16校驗碼,其余為數(shù)據(jù)
          | 0 | 1 | 2 | |.......................| 61 | 62 | 63 |
          Data Data...................Data.....CRCH CRCL
          */
          #define VALID 0x01
          #define INVALID 0x00
          /*-----------------------------------------------------------------------------------------*/
          EEPROMSave.c 文件:
          /*******************************************************************
          *函數(shù)名稱:EepromReadByte()
          *函數(shù)功能:寫一個Byte的數(shù)據(jù)進EEPROM
          *輸入?yún)?shù):address:地址
          *返回參數(shù):從指定地址讀出來的數(shù)據(jù)
          *編寫作者:my_avr
          *編寫時間:2007年8月13日
          *相關(guān)說明:
          ********************************************************************/
          unsigned char EepromReadByte(unsigned char *address)
          {
          unsigned char data;
          data = 0;
          eeprom_busy_wait();
          data = eeprom_read_byte(address);
          return data;
          }
          /*******************************************************************
          *函數(shù)名稱:EepromReadWord();
          *函數(shù)功能:寫一個Word的數(shù)據(jù)進EEPROM
          *輸入?yún)?shù):address:地址
          *返回參數(shù):從指定地址讀出來的數(shù)據(jù)
          *編寫作者:my_avr
          *編寫時間:2007年8月13日
          *相關(guān)說明:
          ********************************************************************/
          uint16_t EepromReadWord(uint16_t *address)
          {
          uint16_t data;
          data = 0;
          eeprom_busy_wait();
          data = eeprom_read_word(address);
          return data;
          }
          /*******************************************************************
          *函數(shù)名稱:EepromWriteByte()
          *函數(shù)功能:寫一個Byte的數(shù)據(jù)進EEPROM
          *輸入?yún)?shù):address:地址;data:數(shù)據(jù)
          *返回參數(shù):無
          *編寫作者:my_avr
          *編寫時間:2007年8月13日
          *相關(guān)說明:
          ********************************************************************/
          void EepromWriteByte(unsigned char *address,unsigned char data)
          {
          eeprom_busy_wait();
          eeprom_write_byte(address,data);
          }
          /*******************************************************************
          *函數(shù)名稱:EepromWriteWord()
          *函數(shù)功能:寫一個Word的數(shù)據(jù)進EEPROM
          *輸入?yún)?shù):address:地址;data:數(shù)據(jù)
          *返回參數(shù):
          *編寫作者:my_avr
          *編寫時間:2007年8月13日
          *相關(guān)說明:
          ********************************************************************/
          void EepromWriteWord(unsigned int *address,unsigned int data)
          {
          eeprom_busy_wait();
          eeprom_write_word(address,data);
          }

          上一頁 1 2 3 4 5 6 7 下一頁

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();