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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > SPI總線驅(qū)動(dòng)(C語(yǔ)言源程序)

          SPI總線驅(qū)動(dòng)(C語(yǔ)言源程序)

          作者: 時(shí)間:2013-01-07 來(lái)源:網(wǎng)絡(luò) 收藏

          unsigned char eral_46()
          {
          data unsigned char temp1;
          data unsigned int temp2;
          cs_93=0;
          sk_93=0;
          //spi_org=1;
          cs_93=1;
          ewen46();
          _nop_();
          cs_93=1;
          _nop_();
          high46();
          wd46(0x20);
          wd46(0x20);
          cs_93=0;
          _nop_();
          cs_93=1;
          temp1=1;
          temp2=50000;
          while(!do_93)
          {
          temp2=temp2-1;
          if(temp2==0)
          {
          temp1=0;
          break;
          }
          }
          cs_93=0;
          return temp1;
          }


          unsigned int read93c46_word(unsigned char address)
          {
          unsigned int dat;
          unsigned char dat0,dat1;
          //gnd_93a=0;
          //gnd_93=0;
          cs_93=sk_93=0;
          //org_93=1;
          cs_93=1;_nop_();
          //address=address1;
          //address=address>>1;
          address=address|0x80;
          address=address|0x80;
          high46();
          wd46(address);
          dat1=rd46();
          dat0=rd46();
          cs_93=0;
          dat=dat1*256+dat0;
          return(dat);
          }
          bit write93c46_word(unsigned char address,unsigned int dat)
          {
          unsigned char e,time,temp=address;
          e=0;
          while (e3)
          {
          //gnd_93a=0;
          //gnd_93=0;
          cs_93=sk_93=0;
          org_93=1;
          cs_93=1;
          ewen46();
          _nop_();
          cs_93=1;
          _nop_();
          high46();
          address=1;//??
          address|=0x80;
          address>>=1;//??
          address|=0x40;
          wd46(address);
          wd46(dat/256);
          wd46(dat%256);
          cs_93=0;
          _nop_();
          cs_93=1;
          time=0;
          do_93=1;
          while (1)
          {
          if (do_93==1)
          break;
          if (time>20)
          break;
          time++;
          }
          cs_93=0;
          if (read93c46_word(temp)==dat)
          {
          return(0);
          }
          e++;
          }
          return(1);
          }
          /*-----------------------------------------------------
          93c57系列函數(shù)調(diào)用(舉例)
          調(diào)用方式:bit write93c57_word(unsigned int address,unsigned int dat) ﹫2001/05/12
          函數(shù)說(shuō)明:私有函數(shù),專用
          -----------------------------------------------------
          void ewen57(void)
          {
          _nop_();
          cs_93=1;
          dip7=0;
          high46();
          low46();
          wd46(0x60);
          cs_93=0;
          }
          unsigned int read93c57_word(unsigned int address)
          {
          unsigned int dat;
          unsigned char dat0,dat1;
          gnd_93=0;
          cs_93=sk_93=0;
          org_93=1;
          cs_93=1;
          address=address>>1;
          high46();
          high46();
          wd46(address);
          dat1=rd46();
          dat0=rd46();
          cs_93=0;
          dat=dat1*256+dat0;
          return(dat);
          }
          bit write93c57_word(unsigned int address,unsigned int dat)
          {
          unsigned char e;
          unsigned int temp=address;
          e=0;
          while (e3)
          {
          gnd_93=0;
          cs_93=sk_93=0;
          org_93=1;
          cs_93=1;
          ewen57();
          cs_93=1;
          _nop_();
          high46();
          low46();
          address>>=1;
          address|=0x80;
          wd46(address);
          wd46(dat/256);
          wd46(dat%256);
          cs_93=0;
          _nop_();
          cs_93=1;
          time=0;
          do_93=1;
          while (1)
          {
          if (do_93==1) break;
          if (time>20) break;
          }
          cs_93=0;
          if (read93c57_word(temp)==dat)
          {
          return(0);
          }
          e++;
          }
          return(1);
          }
          /*-----------------------------------------------------
          93c56系列函數(shù)調(diào)用(舉例)
          調(diào)用方式:bit write93c56_word(unsigned int address,unsigned int dat) ﹫2001/05/12
          函數(shù)說(shuō)明:私有函數(shù),SPI專用
          -----------------------------------------------------
          void ewen56(void)
          {
          _nop_();
          cs_93=1;
          high46();
          low46();
          low46();
          wd46(0xc0);
          cs_93=0;
          }
          unsigned int read93c56_word(unsigned char address)
          {
          unsigned int dat;
          unsigned char dat0,dat1;
          gnd_93=0;
          cs_93=sk_93=0;
          org_93=1;
          cs_93=1;
          address=address>>1;
          high46();
          high46();
          low46();
          wd46(address);
          dat1=rd46();
          dat0=rd46();
          cs_93=0;
          dat=dat1*256+dat0;
          return(dat);
          }
          bit write93c56_word(unsigned char address,unsigned int dat)
          {
          unsigned char e;
          unsigned int temp=address;
          e=0;
          while (e3)
          {
          gnd_93=0;
          cs_93=sk_93=0;
          org_93=1;
          cs_93=1;
          ewen56();
          _nop_();
          cs_93=1;
          _nop_();
          high46();
          low46();
          high46();
          address>>=1;
          wd46(address);
          wd46(dat/256);
          wd46(dat%256);
          cs_93=0;
          _nop_();
          cs_93=1;
          TH0=0;
          time=0;
          do_93=1;
          while (1)
          {
          if (do_93==1) break;
          if (time) break;
          }
          cs_93=0;
          if (read93c56_word(temp)==dat)
          {
          return(0);
          }
          e++;
          }
          return(1);
          }

          c語(yǔ)言相關(guān)文章:c語(yǔ)言教程


          晶振相關(guān)文章:晶振原理


          評(píng)論


          相關(guān)推薦

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