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

          新聞中心

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

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

          作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
          /*******************************************************************
          *函數(shù)名稱:EepromWriteBlock()
          *函數(shù)功能:將緩沖區(qū)中的n個數(shù)據(jù)寫進(jìn)EEPROM
          *輸入?yún)?shù):address:地址;data:數(shù)據(jù)
          *返回參數(shù):
          *編寫作者:my_avr
          *編寫時間:2007年8月13日
          *相關(guān)說明:
          ********************************************************************/
          void EepromWriteBlock(unsigned char *buff,unsigned char *address,unsigned char n)
          {
          unsigned char i;
          for (i = 0; i < n; i++)
          {
          EepromWriteByte((unsigned char *)(address + i),*buff);
          buff++;
          }
          }
          /******************************************************************
          *函數(shù)名稱:unsigned char EepromCheck(unsigned char *pdata,unsigned char packsize)
          *函數(shù)功能:檢查EEPROM的數(shù)據(jù)是否有效,采用CRC16校驗技術(shù)。
          一次校驗?zāi)J(rèn)最后兩個字節(jié)為校驗碼,
          需要注意,packsize包括數(shù)據(jù)長度和校驗碼字節(jié)
          *輸入?yún)?shù):pdata:數(shù)組指針;packsize:數(shù)據(jù)長度
          *返回參數(shù):數(shù)據(jù)是否有效,有效:VALID,無效:INVALID
          *編寫作者:my_avr
          *編寫時間:2007年8月21日
          *相關(guān)說明:
          ********************************************************************/
          unsigned char EepromCheck(unsigned char *pdata,unsigned char packsize)
          {
          unsigned char i,j;
          unsigned int crc,ref_crc;
          crc = 0;
          ref_crc = 0;
          for (i = 0; i < (packsize - 2); i ++)
          {
          crc = crc ^ ((uint16_t) EepromReadByte(pdata) << 8);
          for (j = 0; j < 8; j++)
          {
          if (crc & 0x8000)
          {
          crc = (crc << 1) ^ 0x1021;
          }
          else
          {
          crc = crc << 1;
          }
          }
          pdata ++;
          }
          ref_crc = (uint16_t) EepromReadByte(pdata);
          ref_crc = ref_crc<<8;
          pdata ++;
          ref_crc |= (uint16_t) EepromReadByte(pdata);
          if (crc == ref_crc)
          {
          return VALID;
          }
          else
          {
          return INVALID;
          }
          }
          /*******************************************************************
          *函數(shù)名稱:unsigned char CheckWriteCRC(unsigned char *pdata,unsigned char packsize)
          *函數(shù)功能:為EEPROM數(shù)據(jù)寫CRC校驗碼
          *輸入?yún)?shù):pdata:數(shù)組指針;packsize:數(shù)據(jù)長度
          *返回參數(shù):操作成功否?,成功:VALID,失?。篒NVALID
          *編寫作者:my_avr
          *編寫時間:2007年8月21日
          *相關(guān)說明:
          ********************************************************************/
          unsigned char CheckWriteCRC(unsigned char *pdata,unsigned char packsize)
          {
          unsigned char i,j;
          unsigned int crc;
          crc = 0;
          for (i = 0; i < (packsize - 2); i ++)
          {
          crc = crc ^ ((uint16_t) EepromReadByte(pdata) << 8);
          for (j = 0; j < 8; j++)
          {
          if (crc & 0x8000)
          {
          crc = (crc << 1) ^ 0x1021;
          }
          else
          {
          crc = crc << 1;
          }
          }
          pdata ++;
          }
          EepromWriteByte(pdata,(uint8_t) (crc>>8));
          pdata ++;
          EepromWriteByte(pdata,(uint8_t) crc);
          pdata ++;
          if (EepromCheck((pdata - packsize),packsize))
          {
          return VALID;
          }
          else
          {
          return INVALID;
          }
          }
          /********************************************************************
          *函數(shù)名稱:unsigned char CheckAllPage(void)
          *函數(shù)功能:檢查EEPROM數(shù)據(jù)是否有效,檢查三個備份
          *輸入?yún)?shù):無
          *返回參數(shù):操作成功否?,成功:VALID,失?。篒NVALID
          *編寫作者:my_avr
          *編寫時間:2007年8月21日
          *相關(guān)說明:
          ********************************************************************/
          uint8_t CheckAllPage(void)
          {
          if ((EepromCheck((unsigned char *)EepromPage1Add,EepromPageSize) == VALID)
          &&(EepromCheck((unsigned char *)EepromPage2Add,EepromPageSize) == VALID)
          &&(EepromCheck((unsigned char *)EepromPage3Add,EepromPageSize) == VALID))
          {
          return VALID;
          }
          return INVALID;

          評論


          技術(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); })();