全自动洗衣机程序代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

附 录
程序清单:
#include
#include
typedef unsigned int uint;
typedef unsigned char uchar;
uchar code SKEY[16]={10,11,12,13,3,6,9,14,2,5,8,0,1,4,7,15};
#define EXITISR() EA=0; //关中断
#define ENTERISR() EA=1; //开中断
sbit start=P3^0; //启动/暂停
sbit safe=P3^1; //安全开关
sbit round_1=P1^0; //正转
sbit round_2=P1^1; //反转
sbit lenshui=P1^2; //冷水阀
sbit reshui=P1^3; //热水阀
sbit paishui=P1^4; //排水阀
sbit start_led=P1^5; //启动led
sbit stop_led=P1^6; //暂停led
sbit power_led=P1^7; //电源led
sbit waring=P3^7; //报警
float shuiwei;
unsigned char xdtime;
unsigned char xdt1;
unsigned char xdt2;
unsigned char xdtsh;
unsigned char pxtime;
unsigned char tshtime;
unsigned char jptime;
unsigned char lenreshui;

void delay(uint k)
{
uint date i,j;
for(i=0;ifor(j=0;j<121;j++)
{;}}
}

//===================================
void main(void)
{
char c;
uchar key_value=0;
key_V(); //调用键值处理子程序
key_value=9;
key_V(); //调用键值处理子程序
jptime=0;
lenreshui=0;
P1=10001100; //点亮冷水LED
while(start)
{
c=scan_key(); //调用按键扫描函数
if(c!=-1)key_value=SKEY[c];
key_V(); //调用键值处理子程序
}
wash();
}
//===================================

//==========================//按键扫描函数
char scan_key(void)
{
uchar code act[4]={0xfe,0xfd,0xfb,oxf7};
uchar i,j,in,ini,inj;
bit find=0;
for(i=0;i<4;i++)
{
P2=act[i];
delay(10);
in=P2;
in=in>>4;
in=in|0xf0;
for(j=0;j<4;j++)
{
if(act[j]==in)
{find=1;
inj=j;ini=i;
}
}
}
if(find==0)return -1;
return(ini*4+inj);
}
//===================================

