標(biāo)題:
stm8 dth22驅(qū)動代碼
[打印本頁]
作者:
Tang-天空
時(shí)間:
2018-6-23 20:23
標(biāo)題:
stm8 dth22驅(qū)動代碼
stm8 dth22代碼
#include "main.h"
u8 CMD_rx_buf[8]; //命令緩沖區(qū)
u8 DATA_tx_buf[14]; //返回?cái)?shù)據(jù)緩沖區(qū)
u8 CMD_ID = 0; // 命令序號
u8 Sensor_Type = 0; // 傳感器類型編號
u8 Sensor_ID = 0; // 相同類型傳感器編號
u8 Sensor_Data[6]; // 傳感器數(shù)據(jù)
u8 Sensor_Data_Digital = 0; // 數(shù)字類型傳感器數(shù)據(jù)
u16 Sensor_Data_Analog = 0; // 模擬類型傳感器數(shù)據(jù)
u16 Sensor_Data_Threshod = 0;// 模擬傳感器閾值
void main(void)
{
u8 i = 0;
//初始化時(shí)鐘,設(shè)置內(nèi)部高速時(shí)鐘為16M
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
//串口初始化
Uart1_Init();
//LED初始化
LED_Init();
//DHT22初始化
DHT22_Init();
//初始化數(shù)據(jù)幀(EE CC 0A 01 01 XX XX XX XX XX XX XX XX FF)
for(i = 0;i < 14;i++)
DATA_tx_buf[i] = 0;
for(i = 0;i < 8;i++)
CMD_rx_buf[i] = 0;
Sensor_Type = 0x0A;
Sensor_ID = 1;
CMD_ID = 1;
DATA_tx_buf[0] = 0xEE;
DATA_tx_buf[1] = 0xCC;
DATA_tx_buf[2] = Sensor_Type;
DATA_tx_buf[3] = Sensor_ID;
DATA_tx_buf[4] = CMD_ID;
DATA_tx_buf[13] = 0xFF;
delay_ms(1000);
while (1)
{
// 獲取傳感器數(shù)據(jù)
if(DHT22_Read())
{
Sensor_Data[2] = Humidity >> 8;
Sensor_Data[3] = Humidity&0xFF;
Sensor_Data[4] = Temperature >> 8;
Sensor_Data[5] = Temperature&0xFF;
}
// 組合數(shù)據(jù)幀
for(i = 0;i < 6;i++)
DATA_tx_buf[5+i] = Sensor_Data[i];
// 發(fā)送數(shù)據(jù)幀
UART1_SendString(DATA_tx_buf, 14);
LED_Toggle();
delay_ms(1000);
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
復(fù)制代碼
全部資料51hei下載地址:
DHT22練習(xí) - 副本.zip
(7.06 MB, 下載次數(shù): 28)
2018-6-23 20:23 上傳
點(diǎn)擊文件名下載附件
stm8
下載積分: 黑幣 -5
作者:
jemery1030
時(shí)間:
2019-9-16 13:07
感謝您的分享
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1