久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8443|回復(fù): 14
打印 上一主題 下一主題
收起左側(cè)

STC89C52+LCD12864+DS1302+DS18B20時(shí)鐘原理圖+源程序

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:185443 發(fā)表于 2019-12-26 11:00 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
STC89C52+LCD12864+DS1302 +DS18B20時(shí)鐘供大家學(xué)習(xí)。

            電子智能時(shí)鐘程序
            單 片 機(jī):STC89C52
     晶    振:12MHz
         時(shí)鐘芯片:DS1302
            液 晶 屏:LCD12864

                時(shí)    間:2020年1月1日
                LCD12864使用并口連接方式,PSB、RST接高電平




/*-------------------------------頭文件---------------------------------------*/

#include <reg52.h>

#include <intrins.h>

#include "LCD12864.h"

#include "DS1302.h"

#include "DS18B20.h"

#include "nongli.h"

#include "displaytime.h"

//#include "jieqi.h"

#define uint  unsigned int

#define uchar unsigned char


/*----------------------------定義按鍵---------------------------------------*/

sbit K1  = P2^3; //K1-設(shè)置  

sbit K2  = P2^2; //K2-確認(rèn)、返回   

sbit K3  = P2^1; //K3-加         

sbit K4  = P2^0; //K4-減         

//sbit K5  = P3^7; //液晶背光控制按鍵,按一下亮,再按一下滅                 

//sbit BLK = P3^7; //液晶背光控制輸出,低電平有效,PNP三極管控制。


/*---------------------函數(shù)聲明------------------------------*/

void DelayM(uint);               

void ds_w(void);

void Conver_week(bit c,uchar year,uchar month,uchar day);

/*-----------------------------定義全局變量------------------------------*/

bit q=0, w=0;    //調(diào)時(shí)標(biāo)志位

unsigned char yy,mo,dd,xq,hh,mm,ss,month_moon,day_moon,week,tiangan,dizhi,moontemp1,moontemp2;//定義時(shí)間映射全局變量(專用寄存器)

signed char address,item,max,mini;


/*-----------------------------延時(shí)函數(shù) 1MS/次-------------------------------*/

void DelayM(uint a)               

{

        uchar i;

        while( --a != 0) { for(i = 0; i < 125; i++); }                                      

}

/*-----------------------------日期、時(shí)間設(shè)置函數(shù)-----------------------------*/


void tiaozheng(void){

        yy = read_clock(0x8d);//調(diào)用1302時(shí)鐘數(shù)據(jù)中的年數(shù)據(jù),從地址0x8d中   

        mo = read_clock(0x89);//調(diào)用1302時(shí)鐘數(shù)據(jù)中的月數(shù)據(jù),從地址0x89中   

        dd = read_clock(0x87);//從1302芯片中讀取日數(shù)據(jù),從地址0x87中   

        week = read_clock(0x8b);//從1302芯片中讀取星期數(shù)據(jù),從地址0x8b中   

        lcm_w_test(0,0x80);


        lcm_w_word("20");//顯示內(nèi)容字符20

        write_data(yy/16+0x30);//函數(shù)參數(shù)1,代表本行寫數(shù)據(jù),YY/16+0X30得出年十位數(shù)字的顯示碼地址,送顯示        

        write_data(yy%16+0x30);//函數(shù)?

        lcm_w_word("年");


        write_data(mo/16+0x30);

        write_data(mo%16+0x30);//與16取余數(shù),得到月份的個(gè)位數(shù),加0x30得到該數(shù)字的液晶內(nèi)定顯示碼送顯示

        lcm_w_word("月");     //調(diào)用字符顯示函數(shù),顯示文字 月   


        write_data(dd/16+0x30);

        write_data(dd%16+0x30);//第一個(gè)1參數(shù),表示本行寫數(shù)據(jù),日數(shù)據(jù)與16取余得個(gè)位數(shù),加0x30得到顯示碼

        lcm_w_word("日");//顯示字符 日


        if(read_clock(0x85) != hh){  //如果程序中的小時(shí)與1302芯片中的不同,

                hh = read_clock(0x85);  //刷新程序中的小時(shí)數(shù)據(jù)   

        }

        lcm_w_test(0,0x91);//第一個(gè)參數(shù)0,表示本行寫入LCM的是指令,指定顯示位置91H(第三行左端)

        write_data(hh/16+0x30);  //顯示十位



        write_data(hh%16+0x30);  //顯示個(gè)位

        lcm_w_word("時(shí)");


        if(read_clock(0x83) != mm){//如果1302芯片中的分鐘數(shù)據(jù)與程序中的分鐘變量不相等               

                mm = read_clock(0x83);//刷新程序中的分鐘數(shù)據(jù)

        }

        write_data(mm/16+0x30);//向液晶寫數(shù)據(jù),顯示分鐘的十位數(shù)

        write_data(mm%16+0x30);//向液晶寫數(shù)據(jù),顯示分鐘的個(gè)位數(shù)

        lcm_w_word("分");


        if(read_clock(0x81) != ss){//如果1302芯片中的分鐘數(shù)據(jù)與程序中的秒鐘變量不相等               

                ss = read_clock(0x81);//刷新程序中的秒鐘數(shù)據(jù)

        }

        write_data(ss/16+0x30);//向液晶寫數(shù)據(jù),顯示分鐘的十位數(shù)

        write_data(ss%16+0x30);//向液晶寫數(shù)據(jù),顯示分鐘的個(gè)位數(shù)

        lcm_w_word("秒");         


}


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

