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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于51的EEPROM C語言程序

          基于51的EEPROM C語言程序

          作者: 時(shí)間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
          #include "reg52.h"http://單片機(jī)51頭文件,存放著單片機(jī)的寄存器

          #include
          #define uchar unsigned char
          #define uint unsigned int
          uchar code tab[]="0123456789";
          sbit SID=P2^0; //數(shù)據(jù)信號(hào)
          sbit SCLK=P2^1; //時(shí)鐘信號(hào)
          uint tcnt; //定時(shí)中斷次數(shù)
          bit write=0; //寫24C08的標(biāo)志;
          sbit scl=P3^7; //24c08 SCL
          sbit sda=P3^6; //24c08 SDA
          uchar a,b,c,d,e,f;

          void delay(uint t)
          {
          uint i,j;
          for(i=0; i for(j=0; j<10; j++);
          }

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


          void sendbyte(uchar zdata)
          {
          uint i;
          for(i=0; i<8; i++)
          {
          if((zdata << i) & 0x80)
          {
          SID = 1;
          }
          else
          {
          SID = 0;
          }
          SCLK = 0;
          SCLK = 1;
          }
          }


          void write_com(uchar cmdcode)
          {
          sendbyte(0xf8); //11111abc a如果高表示從LCD讀數(shù)據(jù),低表示往LCD寫數(shù)據(jù)。 b 高表示顯示數(shù)據(jù),低表示控制指令 c 固定為0
          sendbyte(cmdcode & 0xf0); //取cmdcode的高四位
          sendbyte((cmdcode << 4) & 0xf0); //取cmdcode的第四位
          delay(2);
          }


          void write_data(unsigned char Dispdata)
          {
          sendbyte(0xfa);
          sendbyte(Dispdata & 0xf0);
          sendbyte((Dispdata << 4) & 0xf0);
          delay(2);
          }


          void lcdinit()
          {
          delay(200);
          write_com(0x30);
          delay(50);
          write_com(0x0c);
          delay(50);
          write_com(0x01);
          delay(50);
          }


          void hzkdis(unsigned char code *s)
          {
          while(*s > 0)
          {
          write_data(*s);
          s++;
          delay(50);
          }
          }
          void delay1(unsigned char x)
          { unsigned int i;
          for(i=0;i}
          void flash()
          { ; ; }

          void x24c02_init() //24c02初始化子程序
          {scl=1; flash(); sda=1; flash();}

          void start() //啟動(dòng)I2C總線
          {sda=1; flash(); scl=1; flash(); sda=0; flash(); scl=0; flash();}

          void stop() //停止I2C總線
          {sda=0; flash(); scl=1; flash(); sda=1; flash();}
          void writex(uchar j) //寫一個(gè)字節(jié)
          { uchar i,temp;
          temp=j;
          for (i=0;i<8;i++)
          {temp=temp<<1; scl=0; flash(); sda=CY; flash(); scl=1; flash();}
          scl=0; flash(); sda=1; flash();
          }
          uchar readx() //讀一個(gè)字節(jié)
          {
          uchar i,j,k=0;
          scl=0; flash(); sda=1;
          for (i=0;i<8;i++)
          { flash(); scl=1; flash();
          if (sda==1) j=1;
          else j=0;
          k=(k<<1)|j;
          scl=0;}
          flash(); return(k);
          }
          void clock() //I2C總線時(shí)鐘
          {
          uchar i=0;
          scl=1; flash();
          while ((sda==1)&&(i<255))i++;
          scl=0; flash();
          }
          uchar x24c02_read(uchar address)
          {
          uchar i;
          start(); writex(0xa0);
          clock(); writex(address);
          clock(); start();
          writex(0xa1); clock();
          i=readx(); stop();
          delay1(10);
          return(i);
          }
          void x24c02_write(uchar address,uchar info)
          {

          start(); writex(0xa0);
          clock(); writex(address);
          clock(); writex(info);
          clock(); stop();
          delay1(50);
          }
          void yejing()
          {
          write_com(0x90);
          delay(10);
          write_data(tab[a]);
          delay(10);
          write_data(tab[b]);
          //delay(10);
          //write_com(0x91);
          delay(10);
          write_data(tab[c]);
          //write_com(0x90);
          delay(10);
          write_data(tab[d]);
          delay(10);
          write_data(tab[e]);
          delay(10);
          write_data(tab[f]);
          }
          void main(void)
          {
          lcdinit();
          x24c02_init();
          while(1)
          {
          a=x24c02_read(0);//讀出保存的數(shù)據(jù)賦于sec
          b=x24c02_read(1);
          c=x24c02_read(2);
          d=x24c02_read(3);
          e=x24c02_read(4);
          f=x24c02_read(5);
          yejing();
          x24c02_write(0,8);delay(10);
          x24c02_write(1,7);delay(10);
          x24c02_write(2,0);delay(10);
          x24c02_write(3,2);delay(10);
          x24c02_write(4,0);delay(10);
          x24c02_write(5,8);delay(10);
          delay(1000);
          }
          }




          關(guān)鍵詞: 51EEPROMC語言程

          評(píng)論


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