iap15w4k58s4,摇杆采集,AD采集,通过NRF24L01发送数据
单片机源程序如下:
- #include <STC15F2K60S2.H>
- #include <intrins.h>
- #include "NRF24L01.H"
- #include "AD.H"
- #include"51_ADXL345.h"
- int yaogan,yaogan1;
- uchar rece_buf[32];
- void main()
- {
-
- // P0M0 = 0x00;
- // P0M1 = 0x00;
- // P1M0 = 0x00;
- // P1M1 = 0x00;
- // P3M0 = 0x00;
- // P3M1 = 0x00;
- InitADC();
- //ADXL345_Init();
- NRF24L01_RT_Init();
- //LED =1;
- while(1)
- {
- yaogan=GetADCResult(0)*4+ADC_RESL;
- yaogan1=GetADCResult(1)*4+ADC_RESL;
- if(yaogan>750) //判断x轴是否大于750
-
- {
- /***************前进******************************************/
- rece_buf[1]='G';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- if(yaogan1>750)//x,y轴都大于750前进并且左转
- {
- rece_buf[1]='L';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- if((yaogan1<750)&&(yaogan1>400));break;
- }
- if(yaogan1<400) //x>750,y轴都<400前进并且右转
- {
- rece_buf[1]='R';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- if((yaogan1<750)&&(yaogan1>400));break;
- }
-
- }
- /***********************后退******************************/
- if((yaogan<400)) //判断x轴是否小于400
- {
- rece_buf[1]='B';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;;
-
- if(yaogan1>750)//x<400,y轴大于750后退并且左转
- {
- rece_buf[1]='Q';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- if((yaogan1<750)&&(yaogan1>400));break;
- }
- if(yaogan1<400) //x,y轴都<400后退并且右转
- {
- rece_buf[1]='W';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- if((yaogan1<750)&&(yaogan1>400));break;
- }
- }
- /************************停止**********************/
- if((yaogan>400)&&(yaogan<750))//判断Y轴,Y轴不动,若是进入循环发送前进
- {
- rece_buf[1]='S';
- SEND_BUF(rece_buf);
- LED=0;
- NRF24L01_RT_Init();
- LED=1;
- }
- }
- }
复制代码
所有资料51hei提供下载:
遥控器1-最终.zip
(61.76 KB, 下载次数: 85)
|