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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)學(xué)習(xí)——IIC總線及EEPROM實(shí)驗(yàn)之二

          單片機(jī)學(xué)習(xí)——IIC總線及EEPROM實(shí)驗(yàn)之二

          作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
          題目:顯示000~999跑表,先讀數(shù)據(jù)到EEPROM,再?gòu)腅EPROM讀出,再在數(shù)碼管上顯示出 來(lái)

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

          解決方案:(C 語(yǔ)言編程)

          #include
          #include
          #define uchar unsigned char
          #define uint unsigned int
          uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
          0xf8,0x80,0x90};
          uchar code tablewe[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
          uchar bai,shi,ge,num,flag;
          uint shu;
          void delay1(uchar);
          void display(uchar ba,uchar sh,uchar g);
          sbit scl=P3^3;
          sbit sda=P3^4;
          sbit le=P3^6;
          sbit leden=P2^5;
          sbit wkle=P3^7;
          void delay() //短延時(shí)子程序
          {
          ;;
          }
          void init()//初使化子程序
          {
          leden=0;
          wkle=0;

          flag=0;
          shu=0;
          bai=0;
          shi=0;
          ge=0;

          TMOD=0x01;//定時(shí)器初始化
          TH0=0xd8;
          TL0=0xf0;
          EA=1;
          ET0=1;
          TR0=1;

          sda=1;
          scl=1;
          }

          void start() //開(kāi)始子程序
          {
          sda=1;
          delay();
          scl=1;
          delay();
          sda=0;
          delay();
          }

          void stop()
          {
          sda=0;
          delay();
          scl=1;
          delay();
          sda=1;
          delay();
          }
          void write_byte(uchar dat) //寫(xiě)入字節(jié)子程序
          {
          uchar a,temp;
          temp=dat;
          for(a=0;a<8;a++)
          {
          temp=temp<<1;
          scl=0;
          delay();
          sda=CY;
          delay();
          scl=1;
          delay();
          }
          scl=0;
          delay();
          sda=1;
          delay();
          }

          uchar read_byte() //讀出字節(jié)子程序
          {
          uchar a,b,c;
          scl=0;
          delay();
          sda=1;
          delay();
          for(a=0;a<8;a++)
          {
          scl=1;
          delay();
          b=sda;
          c=(c<<1)|b;
          scl=0;
          delay();
          }
          return c;
          }

          void respon()//響應(yīng)子程序
          {
          uchar a;
          scl=1;
          delay();
          while((sda==1)&&(a<100))a++;
          scl=0;
          delay();

          }
          void write(uchar add,uchar dat) //寫(xiě)入子程序
          {
          start();
          write_byte(0xa0);
          respon();
          write_byte(add);
          respon();
          write_byte(dat);
          respon();
          stop();
          }
          uchar read(uchar add) //讀出子程序
          {
          uchar dat;
          start();
          write_byte(0xa0);
          respon();
          write_byte(add);
          respon();
          start();
          write_byte(0xa1);
          respon();
          dat=read_byte();
          respon();
          stop();
          return dat;
          }
          void main() //main 函數(shù)
          {
          init();
          while(1)
          {
          display(bai,shi,ge);
          }
          }
          void time0() interrupt 1//中斷子函數(shù)
          {
          uchar num;
          TH0=0xd8;
          TL0=0xf0;
          num++;
          if(num==10){
          num=0;
          flag=1;
          shu++;
          if(shu==999)
          shu=0;
          bai=shu/100;
          shi=shu%100/10;
          ge=shu%10;
          write(1,tabledu[bai]);
          delay1(3);
          bai=read(1);
          delay1(3);
          write(2,tabledu[shi]);
          delay1(3);
          shi=read(2);
          delay1(3);
          write(3,tabledu[ge]);
          delay1(5);
          ge=read(3);
          }
          }
          void display(uchar ba,uchar sh,uchar g) //顯示子程序
          {
          le=1;
          P2=tablewe[1];
          le=0;
          le=1;
          P0=ba;
          le=0;
          delay1(1);
          le=1;
          P2=tablewe[2];
          le=0;
          le=1;
          P0=sh;
          le=0;
          delay1(1);
          le=1;
          P2=tablewe[3];
          le=0;
          le=1;
          P0=g;
          le=0;
          delay1(1);
          }
          void delay1(uchar a) { //延時(shí)子函數(shù)
          uint i,j;
          for(j=a;j>0;j--)
          for(i=250;i>0;i--) ;
          }



          關(guān)鍵詞: 單片機(jī)IIC總線EEPRO

          評(píng)論


          技術(shù)專(zhuān)區(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); })();