#include <reg52.h>
#include "12864.h"
#include "delay.h"
#define uc unsigned char
sbit led_DJ=P1^0; //电机
sbit led_XY=P1^1; //洗衣
sbit led_JS=P1^2; //进水
sbit led_CS=P1^3; //出水
sbit led_TS=P1^4; //脱水
sbit key_JS=P1^5; //进水按键
sbit key_CS=P1^6; //出水按键
sbit moshi=P3^0; //更改模式光标
sbit queren=P3^1; //确认运行
sbit xuanze=P3^2; //选择不同模式
sbit qingrou=P3^3; //轻柔按键
sbit xidi=P3^4; //洗涤按键
sbit jiare=P3^5; //加热
void delay(); // 延时函数
void jinshui(); // 进水子程序
void chushui(); // 出水子程序
void start(); // 开始子程序
void over(); // 结束子程序
uc cycle=10,pwm=0;
uc xiyi=0,xiyit=20,ret=20,st=5;
uc n,j,second,minute;
//延时函数
/**********************************/
void delay(uc c)
{
uc a,b;
for(;c>0;c--)
for(a=38;a>0;a--)
for(b=130;b>0;b--);
}
// 进水子程序
/**********************************/
void jinshui()
{
if(key_JS==0)
led_JS=0;
delay(2);
while(key_JS==0)
delay(2);
}
// 出水子程序
/**********************************/
void chushu()
{
if(key_CS==0)
led_CS=0;
delay(2);
while(key_CS==0)
delay(2);
}
// 开始子程序
/***********************************/
void start()
{
if(qingrou==0)
led_DJ=0;
delay(2);
while(qingrou==0)
delay(2);
}
void main()
{ unsigned char i,count=0;
TMOD=0X11;
TH0=15536/256;
TL0=15536%256;
TH1=64536/256;
TL1=64536%256;
ET0=1;
ET1=1;
EA=1;
Init_ST7920();
for(i=0;i<20;i++)
DelayMs(200);
ClrScreen();
LCD_PutString(0,1,"轻柔模式");
LCD_PutString(0,2,"洗涤模式");
LCD_PutString(0,3,"当前状态:");
while(1)
{
while(1)
{
if(moshi==0)
{
delay(20);
count++;
if(count==5)
count=1;
while(moshi==0);
delay(20);
while(1)
{switch(count)
{case 1:Write_Cmd(0x80);Write_Data(' ');Write_Data(' ');break;
case 2:Write_Cmd(0x82);Write_Data(' ');Write_Data(' ');break;
case 3:Write_Cmd(0x86);Write_Data(' ');Write_Data(' ');break;
case 4:Write_Cmd(0x92);Write_Data(' ');Write_Data(' ');break;
}
delay(100);
switch(count)
{case 1:if(xiyi==0) LCD_PutString(0,1,"轻柔");else LCD_PutString(0,1,"洗涤");break;
case 2:Write_Cmd(0x82);Write_Data(xiyit/10+'0');Write_Data(xiyit%10+'0');break;
case 3:Write_Cmd(0x86);Write_Data(st/10+'0');Write_Data(st%10+'0');break;
case 4:Write_Cmd(0x92);Write_Data(ret/10+'0');Write_Data(ret%10+'0');break;
}
if(moshi==0||queren==0||xuanze==0) break;
}
}
}
}
if(xuanze==0)
{delay(20);
switch(count)
{case 1:xiyi=!xiyi;break;
case 2:xiyit-=5;if(xiyit==0) xiyit=20;break;
case 3:st--;if(st==0) st=5;break;
case 4:ret-=5;if(ret==0) ret=20;break;
}
switch(count)
{ case 1:if(xiyi==0) LCD_PutString(0,1,"轻柔");else LCD_PutString(0,1,"洗涤");break;
case 2:Write_Cmd(0x82);Write_Data(xiyit/10+'0');Write_Data(xiyit%10+'0');break;
case 3:Write_Cmd(0x86);Write_Data(st/10+'0');Write_Data(st%10+'0');break;
case 4:Write_Cmd(0x92);Write_Data(ret/10+'0');Write_Data(ret%10+'0');break;
}
while(xuanze==0);
DelayMs(20);
}
{DelayMs(20);
switch(count)
{
case 1:xiyi=!xiyi;break;
case 2:xiyit-=5;if(xiyit==0) xiyit=20;break;
case 3:st--;if(st==0) st=5;break;
case 4:ret-=5;if(ret==0) ret=20;break;
}
switch(count)
{
case 1:if(xiyi==0) LCD_PutString(0,1,"轻柔");else LCD_PutString(0,1,"洗涤");break;
case 2:Write_Cmd(0x82);Write_Data(xiyit/10+'0');Write_Data(xiyit%10+'0');break;
case 3:Write_Cmd(0x86);Write_Data(st/10+'0');Write_Data(st%10+'0');break;
case 4:Write_Cmd(0x92);Write_Data(ret/10+'0');Write_Data(ret%10+'0');break;
}
while(xuanze==0);
DelayMs(20);
}
if(queren==0)
count=0;
DelayMs(20);
while(queren==0);
DelayMs(20);
led_JS=0;
LCD_PutString(0,4,"洗涤进水 ");
while(key_JS==0);
led_JS=1;
LCD_PutString(0,4,"洗涤中 ");
if(xiyi==0)
pwm=5;
else
pwm=7;
TR0=1;
TR1=1;
while(minute!=xiyit);
TR0=0;
TR1=0;
TH0=15536/256;
TL0=15536%256;
TH1=64536/256;
TL1=64536%256;
led_DJ=1;
n=j=second=minute=0;
LCD_PutString(0,4,"洗涤排水 ");
led_CS=0;
while(key_CS==0);
LCD_PutString(0,4,"第一次甩干 ");
pwm=10;
TR0=1;
TR1=1;
while(minute!=st);
TR0=0;
TR1=0;
TH0=15536/256;
TL0=15536%256;
TH1=64536/256;
TL1=64536%256;
led_DJ=1;
n=j=second=minute=0;
led_JS=0;
LCD_PutString(0,4,"涮洗进水 ");
while(key_JS==0);
led_JS=1;
if(xiyi==0)
pwm=5;
else
pwm=7;
TR0=1;
TR1=1;
LCD_PutString(0,4,"涮洗 ");
while(minute!=xiyit);
TR0=0;
TR1=0;
TH0=15536/256;
TL0=15536%256;
TH1=64536/256;
TL1=64536%256;
led_DJ=1;
n=j=second=minute=0;
led_CS=0;
LCD_PutString(0,4,"涮洗排水 ");
while(led_JS=0);
led_CS=1;
jiare=0;
LCD_PutString(0,4,"加热烘干 ");
TR0=1;
while(minute!=ret);
TR0=0;
TR1=0;
TH0=15536/256;
TL0=15536%256;
TH1=64536/256;
TL1=64536%256;
jiare=1;
n=j=second=minute=0;
LCD_PutString(0,4,"洗涤结束 ");
}
void dd() interrupt 3
{
TH1=64536/256;
TL1=64536%256;
n++;
if(n==cycle)
n=0;
if(n<pwm)
led_DJ=0;
else
led_DJ=1;
}
void ss() interrupt 1
{ TH0=15536/256;
TL0=15536%256;
j++;
if(j==20)
{second++;
j=0;
}
if(second==60)
{minute++;
second=0;
Write_Cmd(0x9E);
Write_Data(minute/10+'0');
Write_Data(minute%10+'0');
LCD_PutString(7,4,"分 ");
}
}
|