|
MSP430的NRF24L01 低功耗无线收发程序
[复制链接]
单片机源程序如下:
- //接收函数,收到数据后,通过串口显示,串口拨特率设置9600
- #include
- #include "stdio.h"
- #include "common.h"
- #include "nrf2401.h"
- #include "key.h"
- #include "adc.h"
- #include "oled.h"
- #include "cc1101.h"
- unsigned int adczhi;
- unsigned char adl,adh,key;
- char fasonflag,cishuflag;
- char RxBuf[32]=
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- char TxBuf[32]=
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- void main()
- {
- InitSys();
- WDTCTL = WDTPW + WDTHOLD; //禁止看门狗
- init_uart0();
- keyIO_init(); // 普通IO 设置
- P2DIR = 0xff; //设置P2-BIT0口方向为输出
- P2OUT = 0xfe; //点亮D1
- unsigned char i=0;
- int j=0;
- RF24L01_IO_set();
- P6OUT &= ~BIT0;
- init_NRF24L01T() ; nRF24L01_TxPacket(TxBuf); // Transmit Tx buffer data
- // init_NRF24L01R() ;
- ADC_init ();
- OLED_Init(); //初始化OLED
- OLED_Clear(); //oled 清屏
- OLED_ShowString(0,0,"hello word");
- TBCCTL0 = CCIE; // 定时器初始化配置
- TBCCR0 = 65535;
- TBCTL = TBSSEL_1 + MC_2; // SMCLK, contmode
- _EINT();
- _BIS_SR( LPM3_bits + GIE); // Enter LPM0 w/ interrupt
- P2OUT = 0xbb;
- P2DIR = 0xff;
- P2OUT = 0xff;
- P3DIR = 0xff;
- P3OUT = 0xff;
- P4DIR = 0xff;
- P4OUT = 0xff;
- P5DIR = 0xff;
- P5OUT = 0xff;
- while(1)
- {
- if( fasonflag==1 )
- {
- adczhi = get_ADC () ; // 读取AD值
- // OLED_ShowString(0,3,"adc");
- // OLED_ShowChar(40,3,adczhi/1000+0x30);
- // OLED_ShowChar(50,3,adczhi%1000/100+0x30);
- // OLED_ShowChar(60,3,adczhi%100/10+0x30);
- // OLED_ShowChar(70,3,adczhi%10+0x30);
- TxBuf[0] = 0x01; //(char)adczhi; // 装载数据
- TxBuf[1] = 0x01; //(char)(adczhi>>8);
- TxBuf[2] = i;
- P6OUT &= ~BIT0; //mos管 打通
- init_NRF24L01T() ; //初始化NRF
- nRF24L01_TxPacket(TxBuf); // fasong 一个数据包
- SPI_RW_Reg(WRITE_REG+STATUS,0XFF); //清状态寄存器
- Delay(85);//Delay(35);
- P6OUT |= BIT0; // 关闭mos管
- j=!j; i++;
- if(i==250) { i=0; }
- }
- else {
- TBCTL = TBSSEL_1 + MC_2;
- _BIS_SR(LPM3_bits +GIE); // 进低功耗3
- // _BIS_SR(LPM3_bits +GIE);
- }
- }
- }
- // Timer B0 interrupt service routine
- #pragma vector=TIMERB0_VECTOR
- __interrupt void Timer_B (void)
- {
- //_BIS_SR( 0x0000 + GIE); // Enter LPM0 w/ interrupt
- // TACTL = TASSEL_2 +ID_3 + MC_0;
- ……………………
|
|