新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 用AVR純軟件模擬電子時鐘

        用AVR純軟件模擬電子時鐘

        作者: 時間:2016-11-20 來源:網(wǎng)絡(luò) 收藏
        * 目 的:電子時鐘的純軟件模擬*

        * 功 能:實現(xiàn)時鐘的功能
        * 時鐘頻率:內(nèi)部4M *
        * 編譯環(huán)境:ICC-AVR7 *

        本文引用地址:http://www.104case.com/article/201611/318912.htm

        *圖見上一篇日志*

        #include
        #include

        #define uint unsigned int
        #define uchar unsigned char
        #define on_138 PORTC|=BIT(PC7) //on or off 138
        #define off_138 PORTC&=~BIT(PC7)
        #pragma data:code

        uchar flash table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //the data for display
        uchar flash site[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
        uchar time[3];
        uchar temp[6];

        void delay(uint ms) //延時1ms
        {
        uint i,j;
        for(i=0;i for(j=0;j<564;j++);
        }

        void display(uchar i, uchar j) //數(shù)碼管顯示時間
        {
        if(i==1||i==3)
        {
        PORTA=site[i];
        PORTB=table[j];
        PORTB|=0X80;
        }
        else
        {
        PORTA=site[i];
        PORTB=table[j];
        }
        delay(1);
        }

        void time_to_temp() //顯示的時間數(shù)據(jù)送到temp數(shù)組保存
        {
        uchar i,j=0;
        for(i=0;i<3;i++)
        {
        temp[j++]=time[i];
        temp[j++]=time[i]/10;
        }
        }


        void inti() //初始化io口
        {
        DDRA=0X07;
        DDRB=0XFF;
        DDRC=0X80;
        }

        void main()
        {
        uchar i,time_count=0;
        time[0]=0;
        time[1]=26;
        time[2]=19;
        time_to_temp();
        inti();
        while(1)
        {
        for(i=0;i<6;i++)
        {
        on_138;
        display(i,temp[5-i]);
        off_138;
        }

        if(++time_count>=166)
        {
        time_count=0;
        if(++time[0]>=60)
        {
        time[0]=0;
        if(++time[1]>=60)
        {
        time[1]=0;
        if(++time[2]>=24)
        {
        time[2]=0;
        }
        }
        }
        time_to_temp();
        }
        }
        }


        關(guān)鍵詞: AVR純軟件模擬電子時

        評論


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

        關(guān)閉
        主站蜘蛛池模板: 石河子市| 桓台县| 喀喇沁旗| 屏南县| 祁门县| 太仆寺旗| 闸北区| 奉节县| 澳门| 廊坊市| 云龙县| 安塞县| 普定县| 彭山县| 永寿县| 蒲城县| 电白县| 宁乡县| 柘荣县| 新绛县| 合水县| 开江县| 安徽省| 肃宁县| 鄢陵县| 汾西县| 巫山县| 太原市| 英山县| 隆化县| 桐城市| 刚察县| 抚顺县| 清新县| 河北省| 徐州市| 浮山县| 家居| 长治市| 深泽县| 禄劝|