新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 定時器定時模擬數字鐘顯示

        定時器定時模擬數字鐘顯示

        作者: 時間:2016-11-30 來源:網絡 收藏

        #include

        本文引用地址:http://www.104case.com/article/201611/323948.htm
        #define uchar unsigned char
        sbit P2_0 = P2^0;
        sbit P2_1 = P2^1;
        sbit P2_2 = P2^2;
        sbit P2_3 = P2^3;
        static unsigned char second,minute,hour;
        unsigned int tcount;
        unsigned char m;
        uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
        0xf8,0x80,0x90};
        void delay(uchar i)
        {
        uchar j,k;
        for(j=i;j>0;j--)
        for(k=125;k>0;k--);
        }
        void display()
        {
        P0=table[minute/10];
        P2_0 = 0;
        delay(5);
        P2_0 = 1;
        P0=(table[minute%10]& 0x7f);
        P2_1 = 0;
        delay(5);
        P2_1 = 1;
        P0=table[second/10];
        P2_2 = 0;
        delay(5);
        P2_2 = 1;
        P0=table[second%10];
        P2_3 = 0;
        delay(5);
        P2_3 = 1;
        }
        /*演示主程序*/
        void main(void)
        {
        unsigned int a;
        TMOD=0x02;
        TH0=0x06;
        TL0=0x06;
        TR0=1;
        ET0=1;
        EA=1;
        while(1)
        {
        for(a=100;a>0;a--)
        {
        display();
        }
        }
        }
        /*
        ********************************************************************************
        ** 函數名稱 : t0(void) interrupt 1 using 0
        ** 函數功能 : 定時器中斷
        ********************************************************************************
        */
        void t0(void) interrupt 1 using 0
        { tcount++;
        if(tcount==4000)
        {tcount=0;
        second++;
        if(second==60)
        {second=0;
        minute++;
        if(minute==60)
        {minute=0;
        hour++;
        if(hour==24)
        {hour=0;
        }
        }
        }
        }
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 邢台市| 南通市| 灵武市| 舞钢市| 康保县| 绵阳市| 竹山县| 崇文区| 安陆市| 江口县| 柳河县| 四川省| 轮台县| 嵊州市| 中方县| 浠水县| 固原市| 英吉沙县| 五寨县| 凉城县| 灵武市| 德化县| 信丰县| 阿荣旗| 石嘴山市| 贺兰县| 宜城市| 阿拉善盟| 广德县| 安泽县| 关岭| 石门县| 佛学| 金堂县| 巴彦淖尔市| 岑巩县| 临西县| 延津县| 宁强县| 凌海市| 松江区|