在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

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

            基于51的EEPROM C語言程序

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

            #include
            #define uchar unsigned char
            #define uint unsigned int
            uchar code tab[]="0123456789";
            sbit SID=P2^0; //數(shù)據(jù)信號
            sbit SCLK=P2^1; //時鐘信號
            uint tcnt; //定時中斷次數(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.biyoush.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() //啟動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) //寫一個字節(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() //讀一個字節(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總線時鐘
            {
            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語言程

            評論


            技術(shù)專區(qū)

            關(guān)閉