//調(diào)整時(shí)間子函數(shù),設(shè)置鍵、數(shù)據(jù)范圍、上調(diào)加一,下調(diào)減一功能。

void Set_time(unsigned char sel){ //根據(jù)選擇調(diào)整的相應(yīng)項(xiàng)目加1并寫入DS1302,函數(shù)參數(shù)是按動(dòng)設(shè)置鍵的次數(shù)


        write_com(0x30); write_com(0x06);


        lcm_w_test(0,0x98);//第一參數(shù)0表示本行寫入指令,指定下面行的 調(diào)整 顯示起始位置為98H

        lcm_w_word("★調(diào)整");//調(diào)用字符顯示函數(shù),顯示 調(diào)整字樣


/*        if(sel==6)  {lcm_w_word("星期");address=0x8a; max=7;mini=1;         

     tiaozheng();

     ds_w();

     tiaozheng();

          }

*/

//////////////////////////////////////////////////////////////

        if(sel==5)  {lcm_w_word("秒鐘");address=0x80; max=59;mini=0;         

                tiaozheng();  //調(diào)用日期、時(shí)間調(diào)整函數(shù)

           ds_w();                  //被調(diào)數(shù)據(jù)加一或減一函數(shù)

           tiaozheng();



        }        //秒7,按動(dòng)7次顯示 調(diào)整秒鐘   

                //并指定秒鐘數(shù)據(jù)寫入1302芯片的地址是0x82,秒鐘數(shù)據(jù)的最大值是59,最小值是0

   /////////////////////////////////////////////////////////////////////////

        if(sel==4)  {lcm_w_word("分鐘");address=0x82; max=59;mini=0;

           tiaozheng();

           ds_w();

           tiaozheng();


        }        //分鐘6,按動(dòng)6次顯示 調(diào)整分鐘

                //并指定分鐘數(shù)據(jù)寫入1302芯片的地址是0x82,分鐘數(shù)據(jù)的最大值是59,最小值是0



        if(sel==3)  {lcm_w_word("小時(shí)");address=0x84; max=23;mini=0;

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

                 if(address > 12){

                                           address = address-12;        }

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

            tiaozheng();

           ds_w();

           tiaozheng();


        }        //小時(shí)5,按動(dòng)5次顯示 調(diào)整小時(shí)

                //規(guī)定小時(shí)數(shù)據(jù)寫入1302芯片的位置是0x84,小時(shí)數(shù)據(jù)最大值23,最小值是0



        if(sel==2)  {lcm_w_word("日期");

                address=0x86;


                mo = read_clock(0x89);//讀月數(shù)據(jù)

                moontemp1=mo/16;

                moontemp2=mo%16;

                mo=moontemp1*10+moontemp2;//轉(zhuǎn)換成10進(jìn)制月份數(shù)據(jù)


      yy = read_clock(0x8d);//讀年數(shù)據(jù)

        moontemp1=yy/16;

                moontemp2=yy%16;

                yy=moontemp1*10+moontemp2;//轉(zhuǎn)換成10進(jìn)制年份數(shù)據(jù)


        if(mo==2&&yy%4!=0){max=28;mini=1;}//平年2月28天

                if(mo==2&&yy%4==0){max=29;mini=1;}//閏年2月29天

                if(mo==1||mo==3||mo==5||mo==7||mo==8||mo==10||mo==12){max=31;mini=1;}//31天的月份

                if(mo==4||mo==6||mo==9||mo==11){max=30;mini=1;}//30天的月份

                tiaozheng();

                ds_w();

                tiaozheng(); //調(diào)用日期、時(shí)間調(diào)整函數(shù)


  }        //日3,按動(dòng)3次顯示 調(diào)整日期

                //規(guī)定日期數(shù)據(jù)寫入1302的位置地址是0x86,日期最大值31,最小值是1




  if(sel==1)  {lcm_w_word("月份");address=0x88; max=12;mini=1;

     tiaozheng();

     ds_w();

     tiaozheng();


   }        //月2,按動(dòng)2次顯示 調(diào)整月份         

                //規(guī)定月份寫入1302的位置地址是0x88,月份最大值12,最小值1



  if(sel==0)  {lcm_w_word("年份");address=0x8c; max=99; mini=0;

     tiaozheng();

     ds_w();                //被調(diào)數(shù)據(jù)加一或減一函數(shù)

     tiaozheng();        //調(diào)用日期、時(shí)間調(diào)整函數(shù)


   }        //年1,按動(dòng)1次顯示 調(diào)整年份,

                //規(guī)定年份寫入1302的地址是0x8c,年份的最大值99,最小值0


}


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