//==========================//键值处理子程序
void key_V(void)
{
if(key_value=0)
{
P1=00000110; //清空LED
delay(2);
P1=10000110; //点亮标准LED
xdtime=20;
xdt1=10;
xdt2=5;
xdtsh=1;
pxtime=2;
tshtime=3;
}
else if(key_value=1)
{
P1=00000110; //清空LED
delay(2);
P1=01000110; //点亮快速LED
xdtime=12;
xdt1=12;
xdt2=3;
xdtsh=1;
pxtime=1;
tshtime=2;
}
else if(key_value=2)
{
P1=00000110; //清空LED
delay(2);
P1=00100110; //点亮轻柔LED
xdtime=16;
xdt1=9;
xdt2=6;
xdtsh=1;
pxtime=2;
tshtime=2;
}
else if(key_value=3)
{
P1=00000100; //清空LED
delay(2);
P1=00010110; //点亮强洗LED
xdtime=24;
xdt1=12;
xdt2=3;
xdtsh=1;
pxtime=2;
tshtime=4;
}
e

lse if(key_value=4)
{
P1=00000100; //清空LED
delay(2);
P1=10000110; //点亮防皱LED
xdtime=20;
xdt1=9;
xdt2=6;
xdtsh=0;
pxtime=1;
tshtime=0;
}
else if(key_value=5)
{
P1=00000100; //清空LED
delay(2);
P1=01000110; //点亮单漂洗LED
xdtime=0;
xdt1=0;
xdt2=0;
xdtsh=0;
pxtime=2;
tshtime=0;
}
else if(key_value=6)
{
P1=00000100; //清空LED
delay(2);
P1=00010110; //点亮单脱水LED
xdtime=0;
xdtsh=0;
pxtime=0;
tshtime=3;
}
else if(key_value=7)
{
P1=00000100; //清空LED
delay(2);
P1=00010110; //点亮预约LED
yuyue();
}
else if(key_value=8)
{
P1=00011000; //点亮运动浸泡LED
jptime=1;
}
else if(key_value=9)
{
P1=00101000; //点亮50L LED
shuiwei=21.52;
}
else if(key_value=10)
{
P1=01001000; //点亮40L LED
shuiwei=21.98;
}
else if(key_value=11)
{
P1=10001000; //点亮30L LED
shuiwei=22.62;
}
else if(key_value=12)
{
lenreshui=!lenreshui;
if(lenreshui)
{
P1=01001100; //点亮热水LED }
else
{
P1=10001100;//点亮冷水LED
}
}
}
//===================================

//===================================
void yuyue(void)
{
A1: P1=10001000; //点亮洗涤LED
char c;
uchar key_value;
c=scan_key(); //调用按键扫描函数
if(c!=-1)key_value=SKEY[c];
if(key_value=13)
{
xd=xd+4;
xianshi(xd/4);
goto A1;
}
else if(key_value=14)
{
xd=xd-4;
xianshi(xd/4);
goto A1;
}
else if(key_value=15)
{
xdtime=xd;
goto A2;
}
else goto A1;
A2: P1=01001000; //点亮漂洗LED
char c;
uchar key_value;
c=scan_key(); //

调用按键扫描函数
if(c!=-1)key_value=SKEY[c];
if(key_value=13)
{
px=px+1;
xianshi( px*11);
goto A2;
}
else if(key_value=14)
{
px=px-1;
xianshi( px*11);
goto A2;
}
else if(key_value=15)
{
pxtime=px;
goto A3;
}
else goto A2;
A3: P1=00101000; //点亮脱水LED
char c;
uchar key_value;
c=scan_key(); //调用按键扫描函数
if(c!=-1)key_value=SKEY[c];
if(key_value=13)
{
tsh=tsh+1;
xianshi(tsh);
goto A3;
}
else if(key_value=14)
{
tsh=tsh-1;
xianshi(tsh);
goto A2;
}
else if(key_value=15)
{
tshtime=tsh;
goto A3;
}
else goto A3;
A4: P1=00001000; //关灭LED
}
//===================================

//========================//洗衣子程序
void wash(void)
{
if(jptime)
{
jpcx(); //调用浸泡子程序
}
if(jptime)
{
xdcx(); //调用洗涤子程序
}
if(jptime)
{
pxcx(); //调用漂洗子程序
}
if(jptime)
{
tshcx(); //调用脱水子程序
}
baojin();
}
//===================================

//===================================
void jpcx(void)
{
addwater();
do
{
round_1=0; //电机正转
delay(10000);
round_1=1;
round_2=1; //电机停止
delay(50000);
round_2=0; //电机反转
delay(10000);
round_2=1;
round_1=1; //电机停止
delay(50000);
jcshuiwei();
}while(--jptime)
}
//===================================

//===================================
void xdcx(void)
{
P0=10001000;
addwater();
do
{
round_1=0; //电机正转
delay(xdt1*1000);
round_1=1;
round_2=1; //电机停止
delay(xdt2*1000);
round_2=0; //电机反转
delay(xdt1*1000);
round_2=1;
round_1=1; //电机停止
delay(xdt2*1000);
jcshuiwei();
}while(--jptime)
subwater;
if(xdtsh)
{
ET0=1;
ET1=1;
EA=1;
paishui=0; //打开排水阀
round_1=0;
delay(60000);
paishui=0;
round_2=1;
round_1=1; //电机停止
paishui=1; //关闭排水阀
ET0=0;
ET1=0;
EA=0;
}
}
//===================================

//===================================
void pxcx(void)
{
unsigned char xht=7;
P0=01001000;
do
{
addwater();
do
{
round_1=0; //电机正转
delay(10000);
round_1=1;
round_2=1; //电机停止
delay(5000);
round_2=0; //电机反转
delay(10000);
round_2=1;
round_1=1; //电机停止
delay

(5000);
jcshuiwei();
}while(--xht)
subwater;
ET0=1;
ET1=1;
EA=1;
paishui=0; //打开排水阀
round_1=0; //电机正转
delay(60000);
round_2=1;
round_1=1; //电机停止
paishui=1; //关闭排水阀
ET0=0;
ET1=0;
EA=0;
}while(--pxtime)
}
//===================================

//===================================
void counter(void)
{
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long counter;
unsigned char i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{
if(flag==1)
{
flag=0;
counter=T0count*65536+TH0*256+TL0;
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
}
}


void t0(void) interrupt 1 using 0
{
T0count++;
}
 
void t1(void) interrupt 3 using 0
{
unsigned char timecount;
bit flag;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
timecount++;
if(timecount==250)
{
TR0=0;
timecount=0;
flag=1;
}
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
//===================================

//===================================
void tshcx(void)
{
P0=00101000;
ET0=1;
ET1=1;
EA=1;
paishui=0; //打开排水阀
round_1=0;
for(i=0;i<30;i++)
{
delay(6000);
}
paishui=1; //关闭排水阀
round_2=1;
round_1=1; //电机停止
P0=00001000
ET0=0;
ET1=0;
EA=0;
}
//===================================

//===================================
void extern_into(void) interrupt 0 using 0
{
P0=11100000; //显示E
delay(2);
P0=00101000; //显示2
baojin();
}
//===================================

//===================================
void pinhengjzh(void)
{
paishui=1;
round_2=1;
round_1=1; //电机停止
xdtime=2;
xdtsh=o;
xdcx();
}
//===================================

//===================================
void addwater(void) //进水子程序
{
if(lenreshui)
{
reshui=0;
}
else
{
lenshui=0;
}
do
{
countre();
}while(counterreshui=1;
lenshui=1;
}
//===================================

//===================================
void subwater(void) //排水子程序
{
float=26;
paishui=0;
do
{
countre();
}while(counter>dry)
paishui=1;
}
//===================================

//===================================
void watchshuiwei(void) //检测水位子程序
{
float dshuiwei=25.92;
float gshuiwei=21.14;
countre();
if(counter>dshuiwei)
{
while(1)
{
P1=11111111; //停止洗衣
baojin();
P0=11100000; //显示E
delay(2);
P0=00010001; //显示1
}
}
else
{
if(counter{
while(1)

{
P1=11111111; //停止洗衣
baojin();
P0=11100000; //显示E
delay(2);
P0=00010001; //显示1
}
}
}
}
//===================================

相关文档
最新文档