在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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單片機 + ds12c887時鐘芯片 開發(fā)的電子時鐘

            51單片機 + ds12c887時鐘芯片 開發(fā)的電子時鐘

            作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
            原文地址:51單片機+ds12c887時鐘芯片開發(fā)的電子時鐘作者:紫暮秋風











            主要代碼如下

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

            void delay(int z)
            {
            int x,y;
            for(x=z;x>0;x--)
            for(y=110;y>0;y--);
            }

            void write_com(char com) //寫指令操作
            {
            rs=0;
            lcden=0; //這一步萬萬不可少,否則不出結(jié)果
            P0=com;
            delay(5);
            lcden=1;
            delay(5);
            lcden=0;
            }

            void didi()
            {
            beep=0;
            delay(50);
            beep=1;
            delay(100);
            beep=0;
            delay(50);
            beep=1;
            }
            void write_data(char date) //寫命令操作
            {
            rs=1;
            lcden=0; //這一步萬萬不可少,否則不出結(jié)果
            P0=date;
            delay(5);
            lcden=1;
            delay(5);
            lcden=0; //使用完畢后一定要釋放使能端 即置零

            }


            void init() //初始化函數(shù)
            {
            char num;
            EA=1;
            EX0=1;
            IT0=1;
            wela=0;
            dula=0;
            lcden=0;
            set_alarm(17,13,30);
            write_ds(0x0B,0x26);
            read_ds(0x0c);
            write_com(0x38);
            write_com(0x0c);
            write_com(0x06);
            write_com(0x01);
            write_com(0x80);
            for(num=0;num<15;num++)
            {
            write_data(table1[num]);
            delay(5);
            }
            write_com(0x80+0x40);
            for(num=0;num<10;num++)
            {
            write_data(table2[num]);
            delay(5);
            }

            }


            void write_time(char clock,char address1)
            {
            char ge,shi;
            shi=clock/10;
            ge=clock%10;
            write_com(0x80+0x40+address1);
            write_data(0x30+shi);
            delay(10);
            write_data(0x30+ge); //記住此處一定要加0x30 因為char型數(shù)字+0x30才能在液晶上顯示出來,另外字符如a,b等可直接顯示
            } //例如write_data(a) write_data(5+0x30)才是對的//不能寫write_data(a)或write_data(5)

            void keyscan1() //加法檢測
            {
            if(s17==0)
            {
            delay(50);
            if(s17==0&flag1==1)
            {
            flag1=0;
            }
            if((s17==0)&&(s13num==1))
            {
            if(miao==59)
            {
            miao=0;
            }
            miao++;
            write_time(miao,0x08);
            }

            if((s17==0)&&(s13num==2))
            {
            if(fen==59)
            {
            fen=0;
            }

            fen++;
            write_time(fen,0x05);
            }

            if((s17==0)&&(s13num==3))
            {
            if(shi==23)
            {
            shi=0;
            }
            shi++;
            write_time(shi,0x02);
            }

            while(!s17);
            }

            }


            void keyscan2() //減法檢測
            {
            if(s21==0)
            {
            delay(50);

            if(s21==0&flag1==1)
            {
            flag1=0;
            }
            if((s21==0)&&(s13num==1))
            {
            if(miao==0)
            {
            miao=59;
            }
            miao--;
            write_time(miao,0x08);
            }

            if((s21==0)&&(s13num==2))
            {
            if(fen==0)
            {
            fen=59;
            }

            fen--;
            write_time(fen,0x05);
            }

            if((s21==0)&&(s13num==3))
            {
            if(shi==0)
            {
            shi=23;
            }
            shi--;
            write_time(shi,0x02);
            }

            while(!s21);
            }
            }


            void keyscan() //復位鍵檢測
            {
            rd=0;
            if(s13==0)
            {
            delay(5);
            if(s13==0)
            {
            flag=1;
            TR0=0;
            s13num++;
            }
            while(!s13);
            if(flag1==1)
            {
            s13num=4;
            flag1=0;
            }
            write_com(0x0f);
            }

            if(s13num==1)
            {
            write_com(0x80+0x40+0x08);
            }
            if(s13num==2)
            {
            write_com(0x80+0x40+0x05);
            }
            if(s13num==3)
            {
            write_com(0x80+0x40+0x02);
            }
            if(s13num==4)
            {
            s13num=0;
            flag=0;
            write_com(0x0c);
            write_ds(4,shi);
            write_ds(2,fen);
            write_ds(0,miao);
            }

            keyscan1();
            keyscan2();
            }


            void write_ds(char add,char date)
            {
            dscs=0;
            dsas=1;
            dsds=1;
            dsrw=1;
            P0=add;
            dsas=0;
            dsrw=0;
            P0=date;
            dsrw=1;
            dsas=1;
            dscs=1;
            }

            char read_ds(char add)
            {
            char ds_date;
            dscs=0;
            dsas=1;
            dsds=1;
            dsrw=1;
            P0=add;
            dsas=0;
            dsds=0;
            P0=0xff; //此處一定要給P0附0xff
            ds_date=P0;
            dsds=1;
            dsas=1;
            dscs=1;
            return ds_date;
            }


            void set_time()
            {
            write_ds(4,15);
            write_ds(2,03);
            write_ds(0,50);
            }

            void set_alarm(char ashi,char afen,char amiao)
            {
            write_ds(1,amiao);
            write_ds(3,afen);
            write_ds(5,ashi);

            }

            void main()
            {

            init();
            while(1)
            {
            keyscan();
            if(flag1==1)
            didi();
            if(flag==0)
            {
            miao=read_ds(0);
            fen=read_ds(2);
            shi=read_ds(4);
            write_time(miao,0x08);
            write_time(fen,0x05);
            write_time(shi,0x02);
            }

            }

            }

            void ext0() interrupt 0
            {
            char c;
            beep=0;
            c=read_ds(0x0C);
            flag1=1;
            }




            評論


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

            關(guān)閉