|
最近在弄學(xué)校的一個(gè)項(xiàng)目,找了好多無(wú)線溫度的程序,發(fā)現(xiàn)多是51的,只好自己改成stm32了。程序在原子例程的基礎(chǔ)上修改的。
本例使用DS18B20獲取溫度,24L01進(jìn)行無(wú)線傳送,均在串口調(diào)試助手上顯示發(fā)送的溫度值與接收值。
線路連接:
DS18B20接PA1
24L01_CE接PG8
24L01_CS接PG7
24L01_IRQ接PG6
24L01_MISO接PB14
24L01_MOSI接PB15
24L01_SCK接PB13
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "usart.h"
- #include "ds18b20.h"
- #include "24l01.h"
- int i;
- u16 t=0;
- short temperature;
- extern u8 th,tl;
- u8 tmp_buf[33];
- int main (void)
- {
-
- uart_init(115200);
- delay_init();
- NRF24L01_Init();
- NRF24L01_TX_Mode();
- DS18B20_Init();
-
-
- while(1)
- {
-
-
-
-
-
- if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
- {
- temperature=DS18B20_Get_Temp();
- tmp_buf [0]=th; //發(fā)送溫度值高位
- tmp_buf[1]=tl; //發(fā)送溫度值低位
- printf("\n\r %3f \r\n",temperature/100.0);//串口顯示發(fā)送的溫度
- delay_ms(1000);
- }
- }
-
-
- }
-
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
無(wú)線溫度.rar
(10.31 MB, 下載次數(shù): 93)
2017-7-21 19:34 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|