DS18B20智能温度控制器
[09-12 17:54:15] 来源:http://www.88dzw.com 单片机学习 阅读:8225次
文章摘要:DJNZ R7,$RET;实验板上的7段数码管0~9数字的共阴显示代码numtab: DB 3fh,30h,6dh,79h,72h,5bh,5fh,31h,7fh,7bhend以下为C语言版:#include sbit warmer=P1^4;sbit led_run=P1^0;sbit k_power=P3^3; sbit ge=P2^7;sbit shi=P2^6;sbit DQ =P2^2; //定义通信端口//延时函数unsigned char tab[]={ 0x3f,0x30,0x6d,0x79,0x72,0x5b,0x5f,0x31,0x7f,0x7b,0x40};
DS18B20智能温度控制器,标签:单片机开发,单片机原理,单片机教程,http://www.88dzw.comDJNZ R7,$
RET
;实验板上的7段数码管0~9数字的共阴显示代码
numtab: DB 3fh,30h,6dh,79h,72h,5bh,5fh,31h,7fh,7bh
end
以下为C语言版:
#include
sbit warmer=P1^4;
sbit led_run=P1^0;
sbit k_power=P3^3;
sbit ge=P2^7;
sbit shi=P2^6;
sbit DQ =P2^2; //定义通信端口
//延时函数
unsigned char tab[]={ 0x3f,0x30,0x6d,0x79,0x72,0x5b,0x5f,0x31,0x7f,0x7b,0x40};
//0, 1, 2 3 4 5 6 7 8 9
void delay(unsigned int i)
{
while(i--);
}
//初始化函数
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;
unsigned char 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;
}
delay(4);
}
//读取温度
ReadTemperature(void)
{
unsigned char a=0;
unsigned char b=0;
unsigned char t=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar(); //读取温度值低位
b=ReadOneChar(); //读取温度值高位
a=a>>4; //低位右移4位,舍弃小数部分
t=b<<4; //高位左移4位,舍弃符号位
t=ta;
return(t);
}
void display_tempmain(unsigned char i) //主程序温度显示函数
{
P0=tab[i/10];
shi=0;
ge=1;
delay(1000);
P0=tab[i%10];
shi=1;
ge=0;
}
void main(void)
{unsigned int temp;
while(1) //主循环
{ temp=ReadTemperature();
display_tempmain(temp);
}
}
- 上一篇:Actel 提供安全的设计流程
《DS18B20智能温度控制器》相关文章
- › 控制DS1804采用8051兼容微控制器-Controlli
- › DS1870采用外接电阻时的调节范围/分辨率
- › FPGA与DS18B20型温度传感器通信的实现
- › DS18B20智能温度控制器
- › 使用NOKIA3310液晶屏及DS18B20制作的数字温度计
- 在百度中搜索相关文章:DS18B20智能温度控制器
- 在谷歌中搜索相关文章:DS18B20智能温度控制器
- 在soso中搜索相关文章:DS18B20智能温度控制器
- 在搜狗中搜索相关文章:DS18B20智能温度控制器