本科毕业生学士学位论文 return a; }
uchar read_temp(void) {
uchar i,b,c,Th,Tm,Tl; ds18b20_reset(); ds18b20_write(0xcc); ds18b20_write(0x44); delayms(50); ds18b20_reset(); delay(1);
ds18b20_write(0xcc); ds18b20_write(0xbe); b=ds18b20_read(); c=ds18b20_read(); flag1=c;
if(flag1) { //温度为负
TEMP[0]=0; TEMP[1]=0;
}
else{
Th=c/100; Tm=(c0)/10;
Tl=c; //取温度的各个位 if(Th) { //温度高于99度
TEMP[0]=0x0f; TEMP[1]=0x0f; }
else{
TEMP[0]=Tl; TEMP[1]=Tm; } }
if(TEMP[0]>7) Tflag=1; //高温标志 else Tflag=0;
- 25 -
本科毕业生学士学位论文 return(TEMP[2]); }
//LED显示子程序 void Icmdis(uchar TEMP[]) {
char i; ICMWR=0;
ICMMODE=1;//ICM工作于模式1 ICMOUT=0xB0;//输出模式控制字 ICMMODE=0;//ICM工作于模式0 for(i=0;i<2;i++)
ICMOUT=TEMP[i];//输出温度值 }
//A/D转换及液位显示子程序
void ADRun(void) {
ADCS=0; ADWR=0; _nop_(); ADWR=1; ADCS=1; }
uchar ADRead(void) {
ADV=ADIN;
if(ADV>wl*4){ //水位显示为100%
D1=ON; D2=ON; D3=ON; D4=ON; D5=ON;
}
else{
if(ADV>wl*3){ //水位显示为80%
D1=ON;
- 26 -
本科毕业生学士学位论文 D2=ON; D3=ON; D4=ON; D5=OFF; }
else{ //水位显示为60%
if(ADV>wl*2) { //水位显示为40% D1=ON; D2=ON; D3=ON; D4=OFF; D5=OFF;
}
else{
if(ADV>wl) { //水位显示为20%
D1=ON; D2=ON; D3=OFF; D4=OFF; D5=OFF;
}
else { //水位显示为缺水
D1=ON; D2=OFF; D3=OFF; D4=OFF; D5=OFF;
} }
}
}
return ADV; }
//定时器T0中断程序 void T0Run(void) {
TH0=0x3C;
- 27 -
本科毕业生学士学位论文 }
TL0=0xB0; TR0=1;
//启动定时器T0
void timer0(void) interrupt 1 {
TH0=0x3C; TL0=0xB0; T0c++; if(T0c>19) {
T0c=0; if(TW){
TW=0; ADRun(); ADRead(); }
else{
read_temp();
} }
//定时器T1中断程序 void T1Run(void) { }
void timer1(void) interrupt 3 {
TH1=0x3C; TL1=0xB0;
- 28 -
TH1=0x3C; TL1=0xB0; TR1=1;
//启动定时器T0
}
Icmdis();
本科毕业生学士学位论文
T1c++; if(T1c>199) {
T1c=0; //EPflag=0; SOV1=OFF; SOV2=OFF; SOV3=ON; }
} //主程序 main() {
char T0c=0; char T1c=0; IE=0x8A; TMOD=0x11; T0Run(); while(1){
if(S1==0){ ADV0=ADV;
sflag=1;// 手动上水模式标志 TW=1;//液位检测标志
SOV1=ON; SOV2=ON;
SOV3=OFF; }
else {
if(sflag) {
if(ADV>ADV0+wl){ //手动上水一个档位后即停止上水 sflag=0;
SOV1=OFF; SOV2=OFF; SOV3=OFF;
- 29 -
//上水
本科毕业生学士学位论文 }
}
else{
if(SOV1==OFF&&SOV2==OFF) {
//EPflag=1; //排空管道水标志 }
}
T1Run();
SOV3=ON; //排空管道内的水 } }
if(ADV SOV1=ON; SOV2=ON; SOV3=OFF; //水位较低上水} else{ SOV1=OFF; SOV2=OFF; SOV3=OFF; } } - 30 - 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库毕业设计 基于AT89C52的太阳能热水器控制系统 - 图文(8)在线全文阅读。
相关推荐: