起因是制作恒温箱,csdn现有的温度传感器代码在使用中都或多或少有问题,现分享一下。(32版本!!!)
使用的是DS18B20温度传感器模块,三根线直接连接到最小核心系统板,再加上显示屏就能读取显示温度了。本人亲测并使用的代码,完美运行,代码逻辑很简单,看懂不难。
以下为运行代码,可自己更改一下引脚配置,在这我的DQ线连接的PB14口。
DS18B20.c:
#include "stm32f10x.h" // Device header
#include "Delay.h"
#define DS18B20_GPIO GPIOB
#define DS18B20_Pin GPIO_Pin_14
#define DQ_H GPIO_SetBits(DS18B20_GPIO,DS18B20_Pin) //PB14拉高
#define DQ_L GPIO_ResetBits(DS18B20_GPIO,DS18B20_Pin) //PB14拉低
#define DQ_Read GPIO_ReadInputDataBit(DS18B20_GPIO,DS18B20_Pin) //PB14读取
uint8_t flag=0;
void DS18B20_Init(void) //PB1初始化
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE