新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 1602LCD液晶如何編寫數字電子鐘

        1602LCD液晶如何編寫數字電子鐘

        作者: 時間:2016-11-18 來源:網絡 收藏
        以前,學習單片機,都沒有開發板,因此感覺編寫數字電子鐘的程序,是非常難的,簡直就是不知道如何著手。 現在已經對單片機各種操作都逐漸熟悉了,因此剛剛就已經實現了自己關于數字電子鐘的一點小小的設計思想
        由于時間關系,現在已經比較晚了,所以就暫時不編寫按鍵功能,但是已經實現了動態計時功能了,明天再繼續添加按鍵功能。
        #include
        #include"MyFuntion.h" //自定義頭文件
        unsigned char year1=20; // 年1
        unsigned char year2=12; // 年2
        unsigned char month=1; // 月
        unsigned char day=22; // 日
        unsigned char hour=23; // 時
        unsigned char minute=12; // 分
        unsigned char second=56; // 秒
        unsigned char table1[10];
        unsigned char table2[8];
        unsigned char t; //定時器T0 發生中斷次數
        //unsigned char t1; //定時器T1 發生中斷次數
        /*
        //獨立按鍵P1口
        sbit Key1=P3^0; //Key1 取消調時 恢復單片機調時之前的實際時間
        sbit Key2=P3^1; //Key2 進入調整時間狀態: 停止定時器T0,啟動定時器T1.
        sbit Key3=P3^2; //Key3 退出調整時間狀態: 啟動定時器T0,停止定時器T1.
        sbit Key4=P3^3; //Key4 選擇調整時間: 秒, 分, 時, 日, 月, 年
        sbit Key5=P3^4; //Key5 調時: 遞增 同時啟動蜂鳴器
        sbit Key6=P3^5; //Key6 Key6 調時: 遞減 同時啟動蜂鳴器
        */
        void Init_Table_YMD() //年月日
        //進行對 時間的轉換 以致于可以把時間發送到1602LCD顯示
        {
        //把 year, month, day 轉換為一個字符存儲在數組table1
        table1[0]=year1/10;
        table1[1]=year1%10;
        table1[2]=year2/10;
        table1[3]=year2%10;
        table1[4]=-;
        table1[5]=month/10;
        table1[6]=month%10;
        table1[7]=-;
        table1[8]=day/10;
        table1[9]=day%10;
        }
        void Init_Table_HMS() // 時分秒
        {
        //把 hour, minute, second 轉換為一個字符存儲在數組table2
        table2[0]=hour/10;
        table2[1]=hour%10;
        table2[2]=:;
        table2[3]=minute/10;
        table2[4]=minute%10;
        table2[5]=:;
        table2[6]=second/10;
        table2[7]=second%10;
        }
        void IncreaseTime() // 秒鐘 遞增
        {
        second++;
        if(second==60)
        {
        second=0;
        minute++;
        if(minute==60)
        {
        minute=0;
        hour++;
        if(hour==24)
        {
        hour=0;
        }
        }
        }
        Init_Table_HMS(); //時分秒
        DisplayLCD_HMS(table2, 8); //LCD顯示時間 時分秒
        }
        void main()
        {
        TMOD=0X01;
        EA=1;
        ET0=1;
        // ET1=1;
        TR0=1; //啟動定時器T0
        // TR1=0; //停止定時器T1 即還沒有啟動定時器T1
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        InitLCD(); //初始化LCD
        Init_Table_YMD(); // LCD 時間表 年月日
        Init_Table_HMS(); // LCD 時間表 時分秒
        DisplayLCD_YMD(table1, 10); //LCD顯示時間 年月日
        DisplayLCD_HMS(table2, 8); //LCD顯示時間 時分秒
        while(1)
        {
        if(t==20)
        {
        t=0;
        IncreaseTime();
        }
        }
        // while(1);
        }
        void LCD_Timer0() interrupt 1 using 0
        {
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        t++;
        }



        評論


        技術專區

        關閉
        主站蜘蛛池模板: 荥阳市| 裕民县| 天镇县| 奉新县| 博野县| 筠连县| 乡宁县| 子长县| 苏尼特右旗| 华宁县| 长乐市| 德州市| 湛江市| 宝丰县| 安化县| 许昌县| 郧西县| 连平县| 荣成市| 夏邑县| 全南县| 中超| 永昌县| 玛曲县| 东安县| 牡丹江市| 文成县| 五家渠市| 定陶县| 元江| 南昌市| 娱乐| 连云港市| 当雄县| 东光县| 长乐市| 江永县| 惠来县| 钦州市| 宣威市| 思茅市|