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

          新聞中心

          AVR Eeprom的c語言編程

          作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          //***************FileName:Capature.C***************//

          //***************ICCAVR 編譯*****************//

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

          #include
          #define uchar unsigned char
          #define uint unsigned int

          //數(shù)碼管字型表,對應(yīng)0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F//
          uchar Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
          0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
          uchar Read_Data[4]; //定義讀出數(shù)據(jù)

          void DelayMs(uint i) //Ms級延時(shí),參數(shù)i為延時(shí)時(shí)間
          {uint j;
          for(;i!=0;i--)
          {for(j=8000;j!=0;j--) {;}}
          }

          void Display(uchar *p) //動態(tài)顯示函數(shù),參數(shù)p為待顯示的數(shù)組名
          {uchar i,sel=0x01;
          for(i=0;i<4;i++)
          {PORTA=sel; //選通最右邊的數(shù)碼管
          PORTC=0xff-Table[p[i]]; //送字型碼
          DelayMs(1); //顯示延時(shí)
          sel=sel<<1; //移位以顯示前一位
          }
          }

          void Init_IO(void) //初始化I/O口
          {DDRA=0xff; //設(shè)置A口為推挽1輸出
          PORTA=0xff;
          DDRC=0xff; //設(shè)置C口為推挽1輸出
          PORTC=0xff;
          }

          void Write_EEPROM(uchar Data,uint Address)
          {if(EECR&0x20) DelayMs(4);
          EEARH=Address>>8;
          EEARL=Address&0x00ff;
          EEDR=Data;
          EECR=EECR|0x04;
          EECR=EECR|0x02;
          DelayMs(4);
          }

          uchar Read_EEPROM(uint Address)
          {uchar i;
          if(EECR&0x01) DelayMs(4);
          EEARH=Address>>8;
          EEARL=Address&0x00ff;
          EECR=EECR|0x01;
          DelayMs(5);
          i=EEDR;
          return(i);
          }

          void main(void)
          {uchar i;
          Init_IO(); //初始化I/O口
          PORTA=0xff; //點(diǎn)亮以測試所有的數(shù)碼管
          PORTC=0x00;
          DelayMs(300); //延時(shí)
          PORTC=0xff; //熄滅所有的數(shù)碼管
          for(i=0;i<4;i++)
          Write_EEPROM(4*i,i);
          for(i=0;i<4;i++)
          Read_Data[i]=Read_EEPROM(i);
          while(1)
          Display(Read_Data);
          }



          關(guān)鍵詞: AVREepromc語言編

          評論


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