//被調(diào)數(shù)據(jù)加一或減一,并檢查數(shù)據(jù)范圍,寫入1302指定地址保存

void ds_w(void){


        item=((read_clock(address+1))/16)*10 + (read_clock(address+1))%16;

        if(K3 == 0){ //如果按動(dòng)上調(diào)鍵

                item++;  //數(shù)加 1  

        }                                                                                                                 

        if(K4 == 0){  //如果按動(dòng)下調(diào)鍵

                  item--;   //數(shù)減 1

        }

        if(item>max) item=mini;//查看數(shù)值是否在有效范圍之內(nèi)   

        if(item<mini) item=max;//如果數(shù)值小于最小值,則自動(dòng)等于最大值           

        write_clock(0x8e,0x00);//允許寫1302芯片操作

        write_clock(address,(item/10)*16+item%10);//轉(zhuǎn)換成16進(jìn)制寫入1302

        write_clock(0x8e,0x80);//寫保護(hù),禁止寫操作

}


/****可參考***********可參考**************可參考***************以上是調(diào)試********


/*主函數(shù)---------------------------------------------------------------------*/

void main()

{                             

        uchar e=0;

        K1=1;K2=1;K3=1;K4=1;//BLK=0;//K5=1;


        Init_1302();                //時(shí)鐘芯片初始化  

        lcm_init();                        //液晶初始化

        welcome();                    //調(diào)用歡迎信息

        DelayM(4000);                 //歡迎信息 延時(shí)時(shí)間  

        lcm_clr();            //清屏

        Clean_12864_GDRAM();         //清屏

        while(1)

        {

                if (w == 0)                  //正常走時(shí)

                {

                        displaydate();         //顯示日期

//                        displaynl();         //顯示農(nóng)歷

                        nongli();                 //顯示農(nóng)歷

//                        displayjieqi(); //顯示節(jié)氣

                        displaytime();         //顯示時(shí)間

                        read_temp();         //讀取溫度

                        ds1820disp();          //顯示溫度

                        displayxq();         //顯示星期

                }        

                else {}            //否則啟動(dòng)調(diào)時(shí)  


/*----------------------------設(shè)置時(shí)間--------------------------------------*/               

                if (K1 == 0)         

                {

                        DelayM(20);                       //按鍵消抖

                        if(K1 == 0 && w == 1)      //當(dāng)是調(diào)時(shí)狀態(tài) 本鍵用于調(diào)整下一項(xiàng)   

                        {

                                e++;

                                if (e >= 7 ) {e = 0;}

                           while(! K1 );            //等待鍵松開

                                Set_time(e);           //調(diào)整                                

                        }                        

                        if(K1 == 0 && w == 0)      //當(dāng)是正常狀態(tài)時(shí)就進(jìn)入調(diào)時(shí)狀態(tài)   

                        {

                                lcm_clr();            

                                Clean_12864_GDRAM();   //清屏

                                w=1;                       //進(jìn)入調(diào)時(shí)

                                Set_time(e);

                        }

                           while(K1 == 0);            //等待鍵松開

                }

/*--------------------------------------------------------------------------*/               

                if (K2 == 0)                   // 當(dāng)在調(diào)時(shí)狀態(tài)時(shí)就退出調(diào)時(shí)

                {

                        DelayM(20);

                        if(K2 == 0 && w == 1)

                        {                                

                                w = 0;                       //退出調(diào)時(shí)

                                e = 0;                           //"下一項(xiàng)"計(jì)數(shù)器清0                                                               

                        }

                        if(K2 == 0 && w == 0)

                        {                                

                                lcm_clr(); Clean_12864_GDRAM();

                                write_com(0x30); write_com(0x06);

                                welcome();                                

                                while(K2 == 0);  

                        }

                        lcm_clr(); Clean_12864_GDRAM();

                        displaydate();

                        displayxq();

                        displaynl();

                        displaytime();

                        read_temp();

                        ds1820disp();

                        while(K2 == 0);  

                }

/*加調(diào)整--------------------------------------------------------------------*/               

                if (K3 == 0 && w == 1)

                {

                        DelayM(20);

                        if(K3 == 0 && w == 1) { Set_time(e); }

                        while(K3 == 0);

                        while(! K3 );

                }

/*減調(diào)整--------------------------------------------------------------------*/               

                if (K4 == 0 && w == 1)

                {               

                        DelayM(20);

                        if(K4 == 0 && w == 1) { Set_time(e); }

                        while(K4 == 0);

                        while(! K4 );

                }

/*液晶背光控制,按一下亮,再按一下滅----------------------------------------*/

/*                if(K5 == 0)        

                {

                        DelayM(20); q = ~q;      //標(biāo)志位取反

                         if(q){BLK = BLK | 1;}   

                                 else {BLK = BLK & 0;}   

                        while(K5 == 0);           

                }                          */

        }

}

