1602LCD液晶+DS18B20實(shí)現(xiàn)數(shù)字電子鐘
液晶顯示內(nèi)容: 2012-02-02 14C //第1行
00:20:38 Thurs //第2行
這個(gè)時(shí)鐘表 既可以顯示溫度,又可以顯示 當(dāng)前日期是星期幾了。 這個(gè)星期幾的判斷方法就是根據(jù)一個(gè) 國(guó)際日歷公式來(lái)實(shí)現(xiàn)的。
實(shí)現(xiàn)功能:
1. 調(diào)整 年月日 時(shí)分
2. 顯示 當(dāng)前周?chē)鷾囟?/div>
3. 顯示 當(dāng)前日期的 是星期幾
4. 整點(diǎn)報(bào)時(shí)
5. 若調(diào)整時(shí)間 不合理, 比如2012-02-34 ,則 調(diào)整失效
6. 若調(diào)整時(shí)間,則可以放棄所調(diào)整的時(shí)候。
http://blog.163.com/wenxianliang08@126 / /* 阿浪 博客 */
下面是個(gè)人 剛剛實(shí)現(xiàn)的 代碼
#include
#include
#include"DS18B20.h" //溫度
#include"LCD1602.h" //1602液晶
#include"MyFuntion.h" //自定義頭文件
//獨(dú)立按鍵P1口
sbit Key1=P3^0;
sbit Key2=P3^1;
sbit Key3=P3^2;
sbit Key4=P3^3;
sbit Key5=P3^4;
sbit Key6=P3^5;
sbit Key7=P3^6;
unsigned char T; //溫度
unsigned char Week1[]={"Monday"}; //周一
unsigned char Week2[]={"Tuesday"}; //周二
unsigned char Week3[]={"Wednes"};
unsigned char Week4[]={"Thurs"};
unsigned char Week5[]={"Friday"};
unsigned char Week6[]={"Satur"}; //周六
unsigned char Week7[]={"Sunday"}; //周日
unsigned char Week[8];
void DisplayWeek()
{
unsigned char C=20;
unsigned char y;
unsigned char m;
unsigned char d;
unsigned char W;
unsigned char i=0;
if(month<3)
{
y=year2-1;
m=12+month;
}
else
{
y=year2;
m=month;
}
d=day;
W=C/4-2*C+y+y/4+13*(m+1)/5+d-1;
W=W%7;
Write_Command(0x80+0x49);
switch(W)
{
case 0: strcpy(Week, Week7);break;
case 1: strcpy(Week, Week1);break;
case 2: strcpy(Week, Week2);break;
case 3: strcpy(Week, Week3);break;
case 4: strcpy(Week, Week4);break;
case 5: strcpy(Week, Week5);break;
case 6: strcpy(Week, Week6);break;
}
while(Week[i]!=