欢迎来到天天文库
浏览记录
ID:37512077
大小:35.00 KB
页数:7页
时间:2019-05-24
《NRF905无线模块程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、发射#include#include#defineuintunsignedint#defineucharunsignedcharsbitTX_EN=P3^5;sbitTRX_CE=P1^1;sbitPWR_UP=P3^4;sbitCD=P3^3;sbitAM=P1^3;sbitDR=P3^2;sbitMISO=P1^6;sbitMOSI=P1^4;sbitSCK=P1^7;sbitCSN=P1^5;sbitled=P3^0;sbitkey1=P1^2;sbitkey2
2、=P1^0;sbitkey3=P3^7;ucharkey_value=0;voidDelay(uintx){uinti;for(i=0;i3、(2);CSN=0;SpiWrite(0x22);//写发送地址,后面跟4字节地址//SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);CSN=1;Delay(2);CSN=0;SpiWrite(0x20);//写发送数据命令,后面跟三字节数据//SpiWrite(0x01);SpiWrite(0x02);SpiWrite(key_value);CSN=1;Delay(5);TRX_CE=1;//使能发射模式//Delay(500);//4、等带发送完成//TRX_CE=0;while(!DR);}////////////初始化配置寄存器////////////////voidIni_System(void){CSN=1;SCK=0;PWR_UP=1;TRX_CE=0;TX_EN=0;Delay(2);CSN=0;SpiWrite(0x00);//配置命令//SpiWrite(0x6C);//CH_NO,配置频段在433.2MHZSpiWrite(0x0C);//输出功率为10db,不重发,节电为正常模式SpiWrite(0x44);//地址宽5、度设置,为4字节SpiWrite(0x03);SpiWrite(0x03);//接收发送有效数据长度为3字节SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);//接收地址SpiWrite(0xDE);CSN=1;PWR_UP=1;TRX_CE=1;TX_EN=0;Delay(1000);}voidmain(void){Ini_System();DR=1;TRX_CE=0;Delay(1000);TX_EN=0;TRX_CE=1;PWR_U6、P=1;key_value=0x00;while(1){if(!key1)//senfingkey1{Delay(5);if(!key1){Delay(3);while(!key1);key_value=0xa0;}}elseif(!key2)//senfingkey2{Delay(5);if(!key2){Delay(3);while(!key2);key_value=0xa1;}}if(!key3)//senfingkey3{Delay(5);if(!key3){Delay(3);while(!key37、);key_value=0xa2;}}if(key_value!=0x00){led=0;TxPacket();key_value=0x00;TX_EN=0;TRX_CE=1;PWR_UP=1;Delay(6000);led=1;}}}接收#include#include#defineuintunsignedint#defineucharunsignedcharsbitTX_EN=P0^0;sbitTRX_CE=P0^1;sbitPWR_UP=P0^2;sbitCD=8、P0^3;sbitAM=P0^4;sbitDR=P0^5;sbitMISO=P0^6;sbitMOSI=P0^7;sbitSCK=P2^0;sbitCSN=P2^1;sbitled1=P1^1;sbitled2=P1^2;sbitled3=P1^3;ucharTxRxBuffer[3];bitsuccess_flag=0;voidDelay(uintx){uinti;for(i=0;i
3、(2);CSN=0;SpiWrite(0x22);//写发送地址,后面跟4字节地址//SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);CSN=1;Delay(2);CSN=0;SpiWrite(0x20);//写发送数据命令,后面跟三字节数据//SpiWrite(0x01);SpiWrite(0x02);SpiWrite(key_value);CSN=1;Delay(5);TRX_CE=1;//使能发射模式//Delay(500);//
4、等带发送完成//TRX_CE=0;while(!DR);}////////////初始化配置寄存器////////////////voidIni_System(void){CSN=1;SCK=0;PWR_UP=1;TRX_CE=0;TX_EN=0;Delay(2);CSN=0;SpiWrite(0x00);//配置命令//SpiWrite(0x6C);//CH_NO,配置频段在433.2MHZSpiWrite(0x0C);//输出功率为10db,不重发,节电为正常模式SpiWrite(0x44);//地址宽
5、度设置,为4字节SpiWrite(0x03);SpiWrite(0x03);//接收发送有效数据长度为3字节SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);SpiWrite(0xE7);//接收地址SpiWrite(0xDE);CSN=1;PWR_UP=1;TRX_CE=1;TX_EN=0;Delay(1000);}voidmain(void){Ini_System();DR=1;TRX_CE=0;Delay(1000);TX_EN=0;TRX_CE=1;PWR_U
6、P=1;key_value=0x00;while(1){if(!key1)//senfingkey1{Delay(5);if(!key1){Delay(3);while(!key1);key_value=0xa0;}}elseif(!key2)//senfingkey2{Delay(5);if(!key2){Delay(3);while(!key2);key_value=0xa1;}}if(!key3)//senfingkey3{Delay(5);if(!key3){Delay(3);while(!key3
7、);key_value=0xa2;}}if(key_value!=0x00){led=0;TxPacket();key_value=0x00;TX_EN=0;TRX_CE=1;PWR_UP=1;Delay(6000);led=1;}}}接收#include#include#defineuintunsignedint#defineucharunsignedcharsbitTX_EN=P0^0;sbitTRX_CE=P0^1;sbitPWR_UP=P0^2;sbitCD=
8、P0^3;sbitAM=P0^4;sbitDR=P0^5;sbitMISO=P0^6;sbitMOSI=P0^7;sbitSCK=P2^0;sbitCSN=P2^1;sbitled1=P1^1;sbitled2=P1^2;sbitled3=P1^3;ucharTxRxBuffer[3];bitsuccess_flag=0;voidDelay(uintx){uinti;for(i=0;i
此文档下载收益归作者所有