新手上路
- 积分
- 24
- 金钱
- 24
- 注册时间
- 2018-4-27
- 在线时间
- 3 小时
|
4金钱
各位大神晚上好,我接触32位单片机刚刚两个月,前几天看原子哥的视频看到无线通信的内容,想自己动手做一个双向通信的小程序,实现上位机对下位机的LED进行控制,同时下位机通过DS18B20温度传感器将温度传递给上位机的功能。但是始终不能如愿,只能实现单向通信,要么就是只能是下位机给上位机温度信号,要么就是上位机给下位机控制信号,但是就是不能同时进行。烦请各路大神帮我看看我的程序哪里有问题,感激不尽 感激不尽!程序都是原子哥的程序。以下是上位机程序:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "spi.h"
#include "key.h"
#include "24l01.h"
#include "ds18b20.h"
const u8 TEXT_Buffer[]={"Explorer STM32F4 SPI TEST"};
#define SIZE sizeof(TEXT_Buffer)
u8 tmp_buf[33];
int main(void)
{
u8 key,mode;
u8 t=0;
short tem;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
KEY_Init();
NRF24L01_Init();
DS18B20_Init();
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
LCD_ShowString(30,70,200,16,16,"NRF24L01 TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/5/9");
while(NRF24L01_Check())
{}
mode = 1;
while(1)
{
if(mode == 0)
{
NRF24L01_RX_Mode();
while(NRF24L01_RxPacket(tmp_buf)!=0);
tem = tmp_buf[1];
tem<<=8;
tem= tem+tmp_buf[2];
tem=(double)tem*0.625;
LCD_ShowNum(30,190,tem,3,12);
tem = tmp_buf[3];
tem<<=8;
tem= tem+tmp_buf[4];
tem=(double)tem*0.625;
LCD_ShowNum(70,190,tem,3,12);
mode = 1;
delay_ms(10);
}
if(mode == 1)
{
NRF24L01_TX_Mode();
key = KEY_Scan(1);
switch(key)
{
case 0 : tmp_buf[0] = 0;break;
case 1 : tmp_buf[0] = 1;break;
case 2 : tmp_buf[0] = 2;break;
case 3 : tmp_buf[0] = 3;break;
case 4 : tmp_buf[0] = 4;break;
}
while(NRF24L01_TxPacket(tmp_buf)!=TX_OK)
{
LED0 = 0;
delay_ms(300);
LED0 = 1;
delay_ms(300);
}
mode = 0;
delay_ms(10);
}
}
以下是下位机程序:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "spi.h"
#include "key.h"
#include "24l01.h"
#include "ds18b20.h"
const u8 TEXT_Buffer[]={"Explorer STM32F4 SPI TEST"};
#define SIZE sizeof(TEXT_Buffer)
u8 tmp_buf[33];
int main(void)
{
u8 key,mode;
u8 t=0;
short tem;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
KEY_Init();
NRF24L01_Init();
DS18B20_Init();
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
LCD_ShowString(30,70,200,16,16,"NRF24L01 TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/5/9");
while(NRF24L01_Check())
{
}
mode = 1;
while(1)
{
if(mode ==1)
{
NRF24L01_RX_Mode();
while(NRF24L01_RxPacket(tmp_buf)!=0);
switch(tmp_buf[0])
{
case 0 : LED0 = 1; LED1 = 1; break;
case 1 : LED0 = 0; break;
case 2: LED1 = 0; break;
case 3 : LED0 = 0; LED1 = 0; break;
case 4 : LED0 = 0; LED1 = 0;delay_ms(500); break;
}
mode = 0;
delay_ms(10);
}
if(mode == 0)
{
NRF24L01_TX_Mode();
DS18B20_Get_Temp();
DS18B20_Get_Temp1();
while(NRF24L01_TxPacket(tmp_buf)!=TX_OK);
mode = 1;
delay_ms(10);
}
}
|
|