|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
单片机全自动洗衣机控制系统proteus仿真及源程序
& U( S. h: a5 e( X8 Y! }/ }! ^+ E6 T
7 z/ i+ H0 {/ S5 l: f给大家分享一个51单片机做的全自动洗衣机的proteus仿真,下面是仿真原理图,可看出功能十分强大,按键很多。全部的源码可以下载本帖附件:
# Z5 q; L$ n. `1 p i3 m! s4 G [- Q
( ~8 y& b7 W- X4 S- d& G! ^4 N5 o: R" S$ O' _" {
# C2 C) K; d: P: b, Q: F9 s
仿真工程文件及全部源码下载:
% U0 {: {7 n% v+ p$ e+ F7 `4 r# B$ z) }& }6 p3 u! t
/ i; Y' b% f& x
. E9 d+ l+ S' o
单片机源程序:
2 M# h3 P& h' x. E$ t o5 j( z* i/***************************头文件***********************/
0 v, K2 q4 |7 F* b: l5 X#include
4 s* N6 O# }* X8 e/************************数据类型宏定义******************/9 r( l6 U3 e. _' \
#define uchar unsigned char
4 \- B- F& t* r" d# E/ i#define uint unsigned int: g9 l& y! ]4 j- U0 N
/***********************使能、禁止宏定义*****************/
5 d3 t. K3 B1 M. T7 z#define Enable(); EA=1;
( |/ ?8 h% D5 d8 i5 \#define Disable(); EA=0;8 `) p2 L( y' O% R/ |0 g
/********************程序选择功能标志宏定义**************/
( O! b) k' K0 `- X) x5 L#define BIAOZHUN 0+ ]" u4 a% k9 \* U" h( p8 h; o
#define JINGJI 1
5 U/ U; v: [. K4 ]! W8 ]! D#define DANDU 2
5 M9 E, e$ a4 A1 S#define PAISHUI 3
) \' [* U& Y1 { C8 |# z/********************强弱选择功能标志宏定义**************/
. w q: V; v. O! m#define QIANGXI 0) R3 G. p) }' ], j$ B1 p
#define RUOXI 1 7 T4 Y; A' h, ?# E: b h4 L' T4 q
/*******************进水、排水时间限制宏定义*************/
$ R8 I! C7 j" p0 Z( z; N/ d#define T_JinShui 10 //4min*60s7 g) h7 u! Z, l" }0 B7 |
#define T_PaiShui 10 //1min*60s+ P( n M3 Y' V* k! H
#define T_XiDi 10 //6min*60s. ^, m5 b* R+ O- W2 ]
#define T_PiaoXi_1 10 //4min*60s0 y) B* n* W" F x# E7 e
#define T_PiaoXi_2 10 //2min*60s
6 N" @6 C; L) ]' h6 [/ X" d#define T_TuoShui 10 //2min*60s
0 V" x4 r4 R' A" Z1 u/**********************电机控制宏定义********************/, t0 v, z4 w/ Q7 x
#define ZHENGZHUAN 0- M1 @8 `. B4 [. t( y% j
#define STOP 1* j% [$ V- c- y$ r2 a
#define FANZHUAN 2
7 x# D" l* ]% C1 O" S$ K7 h#define ZhengZhuan(); PIN_Motor_A = 0; PIN_Motor_B = 1;% c, O v5 @8 F& q$ n/ y
#define Stop(); PIN_Motor_A = 1; PIN_Motor_B = 1;2 Z" Y' |& w* Q! D$ r1 t6 u/ E
#define FanZhuan(); PIN_Motor_A = 1; PIN_Motor_B = 0;
0 U2 J" a, m) v& v/*******************暂停、继续控制宏定义*****************/
" U1 ^4 {4 j, I2 p& y#define ZanTing(); ET0 = 0; ET1 = 0; Stop();
) B" v8 l, C; S. g2 H$ d W( B#define JiXu(); ET0 = 1; ET1 = 1;
) L. C% X) `; M) O- f% v& B2 B/*************************管脚定义***********************/
' T- A+ n! c7 a* J//都是低有效,因LED是灌电流,而PNP也是低电平时导通8 Q$ I9 t: W2 W$ s& W/ @
sbit LED_BiaoZhun = P1^0; //标准程序显示灯, Z7 e% }+ B/ I c
sbit LED_JingJi = P1^1; //经济程序显示灯
" |" G' G0 D$ Z+ s D( ~, [+ Esbit LED_DanDu = P1^2; //单独程序显示灯% M- z7 d/ E0 t1 k2 U, s
sbit LED_PaiShui = P1^3; //排水程序显示灯 O3 L( }9 H, [. o, J* ]6 t3 M, G
sbit LED_QiangXi = P1^4; //强洗状态灯
+ g+ h$ ^7 z/ \, w/ v+ o8 wsbit LED_RuoXi = P1^5; //弱洗状态灯, ~' v$ ~! i. K, {1 G5 j
sbit LED_XiDi = P1^6; //洗涤状态灯$ k8 q2 ]! I" t& A$ G; U8 d
sbit LED_PiaoXi = P1^7; //漂洗状态灯
2 {: [/ [) f1 ^6 I3 L* k* isbit LED_TuoShui = P2^0; //脱水状态灯
. f5 B% k M1 S! ^; ksbit PIN_BaoJing = P2^1; //报警喇叭
# c0 S" G% O8 S5 W- b$ o% i1 {sbit PIN_JinShui = P2^2; //进水控制
7 X3 V y) ?; d6 E( z, c% j, F' [sbit PIN_PaiShui = P2^3; //排谁控制6 \- j) I1 F% _" R! U# \9 k
sbit PIN_Motor_A = P2^4; //电机脚A4 F! [) ?$ t) r- Z
sbit PIN_Motor_B = P2^5; //电机脚B- q2 a8 [1 L8 b7 N
sbit K_SEL_ChengXu = P3^0; //选择程序键
. [* ~8 D2 g1 osbit K_SEL_QiangRuo = P3^1; //选择强弱键0 V4 g, t. B. ]9 x2 P. P
sbit p32 = P3^2; //
" h/ }2 s! z- A$ V2 ?sbit p33 = P3^3; /// i8 ]' o$ ^; V
sbit SW_ShuiWei = P3^6; //水位开关
& E" x, h. e8 [0 F3 W$ w3 g3 [sbit SW_AnQuan = P3^7; //安全开关. r# b( v1 O+ Y$ G
/************************函数申明***********************/* y0 M) h/ z7 z9 o6 t' ~
void Programme_PaiShui(void);8 k/ R! l6 ~' J1 S' I
/*************************数据定义***********************/
t. K7 l( {+ ?% z8 Y$ Q7 fuchar flag_SEL_ChengXu; //默认为标准程序,
7 h @9 v5 e9 W# Y/ {bit flag_SEl_QiangRuo; //默认为强洗,1为弱洗
$ M) L5 ]2 o$ s4 v1 K6 kbit flag_Run; //运行标志,1为运行
4 d j4 y( F# Z4 ` q( n" h z//bit flag_ZanTing; //暂停标志,1为暂停
) i) S. W0 m F$ K) I+ Q, sbit flag_JinShui; //进水标志,1为进水, K+ \( e) n+ Z& v7 f
bit flag_PaiShui; //排水标志,1为排水& h5 y: B* {* Y
bit flag_XiDi; //置洗涤标志
; @9 `. L) n) o: Sbit flag_PiaoXi; //置漂洗标志
1 K2 ^6 }4 a; c5 F; L- Xbit flag_TuoShui; //脱水标志1 J1 D9 @+ W/ v: i: f- x6 v( L1 r. ]% A
bit flag_BaoJing; //报警标志1 M0 s- T8 I0 h% y( T- I
uchar _50ms; //每50ms加一次的变量
/ \9 s0 o/ B4 C. Yuint s; //秒
3 g# \# }* r" iuint T_S; //定时总时间! R) |. K0 R# t
uchar T_Motor; //电机控制时间. T R. J+ B+ b1 ~
/*************************延时程序*********************/% a4 K+ m9 C# P* Y( E! [
void Delay_10ms(uint T1)
% l5 }$ y" H) ]; q- g* e; z) H{ uint t1,t2;0 _8 [0 p2 o4 K3 h; u( O7 O
for(t1=0;t1<t1;t1++)
7 O5 d8 J- A+ `" w8 `* I for(t2=0;t2<1250;t2++);//10ms
' n ^- l& v* ^5 f7 P}# x/ {5 {2 m' _* k q
/**********************管脚初始化程序******************/
\" l8 _! _" e1 X: d7 B0 Nvoid Pin_Init(void) ' @' E$ R+ k1 T, H
{ LED_BiaoZhun = 0; //默认为标准程序,灯亮
$ U W% u- l/ {; o LED_JingJi = 1; //经济程序显示灯,灭
$ Y) B9 [4 W9 b% I; b LED_DanDu = 1; //单独程序显示灯,灭
4 s/ V3 J2 e# D4 S$ m* ]( b LED_PaiShui = 1; //排水程序显示灯,灭
+ a' l! N' T% z! ? LED_QiangXi = 0; //默认为强洗状态,灯亮- Q/ O0 k/ i1 c# U3 z+ A. Q
LED_RuoXi = 1; //弱洗状态灯,灭9 D! m' @$ I0 s- I
LED_XiDi = 1; //洗涤状态灯,运行后灯亮
0 X- i: Q2 C+ V. X' f0 k0 h8 f LED_PiaoXi = 1; //漂洗状态灯,运行后灯亮
" B! n% w! Q9 g2 g+ [ LED_TuoShui = 1; //脱水状态灯,运行后灯亮
& G5 R. @+ P0 V8 @; B# S PIN_BaoJing = 1; //报警喇叭,不叫. A% j+ v# e$ x+ F6 [
PIN_JinShui = 1; //进水控制,关
0 l4 V9 p+ f7 G) ~8 n' O PIN_PaiShui = 1; //排谁控制,关+ t$ c+ Q8 f/ N$ _7 r) K
PIN_Motor_A = 1; //电机脚A,不走1 m& o$ @' g) C
PIN_Motor_B = 1; //电机脚B,不走
2 l) @, W7 x. y}, J1 O! s. O; X4 m; A- k
/********************中断初始化程序********************/
2 I+ f6 n* X- q2 M- h0 s' Svoid ExInt_Init(void) 4 {/ P1 ~. p9 @
{ IT0 = 1;
$ ]! P! s- E7 j+ b EX0 = 1;
; Q/ t6 N" T9 n5 I x* O/ x IT1 = 1;
1 r% V1 u1 d- _ EX1 = 1;" }& f6 S8 k+ o$ W& K) ?1 |% U8 @
}& o+ j5 _) F [9 N
/*******************定时器0初始化程序******************/
% R9 ]# I6 [8 vvoid Timer0_Init(void) //其中没ET0是为以后控制暂停用的
) c8 N: r3 E6 e+ y/ k{ TMOD = TMOD | 0X01; //定时方式1
6 j7 y4 C5 t+ f/ J; K2 v; L, q' N TH0 = 0X3C; //50ms
0 B9 x5 d. |6 K" v& `8 r TL0 = 0XB0;
5 g z" a% J! W0 U2 G TR0 = 1;2 q, O/ E" j8 \, W8 v8 w. u) i; ]2 L
_50ms = 0;0 t6 a1 n; U4 p3 E; \; B+ b# q6 |
s = 0;. y$ B6 D9 e3 {
}
% j& i( r3 [* ~8 F5 S* i) y9 l/*******************定时器1初始化程序******************/
0 e+ |. ]( x2 {void Timer1_Init(void) //其中没ET1是为以后控制暂停用的: E: H8 q3 f0 X
{ TMOD = TMOD | 0X10; //定时方式1+ {4 s" {7 Z9 j
TH1 = 0X3C; //50ms2 x) A+ I& h7 s0 Q2 g) j5 d6 c
TL1 = 0XB0;) s" U. [. E1 {" g$ m
}
+ M5 B% \6 x* o8 D/********************电机初始化程序********************/+ V' Z2 b/ s, r* j
void T_Motor_Ctl(uchar t1,uchar t2,uchar t3)$ a( |- s+ s* ~) ~
{ if(!flag_SEl_QiangRuo)//强洗
6 l8 M0 L( y+ ~ T_Motor = t1;
/ q( z3 B9 E7 q9 ]6 B& e if(flag_SEl_QiangRuo)//弱洗
! N8 Q, O8 g6 W) z* P T_Motor = t2;
@5 S. x& v3 q if(flag_TuoShui)//脱水
# c7 H6 [/ W2 T& u t0 B c% T$ c T_Motor = t3;
1 x$ X7 q2 h+ m# \}2 G/ h* |! E! Z1 }# Q5 Y
/********************电机初始化程序********************/' v" \$ V% ]' O8 \9 Q) b
void Motor_Init(void)
. d5 n6 s2 R+ K y5 S- E1 {5 s{ ZhengZhuan();1 n, u5 d; x8 j) g" U9 N
T_Motor_Ctl(4,3,5);3 r2 n z; M* p& A
}( V! U" z( n" S. O9 B/ F9 L' T
/**********************解除报警************************/
& {5 w+ t. L. J0 |8 I/ @void No_BaoJing(void)* h1 z) ~- k* E _) R6 n8 e0 H
{ flag_BaoJing= 0; //置报警标志7 w# x9 g$ ]9 g* }/ K+ l) ~; k
PIN_BaoJing = 1; //报警喇叭# T4 q4 E" D8 U9 y
//进水、排水已没时间限制了
4 u4 L. F4 i$ l. H0 d" s, U& g$ L}( `* K$ x0 `" U' q6 M
/**************外部中断0程序为运行或者暂停*************/! |. R% p+ d9 Q: K4 M \5 x
void int0(void) interrupt 0 $ ]5 \. U1 Z1 p% [6 g
{ 0 F, n9 R7 S. S! ]4 c1 @5 G) L6 D
if(!p32)2 E! _/ [- n% M9 q! y# ]
{ Delay_10ms(1); //延时10ms左右,去抖动
$ S4 ^8 x% n/ m1 b if(!p32)% B- P7 h% g/ I% M1 M6 |3 r8 M
{ if(!flag_Run)$ o5 R5 z5 Z; f& ~
flag_Run = 1; //置运行标志
3 [1 T5 C: k; Q. { else if(flag_BaoJing)9 {. y& g3 V _; ~& }5 y
No_BaoJing();
. b/ l# n+ S% ^3 O, H( R$ v; D! {8 r else5 t3 e. [9 [% c' l- f9 Y4 E, L
{ static bit flag_ZanTing;0 n- h$ `2 k0 p6 n$ a
flag_ZanTing = ~flag_ZanTing;
! ?4 O) a9 W& f* `( i# U if(flag_ZanTing)
3 U8 }8 P( u& J! O' {3 \2 ?# \" m ZanTing();
9 X+ E% o* ]( {- Y6 @& ` if(!flag_ZanTing) // 这里用else,编译出错。???? ' q3 q1 T2 `& o' {5 B% n- H
JiXu();
7 v. K6 b' v1 o! \8 V& h" A }//end else# \! E; i) f6 ]1 d
}//end if(!p32) 2% [6 n' M7 U; {* `1 B- @. ^
}//end if(!p32) 1
2 c( o/ b& }) w" j& i% I5 H}
+ Y! N' v6 O* n- S6 u/**********************报警程序************************/
{! S6 S }; d8 Q# K# q |void BaoJing(void)/ n6 a/ ?% x) o
{ flag_BaoJing= 1; //置报警标志+ l$ p* w& }+ }. U `
PIN_BaoJing = 0; //报警喇叭
2 M! W. M4 B- n TR0 = 0;
2 B5 F( V. {: x$ y* }/ t- d}
' E5 @8 c2 z# D9 q/ I1 v/ d/*******************时间到处理程序*********************/
# p" \$ m3 _5 q; s) _6 ]4 d0 ~$ @void Ok_Timer(void)
9 z# h! e9 j% N( S t Y- f{ s = 0;
0 C( R7 ~; C+ R$ ^4 l# M if(flag_JinShui || flag_PaiShui) //进水中~、排水中~! k1 D6 e1 K1 {$ _% I
{ BaoJing(); //报警程序9 ]% I7 s4 P) L2 Y$ j. `
}//end if(flag_JinShui || flag_PaiShui)) o- |; t$ W( w. e( |
else
1 n' L: p+ h& g5 Z { flag_XiDi = 0; //清洗涤标志
6 _4 [; }: d2 |+ k" @1 x# q flag_PiaoXi = 0; //清漂洗标志9 |: |& s; t- W: m
flag_TuoShui= 0; //清脱水标志
1 L! t0 F5 w: m& L: o Stop();
S" P9 X3 ^' r- V$ \ }//end else7 [4 P5 d; C( z
}
9 E, _2 Y! U& Y/********************电机控制程序**********************/
2 o; N y5 [6 \. wvoid Motor(void)
. z5 K0 N. t) {- e. {$ G+ s{ static uchar s_Motor;$ H, h9 Z0 c9 t' B1 |' X: a
s_Motor++;
% E- [& a$ P& V7 z/ u, g if(s_Motor==T_Motor)
6 r) O% x. I2 ~5 v) `0 f% n { static uchar Motors;' m$ Y) v/ ` }6 J
s_Motor = 0;- a: s- D! f6 _
Motors++;- m' S, j! ?8 x/ k% p& K$ I. @# y
if(Motors==3)* [$ n- d+ g$ z
Motors = 0;
4 F2 B; G) C5 c5 M8 ?& ?! R8 e switch(Motors)7 i- V4 k! `! g+ y) N! o
{ case ZHENGZHUAN : ZhengZhuan();
) i# l* m4 q" M. E T_Motor_Ctl(4,3,5);
4 v) X0 o/ t: p( _# U4 I* G% Z break;
7 n7 i% Z5 s( a1 _8 M case STOP : Stop();) o- r( W) L2 u4 M9 P2 M
T_Motor_Ctl(1,2,2);
) E/ ^3 e3 b3 O3 ?. B% Z break;
% p9 x: |+ Y$ d4 F+ O/ t case FANZHUAN : FanZhuan();4 F6 F! C' R) _+ T" d( E, u: k: B' Y
T_Motor_Ctl(4,3,5);! [/ X& L3 ~- ]% ^; d6 p
break;4 ~0 q3 J! W& `+ O& D v2 p9 ^. j
default : break;
3 }! K+ ^. I! y }//end switch! k' k' q- g- r, T8 R
}//end if9 G# c& A- m$ U& E& `6 g& t0 _
}
6 |, q: O& n! v: u; I/*******************定时器0中断程序********************/
) |+ F) F% v N! {void Timer0(void) interrupt 1 # F8 ^) \: o7 ^1 s7 b4 ]
{
" `/ q; ^3 o! C7 h: X: m8 ~ TR0 = 0; //停止计数
3 k; G" N6 I5 A0 a TH0 = 0X3C; //重装定时器值" t' A$ K' b6 g+ g6 `% v
TL0 = 0XB0;
t7 I: t% }" T2 I# M: j TR0 = 1;3 O& ~1 k: j% ^% u1 J& R5 R+ r5 X; m
_50ms++;
1 X0 y# ^: Z+ c1 R. N0 A! T. Z if(_50ms == 20) //1s到
, `2 X, [% `1 n! d a { _50ms = 0;
9 x, F; f, G( S/ ? s++;
( X" y1 J5 n: v) G2 y if(s == T_S) //定时到
" V( {8 L$ E8 d. _9 M1 x Ok_Timer();5 d# R/ Z0 J8 x+ g" N" ]; T/ g+ i
if(flag_XiDi || flag_PiaoXi || flag_TuoShui)
, l6 v @# z& M: a! j* G Motor(); //电机控制程序
+ |. n4 U7 N7 ^+ U }//end if(_50ms == 20) . \& Y+ O3 O7 h6 N2 x ]" i) h
}//end Timer0()
/ V* \7 d( E! Y/**********外部中断1程序为水位到或者盖开处理***********/2 p. W' S1 ^$ U' a) L
void int1(void) interrupt 2
! } [5 _- v' D `{ if(!p33)
7 p( P ~( s) E { Delay_10ms(1); //延时10ms左右,去抖动
1 Z! ~4 y1 k& e7 r$ p if(!p33)4 |* Y4 f, [( T9 y- E+ b9 l' T1 H
{
+ y u# n% d! u }//end if(!p33) 2
1 @- W1 A: m" \4 j+ E' J' X1 a }//end if(!p33) 1( {( D6 W- q. t% P3 D% e$ G& }
}- |8 E$ `5 }* t7 |& q
/***************定时器1中断程序作为闪烁****************/. Y* _) o; J* y/ e S+ u
void Timer1(void) interrupt 3
/ c5 B: e, h; K% o" S{ static uchar _50ms; //每50ms加一次的变量5 d6 d9 K4 L/ v5 y e9 j
TR1 = 0; //停止计数
/ ~: v* A! `4 L0 a. O TH1 = 0X3C; //重装定时器值, {) j8 X1 h( w! e9 V
TL1 = 0XB0;
- c0 ]- P7 a. Z2 z7 r TR1 = 1;
& W t2 n* q! O9 U6 h _50ms++;9 b5 q6 E; ^, n
if(_50ms == 14) //0.7s到6 H' D4 G: b' t- K5 S4 Z" m# A
{ _50ms = 0;
! W- t3 `! O0 ?3 a: m B1 n if(flag_XiDi) //洗涤中~% `( L- N& l) P+ w$ N% S
LED_XiDi = ~LED_XiDi; //洗涤状态灯闪烁
: Y0 h& C* _9 D5 {7 j( l if(flag_PiaoXi) //漂洗中~
: V2 z& Z4 f3 `- ], L LED_PiaoXi = ~LED_PiaoXi; //漂洗状态灯闪烁5 t! M, o- k. |3 h) v- |' `
if(flag_TuoShui) //脱水中~% D' F6 h. [$ l/ F
LED_TuoShui = ~LED_TuoShui; //脱水状态灯闪烁
& B+ B* }7 ^& P6 [$ \/ V1 e- T6 Q }//end if(_50ms == 14) + k; Z/ x V1 G# W
}* A% Y7 N* P' P* C/ N! e
/**********************程序选择程序********************/
& J7 Q1 d+ u$ k! y8 A5 U% l* Ovoid SEL_ChengXU(void) 0 c" D7 E" D7 {$ F& }
{ if(!K_SEL_ChengXu) //程序选择键9 A1 U" D8 T0 f* f: r) D& @
{ Delay_10ms(1); //延时10ms左右,去抖动
3 ~* M5 b' B3 U. {' C$ M. G if(!K_SEL_ChengXu)
9 t |7 h! U0 v6 \8 ?" N B { while(!K_SEL_ChengXu);& G0 {& o$ K% S2 v
flag_SEL_ChengXu++;
* \' X; s$ N3 P/ S! d5 w- ~3 C if(flag_SEL_ChengXu==4)+ |5 B7 ^6 n# w: l" q0 _7 j, A3 C: R
flag_SEL_ChengXu = 0;
$ \$ T$ J6 d! M3 E o# P switch(flag_SEL_ChengXu)
! @0 A; t# z ?" h8 f1 }. k { case BIAOZHUN : LED_BiaoZhun= 0; //亮
% v7 ~7 k1 ~5 ^% o0 s6 n' X: k LED_JingJi = 1; //灭
; d3 N. B9 f6 c8 ] LED_DanDu = 1; //灭 C% k% e8 n9 `% N5 u) |6 o3 N! ^
LED_PaiShui = 1; //灭
0 S0 J- T J; `; t; H4 Z7 h9 L break;
X- X- y4 ?- D4 r \# i+ x4 z case JINGJI : LED_BiaoZhun= 1;
c, E+ |; l% n m2 G2 C( l) Q$ D: X LED_JingJi = 0; 8 n* r/ c2 L: E: x
LED_DanDu = 1;
% A& ~3 g" n6 ]! r. p LED_PaiShui = 1;
. n$ t- C: V" j5 U% j+ Z break;
: T, s. B7 z" o2 h case DANDU : LED_BiaoZhun= 1;, ]; ~& X1 t; v9 I% W
LED_JingJi = 1;
$ X1 E( N& R O8 I8 ^2 T LED_DanDu = 0;
9 I9 j3 c6 P9 T6 x: O LED_PaiShui = 1;
8 L% m! w' q, F; A8 m/ W break;
7 @& W6 ?& ^# y, l2 R) N- t5 _ case PAISHUI : LED_BiaoZhun= 1;
% C) y2 X" x$ w8 ]) J8 ~2 r LED_JingJi = 1; # ]( R3 ~+ f4 X Y. R
LED_DanDu = 1;
2 S3 B: T( B( s) e( f& | LED_PaiShui = 0;
! E' h4 w& Q# y2 T& Y, H break;
6 V, e: B7 u0 k4 c default : break;
+ j7 ]; ?9 e2 d i: M; {7 ^( G5 N }//end switch ' D" z7 R+ A q+ }+ e( q$ `3 m" u
}//end if(!K_Sel_ChengXu) 2
, p) T, h& u F& e9 U }//end if(!K_Sel_ChengXu) 1
! w4 J4 F# _3 S/ g8 Z0 K0 D}//END, I/ j* p2 T1 G6 D# e7 e/ R
/********************强弱选择程序**********************/% x* t3 M- H/ i, C }$ D
void SEL_QiangRuo(void)
6 c s9 N+ ~" T5 p1 a [0 h; \{ if(!K_SEL_QiangRuo) //强弱选择键7 n1 y8 |6 Q; K8 C6 a! e/ r
{ Delay_10ms(1); //延时10ms左右,去抖动6 C( X. F( X6 T5 A ^8 P
if(!K_SEL_QiangRuo)
8 b: O* z7 J1 `1 h/ C { while(!K_SEL_QiangRuo);
, G: q; v0 `% m; `3 y flag_SEl_QiangRuo = ~flag_SEl_QiangRuo;
4 w" d3 u, ^, t6 P! v+ I! x$ |6 Y if(!flag_SEl_QiangRuo) : u3 r, M3 G* o6 I+ F) y
{ LED_QiangXi = 0; //强洗状态,灯亮3 K. \- J/ ]* B' y; o
LED_RuoXi = 1; //弱洗状态灯,灭
" c2 ^, Y3 J5 J }//end if(!flag_SEl_QiangRuo) : c* W4 D# E( ~9 E) }
else
3 F! O. L) G7 i9 t: B" A { LED_QiangXi = 1; //强洗状态,灯亮$ h2 U7 U) G* q; {4 s0 R8 a
LED_RuoXi = 0; //弱洗状态灯,灭
8 a" S+ ?& U) @ X }//end else3 C3 y/ J& h9 b9 r0 t- `- P3 ~
}//end if(!K_SEL_QiangRuo) 2 P& J7 W1 `' @' O- X+ n
}//end if(!K_SEL_QiangRuo) 1
( G; @9 s- Q0 L7 k) [- Z8 n, h7 e0 ^}
/ Q" R! x0 X) y) D, K' G( m) Y/ G/**********************进水程序***********************/& p9 M0 j* q S3 ?
void JinShui(void)
" B: P: T' W- g# I{ PIN_JinShui = 0;) Q7 @; }( |' Z: F1 V
flag_JinShui = 1;
0 S! \4 G" H$ F+ i% `0 E9 ^ TR1 = 0;7 c$ h& s' {8 `7 c% O
Timer0_Init();
3 }4 C% m! x- s( B3 _$ } K T_S = T_JinShui;
/ ^) `; S) N2 V; a; H& ~! C5 O, H2 ~ while(SW_ShuiWei);
" @6 G% L2 }: l PIN_JinShui = 1;
, }+ z/ G4 c! V& c; }) w1 Y3 h flag_JinShui = 0;
# ?, E% _; l- N+ o6 D TR0 = 0;. w9 ?- e- \( C& a" K& X' J
TF0 = 0; - P" b: ?- Y. i# L
}
1 e# ^- O% p3 n5 k# R% e/**********************排水程序***********************/
O# c. R) O5 T8 R2 qvoid PaiShui(void)2 T% B* @$ ^8 x4 ]8 _
{ PIN_PaiShui = 0;
$ W8 d, ?# ^+ n: M- u: s4 T flag_PaiShui = 1;- J; |) D6 J$ |+ x4 N" l, H
TR1 = 0;
, C6 T. A7 ^" y' n& z; }1 L' N8 k Timer0_Init();
$ a- f$ {0 a: W6 ^5 N T_S = T_PaiShui;: I! L. d4 B& B2 J
while(!SW_ShuiWei);
1 Y$ e* U% A- \& t TR0 = 0;0 X+ K& |0 j) y. t' w, R
TF0 = 0;
, _* A; x2 v1 o; H9 x/ k Delay_10ms(500);//延时50s,经验值5000
9 N/ |! S. W- C) z PIN_PaiShui = 1;* @) [9 c0 k7 w" @7 N; n* A }5 S/ G5 r: E
flag_PaiShui = 0; % ?7 o- p j$ h4 j4 V9 _* L
}2 Q7 u) K& P, n" w! }% _
/**********************洗涤程序***********************/
- B. w7 j0 Z8 j# @1 pvoid XiDi(void), M; d F+ z! z) w: O
{ flag_XiDi = 1;
* O' Z. G) l" e- Z( O$ P TR1 = 1;2 L( j. ~2 \7 h( T9 b
Timer0_Init();: d6 x# g, I* s* y4 S
T_S = T_XiDi;
& P% v3 `0 V7 Q2 V& c1 @/ O Motor_Init();! t) _) y( Z5 K1 C) Q$ o! m6 z
while(flag_XiDi);
- X. W; d& B* Y, P1 @9 w+ S TR1 = 0;9 }! j+ k. q" b0 P" q
LED_XiDi = 1;
0 n9 h1 Q7 y( K6 C H}3 t2 @) I3 h1 O0 R3 ~0 M
/**********************漂洗程序***********************/* P8 y7 _# k; G8 k; {
void PiaoXi(uchar t)
7 D9 i3 U4 N, l8 _( _{ flag_PiaoXi = 1;8 I2 L+ L3 x. {3 u
TR1 = 1;
" `; H* C3 V4 M$ j/ R' k- { Timer0_Init();1 r1 _8 q( B& V! N0 G i8 V
T_S = t;
- E# N1 p, L8 ^ Motor_Init();0 _$ e/ k7 t! L4 t- L
while(flag_PiaoXi);
5 Q6 p* y! m. h" t- s" @" N6 m}, Z" O; Q. t( ?* |3 w$ ]0 T
/*********************盖开保护程序********************/
- O1 m( F( n0 m; I/ u( R G8 p! k5 svoid BaoHu_GaiKai(void), s0 c' L4 Q# Z
{ if(SW_AnQuan) //盖开/ ~1 n% L% E3 ], Y$ h) S
{ ZanTing();0 V6 U! K& x4 m8 n8 K/ K# v
LED_TuoShui = 0;
& @: V* \5 r5 c1 o# V; i4 E }//end if. }' Q* e& J u$ z
else; T' ^5 r9 e. [5 B; s
{ JiXu(); //电机不用管,最多5s不转
9 n, _5 b* U4 Q8 ]4 m }//end else& C+ q5 J0 f; Z' s
}
+ x& H' t! t, t8 j& p& @/***********************脱水程序**********************/
" Y8 v2 I I3 jvoid TuoShui(void)
2 G, T, y4 D& u; l{ flag_TuoShui = 1;
, @% y/ T+ }/ E8 M# ? PIN_PaiShui = 0;1 y+ X! ~) e! S" Y3 {5 `: u
TR1 = 1;" A8 }" A( g7 Y/ L% c
Timer0_Init();
/ f4 q6 R/ c7 G. `0 G2 P8 U0 a T_S = T_TuoShui;* O# P# Q# ]! n8 l" O
Motor_Init();' d$ T" f# A. \$ y$ @7 [
while(flag_TuoShui)8 b+ E" ~) Q: X
{ BaoHu_GaiKai(); 8 L, b, }' F0 a1 c2 G8 h G2 v, t
}//end while. R# m% W- b7 ~7 s/ @5 R0 {
TR1 = 0;
. \8 U1 h6 Q8 c" F8 F- n+ Q) O LED_TuoShui = 1; //而出水阀一直开着3 R! k( u+ \3 v/ e7 v% U
}. p7 e8 c4 p: F" @* }4 D
/********************标准洗衣程序*********************/; L4 r( x# |" p8 _- n
void Programme_BiaoZhun(void)4 j2 D- H# K; R8 J
{ LED_XiDi = 0; //洗涤状态灯
$ {, r! C9 T5 p+ g2 ?4 }! E+ n LED_PiaoXi = 0; //漂洗状态灯
/ w- S4 b! u' d* H$ `1 y LED_TuoShui = 0; //脱水状态灯2 d2 q" x3 S) Z+ q
JinShui();3 s/ Y9 J; {7 F ~1 y" ~" k. q
XiDi();) C- @# ^. s0 {( X! k- ^. T
PaiShui(); ( y+ E5 n+ d* R" s
JinShui();& m7 p% e% U& {8 m, o/ R V
PiaoXi(T_PiaoXi_1);//4min*60s//4*60
' n+ N9 J% W4 l9 Q, X2 l, ?$ J* o PaiShui();( H% ?0 r8 z5 J
JinShui();
- u2 l, q, m/ a5 _ PiaoXi(T_PiaoXi_2);//2min*60s//2*60- ^4 K1 Z. J! Y- u5 e/ H
Programme_PaiShui();3 d% s5 L1 `# f. J
}
% ?% k' s/ l8 j+ q7 h/********************经济洗衣程序*********************/% C! l. ]" W+ u2 p$ ?
void Programme_JingJi(void)1 D2 p! G- @4 k6 Y4 U4 D
{ TR1 = 0;' n6 N' ^% k7 d7 D4 w; Q. j
LED_XiDi = 0; //洗涤状态灯0 b$ i( s8 q' d
LED_PiaoXi = 0; //漂洗状态灯9 n7 ~" }* _1 O) h' Q
LED_TuoShui = 0; //脱水状态灯
4 R; O! j. H8 P. Y$ G" M+ |. c. a JinShui();- G5 m4 c- S* j7 D( s
XiDi();
0 x' H. ~9 a7 ^6 h0 j PaiShui();
( V' _4 k" @! X& B2 M) J JinShui();3 H! m( e7 v- `- X {1 i# m
PiaoXi(T_PiaoXi_1);//4min*60s
% k. r. z @8 s7 ~; v) z Programme_PaiShui();
# S0 H) p2 x/ k) p, p}
: n8 H/ k( @ b y8 J! \- x/********************单独洗衣程序*********************/; F$ q* l3 O6 V3 J* V5 D6 G* {
void Programme_DanDu(void)
~. g% R5 g3 ~8 v, V6 j{ LED_XiDi = 0; //洗涤状态灯
E. u& W- n' N- [0 _2 c* I LED_PiaoXi = 1; //漂洗状态灯4 d% G1 P$ Q. y5 _ `$ o
LED_TuoShui = 1; //脱水状态灯
) h3 O& W5 U5 ]% e- l1 M JinShui();
3 t$ ^# f) U' V* W5 [6 u } XiDi();/ `1 a* M# y& x2 E7 j- y& n" i
}
$ h9 A5 [: V; s+ f/********************排水洗衣程序*********************/
|) e6 [2 b; zvoid Programme_PaiShui(void)( P. C" |1 a; a* L3 R9 Y
{ LED_XiDi = 1; //洗涤状态灯, R& k6 Z$ M: E( o0 C- ]
LED_PiaoXi = 1; //漂洗状态灯# {& [: ~- t8 }7 d
LED_TuoShui = 0; //脱水状态灯 j% F$ m6 t2 [0 t' q
PaiShui();
i0 {) B1 `* B- x8 o: b6 [8 f+ P; {" P TuoShui();9 E% G2 @: |4 g1 b2 ?' X
}
: I5 a, I( @- [' s) n8 q/************************主程序************************/
5 Y9 s% r/ | p0 y; N+ b& c) ^void main() 9 e9 R4 r( P% I6 U5 [' n; m/ F8 G
{
( h& W: J1 _' S1 | Pin_Init(); //管脚初始化
3 b: w- S3 t, n! V; E4 |9 f ExInt_Init(); //外中断初始化$ d0 R# A! m6 F2 K3 n3 h
Timer1_Init();
i: v. \- N3 C7 z8 ~& q; P ET0 = 1;
1 S! f: @: `3 S: E ET1 = 1;
9 e4 b# g0 P9 u" T Enable(); //开总中断
( K' \' P$ e G/ j1 W9 L while(1)
" [5 t1 o2 Z3 n% m { if(!flag_Run) //运行前按键才有效
, f# E* R( Q9 N1 l; Y* v; } { SEL_ChengXU(); //程序选择程序 8 O! n7 n& f2 P# F% x; i6 D* Q. `
SEL_QiangRuo(); //强弱选择程序 . n( M- Z9 p3 a T4 l: G/ r9 F
}//end if(!flag_Run)
- t; x+ G6 c: m9 l7 N, \3 ^ if(flag_Run)//用else不,按启动键后,有时没反映????//
; W" N) m/ O/ A: I( S { PIN_PaiShui = 1; //关排水阀+ X, k. j2 \, ~: v/ [. ~
switch(flag_SEL_ChengXu)
# P3 ?' c) F1 w8 D" d: u8 b; ?" S { case BIAOZHUN : Programme_BiaoZhun(); //标准洗衣程序
b# L: l C! x& C7 z; } break;. H! M3 g2 T, e
case JINGJI : Programme_JingJi(); //经济洗衣程序 2 W* F, y' v! v8 b: G
break;
! h0 k- E% j* g1 z4 i case DANDU : Programme_DanDu(); //单独洗衣程序
" c$ D5 O Z. v% k" b break;( V+ G: [ n* Y1 T: ?9 b
case PAISHUI : Programme_PaiShui(); //排水洗衣程序 # v' r8 r: y/ h9 e1 K
break;" p/ z7 C6 W# |2 L
default : break;2 T1 _ V; b5 o% b
}//end switch
/ z0 ?* ]+ A3 T, R3 |1 b- @1 E }//end esle
5 ~% ~; c% _5 m$ H n1 S flag_Run = 0;
r' {; V; r$ N5 T+ [) ] }//end while
. r7 ]$ n; g; [}//end main- K/ J$ X0 t+ t7 }2 R/ Z
r7 E( ~8 W) m
3 R9 s+ R- D& I. h8 x. R
|
|