硬件环境:STC89C52
软件环境:Keil
eeprom.h文件
#include
#include "config.h"
#ifdef pcb
sbit scl=P2^7;
sbit sda=P2^6;
#else
sbit scl=P2^0;
sbit sda=P2^7;
#endif
void delay()
{;;}
/*
void delay1ms(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
*/
//开始
void start()
{
sda=1;
delay();
scl=1; //在scl高电平期间,sda产生一个下降沿启动信号
delay();
delay();
sda=0;
}
//停止
void stop()
{
sda=0;
delay();
scl=1; //在scl高电平期间,sda产生一个上升沿停止信号
delay();
sda=1;
delay();
}
//应答
void respons() //scl高电平期间,sda被设备拉为低电平表示应答
{
uchar i;
scl=1;
delay();
while((sda==1)&&(i<250))i++; //表示若在一段时间内主器件没收到从器件的应答,则主器件默认为收到应答
scl=0;
delay();
}
///****************************向指定地址写一个字节函数模块***************///
void write_byte(uchar dat) //写字节
{
uchar i,temp;
temp=dat;
for(i=0;i<8;i++)
{
temp=temp<<1; //表示将temp左移一位,将最高位移入psw寄存的CY位中
scl=0;
delay();
sda=CY; //然后把CY赋给sda进而在scl的控制下发送出去
delay();
scl=1; //IIC总线在数据传送时,时钟信号为高电平期间,数据线上的数据必须保持稳定,只有在时钟信号为低电平期间,数据线上的高电平或低电平才允许变化
delay();
}
scl=0;
delay();
sda=1;
delay();
}
///*******************************读一个字节函数模块********************///
uchar read_byte() //读字节
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda; //把k左移一位后与sda进行或运算,依次把八个独立的位放入一个字节中来完成接收
scl=0;
delay();
}
return k;
}
///*****************************向指定地址写数据函数模块*******************///
void write_add(uchar address,uchar dat)
{
start();
write_byte(0xa0);
respons(); //每写一字节后都调用一次response()函数,检测应答信号
write_byte(address);
respons();
write_byte(dat);
respons();
stop();
}
///*****************************从指定地址读数据函数模块******************///
uchar read_add(uchar address)
{
uchar dat;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
dat=read_byte();
stop();
return dat;
}
yj.h文件
#include
#include
#include "config.h"
//#define picture
#define LCD_DATA P0 //数据口
#ifdef pcb
sbit RS = P3^5; //并行的指令/数据选择信号, H数据, L命令
sbit E = P3^4; //并行使能端, H有效, L无效
sbit PSB = P3^6; //并/串接口选择, H并,L串
sbit RET = P3^7; //复位, L有效
#else
sbit RS = P2^4; //并行的指令/数据选择信号, H数据, L命令
sbit RW = P2^5; //并行读写选择信号, H读, L写
sbit E = P2^6; //并行使能端, H有效, L无效
sbit PSB = P2^1; //并/串接口选择, H并,L串
sbit RET = P2^3; //复位, L有效
#endif
//#include "delay.h"
#define uchar unsigned char
#define uint unsigned int
///****************************延时2us函数模块*****************************///
void delay2us()
{
nop_();_nop_();
}
///****************************延时nms函数模块*****************************///
void delay_nms(unsigned int a)
{
unsigned int i, j;
for(i = a; i > 0; i--)
for(j = 100; j > 0; j--);
}
///****************************端口定义************************************///
//uchar code datas1[] = {"伊斯曼其洗衣公司"};
//uchar code datas2[] = {"黄河入海流."};
//uchar code datas3[] = {"欲穷千里目,"};
//uchar code datas4[] = {"更上一层楼."};
///**********************检测LCD是否处于忙状态, 若忙返回1, 空闲返回0*******///
///****************************等待LCD到空闲*****************************///
void wait()
{
// while(checkBusy());
}
//写命令
void writeCmd(uchar cmd)
{
wait();
RS = 0;
// RW = 0;
E = 0;
delay2us();
LCD_DATA = cmd;
delay2us();
E = 1;
delay2us();
E = 0;
}
//写数据
void writeData(uchar dat)
{
wait();
RS = 1;
// RW = 0;
E = 0;
delay2us();
LCD_DATA = dat;
delay2us();
E = 1;
delay2us();
E = 0;
}
//初始化LCD
void yj_init(uchar x)
{
PSB = 1; //并口方式
if(x==1)
writeCmd(0x30); //基本指令, 扩充指令为34H
delay_nms(10);
writeCmd(0x0c); //显示开, 关光标
delay_nms(10);
writeCmd(0x01); //清屏
delay_nms(10);
}
void setPosition(uchar x, uchar y)
{
uchar p;
switch(x%4)
{
case 0: p = 0x80; break; //第一行开始地址
case 1: p = 0x90; break; //第二行
case 2: p = 0x88; break; //第三行
case 3: p = 0x98; break; //第四行
}
p += y;
writeCmd(p);
}
void writeString(uchar * str)
{
uchar i = 0;
while(str[i] != '\0')
{
writeData(str[i++]);
}
}
///****************************开机欢迎函数模块*****************************///
void yj_display_huanying()
{
setPosition(0, 0);
writeString("欢迎使用");
setPosition(1, 0);
writeString("伊斯曼其洗衣公司");
setPosition(2, 0);
writeString("洗衣控制系统");
}
void yj_mode_select()
{
writeCmd(0x01); //清屏
delay_nms(10);
setPosition(0, 0);
writeString("请选择工作模式:");
setPosition(1, 0);
writeString("1 洗涤程序选择");
setPosition(2, 0);
writeString("2 手动模式");
setPosition(3, 0);
writeString("3 洗涤时间设置");
// delay_nms(1000);
}
#ifdef picture
/******************************************************************/
/* 液晶初始化-图形 */
/******************************************************************/
void init_pic(void) //LCD显示图片(扩展)初始化程序
{
delay_nms(40); //大于40MS的延时程序
PSB=1; //设置为8BIT并口工作模式
delay_nms(1); //延时
//RET=0; //复位
delay_nms(80); //延时wwwwwwwwwwwwwwwwwwwwwwwww
RET=1; //复位置高
delay_nms(10);
writeCmd(0x36); //Extended Function Set RE=1: extended instruction
delay_nms(100); //大于100uS的延时程序
writeCmd(0x36); //Extended Function Set:RE=1: extended instruction set
delay_nms(37); ////大于37uS的延时程序
writeCmd(0x3E); //EXFUNCTION(DL=8BITS,RE=1,G=1)
delay_nms(100); //大于100uS的延时程序
writeCmd(0x01); //CLEAR SCREEN
delay_nms(100); //大于100uS的延时程序
}
///*************************astman字模*****************************///
uchar code pic_start[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x00,0x00,0x01,0xFF,
0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x00,0x3E,0x00,0x00,0x00,0xFF,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7E,0x00,0x63,0x00,0x00,0x70,0x03,
0x00,0x04,0x00,0xC0,0x01,0x00,0x07,0xC0,
0x00,0xE1,0x00,0xC1,0x80,0x00,0xF8,0x06,
0x00,0x0E,0x61,0xE0,0x07,0x81,0xCF,0xE0,
0x01,0xC0,0x01,0x81,0xC0,0x00,0xF8,0x06,
0x00,0x1E,0xF3,0xE0,0x0F,0xC3,0xFC,0xE0,
0x01,0x80,0x83,0x80,0xC0,0x00,0xE0,0x06,
0x00,0x17,0xDE,0x60,0x18,0xC2,0x70,0x60,
0x03,0x00,0x83,0x00,0x40,0x00,0xC0,0x04,
0x00,0x17,0x8C,0x60,0x30,0x60,0x60,0x70,
0x06,0x00,0x83,0x00,0xC0,0x00,0xC0,0x0C,
0x00,0x27,0x0C,0x60,0x70,0x20,0x60,0x30,
0x06,0x00,0x87,0x00,0x80,0x01,0xC0,0x0C,
0x00,0x27,0x0C,0x60,0x60,0x30,0x60,0x30,
0x0C,0x01,0x07,0x01,0x80,0x03,0x80,0x08,
0x00,0x27,0x0C,0x60,0xC0,0x30,0x60,0x30,
0x0C,0x03,0x06,0x01,0x80,0x03,0x80,0x18,
0x00,0x47,0x0C,0x41,0xC0,0x30,0x60,0x30,
0x18,0x06,0x0E,0x01,0x80,0x05,0x80,0x10,
0x00,0x46,0x18,0xC1,0xC0,0x30,0x60,0x30,
0x18,0x0C,0x0C,0x03,0x80,0x09,0x00,0x30,
0x00,0x0E,0x18,0xC1,0x80,0x70,0xE0,0x30,
0x18,0x18,0x0C,0x03,0x00,0x03,0x00,0x30,
0x00,0x8E,0x18,0xC1,0x80,0x60,0xC0,0x30,
0x18,0x30,0x18,0x03,0x00,0x03,0x00,0x70,
0x00,0x8C,0x10,0xC3,0x80,0x60,0xC0,0x30,
0x18,0x60,0x18,0x03,0x00,0x21,0x80,0xB0,
0x00,0x9C,0x30,0xC3,0x00,0x42,0xC0,0x60,
0x18,0xC0,0x18,0x03,0x00,0x41,0xC1,0xA0,
0x01,0x1C,0x31,0xC3,0x00,0xC0,0xC0,0x60,
0x19,0x80,0x38,0x03,0x00,0x00,0xC3,0x20,
0x01,0x1C,0x31,0x86,0x00,0x84,0xC0,0x60,
0x1F,0x00,0xB8,0x07,0x00,0x00,0x86,0x60,
0x02,0x18,0x31,0x86,0x01,0x80,0xC0,0x60,
0x1E,0x00,0x30,0x07,0x01,0x01,0x8C,0x60,
0x00,0x18,0x71,0x86,0x01,0x81,0xC0,0x60,
0x3C,0x01,0x30,0x0F,0x00,0x01,0xB8,0x60,
0x04,0x38,0x61,0x8E,0x03,0x89,0x80,0x60,
0x9C,0x02,0x30,0x0F,0x0C,0x41,0xF0,0x60,
0x08,0x38,0x61,0x87,0x03,0x89,0x80,0x60,
0x07,0xF8,0x07,0xC0,0x00,0x00,0x00,0x0F,
0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
///****************************图形显示子函数*****************************///
void pic_dis(unsigned char code *adder)
{
int i,j;
//*******显示上半屏内容设置
for(i=0;i<32;i++) //
{
writeCmd((0x80 + i)); //SET 垂直地址 VERTICAL ADD
writeCmd(0x80); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
writeData(*adder);
adder++;
// delay_nms(3);
}
}
//*******显示下半屏内容设置
for(i=0;i<32;i++) //
{
writeCmd((0x80 + i)); //SET 垂直地址 VERTICAL ADD
writeCmd(0x88); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
writeData(*adder);
adder++;
//delay_nms(3);
}
}
}
#endif
timer0.h文件
#include
#define uchar unsigned char
#define uint unsigned int
///*********************定时器0初始化****************************///
void timer0_init()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
//TR0=1;//定时器0开始计数
}
config.h文件
#define pcb
//#define debug
//#define picture
//#define iic_init
#define piaoxi_only_jinyou
main.c文件
#include "yj.h"
#include "timer0.h"
#include "eeprom.h"
#include
#include
#define uchar unsigned char
#define uint unsigned int
void eeprom_init();
//------------------------------门开关指示灯---------------------------//
#define door_open 1
#define door_close 0
//------------------------------蜂鸣器鸣叫信号-------------------------//
#define ring 0
#define not_ring 1
//按键是否按下
#define on 0
#define off 1
//------------------------------衣服干净程度----------------------------//
#define zang1 0
#define zang2 1
#define zang3 2
#define zang4 3
#define zang5 4
//------------------------------不同的模式-----------------------------//
#define zz1 0
#define zz2 1
#define zz3 2
#define zz4 3
#define zz5 4
#define mode_idle 0
#define mode_zidong 1
//手动模式
#define mode_shoudong 2
//设定高低速时间模式
#define mode_set_time 3
//矩阵键盘端口定义
#define mat_key P1
//进油时间存储地址设定
/*
const uchar jinyou_time_add[5] ={1,2,3,4,5};
const uchar paiyou_time_add[5] ={11,12,13,14,15};
const uchar xidi_time_add[5] ={21,22,23,24,25};
const uchar tuoyou_time_add[5] ={31,32,33,34,35};
const uchar piaoxi_time_add[5] ={41,42,43,44,45};
*/
sbit int0_out =P3^2;
sbit P17 =P1^7;
//------------------------------蜂鸣器端口定义---------------------------------//
sbit buffer =P3^3;
sbit led_door =P2^0;
//-----------------------------各继电器定义(开始)------------------------------//
#ifdef pcb
sbit jdq_slow_fast = P2^1;//低速高速继电器
sbit jdq_jinyou = P2^4;//进油继电器
sbit jdq_paiyou = P2^5;//排油继电器
sbit jdq_zhengfan1 = P2^2;//控制电机反转继电器
sbit jdq_zhengfan2 = P2^3;//控制电机正转继电器
#else
sbit jdq_xidi = P1^0;//洗涤启动继电器
sbit jdq_slow_fast = P1^3;//低速高速继电器
sbit jdq_jinyou = P1^4;//进油继电器
sbit jdq_paiyou = P1^5;//排油继电器
sbit jdq_zhengfan1 = P1^6;//控制电机正反转继电器1
sbit jdq_zhengfan2 = P1^7;//控制电机正反转继电器2
#endif
//-----------------------------各继电器定义(结束)------------------------------//
//-------------------------设定模式下存储器相关操作-------------------------
uchar cishu =0;
uchar cishu_1 =0;
uchar set_time_save_add[25]=
{
0,1,2,3,4,
10,11,12,13,14,
20,21,22,23,24,
30,31,32,33,34,
40,41,42,43,44
};
uchar temp_time_set=0;
uchar temp_dis[2]={" "};
uchar temp_dis1[2]={" "};
bit flag_key_push=off;
bit flag_xianzhi=1;//默认的时候没有限制,即洗,漂,脱之间切换有延时
//-----------------------------电机转速快慢定义---------------------------//
#define motor_slow 4
#define motor_fast 5
//-----------------------------电机工作状态定义---------------------------//
#define motor_tingzhi 6
#define motor_zfzhuan1 7
#define motor_zfzhuan2 8
#define bihe 1
#define duankai 0
//-----------------------------手动模式下按键标志位-----------------------//
//手动模式下进油键按下标志位
bit flag_key_shoudong_jinyou=0;
//手动模式下排油键按下标志位
bit flag_key_shoudong_paiyou=0;
//手动模式下脱油键按下标志位
#define flag_key_shoudong_tuoyou 0
//手动模式下洗涤键按下标志位
#define flag_key_shoudong_xidi 1
//手动模式下洗涤键按下标志位
#define flag_key_shoudong_piaoxi 2
#define nothing 3
uchar flag_x_p_t=nothing;
//uchar jinyou_sec=0;
//uchar jinyou_min=0;
//-----------------------------自动模式下相关定义------------------------//
uchar sec=0;
uchar min=0;
uchar second_start=0;
uchar temp_x=0;
uchar auto_dis1[]={" "};
uchar auto_dis2[]={" "};
bit flag_jia_jian=0;
volatile uchar temp_mode_zang;//将要运行程序代号锁存器
//-----------------------------系统和电机状态标志------------------------//
//系统状态(自动-手动-设置)标志量
uchar systerm_state=mode_idle;
//衣服干净度
volatile uchar mode_zang=0;
//干什么
//char do_what=0;
//电机状态(正转-停止-反转)标志量
uchar state_motor=motor_tingzhi;
//电机速度模式(高速-低速)标志量
uchar v_motor=motor_slow;
bit flag_hand=0;
bit flag_1 =0;
bit flag_2 =0;
bit flag_3 =0;
bit flag_4 =0;
bit flag_5 =0;
bit flag_6 =0;
bit flag_7 =0;//
bit flag_8 =0;
bit flag_9 =0;
bit flag_10=0;
bit flag_11=0;
bit flag_12=0;
bit flag_13=0;
bit flag_14=0;
bit flag_15=0;
uchar cnt=20;
uchar code table[]={"0123456789 "};
void jidianqi_init()//继电器初始化,关闭所有继电器
{
//jdq_xidi =duankai;
jdq_slow_fast =duankai;
jdq_jinyou =duankai;
jdq_paiyou =duankai;
jdq_zhengfan1 =duankai;
jdq_zhengfan2 =duankai;
}
//////////////////////////电机运行状态////////////////////////////////////
void zhengzhuan()
{
////jdq_xidi =bihe;
//jdq_slow_fast=duankai;//低速模式
// jdq_paiyou = duankai;
// jdq_jinyou = duankai;
jdq_zhengfan1=duankai;
jdq_zhengfan2=bihe;//正转
}
void fanzhuan()
{
//jdq_slow_fast=duankai;//低速模式
// jdq_paiyou = duankai;
// jdq_jinyou = duankai;
jdq_zhengfan1=bihe;//反转
jdq_zhengfan2=duankai;
}
void tingzhi()
{
//jdq_slow_fast=duankai;
//jdq_paiyou = duankai;
//jdq_jinyou = duankai;
jdq_zhengfan1=duankai;//不转
jdq_zhengfan2=duankai;
}
void motor_run(uchar x,uchar y,uchar z)
{
if(z==1)
{
if(sec<=24)
{
zhengzhuan();
setPosition(x, y);
writeString("顺时针");
}
else if(sec<=29)
{
tingzhi();
setPosition(x, y);
writeString("停止 ");
tingzhi();
}
else if(sec<=54)
{
fanzhuan();
setPosition(x, y);
writeString("逆时针");
}
else if(sec<=59)
{
tingzhi();
setPosition(x, y);
writeString("停止 ");
tingzhi();
}
}
}
//////////////////////////电机运行状态(END)/////////////////////////////////
/************************************************************************/
/*****************************程序设置模式(开始)*************************/
void dis_number()
{
//时间设置显示
temp_time_set=read_add(set_time_save_add[mode_zang]);
temp_dis[0]=table[temp_time_set/10];
if(temp_time_set/10==0)
temp_dis[0]=table[10];
temp_dis[1]=table[temp_time_set%10];
setPosition(2, 4);
writeString(temp_dis);
setPosition(2, 5);
writeString(" ");
//编号显示
setPosition(3, 3);
temp_dis1[0]=table[mode_zang/10];
temp_dis1[1]=table[mode_zang%10];
writeString(temp_dis1);
setPosition(3, 4);
writeString(" ");
}
void time_set_init()
{
writeCmd(0x01); //清屏
delay_nms(10);
setPosition(0, 0);
writeString("洗涤程序选择:");
setPosition(2, 2);
writeString("时间");
setPosition(2, 7);
writeString("分");
setPosition(3, 0);
writeString("编号:");
}
void time_set()
{
if(flag_1==0)
{
flag_1=1;
writeCmd(0x01); //清屏
delay_nms(10);
setPosition(0, 0);
writeString("洗涤程序选择:");
setPosition(2, 2);
writeString("时间");
setPosition(2, 7);
writeString("分");
setPosition(3, 0);
writeString("编号:");
dis_number();
}
if(flag_key_push==on)
{
flag_key_push=off;
switch(mode_zang/5)
{
case zang1:
{
setPosition(1, 0);
writeString("脏1:");
}
break;
case zang2:
{
setPosition(1, 0);
writeString("脏2:");
}
break;
case zang3:
{
setPosition(1, 0);
writeString("脏3:");
}
break;
case zang4:
{
setPosition(1, 0);
writeString("脏4:");
}
break;
case zang5:
{
setPosition(1, 0);
writeString("脏5:");
}
break;
}
switch(mode_zang%5)
{
case zz1:
{
setPosition(2, 0);
writeString("进油");
}
break;
case zz2:
{
setPosition(2, 0);
writeString("洗涤");
}
break;
case zz3:
{
setPosition(2, 0);
writeString("排油");
}
break;
case zz4:
{
setPosition(2, 0);
writeString("漂洗");
}
break;
case zz5:
{
setPosition(2, 0);
writeString("脱油");
}
break;
}
dis_number();
}
}
/************************************************************************/
//////////////////////////////程序设置模式(END)///////////////////////////
/************************************************************************/
/*****************************自动模式(开始)*****************************/
uchar jinyou_max;
uchar paiyou_max;
uchar xidi_max;
uchar piaoxi_max;
uchar tuoyou_max;
uchar bianhao_temp;//衣服干净程度寄存器
//每次切换到自动模式下面都要进行初始化
void zi_dong_mode_init()
{
jidianqi_init();
bianhao_temp=(set_time_save_add[mode_zang]/5)*5;
jinyou_max=read_add(bianhao_temp);
delay_nms(20);
xidi_max=read_add((bianhao_temp+1));
delay_nms(20);
paiyou_max=read_add((bianhao_temp+2));
delay_nms(20);
piaoxi_max=read_add((bianhao_temp+3));
delay_nms(20);
tuoyou_max=read_add((bianhao_temp+4));
delay_nms(20);
writeCmd(0x01); //清屏
//delay_nms(10);
jidianqi_init();
setPosition(0, 0);
writeString("自动模式");
sec=0;
min=0;
sprintf(auto_dis1," ");
sprintf(auto_dis2," ");
EA=1;
ET0=1;
TR0=1;
}
void zidong_dis(uchar h)
{
auto_dis1[0]=table[min/10];
auto_dis1[1]=table[min%10];
auto_dis2[0]=table[sec/10];
auto_dis2[1]=table[sec%10];
setPosition(h, 4); //
writeString(auto_dis1);
setPosition(h, 6);
writeString(auto_dis2);
}
void auto_jinyou() //进油
{
jdq_jinyou =bihe; //进油
jdq_paiyou =duankai;
jdq_zhengfan1 =duankai;
jdq_zhengfan2 =duankai;
jdq_slow_fast =duankai;
writeString("进油");
}
void auto_paiyou()
{
jdq_jinyou =duankai;
jdq_paiyou =bihe; //排油
jdq_zhengfan1 =duankai;
jdq_zhengfan2 =duankai;
jdq_slow_fast =duankai;
writeString("排油 ");
}
void auto_xidi() //洗涤
{
jdq_jinyou =duankai;
jdq_paiyou =duankai;
jdq_slow_fast=duankai;//低速
writeString("洗涤");
motor_run(2,5,1);
}
void auto_piaoxi() //漂洗
{
#ifdef piaoxi_only_jinyou//漂洗的时候只进油
jdq_jinyou =bihe;
jdq_paiyou =duankai;
jdq_slow_fast=duankai;//低速
#else //漂洗的时候进一分钟的油排一分钟的油
if((min/2)*2==min)
{
jdq_slow_fast=duankai;//低速
jdq_jinyou =bihe;
jdq_paiyou =duankai;
}
else
{
jdq_slow_fast=duankai;//低速
jdq_jinyou =duankai;
jdq_paiyou =bihe;
}
#endif
writeString("漂洗");
motor_run(2,5,1);
}
void auto_tuoyou() //脱油
{
jdq_jinyou =duankai;
jdq_paiyou=bihe; //脱油的时候必须排油
jdq_zhengfan1 =duankai;
jdq_zhengfan2 =bihe;//顺时针转动
jdq_slow_fast =bihe;//高速
writeString("脱油");
}
void auto_run()
{
if(flag_13==0)
{
//flag_2=1;
flag_13=1;
writeCmd(0x01); //清屏
delay_nms(100);
/*
bianhao_temp=(temp_mode_zang/10)*10;
jinyou_max=read_add(bianhao_temp);
xidi_max=read_add(bianhao_temp+1);
paiyou_max=read_add(bianhao_temp+2);
piaoxi_max=read_add(bianhao_temp+3);
tuoyou_max=read_add(bianhao_temp+4);
sec=0;
min=0;
sprintf(auto_dis1," ");
sprintf(auto_dis2," ");
EA=1;
ET0=1;
TR0=1;
*/
}
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>=59)
{
sec=0;
min++;
if(min>=(jinyou_max+xidi_max+paiyou_max+tuoyou_max+piaoxi_max+paiyou_max+tuoyou_max))
{
sec=0;
ET0=0;
TR0=0;
}
}
}
zidong_dis(3);
setPosition(2, 0);
if(min {
auto_jinyou();
}
else if(min<(jinyou_max+xidi_max))//洗涤
{
auto_xidi();
}
else if(min<(jinyou_max+xidi_max+paiyou_max))//排油
{
auto_paiyou();
}
else if(min<(jinyou_max+xidi_max+paiyou_max+tuoyou_max))//脱油
{
auto_tuoyou();
}
else if(min<(jinyou_max+xidi_max+paiyou_max+tuoyou_max+piaoxi_max))//漂洗
{
auto_piaoxi();
}
else if(min<(jinyou_max+xidi_max+paiyou_max+tuoyou_max+piaoxi_max+paiyou_max))//排油
{
auto_paiyou();
}
else if(min<(jinyou_max+xidi_max+paiyou_max+tuoyou_max+piaoxi_max+paiyou_max+tuoyou_max))//脱油
{
auto_tuoyou();
}
else if(min>=(jinyou_max+xidi_max+paiyou_max+tuoyou_max+piaoxi_max+paiyou_max+tuoyou_max))//自动洗衣完成
{
jidianqi_init();
ET0=0;
TR0=0;
sec=0;
setPosition(2, 0);
writeString("自动洗衣完成! ");
//systerm_state=mode_idle;
buffer=ring;//自动洗衣完成后鸣叫提示用户
sprintf(auto_dis1," ");
sprintf(auto_dis2," ");
}
switch(mode_zang/5)
{
case zang1:
{
setPosition(1, 0);
writeString("脏1:");
}
break;
case zang2:
{
setPosition(1, 0);
writeString("脏2:");
}
break;
case zang3:
{
setPosition(1, 0);
writeString("脏3:");
}
break;
case zang4:
{
setPosition(1, 0);
writeString("脏4:");
}
break;
case zang5:
{
setPosition(1, 0);
writeString("脏5:");
}
break;
}
if(flag_key_push==on)
{
//flag_2=1;
flag_key_push=off;
writeCmd(0x01); //清屏
delay_nms(10);
setPosition(0, 0);
writeString("自动模式");
setPosition(3, 0);
writeString("已运行:");
setPosition(3, 5);
writeString("分");
setPosition(3, 7);
writeString("秒");
}
}
/************************************************************************/
//////////////////////////////自动模式(END)///////////////////////////////
/************************************************************************/
/*****************************手动模式(开始)*****************************/
////////////////////////////手动模式下时间显示////////////////////////////
void shoudong_dis(uchar h)
{
if(ET0==0)
{
temp_dis[0] =table[10];
temp_dis[1] =table[10];
temp_dis1[0]=table[10];
temp_dis1[1]=table[10];
}
else
{
temp_dis[0]=table[min/10];
temp_dis[1]=table[min%10];
temp_dis1[0]=table[sec/10];
temp_dis1[1]=table[sec%10];
setPosition(h, 3); //
writeString(temp_dis);
setPosition(h, 5);
writeString(temp_dis1);
}
}
void shou_dong_mode_init()
{
ET0=0;
TR0=0;
sec=0;
min=0;
flag_key_shoudong_jinyou=0;
flag_key_shoudong_paiyou=0;
flag_x_p_t=nothing;
delay_nms(10);
jidianqi_init();
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
writeCmd(0x01); //清屏
setPosition(0, 0);
writeString("手动模式");
}
void shou_dong_mode()
{
if(flag_hand==0) //检测到进油\排油\脱油之一后如下
{
// flag_5=0;
//flag_6=0;
flag_hand=1;
writeCmd(0x01); //清屏
delay_nms(10);
jidianqi_init(); //继电器初始化
setPosition(0, 0);
writeString("手动模式");
setPosition(1, 3);
writeString(" ");
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
//EA=0;
ET0=0;
TR0=0;
sec=0;
min=0;
jidianqi_init();
}
////////////////////////////////////////////////////进油,排油,脱油
if((flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou)) //进油模式
{
//flag_5=1;
flag_key_shoudong_paiyou=0; //进油模式下不可排油
flag_x_p_t=nothing; //进油模式下不可脱油
if(flag_5==0)
{
flag_5=1;
//setPosition(2, 0);
//writeString("时间:");
setPosition(1, 4);
writeString("分");
setPosition(1, 6);
writeString("秒");
EA=1;
ET0=1;
TR0=1;
sec=0;
min=0;
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
setPosition(1, 0);
writeString("进油");
}
jdq_jinyou= bihe;
jdq_paiyou= duankai;
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>59)
{
sec=0;
min++;
}
if(min>99)
{
min=0;
}
}
shoudong_dis(1);
}
else if((flag_key_shoudong_paiyou)&&(!flag_key_shoudong_jinyou)) //排油模式
{
//flag_5=1;
flag_key_shoudong_jinyou=0; //排油模式下不可进油
flag_x_p_t=nothing; //排油模式下不可脱油
if(flag_6==0)
{
flag_6=1;
setPosition(1, 0);
writeString("排油");
//setPosition(2, 0);
//writeString("时间:");
setPosition(1, 4);
writeString("分");
setPosition(1, 6);
writeString("秒");
jdq_jinyou= duankai;
jdq_paiyou= bihe;
EA=1;
ET0=1;
TR0=1;
sec=0;
min=0;
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
}
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>59)
{
sec=0;
min++;
}
if(min>99)
{
min=0;
}
}
shoudong_dis(1);
}
else if((!flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou)&&(flag_x_p_t==flag_key_shoudong_tuoyou)) //脱油模式
{
flag_key_shoudong_jinyou=0;//脱油模式下不可进油
flag_key_shoudong_paiyou=0;//脱油模式下不可排油
if(flag_10==0)
{
flag_10=1;
setPosition(1, 0);
writeString("脱油");
//setPosition(2, 0);
//writeString("时间:");
setPosition(1, 4);
writeString("分");
setPosition(1, 6);
writeString("秒");
jdq_jinyou=duankai;
jdq_paiyou=bihe; //脱有的时候必须排油
jdq_zhengfan1 =duankai;
jdq_zhengfan2 =bihe;
jdq_slow_fast=bihe;
EA=1;
ET0=1;
TR0=1;
sec=0;
min=0;
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
}
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>59)
{
sec=0;
min++;
}
if(min>99)
{
min=0;
}
}
shoudong_dis(1);
}
/*
else //if(flag_x_p_t!=flag_key_shoudong_tuoyou) //非脱油模式
{
jdq_xidi=duankai;
jdq_slow_fast=duankai;
jdq_paiyou= duankai;
jdq_jinyou= duankai;
flag_5=0;
flag_6=0;
EA=0;
ET0=0;
TR0=0;
sec=0;
min=0;
//sprintf(temp_dis," ");
//sprintf(temp_dis1," ");
}
*/
if(flag_x_p_t==flag_key_shoudong_xidi) //洗涤模式
{
if(flag_11==0)
{
flag_11=1;
setPosition(1, 0);
writeString("洗涤");
setPosition(1, 4);
writeString("分");
setPosition(1, 6);
writeString("秒");
//jdq_xidi =bihe;
jdq_paiyou=duankai; //脱有的时候必须排油/////////////////
jdq_slow_fast=duankai;
EA=1;
ET0=1;
TR0=1;
sec=0;
min=0;
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
}
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>59)
{
sec=0;
min++;
}
if(min>99)
{
min=0;
}
}
motor_run(2,0,1);//第三行显示正反转停止信息
shoudong_dis(1);//分秒动态扫描显示
}
if(flag_x_p_t==flag_key_shoudong_piaoxi) //漂洗模式
{
if(flag_12==0)
{
flag_12=1;
setPosition(1, 0);
writeString(" ");
setPosition(2, 0);
writeString("漂洗");
setPosition(2, 4);
writeString("分");
setPosition(2, 6);
writeString("秒");
// jdq_xidi =bihe; //低速运转
jdq_slow_fast=duankai;
EA=1;
ET0=1;
TR0=1;
sec=0;
min=0;
sprintf(temp_dis," ");
sprintf(temp_dis1," ");
}
if((cnt==0)||(cnt>20))
{
cnt=20;
sec++;
if(sec>59)
{
sec=0;
min++;
}
if(min>99)
{
min=0;
}
}
#ifdef piaoxi_only_jinyou//漂洗的时候只进油
setPosition(1, 0);
writeString("进油中......");
jdq_jinyou=bihe; //打开进油继电器
jdq_paiyou=duankai;
#else
if((min/2+1)*2<(min+2))
{
setPosition(1, 0);
writeString("排油中......");
jdq_jinyou=duankai;
jdq_paiyou=bihe; //打开排油继电器
}
else if((min/2+1)*2==(min+2))
{
setPosition(1, 0);
writeString("进油中......");
jdq_jinyou=bihe; //打开进油继电器
jdq_paiyou=duankai;
}
#endif
motor_run(3,0,1);//第三行显示正反转停止信息
shoudong_dis(2);
}
else if((flag_x_p_t==nothing)&&(!flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou))
{
setPosition(1, 0);
writeString(" ");
flag_11=0;
flag_12=0;
// jdq_xidi =duankai;
ET0=0;
TR0=0;
sec=0;
min=0;
jdq_zhengfan1=duankai;
jdq_zhengfan2=duankai;
jdq_slow_fast=duankai;
jdq_jinyou=duankai;
jdq_paiyou=duankai; //打开排油继电器
}
}
/************************************************************************/
//////////////////////////////手动模式(END)///////////////////////////////
//------------------------------矩阵键盘扫描-----------------------------//
uchar keyscan1(void) //键盘扫描函数,使用行列反转扫描法
{
uchar cord_h,cord_l; //行列值中间变量
mat_key=0x07; //行线输出全为0
cord_h=mat_key&0x07; //读入列线值
if(cord_h!=0x07) //先检测有无按键按下
{
delay_nms(100); //去抖
if(cord_h!=0x07)
{
cord_h=mat_key&0x07; //读入列线值
mat_key=cord_h|0xf8; //输出当前列线值
cord_l=mat_key&0xf8; //读入行线值
return(cord_h+cord_l);//键盘最后组合码值
}
}return(0xef); //返回该值
}
//----------------------------键盘扫描-----------------------------------
void keyscan()
{
uchar key;
key=keyscan1(); //调用键盘扫描
//if(key!=0xff)
{
if(systerm_state!=mode_idle)//系统运行时开门报警
{
if(int0_out==0)
{
systerm_state=mode_idle;
jidianqi_init();
led_door=door_open;
flag_hand=0;
writeCmd(0x01); //清屏
delay_nms(10);
setPosition(0, 0);
writeString("警告: 门开!!!");
}
}
//按键时蜂鸣器鸣叫
if(key!=0xef)
{
buffer=ring;
}
else
{
buffer=not_ring;
}
switch(key)
{
//****************************自动运行时间设置模式////////////////////////////////////////////////
case 0x6b: //1 程序--------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
if(systerm_state!=mode_set_time)
mode_zang=0;
if((systerm_state!=mode_shoudong))//在非自动非手动模式下不可切换到程序模式下
{
writeCmd(0x01); //清屏
flag_xianzhi=0;//x,p,t无延时
flag_1=0;
flag_key_push=on;
delay_nms(100);
eeprom_init();
cishu_1++;
if(cishu_1!=5)
systerm_state=mode_set_time;
if(cishu_1>=6)
{
cishu_1=0;
}
time_set_init();
switch(cishu_1)
{
case 0:
{
mode_zang=0;
}
break;
case 1:
{
mode_zang=5;
}
break;
case 2:
{
mode_zang=10;
}
break;
case 3:
{
mode_zang=15;
}
break;
case 4:
{
mode_zang=20;
}
break;
case 5:
{
systerm_state=mode_idle;
}
}
}
}
break;
case 0x3e: //s10 设置 //改变的只是地址
{
if(systerm_state==mode_set_time)
{
flag_key_push=on;
flag_xianzhi=0;//x,p,t无延时
delay_nms(80);
eeprom_init();
cishu++;
if(cishu>=5)
{
cishu=0;
}
switch(cishu)
{
case 0:
{
mode_zang=(mode_zang/5)*5;
}
break;
case 1:
{
mode_zang=(mode_zang/5)*5+1;
}
break;
case 2:
{
mode_zang=(mode_zang/5)*5+2;
}
break;
case 3:
{
mode_zang=(mode_zang/5)*5+3;
}
break;
case 4:
{
mode_zang=(mode_zang/5)*5+4;
}
break;
default:
{
// mode_zang=(mode_zang/10)*10;
}
}
}
}
break;
case 0x75: //6 加++++++++++++++
{
if(systerm_state==mode_set_time)
{
//while((key!=0xdd));
flag_xianzhi=0;//x,p,t无延时
delay_nms(100);
flag_key_push=on;
flag_jia_jian=1;//////////////////////有加减操作标志位置位////////////////////////////////////
//delay_nms(100);
temp_time_set=read_add(set_time_save_add[mode_zang]);
delay_nms(50);
temp_time_set++;
if(temp_time_set>99)
{
if((mode_zang%5)==zz3)//排油时间不能为零
temp_time_set=1;
else
temp_time_set=0;
}
//temp_time_set=0;
//delay_nms(100);
write_add(set_time_save_add[mode_zang],temp_time_set);
delay_nms(50);
}
}
break;
case 0x5b: //10 减--------------
{
if(systerm_state==mode_set_time)
{
flag_xianzhi=0;//x,p,t无延时
//while((key==0x7b));
delay_nms(100);
flag_key_push=on;
flag_jia_jian=1;//////////////////////有加减操作标志位置位////////////////////////////////////
//delay_nms(100);
temp_time_set=read_add(set_time_save_add[mode_zang]);
delay_nms(50);
temp_time_set--;
if(temp_time_set<=1)
{
if(mode_zang%5==zz3) //排油时间不能为零
temp_time_set=1;
}
if(temp_time_set>=123)
temp_time_set=99;
//delay_nms(100);
write_add(set_time_save_add[mode_zang],temp_time_set);
delay_nms(100);
}
}
break;
case 0x6d: //4 自动模式切换按键-------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
delay_nms(100);
if(systerm_state!=mode_shoudong)//手动模式下不可以往自动模式切换
{ flag_xianzhi=0;//x,p,t无延时
flag_4=~flag_4;
if(!flag_4)
{
flag_key_push=on;
systerm_state=mode_idle;
}
else
{
flag_13=0;
flag_key_push=on;
systerm_state=mode_zidong;
zi_dong_mode_init();//自动模式下的初始化
}
}
}
break;
//**********************手动模式下/////////////////////////////////////////////////////////
case 0x76: //3 手动模式----------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
delay_nms(200);
if((systerm_state==mode_idle)||(systerm_state==mode_shoudong))//只有在系统空闲时才可以切换到手动模式
{
flag_hand=0; //有键按下标志位
flag_xianzhi=0;//x,p,t无延时
flag_3=~flag_3;
if(!flag_3)
{
flag_key_push=on;
systerm_state=mode_idle;
}
else
{
shou_dong_mode_init();//手动模式下面的初始化
systerm_state=mode_shoudong;//flag_3=1
}
}
}
break;
case 0x6e: //5 手动模式下进油
{
if(systerm_state==mode_shoudong)
{
if((flag_x_p_t==nothing)&&(!flag_key_shoudong_paiyou))//在其他模式时屏蔽该键
{
flag_hand=0; //有键按下标志位
flag_xianzhi=0;//x,p,t无延时
delay_nms(200);
flag_key_shoudong_jinyou=~flag_key_shoudong_jinyou;
if(flag_key_shoudong_jinyou)
flag_5=0;
else
flag_5=1;
flag_key_shoudong_paiyou=0;
}
}
}
break;
case 0x5d: //9 手动模式下排油
{
if(systerm_state==mode_shoudong)
{
if((flag_x_p_t==nothing)&&(!flag_key_shoudong_jinyou))//在其他模式时屏蔽该键
{
flag_hand=0; //有键按下标志位
flag_xianzhi=0;//x,p,t无延时
delay_nms(200);
flag_key_shoudong_paiyou=~flag_key_shoudong_paiyou;
if(flag_key_shoudong_paiyou)
flag_6=0;
else
flag_6=1;
flag_key_shoudong_jinyou=0;
}
}
}
break;
case 0x3d: //*****************************************7 手动模式下洗涤
{
if(systerm_state==mode_shoudong)
{
if((flag_x_p_t!=flag_key_shoudong_piaoxi)&&(flag_x_p_t!=flag_key_shoudong_tuoyou)&&(!flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou))
{
delay_nms(150);
flag_hand=0; //有键按下标志位
flag_8=~flag_8;
if(flag_8) //flag_8=1的时候是洗涤模式
{
flag_x_p_t=flag_key_shoudong_xidi;
flag_11=0;
}
else
{
flag_x_p_t=nothing;
flag_11=1;
}
}
}
}
break;
case 0x5e: //8 手动模式下漂洗
{
if(systerm_state==mode_shoudong)
{
if((flag_x_p_t!=flag_key_shoudong_xidi)&&(flag_x_p_t!=flag_key_shoudong_tuoyou)&&(!flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou))
{
delay_nms(200);
flag_hand=0; //有键按下标志位
flag_9=~flag_9;
if(flag_9) //flag_9=1的时候是漂洗模式
flag_x_p_t=flag_key_shoudong_piaoxi;
else
flag_x_p_t=nothing;
}
}
}
break;
case 0x73: //11 手动模式下脱油
{
if(systerm_state==mode_shoudong)
{
if((flag_x_p_t!=flag_key_shoudong_xidi)&&(flag_x_p_t!=flag_key_shoudong_piaoxi)&&(!flag_key_shoudong_jinyou)&&(!flag_key_shoudong_paiyou))
{
delay_nms(200);
flag_hand=0; //有键按下标志位
flag_7=~flag_7;
if(flag_7) //flag_7=1的时候是脱油模式
{
flag_x_p_t=flag_key_shoudong_tuoyou;
flag_10=0; //重新进入脱油模式时,重新初始化一次
}
else
flag_x_p_t=nothing;
}
}
}
break;
}
}
}
//----------------------------键盘扫描-------------------------------------//
//----------------------------EEPROM初始化-----------------------------------
void eeprom_init()
{
sda=1; //将总线都拉高以释放总线
delay();
scl=1; //将总线都拉高以释放总线
delay();
}
//----------------------------EEPROM初始化-----------------------------------//
//----------------------------系统初始化(开始)--------------------------------
void systerm_init()
{
uchar i=0;
P17=0;
led_door=door_close;
EA=1;//开总中断
//EX0=1;//允许外部中断0
//IT0=0;//电平触发方式,低电平有效
jidianqi_init();//继电器初始化
//delay_nms(1000);
#ifdef picture
//yj_init(1); //12864液晶初始化
init_pic();
delay_nms(200);
pic_dis(pic_start);
delay_nms(1000);
#endif
writeCmd(0x01); //清屏
delay_nms(500);
yj_init(2); //12864液晶初始化
timer0_init(); //定时器0初始化
eeprom_init(); //存储器初始化
#ifdef iic_init
for(i=0;i<25;i++)
{
write_add(set_time_save_add[i],1);
delay_nms(400);
}
#endif
writeCmd(0x01); //清屏 //////////////////////////////////////////
delay_nms(400);
buffer=not_ring;
yj_display_huanying(); //系统开机欢迎界面
delay_nms(1500);
yj_mode_select();
}
//----------------------------系统初始化(END)---------------------------//
/************************************************************************/
/*****************************系统主函数(开始)***************************/
void main()
{
systerm_init();
/*
while(1)
{
buffer=ring;
delay_nms(2000);
buffer=not_ring;
delay_nms(2000);
}
*/
while(1)
{
keyscan();
//systerm_state=mode_shoudong;////
//flag_key_shoudong_jinyou=1;
//flag_hand=0;
if(systerm_state==mode_set_time)
{
//chengxu();
//if(do_what!=0)
time_set();
led_door=door_close;
}
else if(systerm_state==mode_zidong)
{
auto_run();
led_door=door_close;
}
else if(systerm_state==mode_shoudong)
{
shou_dong_mode();
led_door=door_close;
}
else if(systerm_state==mode_idle)
{
if(flag_key_push==on)
{
flag_key_push=off;
led_door=door_close;
buffer=not_ring; //关闭蜂鸣器
jidianqi_init(); //在空闲模式下完成继电器的初始化
keyscan(); //在空闲模式下不停地进行键盘扫描
yj_mode_select(); //空闲模式下进行显示器的初始化,显示系统主界面
}
}
}
}
/************************************************************************/
/*****************************系统主函数(END)***************************/
#ifdef debug //为了调试方便使调试时运行加快
void timer0() interrupt 1
{
TH0=(65535-5000)/256;
TL0=(65535-5000)%256;
cnt--;
}
#else
///*********************外部中断0服务子函数****************************///
void int0() interrupt 0
{
systerm_state=mode_idle;
jidianqi_init();
led_door=door_open;
delay_nms(3000);
}
///*********************定时器0中断服务子函数****************************///
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
cnt--;
}
#endif