51单片机做的一个很简单的DS1302数字时钟+DS18B20温度检测,加入了NRF24L01的无线模块,将其数据发送到战舰开发板。
STM32这边直接用的做无线实验时调好的代码
51这边温度是1秒钟一采集,无线发送也是定时一秒钟,1602和TFT显示可以实现同步。
单片机源程序如下:
- #include"delay.h"
- #include"sys.h"
- #include"usart.h"
- #include"wkup.h"
- #include"led.h"
- #include"key.h"
- #include"lcd.h"
- #include"spi.h"
- //#include"adc.h"
- //#include"dma.h"
- #include"wkup.h"
- #include"nrf24l01.h"
-
- const u8 Send_Buff[]="I have received the massege!";
- #define SIZE sizeof(Send_Buff)
-
- u8 Receive_Buff[32];
-
- int main(void)
- {
- delay_init();
- uart_init(9600);
- LCD_Init();
- LED_Init();
- KEY_Init();
- WKUP_Init();
- NRF24L01_Init();
- // ADC1_Init();
- // DMA1_Init();
- LCD_Clear(BLACK);
- POINT_COLOR=WHITE;
- BACK_COLOR=BLACK;
- LCD_ShowString(60,50,200,16,16,"WarShip STM32");
- LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST");
- LCD_ShowString(60,100,200,16,16,"2013/12/15");
- while(NRF24L01_Check()) //检查NRF24L01是否在位.
- {
- LCD_ShowString(60,130,200,16,16,"NRF24L01 Check Error!");
- delay_ms(200);
- LED0=~LED0;
- delay_ms(200);
- }
- LCD_Clear(WHITE);
- POINT_COLOR=RED;
- BACK_COLOR=WHITE;
- LCD_ShowString(60,50,200,16,16,"WarShip STM32");
- LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST");
- LCD_ShowString(60,100,200,16,16,"2013/12/17");
- LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");
- LCD_ShowString(60,150,200,16,16,"KEY0:Send ");
- LCD_ShowString(60,170,200,16,16,"KEY2:Receive");
- LCD_ShowString(60,200,200,16,16,"STATUS:");
- // ADC_SoftwareStartConvCmd(ADC1,ENABLE); //软件启动ADC
- // ADC_DMACmd(ADC1,ENABLE);//开始ADC_DMA传输
-
- while(1)
- {
- u8 keyval,sta,t,mode=0;
- keyval=KEY_Scan(0);
- if(keyval==1)
- {
- mode=1;//发送模式
- }
- else if(keyval==3)
- {
- mode=0;//接收模式
- }
- if(mode)
- {
- TX_Mode();
- LED1=0;
- sta=RF_TX_Pack((u8*)Send_Buff);
- LCD_ShowxNum(116,200,sta,3,16,0);
- if(sta&TX_OK)
- LCD_ShowString(60,230,200,16,16,(u8*)Send_Buff);
- }
- else
- {
- RX_Mode();
- LED1=1;
- sta=RF_RX_Pack((u8*)Receive_Buff);
- LCD_ShowxNum(116,200,sta,3,16,0);
- if(sta&RX_OK)
- LCD_ShowString(60,230,200,16,16,(u8*)Receive_Buff);
- }
- delay_ms(10);
- t++;
- if(t==50)
- {
- LED0=~LED0;
- t=0;
- }
- }
- }
复制代码 转载于www点openedv点com/posts/list/26309.htm
所有资料51hei提供下载:
STM32无线温度接收.7z
(203.85 KB, 下载次数: 41)
无线温度采集.zip
(63.61 KB, 下载次数: 33)
NRF24L01+寄存器及指令集.doc
(54.5 KB, 下载次数: 21)
|