在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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)用 > 單片機學(xué)習(xí)——IIC總線及EEPROM實驗之二

            單片機學(xué)習(xí)——IIC總線及EEPROM實驗之二

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

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

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

            #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() //短延時子程序
            {
            ;;
            }
            void init()//初使化子程序
            {
            leden=0;
            wkle=0;

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

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

            sda=1;
            scl=1;
            }

            void start() //開始子程序
            {
            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) //寫入字節(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) //寫入子程序
            {
            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ù)
            uint i,j;
            for(j=a;j>0;j--)
            for(i=250;i>0;i--) ;
            }



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

            評論


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

            關(guān)閉