/*結(jié)束----------------------------------------------------------------------*/



代碼+pdf格式原理圖.7z (194.38 KB, 下載次數(shù): 361)

評(píng)分

參與人數(shù) 2黑幣 +54 收起 理由
20768797 + 4 資料里沒有pcb 只有原理圖 pdf格式的2個(gè) .
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏17 分享淘帖 頂1 踩1
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:59151 發(fā)表于 2020-1-23 00:07 | 只看該作者
很好的資料,正在學(xué)習(xí)中,謝謝分享!
回復(fù)

使用道具 舉報(bào)

板凳
ID:88256 發(fā)表于 2020-1-24 00:20 | 只看該作者
下載一個(gè)PCB圖參考一下,謝謝了!
回復(fù)

使用道具 舉報(bào)

地板
ID:88256 發(fā)表于 2020-1-24 00:23 | 只看該作者
下載的第二個(gè)附件里面并沒有PCB圖
回復(fù)

使用道具 舉報(bào)

5#
ID:468209 發(fā)表于 2020-1-24 23:22 來自手機(jī) | 只看該作者
非常感謝
回復(fù)

使用道具 舉報(bào)

6#
ID:688109 發(fā)表于 2020-1-25 12:05 | 只看該作者
謝謝啦
回復(fù)

使用道具 舉報(bào)

7#
ID:688109 發(fā)表于 2020-1-25 12:24 | 只看該作者
0謝謝
回復(fù)

使用道具 舉報(bào)

8#
ID:60026 發(fā)表于 2020-2-8 18:57 | 只看該作者
很好的資料,謝謝分享!
回復(fù)

使用道具 舉報(bào)

9#
ID:154109 發(fā)表于 2020-2-9 17:44 | 只看該作者
謝謝樓主,很好的資料,學(xué)習(xí)了
回復(fù)

使用道具 舉報(bào)

10#
ID:418887 發(fā)表于 2020-2-17 20:20 | 只看該作者
不錯(cuò),很好,最近需要
回復(fù)

使用道具 舉報(bào)

11#
ID:535242 發(fā)表于 2020-2-18 15:10 | 只看該作者
找了幾天了
回復(fù)

使用道具 舉報(bào)

12#
ID:266164 發(fā)表于 2020-2-18 17:11 | 只看該作者
正在找這個(gè)資料,謝謝分享
回復(fù)

使用道具 舉報(bào)

13#
ID:720241 發(fā)表于 2020-4-5 17:19 | 只看該作者
找了幾天,這個(gè)能用
回復(fù)

使用道具 舉報(bào)

14#
ID:966104 發(fā)表于 2021-10-3 23:54 | 只看該作者

很好的資料,正在學(xué)習(xí)中,謝謝分享!
回復(fù)

使用道具 舉報(bào)

15#
ID:290578 發(fā)表于 2022-4-7 23:10 | 只看該作者
多謝分享,解決了我一直困擾的時(shí)序問題!
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲精品一二三 | 中文在线日韩 | 久久久久久久久久久久久9999 | 精品亚洲第一 | 亚洲二区精品 | 久久av资源网 | 久久手机视频 | 国产免费国产 | 无人区国产成人久久三区 | 亚洲一区二区在线 | 91久久久久 | 成人日韩 | 久久夜色精品国产 | 亚洲国产精品91 | 日本在线观看视频 | 福利一区二区在线 | 久久久精品视频免费 | 色www精品视频在线观看 | 成人精品国产免费网站 | 亚洲一二三区精品 | 另类专区亚洲 | 久久久久国产成人精品亚洲午夜 | 一区二区三区四区电影 | 日韩成人在线一区 | 日日摸天天添天天添破 | 日韩久久中文字幕 | 久久久影院 | www.99热| 久久精品16| 欧美精品一区二区三区在线播放 | a欧美 | 国产欧美视频一区 | 99视频入口 | 久久丁香 | 香蕉一区二区 | 欧美激情网站 | 日本不卡免费新一二三区 | 久久99精品久久久久久国产越南 | 视频精品一区二区三区 | 亚洲精品视频久久 | 91久久久久久 |