?? xiyiji.c
字號:
/*P1.0~~~p1.5 鍵盤掃描口
P3.5 測溫器
P3.6 加熱器
P0 顯示數據口
P2.0~~~P2.2 顯示口控制線
P2.3 檢測水滿
P2.4 檢測水排光
P2.5 加水閘;
P2.6 排水閘;
P2.7 喇叭
3.0 洗衣服電機
P3.1 洗衣服電機
P3.2 P3.3 P3.4 狀態燈口
剩下沒用到的口有
P3.7 P1.6 P1.7
*/
//*******************************************************
#include <at89x51.h>
unsigned char minite=24; //分鐘全局變量在定時器0中用到
unsigned char second=8; //秒鐘全局變量在定時器0中用到
unsigned char wdz=37; //全局變量可調節的臨界溫度值變量
bit flag=0;
bit sflag=0; //設置慢洗中的變量 在定時器0中用到
bit sflagg=0; //設置報警中的變量 在定時器1中用到
unsigned char san=0; //設置三分鐘排水 報警中的變量 在定時器1中用到
unsigned char ba=0; //設置八分鐘排水 報警中的變量 在定時器1中用到
unsigned char biao=0; //設置標號選擇 識別按鍵值
unsigned char su=0; //確定鍵的標識號
unsigned char jc1,jc2;//暫停時 寄存 p2 p3 口
//******************************************************
void jia();
void jian();
void getkey(void);
void jiashui(void);
void paishui(void);
void jiawen(void);
void threetime(void );
void twotime(void);
void manxi(void);
void sure(void);
void baojing(void);
//*************************************************
void daojishi(void) ;//定時器0
void dingshi(void) ;//定時器1
//************************************************
void disauto3();//以下是六個操作按鍵的顯示函數
void disauto2(void);
void diskxi(void);
void dismxi(void);
void distuoshui(void);
void disjiare(void);
//*************************************************
void delay(unsigned int i);//延時
void Delay1ms(unsigned int count);//延時
//LCD燈顯示的初始化******************************************
sbit LcdRs = P2^0;
sbit LcdRw = P2^1;
sbit LcdEn = P2^2;
#define DBPort P0
#define LCD_COMMAND 0 // Command
#define LCD_DATA 1 // Data
unsigned char LCD_Wait(void);
void LCD_Write(bit style, unsigned char input);
void LCD_Initial();
void GotoXY(unsigned char x, unsigned char y);
void Print(unsigned char *str);
void IntToStr( unsigned char *str) ;
void charToStr( unsigned char *str) ;
void display(void);//顯示當前溫度和設置要到的溫度
void disp(void);//
void wdszStr( unsigned char *str) ;
void wdszdis(void);
//**************************************
sbit DQ=P3^5;//讀溫度是用到的函數
ReadOneChar(void);//讀一個字節
WriteOneChar(unsigned char dat);
unsigned int ReadTemperature(void);//讀取溫度
//***************************************************
void main(void)
{
unsigned char n;
for(n=0;n<2;n++)
{
P2=0;P3=0;
LCD_Initial();
Delay1ms(10);
GotoXY(0,0);
Print("Hello Welcome to");
GotoXY(0,1);
Print("Washing System !");
}
while(1)
{
getkey();
if((biao==3)||(biao==4)||(biao==5))disp();
if(biao==6)display();
}
}
//************************************************************************
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
void delay(unsigned int i)//延時函數
{
while(i--);
}
//*************************************************************************
bit pkey(void)//判斷鍵的否被按下,通過返回值確定
{
P1=0x38; //p.0~p1.2接行,p1.3~~~p1.5接列。。給行輸入低電平,給列輸入高電平,整體掃描
if(P1!=0x38)
{
Delay1ms(50);
if(P1!=0x38)
return 1;//如果有按鍵按下返回1
else
return 0;
}
else return 0;//沒有按鍵按下返回0
}
void getkey(void)
{
unsigned char key=0x09,s,k,c;
while(1)
{
if(pkey()==1)
{
P1=0x3e;
k=0x3e;
for(c=0;c<3;c++)
{
s=P1&0x38;
switch(s)
{
case 0x30: key=3*c+0; break;
case 0x28: key=3*c+1; break;
case 0x18: key=3*c+2; break;
default: break;
}
k=(k<<1)|0x01;
P1=k;
}
while(pkey());
switch(key)
{
case 0x00 :if(su==0)disauto3(); break;//自動洗3次加脫水
case 0x01 :if(su==0)disauto2(); break;//自動洗2次加脫水
case 0x02 :if(su==0)diskxi();break;//快速洗一次
case 0x03 :if(su==0)dismxi() ;break;//慢速洗一次
case 0x04 :if(su==0)distuoshui();break;//脫水
case 0x05 :if(su==0)disjiare();break; //加溫
case 0x06 :jia(); break;//加
case 0x07 :jian();break;//減
case 0x08 :su++;if(su>=4)su=2;sure();break;//確定鍵和暫停
default :break;
}
}
else
break;
}
}
//****************************************************
void disauto3(void)
{
P3_2=0;P3_3=1;P3_4=1;TR1=0;
GotoXY(0,0);
Print("system will auto");
GotoXY(0,1);
Print("wash three times");
biao=1;
}
void disauto2(void)
{
P3_2=1;P3_3=0;P3_4=1;TR1=0;
GotoXY(0,0);
Print("system will auto");
GotoXY(0,1);
Print(" wash two times ");
biao=2;
}
void diskxi(void)
{
P3_2=0;P3_3=0;P3_4=1;TR1=0;
minite=8;
GotoXY(0,0);
Print(" kuai xi yi ci ");
GotoXY(0,1);
Print("time: ");
biao=3;
}
void dismxi(void)
{
P3_2=1;P3_3=1;P3_4=0;TR1=0;
minite=8;
GotoXY(0,0);
Print(" man xi yi ci ");
GotoXY(0,1);
Print("time: ");
biao=4;
}
void distuoshui(void)
{
P3_2=0;P3_3=1;P3_4=0;TR1=0;
minite=7;P2_6=1;
GotoXY(0,0);
Print("tuo shui shijian");
GotoXY(0,1);
Print("time: ");
biao=5;
}
void disjiare(void)
{
P3_2=1;P3_3=0;P3_4=0;TR1=0;
GotoXY(0,0);
Print("from: ");
GotoXY(0,1);
Print("to: ");
biao=6;
}
//************************************************************
void jia(void)
{
minite++; wdz++;
if(minite==60) minite=0;
}
void jian(void)
{
minite--; wdz--;
if(minite<=0) minite=0;
}
//*************************************************************************
void sure(void)
{
while(su==1)
{
if(biao==0){su=0;TR1=0;}
while((biao==1)||(biao==2))
{
jiawen();
if(biao==1)
threetime();
else
twotime();
}
while((biao==3)||(biao==4)||(biao==5))
{
if((biao==3)||(biao==4))
jiashui();
daojishi();
P3_1=0;P3_0=1;
GotoXY(0,0);
if(biao==3)Print(" kuai xi yi ci ");
if(biao==4)Print(" man xi yi ci ");
GotoXY(0,1);
Print("time: ");
while(1)
{
disp();if(biao==4)manxi();
getkey();
while((second<=5)&&(minite==0))
{
P2_6=1;P3_0=0;su=0;GotoXY(0,1);
Print("wan cheng le ");baojing();
}
}
}
while(biao==6)
{
jiawen();
P3_6=0;
GotoXY(0,0);
Print("jia wen jie su");
GotoXY(0,1);
Print("keyi xiyi le ");
su=0;baojing();
}
}
while(su==2)
{
P3_2=1;P3_3=1;P3_4=1;
jc1=P2;
jc2=P3;
TR0=0;
P3=0;
P2=0;
while(1)
{getkey();}
}
while(su==3)
{
P3_2=0;P3_3=0;P3_4=0;TR0=1;
P2=jc1;
P3=jc2;
while(1)
{getkey();if(biao==6)display();else disp();}
}
}
//*****************************************************************************
void jiashui(void)// P2.3檢測水滿//P2.4檢測水排光//P2.5加水閘;//P2.6排水閘;
{
P3=0;
GotoXY(0,0);
Print("xi tong zheng ");
GotoXY(0,1);
Print("zai jia shui ");
dingshi();
while(P2_3!=1||P2_4!=1)
{ su=0;
P2_5=1; if(san)baojing();
}
P2_5=0;TR1=0;
}
//***********************************************************************************
void paishui(void)//排水 縋2.3檢測水滿; P2.4檢測水排光; P2.5加水閘; P2.6排水閘;
{
P3=0;
GotoXY(0,0);
Print("xi tong zheng ");
GotoXY(0,1);
Print("zai pai shui ");
dingshi();
while(P2_4==1||P2_3==1)
{ su=0;
P2_6=1;if(san)baojing();
}
P2_6=0;TR1=0;
}
//******************************************************
void jiawen(void)//P3.7 測溫器 P3.6 加熱器
{
ReadTemperature() ;
jiashui();
GotoXY(0,0);
Print("from: ");
GotoXY(0,1);
Print("to: ");
// Delay1ms(800);
dingshi();
while(ReadTemperature()<=wdz)
{
P3_6=1;
display();
getkey();su=0;
if(ba)baojing();
}
P3_6=0;
TR1=0;
}
//************************************
void manxi(void)
{
daojishi();
if(sflag)P3_0=1;
else P3_0=0;
}
//自動洗3次**********************************************************
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -