1、#include /=#define uchar unsigned char#define uint unsigned int#define uclong unsigned long/=TXEN,TRX_CE,PWR_0 为收发模式控制端口=#define TXEN_0 P6OUT char TxAddress4=0xcc,0xcc,0xcc,0xcc;char DATA_BUF;/=NRF905:10 寄存器配置=unsigned char RFConf11=WC, /SPI 写操作命令0x4c, /CH_NO,配置频段在 430MHZ0x0C, /输出功率为 10db,不重发,节电为正常模
2、式0x44, /地址宽度设置,为 4 字节0x20,0x20, /接收发送有效数据长度为 32 字节0xCC,0xCC,0xCC,0xCC, /接收地址0x58, /CRC 充许,8 位 CRC 校验,外部时钟信号不使能,16M 晶振;/*系统初始化*/void InitSys()unsigned int iq0;_DINT();BCSCTL1 doIFG1 / 清除振荡器失效标志for (iq0 = 0xFF; iq0 0; iq0-); / 延时,等待 XT2 起振while (IFG1 / 判断 XT2 是否起振BCSCTL2 =SELM1+SELS; /MCLK,SMCLK 时钟为 X
3、T2/?USART0/=初始化nRF905=void nRF905_IO_set(void)P6DIR |= 0x07; P6DIR P6SEL P2DIR |= 0xFF; P2DIR P2SEL P5DIR |= 0xC0; P5DIR |= 0xFB; P5SEL CSN_1; / Spi disableSCK_0; / Spi clock line init lowPWR_1; / nRF905 power onTRX_CE_0; / Set nRF905 in standby modeTXEN_0; / set radio in Rx mode/=void LED_IO_set(vo
4、id) / P6DIR |= BIT2;P6OUT |= BIT2; /关闭电平转换 /=延时=void Delay(uchar n)uint i;while(n-)for(i=0;i=650us)/=数据发送=void TX(void)SetTxMode();TxPacket();/=主函数=void main(void) WDTCTL = WDTPW + WDTHOLD; /禁止看门狗InitSys();nRF905_IO_set();LED_IO_set();Config905();LED1_1 ; LED2_1 ;while(1)TX(); P2OUT=P6OUT;Delay(200); Delay(200); Delay(200);LED1_0 ; Delay(200); Delay(200); Delay(200); Delay(200); Delay(200); LED1_1;