
FPGA上DS18B20温度测量的实现
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本文介绍了在FPGA平台上使用DS18B20传感器进行温度测量的具体方法和步骤,详细阐述了硬件连接与软件编程技巧。
通过Verilog实现了对温度传感器DS18B20的控制功能,并提供了详细的注释以方便理解代码。只需根据个人实际情况稍作调整即可直接使用。实际测试表明该代码在硬件上可以正常运行。
全部评论 (0)
还没有任何评论哟~


简介:
本文介绍了在FPGA平台上使用DS18B20传感器进行温度测量的具体方法和步骤,详细阐述了硬件连接与软件编程技巧。
通过Verilog实现了对温度传感器DS18B20的控制功能,并提供了详细的注释以方便理解代码。只需根据个人实际情况稍作调整即可直接使用。实际测试表明该代码在硬件上可以正常运行。



unsigned char seg7code[11] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x40};
void Delay(unsigned int tc) {
while (tc != 0) {
unsigned int i;
for(i = 0; i < 100; i++);
tc--;
}
}
sbit TMDAT = P3^1;
unsigned char tmrbyte(void);
void dmsec(unsigned int count);
void tmreset(void);
int main() {
// 初始化代码
tmreset();
// 主循环读取温度数据并显示
while(1) {
unsigned char data;
// 读取DS18B20中的数据
data = tmrbyte();
// 显示处理逻辑(此处省略)
Delay(50);
}
}
void dmsec(unsigned int count) {
unsigned char i;
while(count--) {
for(i = 0; i < 115; i++);
}
}
void tmreset(void) {
unsigned char i;
TMDAT = 0;
for(i = 0; i < 103; i++);
TMDAT = 1;
}
unsigned char tmrbyte(void) {
unsigned char dat, j;
dat = 0;
for (j=8;j>0;j--) {
bit testb;
if (TMDAT == 1)
testb = 1; // 主机发送的位
else
testb = tmrbit(); // 接收从设备回送的数据
dat <<= 1;
if(testb)
dat |= 0x01;
}
return (dat);
}
void tmwbyte(unsigned char dat) {
unsigned char j, i; bit testb;
for(j=8;j>0;j--) {
testb = dat & 0x01;
if(testb)
TMDAT = 1;
else
TMDAT = 0;
dmsec(4);
dat >>= 1;
}
}
```
以上代码片段展示了如何初始化DS18B20并读取其温度数据。通过该示例,开发者可以进一步开发出更复杂的应用程序来利用此传感器的功能。
总之,由于其高精度和易于使用的特性,DS18B20在各种测温应用中发挥着重要作用,并且对于电子爱好者来说是一个理想的入门级项目选择。