|
電子萬(wàn)年歷是一種非常廣泛日常計(jì)時(shí)工具,給人們的帶來(lái)了很大的方便,在社會(huì)上越來(lái)越流行。 它可以對(duì)年、月、日、時(shí)、分、秒進(jìn)行計(jì)時(shí),采用直觀的數(shù)字顯示,可以同時(shí)顯示年月日時(shí)分秒和溫度等信息,還有時(shí)間校準(zhǔn)、鬧鐘等功能。該電子萬(wàn)年歷主要采用STC89C52單片機(jī)作為主控核心,用DS1302時(shí)鐘芯片作為時(shí)鐘、液晶12864顯示屏顯示。STC89C52單片機(jī)是由宏晶公司推出的,功耗小,電壓可選用4~6V電壓供電;DS1302時(shí)鐘芯片是美國(guó)DALLAS公司推出的具有細(xì)電流充電功能的低功耗實(shí)時(shí)時(shí)鐘芯片,它可以對(duì)年、月、日、星期、時(shí)、分、秒進(jìn)行計(jì)時(shí),還具有閏年補(bǔ)償?shù)榷喾N功能,而且DS1302的使用壽命長(zhǎng),誤差;數(shù)字顯示是采用的12864液晶顯示屏來(lái)顯示,可以同時(shí)顯示年、月、日、星期、時(shí)、分、秒和溫度等信息。此外,該電子萬(wàn)年歷還具有時(shí)間校準(zhǔn)等功能。
1. 系統(tǒng)總體功能
本設(shè)計(jì)采用的是宏晶公司的STC89C52單片機(jī)為核心,通過(guò)單片機(jī)與時(shí)鐘芯片DS1302通信來(lái)對(duì)時(shí)間的讀寫(xiě),保證時(shí)鐘時(shí)間的穩(wěn)定性,并帶有內(nèi)部電源模塊,使系統(tǒng)斷電時(shí)時(shí)鐘數(shù)據(jù)不會(huì)丟失,以DS18B20溫度感應(yīng)芯片作為溫度電路的核心,向單片機(jī)發(fā)出獲取到的溫度數(shù)據(jù),并通過(guò)LCD1602將時(shí)間、顯示出來(lái),并可以通過(guò)按鍵調(diào)整時(shí)間日期和鬧鐘時(shí)間
2. 總體電路圖
20181219221654961.jpg (100.69 KB, 下載次數(shù): 52)
下載附件
2019-1-21 19:45 上傳
3. 程序設(shè)計(jì)
(1) LCD1602驅(qū)動(dòng)程序
- sbit rs = P2^0;
- sbit rw = P2^1;
- sbit e = P2^2;
- #define lcddata P0
- sbit busy=P0^7; //lcd busy bit
- void wr_d_lcd(uchar content);
- void wr_i_lcd(uchar content);
- void clrram_lcd (void);
- void init_lcd(void);
- void busy_lcd(void);
- void rev_row_lcd(uchar row);
- void rev_co_lcd(uchar row,uchar col,uchar mode);
- void clr_lcd(void);
- void wr_co_lcd(uchar row,uchar col,uchar lcddata1,uchar lcddtta2);
- void wr_row_lcd(uchar row,char *p);
- //**********************************
- //液晶初始化
- //**********************************
- void init_lcd(void)
- {
- wr_i_lcd(0x06); /*光標(biāo)的移動(dòng)方向*/
- wr_i_lcd(0x0c); /*開(kāi)顯示,關(guān)游標(biāo)*/
- }
- //***********************************
- //填充液晶DDRAM全為空格
- //**********************************
- void clrram_lcd (void)
- {
- wr_i_lcd(0x30);
- wr_i_lcd(0x01);
- }
- //***********************************
- //對(duì)液晶寫(xiě)數(shù)據(jù)
- //content為要寫(xiě)入的數(shù)據(jù)
- //***********************************
- void wr_d_lcd(uchar content)
- {
- busy_lcd();
- rs=1;
- rw=0;
- lcddata=content;
- e=1;
- ;
- e=0;
- }
- //********************************
- //對(duì)液晶寫(xiě)指令
- //content為要寫(xiě)入的指令代碼
- //*****************************
- void wr_i_lcd(uchar content)
- {
- busy_lcd();
- rs=0;
- rw=0;
- lcddata=content;
- e=1;
- ;
- e=0;
- }
- //********************************
- //液晶檢測(cè)忙狀態(tài)
- //在寫(xiě)入之前必須執(zhí)行
- //********************************
- void busy_lcd(void)
- {
- lcddata=0xff;
- rs=0;
- rw=1;
- e =1;
- while(busy==1);
- e =0;
- }
- //********************************
- //指定要顯示字符的坐標(biāo)
- //*******************************
- void gotoxy(unsigned char y, unsigned char x)
- {
- if(y==1)
- wr_i_lcd(0x80|x);
- if(y==2)
- wr_i_lcd(0x90|x);
- if(y==3)
- wr_i_lcd((0x80|x)+8);
- if(y==4)
- wr_i_lcd((0x90|x)+8);
- }
- //**********************************
- //液晶顯示字符串程序
- //**********************************
- void print(uchar *str)
- {
- while(*str!='\0')
- {
- wr_d_lcd(*str);
- str++;
- }
- }
- //***************************************
- //液晶顯示主程序模塊
- //***************************************
- void show_time()
- {
- DS1302_GetTime(&CurrentTime); //獲取時(shí)鐘芯片的時(shí)間數(shù)據(jù)
- TimeToStr(&CurrentTime); //時(shí)間數(shù)據(jù)轉(zhuǎn)換液晶字符
- DateToStr(&CurrentTime); //日期數(shù)據(jù)轉(zhuǎn)換液晶字符
- ReadTemp(); //開(kāi)啟溫度采集程序
- temp_to_str(); //溫度數(shù)據(jù)轉(zhuǎn)換成液晶字符
- gotoxy(4,0);
- print("溫度");
- gotoxy(4,2); //液晶字符顯示位置
- print(TempBuffer); //顯示溫度
- gotoxy(4,6);
- print("℃");
- gotoxy(3,0);
- print("時(shí)間:");
- gotoxy(3,3);
- print(CurrentTime.TimeString); //顯示時(shí)間
- gotoxy(2,3);
- print(CurrentTime.DateString); //顯示日期
- gotoxy(2,0);
- print("星期");
- gotoxy(2,2);
- print(week_value); //顯示星期
- gotoxy(1,1);
- print("【萬(wàn)年歷】");
- mdelay(500); //掃描延時(shí)
- }
復(fù)制代碼 (2) DS1302驅(qū)動(dòng)程序
- //***********************************
- //DS1302時(shí)鐘部分子程序模塊
- //***********************************
- typedef struct __SYSTEMTIME__
- {
- uchar Second;
- uchar Minute;
- uchar Hour;
- uchar Week;
- uchar Day;
- uchar Month;
- uchar Year;
- uchar DateString[11];
- uchar TimeString[9];
- }SYSTEMTIME; //定義的時(shí)間類型
- SYSTEMTIME CurrentTime;
- #define AM(X) X
- #define PM(X) (X+12) // 轉(zhuǎn)成24小時(shí)制
- #define DS1302_SECOND 0x80 //時(shí)鐘芯片的寄存器位置,存放時(shí)間
- #define DS1302_MINUTE 0x82
- #define DS1302_HOUR 0x84
- #define DS1302_WEEK 0x8A
- #define DS1302_DAY 0x86
- #define DS1302_MONTH 0x88
- #define DS1302_YEAR 0x8C
- //**********************************
- //實(shí)時(shí)時(shí)鐘寫(xiě)入一字節(jié)(內(nèi)部函數(shù))
- //**********************************
- void DS1302InputByte(uchar d)
- {
- uchar i;
- ACC = d;
- for(i=8; i>0; i--)
- {
- DS1302_IO = ACC0; //相當(dāng)于匯編中的 RRC
- DS1302_CLK = 1;
- DS1302_CLK = 0;
- ACC = ACC >> 1;
- }
- }
- //*************************************
- //實(shí)時(shí)時(shí)鐘讀取一字節(jié)(內(nèi)部函數(shù))
- //*************************************
- uchar DS1302OutputByte(void)
- {
- uchar i;
- for(i=8; i>0; i--)
- {
- ACC = ACC >>1; //相當(dāng)于匯編中的 RRC
- ACC7 = DS1302_IO;
- DS1302_CLK = 1;
- DS1302_CLK = 0;
- }
- return(ACC);
- }
- //**************************************
- //ucAddr: DS1302地址, ucData: 要寫(xiě)的數(shù)據(jù)
- //**************************************
- void Write1302(uchar ucAddr, uchar ucDa)
- {
- DS1302_RST = 0;
- DS1302_CLK = 0;
- DS1302_RST = 1;
- DS1302InputByte(ucAddr); // 地址,命令
- DS1302InputByte(ucDa); // 寫(xiě)1Byte數(shù)據(jù)
- DS1302_CLK = 1;
- DS1302_RST = 0;
- }
- //**************************************
- //讀取DS1302某地址的數(shù)據(jù)
- //**************************************
- uchar Read1302(uchar ucAddr)
- {
- uchar ucData;
- DS1302_RST = 0;
- DS1302_CLK = 0;
- DS1302_RST = 1;
- DS1302InputByte(ucAddr|0x01); // 地址,命令
- ucData = DS1302OutputByte(); // 讀1Byte數(shù)據(jù)
- DS1302_CLK = 1;
- DS1302_RST = 0;
- return(ucData);
- }
- //******************************************
- //獲取時(shí)鐘芯片的時(shí)鐘數(shù)據(jù)到自定義的結(jié)構(gòu)型數(shù)組
- //******************************************
- void DS1302_GetTime(SYSTEMTIME *Time)
- {
- uchar ReadValue;
- ReadValue = Read1302(DS1302_SECOND);
- Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//轉(zhuǎn)換為相應(yīng)的10進(jìn)制數(shù)
- ReadValue = Read1302(DS1302_MINUTE);
- Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_HOUR);
- Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_DAY);
- Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_WEEK);
- Time->Week = ((ReadValue&0x10)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_MONTH);
- Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_YEAR);
- Time->Year = ((ReadValue&0xf0)>>4)*10 + (ReadValue&0x0F);
- }
- //******************************************
- //將時(shí)間年,月,日,星期數(shù)據(jù)轉(zhuǎn)換成液
- //晶顯示字符串,放到數(shù)組里DateString[]
- //******************************************
- void DateToStr(SYSTEMTIME *Time)
- {
- uchar tab[ ]={0XD2,0XBB,0XB6,0XFE,0XC8,0XFD,0XCB,0XC4,0XCE,0XE5,0XC1,0XF9,0XC8,0XD5};
- if(hide_year<2) //這里的if,else語(yǔ)句都是判斷位閃爍,<2顯示數(shù)據(jù),>2就不顯示,輸出字符串為 2007/07/22
- {
- Time->DateString[0] = '2';
- Time->DateString[1] = '0';
- Time->DateString[2] = Time->Year/10 + '0';
- Time->DateString[3] = Time->Year%10 + '0';
- }
- else
- {
- Time->DateString[0] = ' ';
- Time->DateString[1] = ' ';
- Time->DateString[2] = ' ';
- Time->DateString[3] = ' ';
- }
- Time->DateString[4]='-';
- if(hide_month<2)
- {
- Time->DateString[5] = Time->Month/10 + '0';
- Time->DateString[6] = Time->Month%10 + '0';
- }
- else
- {
- Time->DateString[5] = ' ';
- Time->DateString[6] = ' ';
- }
- Time->DateString[7]='-';
- if(hide_day<2)
- {
- Time->DateString[8] = Time->Day/10 + '0';
- Time->DateString[9] = Time->Day%10 + '0';
- }
- else
- {
- Time->DateString[8] = ' ';
- Time->DateString[9] = ' ';
- }
- if(hide_week<2)
- {
- week_value[0] =tab[2*(Time->Week%10)-2]; //星期的數(shù)據(jù)另外放到 week_value[]數(shù)組里,跟年,月,日的分開(kāi)存放,因?yàn)榈纫幌乱谧詈箫@示
- week_value[1] =tab[2*(Time->Week%10)-1];
- }
- else
- {
- week_value[0] = ' ';
- week_value[1]=' ';
- }
- week_value[2] = '\0';
- Time->DateString[10] = '\0'; //字符串末尾加 '\0' ,判斷結(jié)束字符
- }
- //******************************************
- //將時(shí),分,秒數(shù)據(jù)轉(zhuǎn)換成液晶
- //顯示字符放到數(shù)組 TimeString[]
- //*****************************************
- void TimeToStr(SYSTEMTIME *Time)
- { if(hide_hour<2)
- {
- Time->TimeString[0] = Time->Hour/10 + '0';
- Time->TimeString[1] = Time->Hour%10 + '0';
- }
- else
- {
- Time->TimeString[0] = ' ';
- Time->TimeString[1] = ' ';
- }
- Time->TimeString[2] = ':';
- if(hide_min<2)
- {
- Time->TimeString[3] = Time->Minute/10 + '0';
- Time->TimeString[4] = Time->Minute%10 + '0';
- }
- else
- {
- Time->TimeString[3] = ' ';
- Time->TimeString[4] = ' ';
- }
- Time->TimeString[5] = ':';
- if(hide_sec<2)
- {
- Time->TimeString[6] = Time->Second/10 + '0';
- Time->TimeString[7] = Time->Second%10 + '0';
- }
- else
- {
- Time->TimeString[6] = ' ';
- Time->TimeString[7] = ' ';
- }
- Time->TimeString[8] = '\0';
- }
- //******************************
- //時(shí)鐘芯片初始化
- //******************************
- void Initial_DS1302(void)
- {
- uchar Second=Read1302(DS1302_SECOND);
- if(Second&0x80) //判斷時(shí)鐘芯片是否關(guān)閉
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x8c,0x07); //以下寫(xiě)入初始化時(shí)間 日期:07/07/25.星期: 3. 時(shí)間: 23:59:55
- Write1302(0x88,0x07);
- Write1302(0x86,0x25);
- Write1302(0x8a,0x07);
- Write1302(0x84,0x23);
- Write1302(0x82,0x59);
- Write1302(0x80,0x55);
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- }
- }
復(fù)制代碼 (3)DS18B20驅(qū)動(dòng)程序
(4) 按鍵驅(qū)動(dòng)程序
- //************************************
- //跳出調(diào)整模式,返回默認(rèn)顯示
- //************************************
- void outkey()
- { uchar Second;
- if(out==0)
- { mdelay(5);
- count=0;
- hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0;
- Second=Read1302(DS1302_SECOND);
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x80,Second&0x7f);
- Write1302(0x8E,0x80); //禁止寫(xiě)入
- done=0;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //*************************
- //升序按鍵
- //*************************
- void Upkey()
- {
- Up=1;
- if(Up==0)
- {
- mdelay(5);
- switch(count)
- {case 1:
- temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //秒數(shù)加1
- up_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
- if((temp)>59) //超過(guò)59秒,清零
- temp=0;
- temp=temp/10*16+temp%10;
- break;
- case 2:
- temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //分?jǐn)?shù)加1
- up_flag=1;
- if(temp>59) //超過(guò)59分,清零
- temp=0;
- temp=temp/10*16+temp%10;
- break;
- case 3:
- temp=Read1302(DS1302_HOUR); //讀取小時(shí)數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //小時(shí)數(shù)加1
- up_flag=1;
- if(temp>23) //超過(guò)23小時(shí),清零
- temp=0;
- temp=temp/10*16+temp%10;
- break;
- case 4:
- temp=Read1302(DS1302_WEEK); //讀取星期數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //星期數(shù)加1
- up_flag=1;
- if(temp>7)
- temp=1;
- temp=temp/10*16+temp%10;
- break;
- case 5:
- temp=Read1302(DS1302_DAY); //讀取日數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //日數(shù)加1
- up_flag=1;
- if(temp>31)
- temp=1;
- temp=temp/10*16+temp%10;
- break;
- case 6:
- temp=Read1302(DS1302_MONTH); //讀取月數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp+1; //月數(shù)加1
- up_flag=1;
- if(temp>12)
- temp=1;
- temp=temp/10*16+temp%10;
- break;
- case 7:
- temp=Read1302(DS1302_YEAR); //讀取年數(shù)
- temp=((temp&0xf0)>>4)*10 + (temp&0x0F);
- temp=temp+1; //年數(shù)加1
- up_flag=1;
- if(temp>99)
- temp=0;
- temp=temp/10*16+temp%10;
- break;
- default:break;
- }
-
- // while(Up==0);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //************************
- //降序按鍵
- //************************
- void Downkey()
- {
- Down=1;
- if(Down==0)
- {
- mdelay(5);
- switch(count)
- {case 1:
- temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //秒數(shù)減1
- down_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
- if(temp==-1) //小于0秒,返回59秒
- temp=59;
- temp=temp/10*16+temp%10;
- break;
- case 2:
- temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //分?jǐn)?shù)減1
- down_flag=1;
- if(temp==-1)
- temp=59; //小于0秒,返回59秒
- temp=temp/10*16+temp%10;
- break;
- case 3:
- temp=Read1302(DS1302_HOUR); //讀取小時(shí)數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //小時(shí)數(shù)減1
- down_flag=1;
- if(temp==-1)
- temp=23;
- temp=temp/10*16+temp%10;
- break;
- case 4:
- temp=Read1302(DS1302_WEEK); //讀取星期數(shù);
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //星期數(shù)減1
- down_flag=1;
- if(temp==0)
- temp=7;
- temp=temp/10*16+temp%10;
- break;
- case 5:
- temp=Read1302(DS1302_DAY); //讀取日數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //日數(shù)減1
- down_flag=1;
- if(temp==0)
- temp=31;
- temp=temp/10*16+temp%10;
- break;
- case 6:
- temp=Read1302(DS1302_MONTH); //讀取月數(shù)
- temp=((temp&0x70)>>4)*10 + (temp&0x0F);
- temp=temp-1; //月數(shù)減1
- down_flag=1;
- if(temp==0)
- temp=12;
- temp=temp/10*16+temp%10;
- break;
- case 7:
- temp=Read1302(DS1302_YEAR); //讀取年數(shù)
- temp=((temp&0xf0)>>4)*10 + (temp&0x0F);
- temp=temp-1; //年數(shù)減1
- down_flag=1;
- if(temp==-1)
- temp=99;
- temp=temp/10*16+temp%10;
- break;
- default:break;
- }
-
- // while(Down==0);
- }
- }
- //**************************
- //模式選擇按鍵
- //**************************
- void Setkey()
- {
- Set=1;
- if(Set==0)
- {
- mdelay(5);
- count=count+1; //Setkey按一次,count就加1
- done=1; //進(jìn)入調(diào)整模式
- while(Set==0);
- }
- }
- //*************************
- //按鍵功能執(zhí)行
- //*************************
- void keydone()
- {
- uchar Second;
- /* if(flag==0) //關(guān)閉時(shí)鐘,停止計(jì)時(shí)
- { Write1302(0x8e,0x00); //寫(xiě)入允許
- temp=Read1302(0x80);
- Write1302(0x80,temp|0x80);
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- flag=1;
- }*/
- Setkey(); //掃描模式切換按鍵
- switch(count)
- {
- case 1:do //count=1,調(diào)整秒
- {
- outkey(); //掃描跳出按鈕
- Upkey(); //掃描加按鈕
- Downkey(); //掃描減按鈕
- if(up_flag==1||down_flag==1) //數(shù)據(jù)更新,重新寫(xiě)入新的數(shù)據(jù)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x80,temp); //寫(xiě)入新的秒數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_sec++;
- if(hide_sec>3)
- hide_sec=0;
- }
- else hide_sec=0;
- show_time(); //液晶顯示數(shù)據(jù)
- }while(count==2);break;
- case 2:do //count=2,調(diào)整分
- {
- hide_sec=0;
- outkey();
- Upkey();
- Downkey();
- if(temp>0x60)
- temp=0;
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x82,temp); //寫(xiě)入新的分?jǐn)?shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_min++;
- if(hide_min>3)
- hide_min=0;
- }
- else hide_min=0;
- show_time();
- }while(count==3);break;
- case 3:do //count=3,調(diào)整小時(shí)
- {
- hide_min=0;
- outkey();
- Upkey();
- Downkey();
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x84,temp); //寫(xiě)入新的小時(shí)數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_hour++;
- if(hide_hour>3)
- hide_hour=0;
- }
- else hide_hour=0;
- show_time();
- }while(count==4);break;
- case 4:do //count=4,調(diào)整星期
- {
- hide_hour=0;
- outkey();
- Upkey();
- Downkey();
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x8a,temp); //寫(xiě)入新的星期數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_week++;
- if(hide_week>3)
- hide_week=0;
- }
- else hide_week=0;
- show_time();
- }while(count==5);break;
- case 5:do //count=5,調(diào)整日
- {
- hide_week=0;
- outkey();
- Upkey();
- Downkey();
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x86,temp); //寫(xiě)入新的日數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_day++;
- if(hide_day>3)
- hide_day=0;
- }
- else hide_day=0;
- show_time();
- }while(count==6);break;
- case 6:do //count=6,調(diào)整月
- {
- hide_day=0;
- outkey();
- Upkey();
- Downkey();
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x88,temp); //寫(xiě)入新的月數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_month++;
- if(hide_month>3)
- hide_month=0;
- }
- else hide_month=0;
- show_time();
- }while(count==7);break;
- case 7:do //count=7,調(diào)整年
- {
- hide_month=0;
- outkey();
- Upkey();
- Downkey();
- if(up_flag==1||down_flag==1)
- {
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x8c,temp); //寫(xiě)入新的年數(shù)
- Write1302(0x8e,0x80); //禁止寫(xiě)入
- up_flag=0;
- down_flag=0;
- }
- if(Down!=0&&Up!=0)
- {
- hide_year++;
- if(hide_year>3)
- hide_year=0;
- }
- else hide_year=0;
- show_time();
- }while(count==8);break;
- case 8: count=0;hide_year=0; //count8, 跳出調(diào)整模式,返回默認(rèn)顯示狀態(tài)
- Second=Read1302(DS1302_SECOND);
- Write1302(0x8e,0x00); //寫(xiě)入允許
- Write1302(0x80,Second&0x7f);
- Write1302(0x8E,0x80); //禁止寫(xiě)入
- done=0;
- break; //count=7,開(kāi)啟中斷,標(biāo)志位置0并退出
- default:break;
- }
- }
復(fù)制代碼 (5) 主程序
- main()
- {
- // flag=1; //時(shí)鐘停止標(biāo)志
- init_lcd();
- clrram_lcd();
- Init_DS18B20( ) ; //DS18B20初始化
- Initial_DS1302(); //時(shí)鐘芯片初始化
- up_flag=0;
- down_flag=0;
- done=0; //進(jìn)入默認(rèn)液晶顯示
- while(1)
- {
- while(done==1)
- keydone(); //進(jìn)入調(diào)整模式
- while(done==0)
- {
- show_time(); //液晶顯示數(shù)據(jù)
- // flag=0;
- Setkey(); //掃描各功能鍵
- }
- }
- }
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|