📄 xiyiji.c
字号:
void threetime(void)
{
unsigned char i;
minite=24;
while(minite>19) //3.0 洗衣服电机 P3.1 洗衣服电机
{ GotoXY(0,0);
Print("wash three times");
GotoXY(0,1);
Print("time: ");
daojishi();
disp();
P3_0=0;
P3_1=1;
for(i=0;i<100;i++){ getkey();disp();}
P3_0=1;
P3_1=0;
for(i=0;i<100;i++){ disp();getkey();}
P3_0=0;
P3_1=1;
for(i=0;i<100;i++){ disp();getkey();}
P3_0=1;
P3_1=0;
while(minite>=19)
{disp();getkey();}
}
while(minite<=19)
{
paishui();
jiashui();
twotime();
}
}
//自动洗两次*******************************************************
void twotime(void)
{
unsigned char i;
minite=17;
while(minite>12) //3.0 洗衣服电机 P3.1 洗衣服电机
{
GotoXY(0,0);
Print("wash two times");
GotoXY(0,1);
Print("time: ");
daojishi();
disp();
P3_0=0;
P3_1=1;
for(i=0;i<100;i++) {disp();getkey();}
P3_0=1;
P3_1=0;
for(i=0;i<100;i++) {disp();getkey();}
P3_0=0;
P3_1=1;
while(minite>12)
{disp();getkey();}
}
while((minite>5)&&(minite<=12))
{
paishui();
jiashui();
GotoXY(0,0);
Print("wash 0ne times");
GotoXY(0,1);
Print("time: ");
P3_0=0;
P3_1=1;
while(minite>5)
{disp();getkey();}
}
while((minite>=0)&&(minite<=5))//排水 2.3检测水满; P2.4检测水排光; P2.5加水闸; P2.6排水闸;
{
paishui();
P2_6=1;
P3_0=0;
P3_1=1;
GotoXY(0,0);
Print(" tuo shui zhong ");
GotoXY(0,1);
Print("time: ");
while(minite>=0)
{
disp();getkey();
while((second<=5)&&(minite==0))
{
P3=0;
P2=0;
GotoXY(0,0);
Print("washing is over ");
GotoXY(0,1);
Print(" close powere!!!");
EA=0;su=0;baojing();
}
}
}
}
//定时器1定时加排水出错报警************************************************
void dingshi(void)
{
TMOD=0x10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
ET1=1;
EA=1;
}
void t1(void) interrupt 3 using 2
{
unsigned int count,sanfen,bafen,sec30;
count++;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
sflagg=~sflagg;
if(count==20)
{
count=0;
sanfen++;
bafen++;
sec30++;
if(sec30==30)flag=1;
if(sanfen==180){sanfen=0;san=1;}
if(bafen==480){bafen=0;ba=1;}
}
}
void baojing(void)
{ P2=P3=0;
dingshi();
while(~pkey())
{
if(sflagg)P2_7=1;
else P2_7=0;
pkey();
if(flag)TR1=0;
}
while(1)
{ getkey();
if((biao==3)||(biao==4)||(biao==5))disp();
if(biao==6)display();
}
}
//LCD显示***************************************************************************
unsigned char LCD_Wait(void)
{
LcdRs=0;
LcdRw=1; //_nop_();
LcdEn=1; //_nop_();
//while(DBPort&0x80);//在用Proteus仿真时,注意用屏蔽此语句,在调用GotoXY()时,会进入死循环,
//可能在写该控制字时,该模块没有返回写入完备命令,即DBPort&0x80==0x80
//实际硬件时打开此语句
LcdEn=0;
return DBPort;
}
//向LCD写入命令或数据************************************************************
void LCD_Write(bit style, unsigned char input)
{
LcdEn=0;
LcdRs=style;
LcdRw=0; //_nop_();
DBPort=input; //_nop_();//注意顺序
LcdEn=1; //_nop_();//注意顺序
LcdEn=0; //_nop_();
LCD_Wait();
}
//初始化LCD*****************************************************************
void LCD_Initial()
{
LcdEn=0;
LCD_Write(LCD_COMMAND,0x38); //8位数据端口,2行显示,5*7点阵
LCD_Write(LCD_COMMAND,0x38);
LCD_Write(LCD_COMMAND,0x0c); //开启显示, 无光标
LCD_Write(LCD_COMMAND,0x01); //清屏
LCD_Write(LCD_COMMAND,0x06); //AC递增, 画面不动
}
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
LCD_Write(LCD_COMMAND,0x80|x);
if(y==1)
LCD_Write(LCD_COMMAND,0x80|(x-0x40));
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
LCD_Write(LCD_DATA,*str);
str++;
}
}
unsigned char TempBuffer[10];
void IntToStr( unsigned char *str)
{
unsigned char a[5]; char i;
a[0]=minite/10 ; //取得整数值到数组
a[1]=minite%10 ;
a[2]=':' ;
a[3]=second/10;
a[4]=second%10;
for(i=0; i<5; i++) //转成ASCII码
{if (i!=2) a[i]=a[i]+'0'; }
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的数字
*str='\0';
}
unsigned char tep[10];
void charToStr( unsigned char *str)
{
unsigned char a[5]; char i, t;
t= ReadTemperature() ;
a[0]=' '; //取得整数值到数组
a[1]=(t%100)/10;
a[2]=(t%100)%10;
a[3]=0xdf;
a[4]='c';
for(i=1; i<3; i++) //转成ASCII码
a[i]=a[i]+'0';
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的数字
*str='\0';
}
unsigned char wdsz[10];
void wdszStr( unsigned char *str)
{
unsigned char a[5]; char i;
a[0]=' '; //取得整数值到数组
a[1]=(wdz%100)/10;
a[2]=(wdz%100)%10;
a[3]=0xdf;
a[4]='c';
for(i=1; i<3; i++) //转成ASCII码
a[i]=a[i]+'0';
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的数字
*str='\0';
}
//显示当前温度温度和要达到的的温度********************************
void display(void)
{
wdszStr(&wdsz[0]);
GotoXY(8,1);
Print(&wdsz[0]);
Delay1ms(100);
charToStr(&tep[0]);
GotoXY(8,0);
Print(&tep[0]);
Delay1ms(100);
}
//只有时间的显示****************************************************
void disp(void)
{
IntToStr(&TempBuffer[0]);
GotoXY(8,1);
Print(&TempBuffer[0]);
Delay1ms(100);
}
//定时器0的使用 实现倒计时 和慢洗衣服时 PWM 比值******************************
void daojishi(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
}
void t0(void) interrupt 1 using 0
{
unsigned int tcnt,pwm;
tcnt++;
if(tcnt==4000)
{
pwm++;
if(pwm==3)sflag=1;
if(pwm==9) {sflag=0;pwm=0;}
tcnt=0;
second--;
if(second==0)
{
second=59;
minite--;
if(minite<=0)
{
minite=0;
}
}
}
}
//DS18B20读取温度的全部函数如下***************************************************
Init_DS18B20(void)//初始化函数
{
unsigned char x=0;
DQ = 1; //DQ复位
delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
delay(14);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(20);
}
//读一个字节**********************************************************
ReadOneChar(void)
{
unsigned char i=0,dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
delay(4);
}
return(dat);
}
//写入一个字节***********************************************************
WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
delay(5);
DQ = 1;
dat>>=1;
}
}
//读温度值*****************************************************************
unsigned int ReadTemperature(void)//读取温度
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
Init_DS18B20();//初始化
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
Init_DS18B20();//初始化
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar();//读取低字节
b=ReadOneChar();//读取高字节
if((b& 0xf8)!=0x00) //如果是负数 则取反加一
{
b=~b;
a=~a;
a=a+1;
if(a>255)
b++;
}
b=b<<4;// 高字节的低4位与低字节的高4位 组合为温度值
b=b & 0x70;
a=a>>4;
a=a & 0x0f;
t=a | b;
return(t);
}
//**************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -