单片机控制洗衣机C程序设计
#include
#define waterin P1_6
#define waterout P1_5
#define swim P1_7
bit flag;
char Count,t,waterinflag,wateroutflag,swimflag; // 用于中断程序的计数
unsigned char second;
void Timeinit(void)
{
//秒表初始化
Count=0; t=0; second=0; flag=0;
// 开定时器1,设定为工作方式2, 让定时中断时自动加载定时的初值
IE=0x8a; //允许中断,选中T0,T1中断
TMOD=0x21; //定时器0,使用TR0启动方式,选中工作方式1,定时器1,使用TR1启动方式,工作方式2
TH1=0x06; //设置定时初值 256-250=6(250us,要实现10ms就要40次)
TL1=0x06;
TR1=1;
}
//用T1定时的秒表中断程序,工作方式2
void Miao(void) interrupt 3
{
Count++;
if(Count==40){
Count=0;
t++; //百分秒
if(t==100){
flag=1;
t=0;
if(second==10) second=0;
else second++;
}
}
}
void Initcover() { //盖子的中断程序
EA=1;
ET1=0;
EX1=1;
}
void coverinterrupt() interrupt 2 {
waterin=1;
waterout=1;
swim=1;
while (P3_3==0) ;
waterin=waterinflag;
waterout=wateroutflag;
swim=swimflag;
}
main() { //洗衣机工作过程
int i=0;
Initcover();
waterout=1;
wateroutflag=1;
swim=1;
swimflag=1;
P3_2=1;
if (P1_0==1) {
waterin=0;
waterinflag=0;
while(P3_2==1) {
waterin=1;
waterinflag=1;
for (i=0;i<10;i++) {
Timeinit();
while (second!=10) {
swim=0;
swimflag=0;
if(flag) {
flag=0;
P1=~(second*2);
waterin=waterinflag;
waterout=wateroutflag;
swim=swimflag;
}
}
P1=0xff;
waterin=waterinflag;
waterout=wateroutflag;
swim=swimflag;
Timeinit();
while (second!=3) {
swim=1;
swimflag=1;
if(flag) {
flag=0;
P1=~(second*2);
waterin=waterinflag;
waterout=wateroutflag;
swim=swimflag;
}
}
}
Timeinit();
while (second!=10 ) {
waterout=0;
wateroutflag=0;
if(flag) {
flag=0;
P1=~(second*2);
waterin=waterinflag;
waterout=wateroutflag;
swim=swimflag;
}
}
waterout=1;
wateroutflag=1;
}
}
}}
【单片机控制洗衣机C程序设计】
推荐阅读
- 利用89C51单片机的P1口控制8个发光二极管LED编程
- 第二节:PIC16C5X系列单片机型号介绍及引脚介绍
- 将TNY279 电源芯片作为开关电源的控制芯片,效果如何?
- 什么是单片机的寻址_举例介绍
- 上位机控制单片机LED
- PIC单片机滚动码解码C程序
- 海尔洗衣机怎么样 一起看看品牌如何
- 单片机I/O口管脚内部结构
- 51单片机_STC89C52RC光电耦合控制继电器实验
- 关于单片机串口发送和接收的问题