|
能夠顯示溫度,鬧鈴自動(dòng)響,掉電不丟失。附加仿真圖,顯示屏是LM041L
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
0.png (34.13 KB, 下載次數(shù): 64)
下載附件
2017-5-31 16:47 上傳
0.png (63.84 KB, 下載次數(shù): 63)
下載附件
2017-5-31 16:47 上傳
單片機(jī)源程序如下:
- #include <reg51.h>
- #include "ds1302.h"
- #include "lcd1602.h"
- #include "eeproom.h"
- #include "ds18b20.h"
- #define uchar unsigned char
- #define uint unsigned int
- uchar seth[]="00";
- uchar setm[]="00";
- uchar flag=0;
- uchar a=0,b=0,c=0,d=0;
- sbit qie=P3^4;
- sbit jia=P3^5;
- sbit jian=P3^6;
- sbit back=P3^7;
- sbit speak=P1^7;
- void tiao(uchar i,uchar j,uchar *m);
- void time();
- void display(int v)
- {
- unsigned char count;
- unsigned int tmp = abs(v);
-
- datas[0] = tmp / 10000;
- datas[1] = tmp % 10000 / 1000;
- datas[2] = tmp % 1000 / 100;
- datas[3] = tmp % 100 / 10;
-
- if(v < 0)
- {
- lcdoutput(3,5,"- ");
- }
- else
- {
- lcdoutput(3,5,"+ ");
- }
- lcdwrite(command,0x90+6);
- if(datas[0] != 0)
- {
- lcdwrite(data,'0'+datas[0]);
- }
- for(count = 1; count != 5; count++)
- {
- lcdwrite(data,'0'+datas[count]);
- if(count == 2)
- {
- lcdwrite(data,'.');
- }
- }
-
- }
- void reeep()
- {
-
- a=read24c02(1);
- b=read24c02(2);
- c=read24c02(3);
- d=read24c02(4);
- seth[0]=a+0x30;
- seth[1]=b+0x30;
- setm[0]=d+0x30;
- setm[1]=c+0x30;
- }
- void init()
- {
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- IE=0X82;
-
- }
- void delay(uchar m)
- {
- uchar i,j;
- for(i=m;i>0;i--)
- for(j=110;j>0;j--);
- }
- void gettime()
- {
- systemtime datetime;
-
- dsgettime(&datetime);
- datezstr(&datetime,datestring);
- timezstr(&datetime,timestring);
- //獲取時(shí)間
- lcdoutput(1,0,"DATE:"); //日期
- lcdoutput(1,5,"20");
- lcdoutput(1,7,datestring);
- lcdoutput(2,0,"TIME:");
- lcdoutput(2,5,timestring);
- lcdoutput(3,0,"wen:");
- lcdoutput(4,0,"Alarm:");
- lcdoutput(4,7,seth);
- lcdoutput(4,9,"-");
- lcdoutput(4,10,setm);
- display(getTmpValue());
- sendChangeCmd();
- delay(300);
- }
- void main()
- {
- uchar count=0;
- lcdwrite(command,clear_screen);
- ds1302init();
- init();
- nit();
- lcdini();
- reeep();
- while(1)
- {
- time();
- gettime();
- if(qie==0)
- {
- delay(500);
- if(qie==0)
- {
- flag=1;
- lcdwrite(command,clear_screen);
-
- }
-
- }
- if(flag==1)
- {
- lcdoutput(1,8,"Set");
- lcdoutput(3,0,"Time:");
- lcdoutput(3,6,seth);
- lcdoutput(3,8,"-");
- lcdoutput(3,9,setm);
-
-
- }
- while(flag==1)
- {
-
- if(qie==0)
- {
- delay(500);
- if(qie==0)
- {
- count++;
- if(count>2)
- count=0;
-
- }
-
- }
- switch(count)
- {
-
- case 1:tiao(3,7,seth);break;
- case 2:tiao(3,10,setm);break;
- default:break;
- }
- if(back==0)
- {
- delay(10);
- if(back==0)
- {
- lcdwrite(command,clear_screen);
- flag=0;
- }
- }
-
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
鬧鈴系統(tǒng).rar
(100.05 KB, 下載次數(shù): 76)
2017-5-31 16:31 上傳
點(diǎn)擊文件名下載附件
帶溫度顯示鬧鈴 下載積分: 黑幣 -5
|
|