DS18B20的STM32單片機程序,我調試過了
全部源碼下載:
DS18B20.rar
(2.99 MB, 下載次數: 344)
2017-2-14 16:27 上傳
點擊文件名下載附件
主程序:
- /****************************************Copyright (c)****************************************************
- **
- **
- **
- **--------------File Info---------------------------------------------------------------------------------
- ** File name:
- ** Last modified Date:
- ** Last Version:
- ** Descriptions:
- **--------------------------------------------------------------------------------------------------------
- ** Created by: FiYu
- ** Created date: 2015-12-12
- ** Version: 1.0
- ** Descriptions: DS18B20溫度傳感器實驗
- **--------------------------------------------------------------------------------------------------------
- ** Modified by: FiYu
- ** Modified date:
- ** Version:
- ** Descriptions:
- ** Rechecked by:
- **********************************************************************************************************/
- /****-----請閱讀ReadMe.txt進行實驗-----***********/
- #include "stm32f10x.h"
- #include "delay.h"
- #include "ds18b20.h"
- #include "usart.h"
- /**************************************************************************************
- * 描 述 : GPIO/USART1初始化配置
- * 入 參 : 無
- * 返回值 : 無
- **************************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable the GPIO_LED Clock */
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
-
- GPIO_DeInit(GPIOB); //將外設GPIOA寄存器重設為缺省值
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_DeInit(GPIOA); //將外設GPIOA寄存器重設為缺省值
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽輸出
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空輸入
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_SetBits(GPIOB , GPIO_Pin_9); //初始狀態,熄滅指示燈LED1
- }
- /**************************************************************************************
- * 描 述 : MAIN函數
- * 入 參 : 無
- * 返回值 : 無
- **************************************************************************************/
- int main(void)
- {
- SystemInit(); //設置系統時鐘72MHZ
- GPIO_Configuration();
- USART1_Init(); //初始化配置TIM
- GPIO_ResetBits(GPIOB , GPIO_Pin_9);
- delay_ms(500);
-
- while( DS18B20_Init())
- {
- printf("\r\n no ds18b20 exit \r\n");
- GPIO_SetBits(GPIOB , GPIO_Pin_9);
- }
- printf("\r\n ds18b20 exit \r\n");
- GPIO_SetBits(GPIOB , GPIO_Pin_9);
-
- for(;;)
- {
- printf("\r\n temperature %.1f\r\n",DS18B20_Get_Temp());
- delay_ms(1500); // 1.5s 讀取一次溫度值
- }
-
- }
- /*********************************END FILE********************************************/
復制代碼
|