初级会员
- 积分
- 125
- 金钱
- 125
- 注册时间
- 2015-3-26
- 在线时间
- 14 小时
|
//发送<br />
#include "sys.h"<br />
#include "usart.h" <br />
#include "delay.h" <br />
#include "led.h" <br />
#include "beep.h" <br />
#include "key.h" <br />
#include "exti.h" <br />
#include "wdg.h" <br />
#include "timer.h" <br />
#include "tpad.h"<br />
#include "oled.h" <br />
#include "lcd.h"<br />
#include "rtc.h" <br />
#include "wkup.h" <br />
#include "adc.h" <br />
#include "dac.h" <br />
#include "dma.h" <br />
#include "24cxx.h" <br />
#include "flash.h" <br />
#include "rs485.h" <br />
#include "can.h" <br />
#include "touch.h" <br />
#include "remote.h" <br />
#include "24l01.h"<br />
<br />
/* <br />
<br />
±????ò ?? 2.4G??·??????ò mode =?®A?® ?± ???????? <br />
mode = 'B ' ?± ?????????? spi2 <br />
<br />
<br />
*/<br />
<br />
<br />
<br />
int main(void)<br />
{ <br />
u32 oldcnt=0;<br />
<br />
u8 key,mode;<br />
u8 mode1;<br />
u16 c; <br />
u8 tmp_buf[32]={0};<br />
Stm32_Clock_Init(9); //?????±???è??<br />
delay_init(72); //???±?????? <br />
LCD_Init(); //??????LCD<br />
KEY_Init(); //°??ü??????<br />
<br />
LED_Init ();<br />
<br />
//TIM2_Excnt_Init(999,7199);<br />
TIM3_CH2_Excnt_Init(0xffff,0);<br />
NRF24L01_Init(); //??????NRF24L01 ``<br />
<br />
POINT_COLOR=RED; //?è??×??????ì?? <br />
LCD_ShowString(60,50,200,16,16,"XYD 2014.01.16"); <br />
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST"); ; <br />
<br />
while(NRF24L01_Check()) //?ì?éNRF24L01??·?????. `0000000000.<br />
<br />
{<br />
LCD_ShowString(60,110,200,16,16,"NRF24L01 Error");<br />
delay_ms(200);<br />
LCD_Fill(60,130,239,130+16,WHITE);<br />
delay_ms(200);<br />
}<br />
<br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");<br />
<br />
while(1) //??????·??·?¨????????????!<br />
{<br />
<br />
delay_ms(10);<br />
if(oldcnt!=TIM3->CNT)<br />
<br />
{<br />
oldcnt=TIM3->CNT;<br />
LCD_ShowNum(0,280,oldcnt,8,16);<br />
} <br />
<br />
<br />
<br />
<br />
<br />
<br />
key=KEY_Scan(0);<br />
<br />
if(key == KEY_DOWN )<br />
{<br />
mode = 1;<br />
mode1 = 'A';<br />
<br />
if (mode == 1)//TX????<br />
{ <br />
<br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 TX_Mode1"); <br />
NRF24L01_TX_Mode();<br />
<br />
tmp_buf[0]=mode1; <br />
<br />
// tmp_buf[32]=0;//?????á??·?<br />
<br />
if(NRF24L01_TxPacket(tmp_buf) ==TX_OK ) //TX_OK)<br />
{<br />
LCD_ShowString(60,170,239,32,16,"Sended DATA1:"); <br />
LCD_ShowString(0,190,239,32,16,tmp_buf); <br />
} <br />
else<br />
{ <br />
LCD_ShowString(60,170,239,32,16,"Send Failed1 "); <br />
LCD_Fill(0,188,240,218,WHITE);//??????????????<br />
LED0=!LED0;<br />
<br />
} <br />
} <br />
}<br />
<br />
<br />
else if(key==KEY_RIGHT )<br />
{<br />
<br />
mode= 1 ;<br />
mode1 = 'B';<br />
<br />
if (mode == 1)//TX????<br />
{ <br />
<br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 TX_Mode2"); <br />
NRF24L01_TX_Mode();<br />
<br />
tmp_buf[0] = mode1;<br />
<br />
if(NRF24L01_TxPacket(tmp_buf) == TX_OK )<br />
{<br />
<br />
LCD_ShowString(60,170,239,32,16,"Sended DATA2:"); <br />
LCD_ShowString(0,190,239,32,16,tmp_buf); <br />
} <br />
else<br />
{ <br />
LCD_ShowString(60,170,239,32,16,"Send Failed2"); <br />
LCD_Fill(0,188,240,218,WHITE);//?????????????? <br />
LED1 =!LED1 ; <br />
} <br />
} <br />
<br />
}<br />
<br />
//LCD_ShowNum(0,280,right_motorspeed ,16,16);<br />
<br />
} <br />
<br />
LCD_Fill(10,150,240,166,WHITE);//?????????????? <br />
POINT_COLOR=BLUE;//?è??×????????? <br />
}<br />
<div>
<br />
</div>
<br />
<br />
<br />
// 2.4G 接收<br />
<br />
<br />
#include "sys.h"<br />
#include "usart.h" <br />
#include "delay.h" <br />
#include "led.h" <br />
#include "beep.h" <br />
#include "key.h" <br />
#include "exti.h" <br />
#include "wdg.h" <br />
#include "timer.h" <br />
#include "tpad.h"<br />
#include "oled.h" <br />
#include "lcd.h"<br />
#include "rtc.h" <br />
#include "wkup.h" <br />
#include "adc.h" <br />
#include "dac.h" <br />
#include "dma.h" <br />
#include "24cxx.h" <br />
#include "flash.h" <br />
#include "rs485.h" <br />
#include "can.h" <br />
#include "touch.h" <br />
#include "remote.h" <br />
#include "24l01.h"<br />
<br />
<br />
<br />
/*<br />
±????ò ?? 2.4G ???????ò ?±?????? ?? 'A' ?± ???°LED0 ????<br />
?±???? 'B ' ?± ???° LED1 ????<br />
<br />
?ó???????? SPI1 ?±?????? 'A ' ?±,???????? ??<br />
?±?????? ??B?® ?± ???????????? <br />
<br />
<br />
*/<br />
<br />
int main(void)<br />
{<br />
u8 key,mode = 0;<br />
u16 t=0; <br />
u8 tmp_buf[33];<br />
Stm32_Clock_Init(9); //?????±???è??<br />
delay_init(72); //???±?????? <br />
LCD_Init(); //??????LCD<br />
KEY_Init(); //°??ü??????<br />
LED_Init ();<br />
<br />
NRF24L01_Init(); //??????NRF24L01 ``<br />
<br />
POINT_COLOR=RED; //?è??×??????ì?? <br />
LCD_ShowString(60,50,200,16,16,"XYD 2014.01.16"); <br />
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST"); ; <br />
<br />
while(NRF24L01_Check()) //?ì?éNRF24L01??·?????. `0000000000.<br />
<br />
{<br />
LCD_ShowString(60,110,200,16,16,"NRF24L01 Error");<br />
delay_ms(200);<br />
LCD_Fill(60,130,239,130+16,WHITE);<br />
delay_ms(200);<br />
}<br />
<br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");<br />
<br />
<br />
// 2.4G ???????ò<br />
if(mode==0)//RX????<br />
{<br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 RX_Mode"); <br />
LCD_ShowString(60,170,200,16,16,"Received DATA:"); <br />
NRF24L01_RX_Mode(); <br />
while(1)<br />
{ <br />
if(NRF24L01_RxPacket(tmp_buf)==0)//???©??????????,?ò????????.<br />
{<br />
tmp_buf[32]=0; //????×?·??®?á??·?<br />
LCD_ShowString(0,190,239,32,16,tmp_buf);<br />
<br />
if(tmp_buf[0] == 'A')<br />
{<br />
LED0=!LED0; <br />
}<br />
else if(tmp_buf[0] == 'B' )<br />
{<br />
LED1 = !LED1;<br />
}<br />
<br />
}<br />
else ;<br />
<br />
delay_us(100); <br />
t++;<br />
if(t==10000)//?ó??1s????±?????×???<br />
{<br />
t=0;<br />
LED0=!LED0;<br />
}<br />
<br />
}; <br />
}<br />
<br />
<br />
}<br />
<br />
<br /> |
|