DS18b20与Stm32f103c8t8的接线
DQ-----PB9
VCC----3.3v
GND----GND
主程序
int main(void)
{
char buf[10];
unsigned int temper;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200); //初始化串口,波特率为115200
LED_GPIO_Configuration(); //初始化LED灯
USART_SendStr(USART1,"温度测量:");
while (1)
{
temper = DS18B20_Read_Temp();
sprintf(buf,"%d.%d",temper/10,temper);
USART_SendStr(USART1,"当前温度为:");
USART_SendStr(USART1,buf);
USART_SendStr(USART1," C\n");
LEDToggle(1000); //指示灯闪烁,每1s打印一次温度
}
}
1