|
基于MSP430的NRF24L01 低功耗無(wú)線收發(fā)程序 用于低功耗的功耗測(cè)試
0.png (12.75 KB, 下載次數(shù): 91)
下載附件
2017-10-19 19:43 上傳
單片機(jī)源程序如下:
- //接收函數(shù),收到數(shù)據(jù)后,通過(guò)串口顯示,串口撥特率設(shè)置9600
- #include <msp430x14x.h>
- #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; //禁止看門(mén)狗
- init_uart0();
- keyIO_init(); // 普通IO 設(shè)置
-
- P2DIR = 0xff; //設(shè)置P2-BIT0口方向?yàn)檩敵?br />
- P2OUT = 0xfe; //點(diǎn)亮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; // 定時(shí)器初始化配置
- 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; // 裝載數(shù)據(jù)
- TxBuf[1] = 0x01; //(char)(adczhi>>8);
- TxBuf[2] = i;
-
-
- P6OUT &= ~BIT0; //mos管 打通
- init_NRF24L01T() ; //初始化NRF
- nRF24L01_TxPacket(TxBuf); // fasong 一個(gè)數(shù)據(jù)包
- SPI_RW_Reg(WRITE_REG+STATUS,0XFF); //清狀態(tài)寄存器
- Delay(85);//Delay(35);
- P6OUT |= BIT0; // 關(guān)閉mos管
-
- j=!j; i++;
- if(i==250) { i=0; }
-
-
- }
- else {
- TBCTL = TBSSEL_1 + MC_2;
- _BIS_SR(LPM3_bits +GIE); // 進(jìn)低功耗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;
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
fason duoci.zip
(126.18 KB, 下載次數(shù): 56)
2017-10-19 16:13 上傳
點(diǎn)擊文件名下載附件
NRF發(fā)送程序員 下載積分: 黑幣 -5
|
|