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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AVR內(nèi)部EEPROM擦寫次數(shù)測試程序

          AVR內(nèi)部EEPROM擦寫次數(shù)測試程序

          作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
          略作修改的程序,請?jiān)僭u測。

          /*****************************************************/
          /* 廣州天河雙龍電子公司北京分公司 */
          /* 測試EEPROM讀寫次數(shù) */
          /* 2004年12月21日 */
          /* 目標(biāo)MCU:MEGA48 晶振:內(nèi)部RC(INT) 8MHZ */
          /*****************************************************/
          #include "iom48v.h"
          #include "macros.h"
          #define fosc 8000000 //內(nèi)部8MHZ晶振
          #define baud 19200 //波特率
          unsigned CHAR eep_r;//EEPROM讀出的數(shù)據(jù)
          unsigned CHAR N;//EEPROM讀寫次數(shù)第一部分
          unsigned CHAR kk;//EEPROM讀寫次數(shù)第二部分
          unsigned int count;//EEPROM讀寫次數(shù)第三部分

          本文引用地址:http://www.ex-cimer.com/article/201612/324634.htm

          /***************************************
          串口輸出函數(shù),用于發(fā)送記數(shù)結(jié)果
          ****************************************/
          void putCHAR(unsigned CHAR c)
          {
          while (!(UCSR0A&(1< UDR0=c;//數(shù)據(jù)寄存器
          }

          /**************************************
          串口初始化
          ***************************************/
          void uart_init(void)
          {
          UCSR0B=(1<UBRR0L=(fosc/(16*baud)-1)%256;//對波特率寄存器預(yù)置數(shù)
          UBRR0H=(fosc/(16*baud)-1)/256;
          UCSR0C=(0<}


          /***********************************
          主程序
          ***********************************/
          void main(void)
          {
          PORTD=0xFF; //開放D口
          DDRD=0xFF;
          PORTB=0xFF;//開放B口
          DDRB=0xFF;
          uart_init();
          CLI(); //關(guān)中斷,以免干涉EEPROM的寫入
          while(1)
          {
          EEPROM_write(0x00FD,0X5A);//寫地址和數(shù)據(jù),可修改
          eep_r=EEPROM_read(0x00FD);
          comp();
          EEPROM_write(0x00FD,0XA5);//寫地址和數(shù)據(jù),可修改
          eep_r=EEPROM_read(0x00FD);
          comp();
          }
          }

          /*******************************************************************
          對讀出的數(shù)據(jù)進(jìn)行比較 正確……LED顯示R,并從串口發(fā)送數(shù)據(jù)kk
          錯(cuò)誤……LED顯示F,并從串口發(fā)送數(shù)據(jù)kk,count

          讀寫總次數(shù)為:(N*256+kk)*4000+count
          ******************************************************************/
          void comp(void)
          {
          unsigned CHAR eep_old,count_high,count_low;
          eep_old = eep_r&0x0f; //取EEPROM的低4位
          eep_r = eep_r >> 4; //取EEPROM的高4位
          if(eep_old+eep_r != 0x0f ) //低4位加高4位,結(jié)果和F比較
          {
          count_high =count >> 8;
          count_low=count&0xff;
          putCHAR(N);//輸出最終記數(shù)值
          putCHAR(kk); //輸出最終記數(shù)值
          putCHAR(count_high); //輸出此時(shí)的已讀寫次數(shù),總數(shù)為:(N*256+kk)*4000+count(次)
          putCHAR(count_low);
          PORTB=0x8E; //點(diǎn)亮LED
          PORTD=0xEF;
          while(1); //讀取數(shù)據(jù),發(fā)生一次錯(cuò)誤后,程序在此處掛起。
          }
          else
          {
          count++; //每讀寫一次,count累加1
          if(count>=4000) //每讀寫4000次,KK累加1
          { //并從串口送出KK
          count=count-4000;
          kk++;
          if(kk>=255)
          {
          N++;
          }
          putCHAR(N);
          putCHAR(kk);
          } //點(diǎn)亮LED
          PORTB=0x88;
          PORTD=0x7F;
          }
          }

          /*********************************************
          EEPROM寫操作
          ********************************************/
          void EEPROM_write(unsigned int uiAddress, unsigned CHAR ucData)
          {
          while(EECR & (1<EEAR = uiAddress;
          EEDR = ucData;
          EECR |= (1<EECR |= (1<}

          /********************************************
          EEPROM讀操作
          *******************************************/
          unsigned CHAR EEPROM_read(unsigned int uiAddress)
          {
          while(EECR & (1<EEAR = uiAddress;
          EECR |= (1<return EEDR;
          }



          評論


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