新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 自制51單片機(jī)超大數(shù)碼管時(shí)鐘

        自制51單片機(jī)超大數(shù)碼管時(shí)鐘

        作者: 時(shí)間:2012-08-04 來源:網(wǎng)絡(luò) 收藏

        delay()
        {
        int j;
        for (j=0;j100;j++);
        }

        void display(unsigned char *lp)//顯示
        {
        uint k;
        for (k=0;k4;k++)
        {
        pos=w[k];
        segs=d[lp[k]];
        delay();
        segs=d[17];
        }

        pos=w[4];
        segs=d[flash]; //秒閃爍燈
        delay();
        segs=d[17];

        }

        void Write_Ds1302_Byte(unsigned char temp)
        {
        unsigned char i;
        for (i=0;i8;i++) //循環(huán)8次 寫入數(shù)據(jù)
        {
        SCL2=0;
        SDA2=temp0x01; //每次傳輸?shù)妥止?jié)
        temp>>=1; //右移一位
        SCL2=1;
        }
        }

        /***********************************************************

        *****************/
        void Write_Ds1302( unsigned char address,unsigned char dat )
        {
        RST=0;
        _nop_();
        SCL2=0;
        _nop_();
        RST=1;
        _nop_(); //啟動(dòng)
        Write_Ds1302_Byte(address); //發(fā)送地址
        Write_Ds1302_Byte(dat); //發(fā)送數(shù)據(jù)
        RST=0; //恢復(fù)
        }
        /*********************************************************

        *******************/
        unsigned char Read_Ds1302 ( unsigned char address )
        {
        unsigned char i,temp=0x00;
        RST=0;
        _nop_();
        SCL2=0;
        _nop_();
        RST=1;
        _nop_();
        Write_Ds1302_Byte(address);
        for (i=0;i8;i++) //循環(huán)8次 讀取數(shù)據(jù)
        {
        if(SDA2)
        temp|=0x80; //每次傳輸?shù)妥止?jié)
        SCL2=0;
        temp>>=1; //右移一位
        SCL2=1;
        }
        RST=0;
        _nop_(); //以下為DS1302復(fù)位的穩(wěn)定時(shí)間
        RST=0;
        SCL2=0;
        _nop_();
        SCL2=1;
        _nop_();
        SDA2=0;
        _nop_();
        SDA2=1;
        _nop_();
        return (temp); //返回
        }
        /**************************************************************

        **************/
        void Read_RTC(void) //讀取 日歷
        {
        unsigned char i,*p;
        p=read_rtc_address; //地址傳遞
        for(i=0;i7;i++) //分7次讀取 年月日時(shí)分秒星期
        {
        now[i]=Read_Ds1302(*p);
        p++;
        }
        }
        /***********************************************************

        ************/
        void Set_RTC(void) //設(shè)定 日歷
        {
        unsigned char i,*p,tmp;
        for(i=0;i7;i++){
        tmp=now[i]/10;
        now[i]=now[i]%10;
        now[i]=now[i]+tmp*16;
        }
        Write_Ds1302(0x8E,0X00);

        p=write_rtc_address; //傳地址
        for(i=0;i7;i++) //7次寫入 年月日時(shí)分秒星期
        {
        Write_Ds1302(*p,now[i]);
        p++;
        }
        Write_Ds1302(0x8E,0x80);
        }

        void keydelay(unsigned char t)
        {
        unsigned char i,j;
        for(i=0;it;i++)
        for(j=0;j120;j++);
        }

        51單片機(jī)相關(guān)文章:51單片機(jī)教程



        上一頁 1 2 下一頁

        關(guān)鍵詞: 51單片機(jī) 超大數(shù)碼管時(shí)鐘

        評論


        相關(guān)推薦

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

        關(guān)閉
        主站蜘蛛池模板: 苗栗市| 微山县| 鱼台县| 乐平市| 镇安县| 西和县| 山西省| 东城区| 伊吾县| 彭州市| 福鼎市| 石门县| 建阳市| 开远市| 方城县| 本溪市| 怀化市| 温州市| 卓尼县| 万安县| 五家渠市| 宿迁市| 凯里市| 鄂托克前旗| 巧家县| 镇巴县| 中阳县| 常州市| 龙泉市| 泗水县| 泰宁县| 丹江口市| 勐海县| 安多县| 石渠县| 封丘县| 莱阳市| 平泉县| 营山县| 彭泽县| 山东|