?? zh.c
字號:
b=ReadOneChar(); //讀取溫度值高位
temp_value=b<<4;
temp_value+=(a&0xf0)>>4;
}
void temp_to_str() //溫度數(shù)據(jù)轉(zhuǎn)換成液晶字符顯示
{
TempBuffer[0]=temp_value/10+'0'; //十位
TempBuffer[1]=temp_value%10+'0'; //個(gè)位
TempBuffer[2]=0xdf; //溫度符號
TempBuffer[3]='C';
TempBuffer[4]='\0';
}
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
/*延時(shí)子程序*/
void mdelay(uint delay)
{ uint i;
for(;delay>0;delay--)
{for(i=0;i<62;i++) //1ms延時(shí).
{;}
}
}
void outkey() //跳出調(diào)整模式,返回默認(rèn)顯示
{ uchar Second;
if(out==0||wireless_1==1)
{ mdelay(8);
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); //寫入允許
Write1302(0x80,Second&0x7f);
Write1302(0x8E,0x80); //禁止寫入
done=0;
while(out==0);
while(wireless_1==1);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Upkey()//升序按鍵
{
Up=1;
if(Up==0||wireless_2==1)
{
mdelay(8);
switch(count)
{case 1:
temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
temp=temp+1; //秒數(shù)加1
up_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
if((temp&0x7f)>0x59) //超過59秒,清零
temp=0;
break;
case 2:
temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
temp=temp+1; //分?jǐn)?shù)加1
up_flag=1;
if(temp>0x59) //超過59分,清零
temp=0;
break;
case 3:
temp=Read1302(DS1302_HOUR); //讀取小時(shí)數(shù)
temp=temp+1; //小時(shí)數(shù)加1
up_flag=1;
if(temp>0x23) //超過23小時(shí),清零
temp=0;
break;
case 4:
temp=Read1302(DS1302_WEEK); //讀取星期數(shù)
temp=temp+1; //星期數(shù)加1
up_flag=1;
if(temp>0x7)
temp=1;
break;
case 5:
temp=Read1302(DS1302_DAY); //讀取日數(shù)
temp=temp+1; //日數(shù)加1
up_flag=1;
if(temp>0x31)
temp=1;
break;
case 6:
temp=Read1302(DS1302_MONTH); //讀取月數(shù)
temp=temp+1; //月數(shù)加1
up_flag=1;
if(temp>0x12)
temp=1;
break;
case 7:
temp=Read1302(DS1302_YEAR); //讀取年數(shù)
temp=temp+1; //年數(shù)加1
up_flag=1;
if(temp>0x85)
temp=0;
break;
default:break;
}
while(Up==0);
while(wireless_2==1);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Downkey()//降序按鍵
{
Down=1;
if(Down==0||wireless_3==1)
{
mdelay(8);
switch(count)
{case 1:
temp=Read1302(DS1302_SECOND); //讀取秒數(shù)
temp=temp-1; //秒數(shù)減1
down_flag=1; //數(shù)據(jù)調(diào)整后更新標(biāo)志
if(temp==0x7f) //小于0秒,返回59秒
temp=0x59;
break;
case 2:
temp=Read1302(DS1302_MINUTE); //讀取分?jǐn)?shù)
temp=temp-1; //分?jǐn)?shù)減1
down_flag=1;
if(temp==-1)
temp=0x59; //小于0秒,返回59秒
break;
case 3:
temp=Read1302(DS1302_HOUR); //讀取小時(shí)數(shù)
temp=temp-1; //小時(shí)數(shù)減1
down_flag=1;
if(temp==-1)
temp=0x23;
break;
case 4:
temp=Read1302(DS1302_WEEK); //讀取星期數(shù)
temp=temp-1; //星期數(shù)減1
down_flag=1;
if(temp==0)
temp=0x7;;
break;
case 5:
temp=Read1302(DS1302_DAY); //讀取日數(shù)
temp=temp-1; //日數(shù)減1
down_flag=1;
if(temp==0)
temp=31;
break;
case 6:
temp=Read1302(DS1302_MONTH); //讀取月數(shù)
temp=temp-1; //月數(shù)減1
down_flag=1;
if(temp==0)
temp=12;
break;
case 7:
temp=Read1302(DS1302_YEAR); //讀取年數(shù)
temp=temp-1; //年數(shù)減1
down_flag=1;
if(temp==-1)
temp=0x85;
break;
default:break;
}
while(Down==0);
while(wireless_3==1);
}
}
void Setkey()//模式選擇按鍵
{
Set=1;
if(Set==0||wireless_4==1)
{
mdelay(8);
count=count+1; //Setkey按一次,count就加1
done=1; //進(jìn)入調(diào)整模式
while(Set==0);
while(wireless_4==1);
}
}
void keydone()//按鍵功能執(zhí)行
{ uchar Second;
if(flag==0) //關(guān)閉時(shí)鐘,停止計(jì)時(shí)
{ Write1302(0x8e,0x00); //寫入允許
temp=Read1302(0x80);
Write1302(0x80,temp|0x80);
Write1302(0x8e,0x80); //禁止寫入
flag=1;
}
Setkey(); //掃描模式切換按鍵
switch(count)
{case 1:do //count=1,調(diào)整秒
{
outkey(); //掃描跳出按鈕
Upkey(); //掃描加按鈕
Downkey(); //掃描減按鈕
if(up_flag==1||down_flag==1) //數(shù)據(jù)更新,重新寫入新的數(shù)據(jù)
{
Write1302(0x8e,0x00); //寫入允許
Write1302(0x80,temp|0x80); //寫入新的秒數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_sec++; //位閃計(jì)數(shù)
if(hide_sec>3)
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); //寫入允許
Write1302(0x82,temp); //寫入新的分?jǐn)?shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_min++;
if(hide_min>3)
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); //寫入允許
Write1302(0x84,temp); //寫入新的小時(shí)數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_hour++;
if(hide_hour>3)
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); //寫入允許
Write1302(0x8a,temp); //寫入新的星期數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_week++;
if(hide_week>3)
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); //寫入允許
Write1302(0x86,temp); //寫入新的日數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_day++;
if(hide_day>3)
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); //寫入允許
Write1302(0x88,temp); //寫入新的月數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_month++;
if(hide_month>3)
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); //寫入允許
Write1302(0x8c,temp); //寫入新的年數(shù)
Write1302(0x8e,0x80); //禁止寫入
up_flag=0;
down_flag=0;
}
hide_year++;
if(hide_year>3)
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); //寫入允許
Write1302(0x80,Second&0x7f);
Write1302(0x8E,0x80); //禁止寫入
done=0;
break; //count=7,開啟中斷,標(biāo)志位置0并退出
default:break;
}
}
void show_time() //液晶顯示程序
{
DS1302_GetTime(&CurrentTime); //獲取時(shí)鐘芯片的時(shí)間數(shù)據(jù)
TimeToStr(&CurrentTime); //時(shí)間數(shù)據(jù)轉(zhuǎn)換液晶字符
DateToStr(&CurrentTime); //日期數(shù)據(jù)轉(zhuǎn)換液晶字符
ReadTemp(); //開啟溫度采集程序
temp_to_str(); //溫度數(shù)據(jù)轉(zhuǎn)換成液晶字符
GotoXY(12,1); //液晶字符顯示位置
Print(TempBuffer); //顯示溫度
GotoXY(0,1);
Print(CurrentTime.TimeString); //顯示時(shí)間
GotoXY(0,0);
Print(CurrentTime.DateString); //顯示日期
GotoXY(15,0);
Print(week_value); //顯示星期
GotoXY(11,0);
Print("Week"); //在液晶上顯示 字母 week
Delay1ms(400); //掃描延時(shí)
}
void main()
{
flag=1; //時(shí)鐘停止標(biāo)志
LCD_Initial(); //液晶初始化
Init_DS18B20( ) ; //DS18B20初始化
Initial_DS1302(); //時(shí)鐘芯片初始化
up_flag=0;
down_flag=0;
done=0; //進(jìn)入默認(rèn)液晶顯示
wireless_1=0;
wireless_2=0;
wireless_3=0;
wireless_4=0;
while(1)
{
while(done==1)
keydone(); //進(jìn)入調(diào)整模式
while(done==0)
{
show_time(); //液晶顯示數(shù)據(jù)
flag=0;
Setkey(); //掃描各功能鍵
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -