?? xiyiji.c
字號(hào):
void threetime(void)
{
unsigned char i;
minite=24;
while(minite>19) //3.0 洗衣服電機(jī) P3.1 洗衣服電機(jī)
{ 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();
}
}
//自動(dòng)洗兩次*******************************************************
void twotime(void)
{
unsigned char i;
minite=17;
while(minite>12) //3.0 洗衣服電機(jī) P3.1 洗衣服電機(jī)
{
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檢測(cè)水滿; P2.4檢測(cè)水排光; 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();
}
}
}
}
//定時(shí)器1定時(shí)加排水出錯(cuò)報(bào)警************************************************
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仿真時(shí),注意用屏蔽此語(yǔ)句,在調(diào)用GotoXY()時(shí),會(huì)進(jìn)入死循環(huán),
//可能在寫該控制字時(shí),該模塊沒有返回寫入完備命令,即DBPort&0x80==0x80
//實(shí)際硬件時(shí)打開此語(yǔ)句
LcdEn=0;
return DBPort;
}
//向LCD寫入命令或數(shù)據(jù)************************************************************
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位數(shù)據(jù)端口,2行顯示,5*7點(diǎn)陣
LCD_Write(LCD_COMMAND,0x38);
LCD_Write(LCD_COMMAND,0x0c); //開啟顯示, 無光標(biāo)
LCD_Write(LCD_COMMAND,0x01); //清屏
LCD_Write(LCD_COMMAND,0x06); //AC遞增, 畫面不動(dòng)
}
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 ; //取得整數(shù)值到數(shù)組
a[1]=minite%10 ;
a[2]=':' ;
a[3]=second/10;
a[4]=second%10;
for(i=0; i<5; i++) //轉(zhuǎn)成ASCII碼
{if (i!=2) a[i]=a[i]+'0'; }
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數(shù)字
*str='\0';
}
unsigned char tep[10];
void charToStr( unsigned char *str)
{
unsigned char a[5]; char i, t;
t= ReadTemperature() ;
a[0]=' '; //取得整數(shù)值到數(shù)組
a[1]=(t%100)/10;
a[2]=(t%100)%10;
a[3]=0xdf;
a[4]='c';
for(i=1; i<3; i++) //轉(zhuǎn)成ASCII碼
a[i]=a[i]+'0';
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數(shù)字
*str='\0';
}
unsigned char wdsz[10];
void wdszStr( unsigned char *str)
{
unsigned char a[5]; char i;
a[0]=' '; //取得整數(shù)值到數(shù)組
a[1]=(wdz%100)/10;
a[2]=(wdz%100)%10;
a[3]=0xdf;
a[4]='c';
for(i=1; i<3; i++) //轉(zhuǎn)成ASCII碼
a[i]=a[i]+'0';
for(i=0; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數(shù)字
*str='\0';
}
//顯示當(dāng)前溫度溫度和要達(dá)到的的溫度********************************
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);
}
//只有時(shí)間的顯示****************************************************
void disp(void)
{
IntToStr(&TempBuffer[0]);
GotoXY(8,1);
Print(&TempBuffer[0]);
Delay1ms(100);
}
//定時(shí)器0的使用 實(shí)現(xiàn)倒計(jì)時(shí) 和慢洗衣服時(shí) 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讀取溫度的全部函數(shù)如下***************************************************
Init_DS18B20(void)//初始化函數(shù)
{
unsigned char x=0;
DQ = 1; //DQ復(fù)位
delay(8); //稍做延時(shí)
DQ = 0; //單片機(jī)將DQ拉低
delay(80); //精確延時(shí) 大于 480us
DQ = 1; //拉高總線
delay(14);
x=DQ; //稍做延時(shí)后 如果x=0則初始化成功 x=1則初始化失敗
delay(20);
}
//讀一個(gè)字節(jié)**********************************************************
ReadOneChar(void)
{
unsigned char i=0,dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 給脈沖信號(hào)
dat>>=1;
DQ = 1; // 給脈沖信號(hào)
if(DQ)
dat|=0x80;
delay(4);
}
return(dat);
}
//寫入一個(gè)字節(jié)***********************************************************
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); // 跳過讀序號(hào)列號(hào)的操作
WriteOneChar(0x44); // 啟動(dòng)溫度轉(zhuǎn)換
Init_DS18B20();//初始化
WriteOneChar(0xCC); //跳過讀序號(hào)列號(hào)的操作
WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個(gè)寄存器) 前兩個(gè)就是溫度
a=ReadOneChar();//讀取低字節(jié)
b=ReadOneChar();//讀取高字節(jié)
if((b& 0xf8)!=0x00) //如果是負(fù)數(shù) 則取反加一
{
b=~b;
a=~a;
a=a+1;
if(a>255)
b++;
}
b=b<<4;// 高字節(jié)的低4位與低字節(jié)的高4位 組合為溫度值
b=b & 0x70;
a=a>>4;
a=a & 0x0f;
t=a | b;
return(t);
}
//**************************************************************************
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -