OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2028|回复: 1

智能小车 2.4G 控制 接收和发送

[复制链接]

12

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
125
金钱
125
注册时间
2015-3-26
在线时间
14 小时
发表于 2015-7-14 23:04:53 | 显示全部楼层 |阅读模式
//发送<br />
#include "sys.h"<br />
#include "usart.h" <br />
#include "delay.h" <br />
#include "led.h"&nbsp;<br />
#include "beep.h"                 &nbsp;<br />
#include "key.h"                 &nbsp;<br />
#include "exti.h"                 &nbsp;<br />
#include "wdg.h"         &nbsp;<br />
#include "timer.h"                         &nbsp;<br />
#include "tpad.h"<br />
#include "oled.h"                         &nbsp;<br />
#include "lcd.h"<br />
#include "rtc.h"                 &nbsp;<br />
#include "wkup.h" <br />
#include "adc.h"         &nbsp;<br />
#include "dac.h"         &nbsp;<br />
#include "dma.h"         &nbsp;<br />
#include "24cxx.h"         &nbsp;<br />
#include "flash.h"         &nbsp;<br />
#include "rs485.h"         &nbsp;<br />
#include "can.h"         &nbsp;<br />
#include "touch.h"         &nbsp;<br />
#include "remote.h"         &nbsp;<br />
#include "24l01.h"<br />
<br />
/*&nbsp;<br />
<br />
&nbsp; ±????ò &nbsp;?? 2.4G??·??????ò &nbsp; mode =?&reg;A?&reg; ?± &nbsp; &nbsp;????????&nbsp;<br />
&nbsp; mode = 'B ' ?± &nbsp; &nbsp; ?????????? &nbsp;spi2&nbsp;<br />
&nbsp;&nbsp;<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;                &nbsp;<br />
u8 tmp_buf[32]={0};<br />
&nbsp;        Stm32_Clock_Init(9);        //?????±???è??<br />
delay_init(72);         &nbsp;                  //???±??????&nbsp;<br />
LCD_Init();                         &nbsp;         //??????LCD<br />
&nbsp;        KEY_Init();        //°??ü??????<br />
<br />
LED_Init ();<br />
<br />
//TIM2_Excnt_Init(999,7199);<br />
TIM3_CH2_Excnt_Init(0xffff,0);<br />
&nbsp;        NRF24L01_Init(); &nbsp; &nbsp;        //??????NRF24L01 ``<br />
<br />
&nbsp;        POINT_COLOR=RED; &nbsp; &nbsp; &nbsp; //?è??×??????ì??&nbsp;<br />
LCD_ShowString(60,50,200,16,16,"XYD 2014.01.16"); <br />
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST");        ; <br />
&nbsp;&nbsp;<br />
&nbsp;        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 />
&nbsp;                delay_ms(200);<br />
}<br />
<br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");<br />
<br />
&nbsp;        while(1) &nbsp; &nbsp;//??????·??·?¨????????????!<br />
{<br />
<br />
delay_ms(10);<br />
if(oldcnt!=TIM3-&gt;CNT)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldcnt=TIM3-&gt;CNT;<br />
LCD_ShowNum(0,280,oldcnt,8,16);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<br />
<br />
<br />
<br />
<br />
<br />
<br />
key=KEY_Scan(0);<br />
<br />
if(key == KEY_DOWN &nbsp;)<br />
{<br />
mode = 1;<br />
mode1 = 'A';<br />
<br />
if (mode == 1)//TX????<br />
{ &nbsp; <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 />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<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 />
}&nbsp;<br />
else<br />
{                                                                                 &nbsp; <br />
LCD_ShowString(60,170,239,32,16,"Send Failed1 ");&nbsp;<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 />
{ &nbsp; <br />
<br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 TX_Mode2"); <br />
NRF24L01_TX_Mode();<br />
<br />
tmp_buf[0] = mode1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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 />
}&nbsp;<br />
else<br />
{                                                                                 &nbsp; <br />
LCD_ShowString(60,170,239,32,16,"Send Failed2");&nbsp;<br />
LCD_Fill(0,188,240,218,WHITE);//??????????????                         &nbsp;&nbsp;<br />
&nbsp; &nbsp;LED1 =!LED1 ; <br />
} <br />
} <br />
<br />
}<br />
<br />
//LCD_ShowNum(0,280,right_motorspeed ,16,16);<br />
&nbsp;<br />
}&nbsp;<br />
<br />
&nbsp;        LCD_Fill(10,150,240,166,WHITE);//??????????????                 &nbsp;<br />
&nbsp;        POINT_COLOR=BLUE;//?è??×?????????         &nbsp;<br />
}<br />
<div>
        <br />
</div>
<br />
<br />
<br />
// &nbsp;2.4G 接收<br />
<br />
<br />
#include "sys.h"<br />
#include "usart.h" <br />
#include "delay.h" <br />
#include "led.h"&nbsp;<br />
#include "beep.h"                 &nbsp;<br />
#include "key.h"                 &nbsp;<br />
#include "exti.h"                 &nbsp;<br />
#include "wdg.h"         &nbsp;<br />
#include "timer.h"                         &nbsp;<br />
#include "tpad.h"<br />
#include "oled.h"                         &nbsp;<br />
#include "lcd.h"<br />
#include "rtc.h"                 &nbsp;<br />
#include "wkup.h" <br />
#include "adc.h"         &nbsp;<br />
#include "dac.h"         &nbsp;<br />
#include "dma.h"         &nbsp;<br />
#include "24cxx.h"         &nbsp;<br />
#include "flash.h"         &nbsp;<br />
#include "rs485.h"         &nbsp;<br />
#include "can.h"         &nbsp;<br />
#include "touch.h"         &nbsp;<br />
#include "remote.h"         &nbsp;<br />
#include "24l01.h"<br />
<br />
<br />
<br />
/*<br />
&nbsp; &nbsp; ±????ò ?? &nbsp;2.4G &nbsp;???????ò &nbsp; ?±?????? &nbsp;?? &nbsp;'A' &nbsp; ?± &nbsp;???°LED0 ????<br />
?±???? 'B ' &nbsp;?± &nbsp;???° LED1 ????<br />
<br />
?ó???????? &nbsp;SPI1 &nbsp; &nbsp; ?±?????? &nbsp;'A &nbsp;' ?±,???????? ??<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?±?????? &nbsp;??B?&reg; ?± ???????????? <br />
<br />
<br />
*/<br />
<br />
int main(void)<br />
{<br />
u8 key,mode = 0;<br />
u16 t=0;                        &nbsp;<br />
u8 tmp_buf[33];<br />
&nbsp;        Stm32_Clock_Init(9);        //?????±???è??<br />
delay_init(72);         &nbsp;                  //???±??????&nbsp;<br />
LCD_Init();                         &nbsp;         //??????LCD<br />
&nbsp;        KEY_Init();                                //°??ü??????<br />
LED_Init ();<br />
<br />
&nbsp;        NRF24L01_Init(); &nbsp; &nbsp;        //??????NRF24L01 ``<br />
<br />
&nbsp;        POINT_COLOR=RED; &nbsp; &nbsp; &nbsp; //?è??×??????ì??&nbsp;<br />
LCD_ShowString(60,50,200,16,16,"XYD 2014.01.16"); <br />
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST");        ; <br />
&nbsp;&nbsp;<br />
&nbsp;        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 />
&nbsp;                delay_ms(200);<br />
}<br />
<br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");<br />
<br />
<br />
// &nbsp; 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();                 &nbsp;<br />
while(1)<br />
{         &nbsp;<br />
if(NRF24L01_RxPacket(tmp_buf)==0)//???&copy;??????????,?ò????????.<br />
{<br />
tmp_buf[32]=0; &nbsp;//????×?·??&reg;?á??·?<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);         &nbsp;&nbsp;<br />
t++;<br />
if(t==10000)//?ó??1s????±?????×???<br />
{<br />
t=0;<br />
LED0=!LED0;<br />
}<br />
<br />
}; <br />
}<br />
<br />
<br />
}<br />
<br />
<br />
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2015-7-14 23:16:26 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-23 12:44

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表