第五章 系统调试
C51COMPILERV9.01 05/02/2016 13:13:23 PAGE 2
56 2 DQ=0; // 给脉冲信号 57 2 dat>>=1;
58 2 DQ=1; // 给脉冲信号 59 2 if(DQ) 60 2 dat|=0x80;
61 2 delay_18B20(4); 62 2 63 1 64 1 65 66 67 68 1 69 1 70 1 71 2 72 2 73 2 74 2 75 2 76 2 77 1 78 79 80 81 1 82 1 83 1 84 1 85 1 86 1 87 1 important
88 1 89 1 90 1 9个寄存器) 91 1 92 1 93 1 94 1 }
return(dat); }
/*************ds18b20写一个字节****************/ void WriteOneChar(uchar dat) {
uchar i=0;
for (i=8;i>0;i--) {
DQ=0;
DQ=dat&0x01; delay_18B20(5); DQ=1; dat>>=1; } }
/**************读取ds18b20当前温度************/ void ReadTemperature(void) {
uchar a=0; uchar b=0; uchar t=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作 WriteOneChar(0x44); // 启动温度转换
delay_18B20(100); // this message is wery Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作 WriteOneChar(0xBE); //读取温度寄存器等(共可读前两个就是温度
delay_18B20(100);
a=ReadOneChar(); //读取温度值低位
b=ReadOneChar(); //读取温度值高位 wen_du=((b*256+a)>>4); //当前采集温度值除16得
20
实际温度值
95 1 }
96 void display(void)//显示温度 97 {
98 1 if(flag==1||flag==2) 99 1 xianshi[0]=d1; 100 1 else
101 1 xianshi[0]=d1+'0'; 102 1 xianshi[1]='-'; 103 1 104 1 105 1 106 1 107 1 108 1 109 110 111 1 112 1 113 2 114 2 115 2 116 2 117 1 xianshi[2]=d2+'0'; xianshi[3]=d3+'0'; xianshi[4]='C';
SandtheStr(0,5,\ SandtheStr(1,5,xianshi); }
void zi_keyscan(void)//自动模式按键扫描函数{
if(key1==0) {
delay(10);
if(key1==0)flag=1;
while(key1==0);//松手检测 }
while(flag==1)
21
第五章 系统调试
C51COMPILERV9.01 05/02/2016 13:13:23 PAGE 3
118 1 {
119 2 d1='H';d2=shang/10;d3=shang; 120 2 display(); 121 2 if(key1==0) 122 2 {
123 3 delay(10);
124 3 125 3 126 3 127 2 128 2 129 3 130 3 131 3 132 4 133 4 134 4 135 3 136 2 137 2 138 3 139 3 140 3 141 4 142 4 143 4 144 3 145 2 146 1 147 1 148 2 149 2 150 2 151 2 152 3 153 3 154 3 155 3 156 2 157 2 158 3 if(key1==0)flag=2;
while(key1==0);//松手检测 }
if(key2==0) {
delay(10); if(key2==0) {
shang+=5;
if(shang>=100)shang=100; }while(key2==0);//松手检测 }
if(key3==0) {
delay(10); if(key3==0) {
shang-=1;
if(shang<=10)shang=10; }while(key3==0);//松手检测 } }
while(flag==2) {
d1='L';d2=xia/10;d3=xia; display(); if(key1==0) {
delay(10);
if(key1==0)flag=0;
while(key1==0);//松手检测 }
if(key2==0) {
delay(10);
22
159 3 if(key2==0) 160 3 {
161 4 xia+=5;
162 4 if(xia>=95)xia=95; 163 4 }while(key2==0);//松手检测 164 3 }
165 2 if(key3==0) 166 2 {
167 3 delay(10); 168 3 169 3 170 4 171 4 172 4 173 3 174 2 175 1 176 177 178 1 179 1 if(key3==0) {
xia-=1;
if(xia<=0)xia=0; }while(key3==0);//松手检测 } } }
void zi_dong()//自动温控模式 {
uchar i;
d1=dang;d2=wen_du/10;d3=wen_du;
23
第五章 系统调试
C51COMPILERV9.01 05/02/2016 13:13:23 PAGE 4
180 1 zi_keyscan();//按键扫描函数 181 1 display();
182 1 if(wen_du
185 2 dang=1; 186 2 for(i=0;i<5;i++){dj=0;zi_keyscan();} //display(); 187 2 for(i=0;i<5;i++){dj=1;zi_keyscan();} //display();
188 2 }
189 1 if(wen_du>shang){dj=1;dang=2;Beep=0;}//高温全速 大于上限蜂鸣器
190 1 else
191 1 Beep=1; 192 1 }
193 void main() 194 {
195 1 uchar j; 196 1
197 1 LcdInit(); 198 1 dj=0;
199 1 shang=30; 200 1 xia=20;
201 1 for(j=0;j<80;j++) 202 1 ReadTemperature(); 203 1
204 1 while(1) 205 1 {
206 2 ReadTemperature();
207 2 zi_dong();//自动温控模式 208 2 } 209 1 }
MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 952 ---- CONSTANT SIZE = 6 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 19 14 IDATA SIZE = ---- ----
24