输出含有注释的上述代码
时间: 2023-07-09 08:16:15 浏览: 41
注释已添加在代码中,如下所示:
```c
#include <reg52.h>
#include <onewire.h>
unsigned char duanma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; // 数码管常规数字显示数组
unsigned char duanma_x[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; // 数码管小数位数字显示数组
unsigned int temp=0; // 当前温度值
unsigned int temp_h=0; // 最高温度值
unsigned int temp_l=30; // 最低温度值
void Delay_SMG(unsigned int t) {
while(t--);
}
void SelectHC573(unsigned char n) {
switch(n) {
case 0 : P2 = (P2 & 0x1f ) | 0x00; break;
case 4 : P2 = (P2 & 0x1f ) | 0x80; break;
case 5 : P2 = (P2 & 0x1f ) | 0xa0; break;
case 6 : P2 = (P2 & 0x1f ) | 0xc0; break;
case 7 : P2 = (P2 & 0x1f ) | 0xe0; break;
}
}
void DisplaySMG_Bit(unsigned char pos,unsigned char dat) {
P2=0xE0;P0=0xff;//先全部关掉数码管,避免显示不正常
P2=0xC0;P0=0x01<<pos;
P2=0xE0;P0=dat;
}
void DisplaySMG_temp() {
DisplaySMG_Bit(1,duanma[temp%10]); // 显示个位数字
Delay_SMG(100);
DisplaySMG_Bit(0,duanma[temp/10]); // 显示十位数字
Delay_SMG(100);
DisplaySMG_Bit(5,0xbf); // 显示小数点
Delay_SMG(100);
DisplaySMG_Bit(7,duanma[temp_l%10]); // 显示小数位个位数字
Delay_SMG(100);
DisplaySMG_Bit(6,duanma[temp_l/10]); // 显示小数位十位数字
Delay_SMG(100);
DisplaySMG_Bit(2,0xbf); // 显示小数点
Delay_SMG(100);
DisplaySMG_Bit(4,duanma[temp_h%10]); // 显示最高温度个位数字
Delay_SMG(100);
DisplaySMG_Bit(3,duanma[temp_h/10]); // 显示最高温度十位数字
Delay_SMG(100);
P2=0xC0;P0=0xff; // 关闭所有数码管的显示
P2=0xE0;P0=0xff;
}
void Delay(unsigned int t) {
while(t--) {
DisplaySMG_temp();
}
}
void Read_DS18B20_temp() {
unsigned char LSB,MSB;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay(1000);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
LSB=Read_DS18B20();
MSB=Read_DS18B20();
temp=MSB;
temp=(temp<<8)|LSB;
temp>>=4;
}
void open_buzz() {
P0|=0x40;
SelectHC573(5);
SelectHC573(0);
}
void close_buzz() {
P0&=0xbf;
SelectHC573(5);
SelectHC573(0);
}
void main() {
P2=0x80;P0=0xff;
while(1) {
Read_DS18B20_temp(); // 读取温度值
if(temp>temp_h) { // 更新最高温度值
temp_h=temp;
}
if(temp_l>temp) { // 更新最低温度值
temp_l=temp;
}
if(temp>=30) { // 当温度大于等于30度时,打开蜂鸣器
open_buzz();
}else if(temp<30) { // 当温度小于30度时,关闭蜂鸣器
close_buzz();
}
DisplaySMG_temp(); // 显示温度值和最高/低温度值
}
}
```