|
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit beep=P2^7;//蜂鳴器
sbit k1=P3^2;
sbit k2=P3^3;
sbit k3=P3^4;
sbit k4=P3^5;
//-----------------------------------顯示數(shù)組
uchar ye=0;//第一頁
uchar hang1[]="2000.00.00 0 ";//日期+星期
uchar hang2[]="00:00:00 T:000 C";//時(shí)間+溫度
uchar hang3[]="lock 00:00 ";//第二頁 鬧鐘
uchar hang4[]="L:000 C H:000 C";//溫度閥值
uchar lcd_xian=0;//顯示延時(shí)變量
//-----------------------------------
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>光標(biāo)位置
uchar cursor=0;//光標(biāo)位置
uchar code cursor_num[]={1,3,1,6,1,9,1,12,2,1,2,4,2,7,1,6,1,9,2,4,2,13};//光標(biāo)位置數(shù)組.行+列
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//###################################測(cè)量值變量
uchar wendu=0,wen_L=10,wen_H=30;//溫度+閥值
uchar shi=6,fen=0;//鬧鐘
//###################################
//**************************************主函數(shù)
void main()
{
uchar two;
//11111111111111111111111111111111基本模塊初始化
hang2[14]=0xdf;
hang4[5]=0xdf;
hang4[14]=0xdf;
init_1602();
Ds1302ReadTime();//啟動(dòng)DS1302
TIME[0]=0;
Ds1302Init();
//11111111111111111111111111111111
//22222222222222222222222222222222顯示初始化
wen_L=At24c02Read(0); //讀取溫度閥值
if(wen_L>200)
{
wen_L=10;
At24c02Write(0,wen_L);
Delay1ms(10);
}
wen_H=At24c02Read(1);
if(wen_H>200)
{
wen_H=10;
At24c02Write(1,wen_H);
Delay1ms(30);
}
shi=At24c02Read(2);
if(shi>200)
{
shi=6;
At24c02Write(2,shi);
Delay1ms(10);
}
fen=At24c02Read(3);
if(fen>200)
{
fen=0;
At24c02Write(3,fen);
Delay1ms(10);
}
//22222222222222222222222222222222
//===============定時(shí)器初始化
TMOD|=0X01;
TH0=0X3C;
TL0=0XB0;
ET0=1;//打開定時(shí)器0中斷允許
EA=1;//打開總中斷
TR0=1;//打開定時(shí)器while(1)
{
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;判斷報(bào)警
if((wendu>wen_H)||(wendu<wen_L)||((TIME[2]==shi)&&(TIME[1]==fen)))//蜂鳴器判斷
beep=0;
else
beep=1;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//'''''''''''''''''''''''''''''''''''''''''''按鍵檢測(cè)
if(!k1) //換頁
{
ye=!ye;
if(ye)
cursor=7;//設(shè)置光標(biāo)
else
cursor=0;
while(!k1);
}
if(!k2) //下一個(gè)
{
if(ye)
{
if(cursor<10)
cursor++;
else
cursor=7;
}
else
{
if(cursor<6)
cursor++;
else
cursor=0;
}
while(!k2);
}
if(!k3)//加
{
switch(cursor)
{
case 0://設(shè)置年
two=(TIME[6]>>4)*10+(TIME[6] &0x0f);
if(two<99)
two++;
TIME[6]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 1://設(shè)置月
two=(TIME[4]>>4)*10+(TIME[4] &0x0f);
if(two<12)
two++;
TIME[4]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 2://設(shè)置日
two=(TIME[3]>>4)*10+(TIME[3] &0x0f);
if(two<30)
two++;
TIME[3]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 3://設(shè)置星期
if(TIME[5]<8)
TIME[5]++;
Ds1302Init();
break;
case 4://設(shè)置時(shí)
two=(TIME[2]>>4)*10+(TIME[2] &0x0f);
if(two<23)
two++;
TIME[2]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 5://設(shè)置分
two=(TIME[1]>>4)*10+(TIME[1] &0x0f);
if(two<59)
two++;
TIME[1]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 6://設(shè)置秒
two=(TIME[0]>>4)*10+(TIME[0] &0x0f);
if(two<59)
two++;
TIME[0]=(two/10<<4)+two%10;
Ds1302Init();
break;
case 7://設(shè)置時(shí) 鬧鐘
two=(shi>>4)*10+(shi &0x0f);
if(two<23)
two++;
shi=(two/10<<4)+two%10;
At24c02Write(2,shi);
Delay1ms(10);
break;
case 8://設(shè)置分
two=(fen>>4)*10+(fen &0x0f);
if(two<59)
two++;
錯(cuò)誤是:
compiling shizhong1.c...
shizhong1.c(34): warning C206: 'init_1602': missing function-prototype
shizhong1.c(35): warning C206: 'Ds1302ReadTime': missing function-prototype
shizhong1.c(36): error C202: 'TIME': undefined identifier
shizhong1.c - 1 Error(s), 2 Warning(s). |
|