基于MSP430單片機(jī)驅(qū)動(dòng)NRF24L01無線模塊接收C語言程序 作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對(duì)面交流海量資料庫(kù)查詢 收藏 uint recieve_adrs(){int k,a;uint buffer1=0x0000,b=0x0000;Delayus(250);for(k=32;k>0;k--){alldata[k]=P2IN&0x02;Delayus(1000);}for(k=32;k>16;k--){a=alldata[k];a=a>>1;b=b|a;b=b<<15;buffer1=buffer1>>1;buffer1=buffer1|b;}return buffer1;}ulong recieve_data(){int k,a;ulong buffer2=0x0000,b=0x0000;for(k=16;k>0;k--){a=alldata[k];a=a>>1;b=b|a;b=b<<15;buffer2=buffer2>>1;buffer2=buffer2|b;}return buffer2;}/*************************************************************************///顯示數(shù)據(jù)void print_tmp(){ulong TEMP=0;int TEMPFLG=0;char TEMP1,TEMP2,TEMP3,TEMP4;TEMP = recieve_data()&0xfff8;if(TEMP>0x8000){TEMP=TEMP>>3;TEMP=TEMP<<3;TEMP=0xffff-TEMP+1;TEMPFLG=1;}TEMP = TEMP*10;TEMP = TEMP/128;// if( TEMP>35)//P1OUT &= ~BIT1;// Delayus_ms(700);TEMP1=char11[TEMP/1000];TEMP2=char11[TEMP%1000/100];TEMP3=char11[TEMP%100/10];TEMP4=char11[TEMP%10];if(TEMP1==0){ if(TEMP2==0){if(TEMPFLG==1)writechar(0x90,-);writechar(0x91,TEMP3);writechar(0x92,.);writechar(0x93,TEMP4);}else{if(TEMPFLG==1)writechar(0x90,-);writechar(0x91,TEMP2);writechar(0x92,TEMP3);writechar(0x93,.);writechar(0x94,TEMP4);}}else{if(TEMPFLG==1)writechar(0x90,-);writechar(0x91,TEMP1);writechar(0x92,TEMP2);writechar(0x93,TEMP3);writechar(0x94,.);writechar(0x95,TEMP4);}}void print_light(){ulong lgt;lgt=recieve_data()&0x0004;lgt=lgt>>2;if(lgt)writechinese(0x98,"暗");elsewritechinese(0x98,"亮");}void print_data(){uchar num;num=char11[Rx_Buff[0]];writechar(0x90,num);num=char11[Rx_Buff[1]];writechar(0x91,num);num=char11[Rx_Buff[2]];writechar(0x92,num);}/********************************************************************************///鍵盤void key_Init(){P5SEL = 0;P6SEL = 0;P6DIR|=0xff; //P6=OUTP5DIR=0x8b; //P5.2、4、5、6=in,P5.0、1、3、7=out}void key_read(){//第一排掃描P6OUT=0x18;Delayus(100);key0=P5IN&0x70 ;if (key0==0x30){key11=1;if(keyflg==0){CLEAR();writechinese(0x80,"單獨(dú)探測(cè)節(jié)點(diǎn)");writechinese(0x90,"1-選擇1#節(jié)點(diǎn)");writechinese(0x88,"2-選擇2#節(jié)點(diǎn)");writechinese(0x98,"g-返回主菜單");keyflg=1;}else if(keyflg==1){CLEAR();writechinese(0x80,"尋檢1#節(jié)點(diǎn)");writechinese(0x90,"d-確認(rèn),g-返回");keyflg=2;}Delayus(30000);}if (key0==0x40){key11=2;if(keyflg==0){CLEAR();writechinese(0x80,"輪尋模式");writechinese(0x90,"d-確認(rèn),g-返回");keyflg=4;}if(keyflg==1){CLEAR();writechinese(0x80,"尋檢2#節(jié)點(diǎn)");writechinese(0x90,"d-確認(rèn),g-返回");keyflg=3;}Delayus(30000);}if (key0==0x50){key11=3;Delayus(30000);}if (key0==0x60){Delayus(30000);key11=4;}//第二排掃描P6OUT=0x20;Delayus(100);key0=P5IN&0x70 ;if (key0==0x30){key11=5;Delayus(30000);}if (key0==0x40){key11=6;Delayus(30000);}if (key0==0x50){key11=7;Delayus(30000);}if (key0==0x60){key11=8;Delayus(30000);}//第三排掃描P6OUT=0x28;Delayus(100);key0=P5IN&0x70 ;if (key0==0x30){key11=9;Delayus(30000);}if (key0==0x40){key11=A;Delayus(30000);}if (key0==0x50){key11=B;Delayus(30000);}if (key0==0x60){key11=C;Delayus(30000);}//第四排掃描P6OUT=0x30;Delayus(100);key0=P5IN&0x70 ;if (key0==0x30){key11=D;if(keyflg==2){CLEAR();writechinese(0x80,"發(fā)送1#節(jié)點(diǎn)請(qǐng)求");send_bit1();send_adrs(0x0001);_EINT();//發(fā)送1號(hào)節(jié)點(diǎn)請(qǐng)求}if(keyflg==3){CLEAR();writechinese(0x80,"發(fā)送2#節(jié)點(diǎn)請(qǐng)求");send_bit1();send_adrs(0x0002);_EINT();//發(fā)送2號(hào)節(jié)點(diǎn)請(qǐng)求}if(keyflg==4){CLEAR();writechinese(0x80,"發(fā)送1#節(jié)點(diǎn)請(qǐng)求");send_bit1();send_adrs(0x0001);keyflg=2;Delayus(20000);writechinese(0x80,"發(fā)送2#節(jié)點(diǎn)請(qǐng)求");send_bit1();send_adrs(0x0002);keyflg=3;_EINT();}Delayus(30000);}if (key0==0x40){key11=E;Delayus(30000);}if (key0==0x50){key11=F;Delayus(30000);}if (key0==0x60){key11=G;CLEAR();writechinese(0x80,"江南大學(xué)");writechinese(0x90,"通信與控制工程");writechinese(0x88,"無線監(jiān)測(cè)模擬裝置");Delayus(100000);CLEAR();writechinese(0x80,"選擇接受模式");writechinese(0x90,"1-單獨(dú)探測(cè)節(jié)點(diǎn)");writechinese(0x88,"2-輪巡模式");keyflg=0;Delayus(30000);Init_nRF24L01_IO();}}void print1(ulong x){ulong cvt0,cvt1; int k,i;char data[10];cvt0=x;for(k=4,i=0;k>0;k--,i++){cvt1=cvt0&0x000f;data[i]=char11[cvt1%16];cvt0=cvt0>>4;}writechar(0x90,data[3]);writechar(0x91,data[2]);writechar(0x92,data[1]);writechar(0x93,data[0]);}/********************************************************************///主程序void main(void){WDTCTL=WDTPW+WDTHOLD;_DINT();Init_Port1();IO_Init();LCD_Init();CLEAR();key11=M;// LCDL=安;//漢字顯示示例writechinese(0x80,"江南大學(xué)");writechinese(0x90,"通信與控制工程");writechinese(0x88,"無線監(jiān)測(cè)模擬裝置");Delayus(100000);CLEAR();writechinese(0x80,"調(diào)試接收模式");//writechinese(0x90,"1-單獨(dú)探測(cè)節(jié)點(diǎn)");//writechinese(0x88,"2-輪巡模式");keyflg=0;bostart=0x00;boflg=0x00;key_Init();Init_nRF24L01_IO();nRF24L01_RX_MODE();nRF24L01_Set_Rx_Address(nRF24L01_W_REGISTER+nRF24L01_RX_ADDR_P0,Rx_Address,5);nRF24L01_Flush_RX_FIFO();nRF24L01_CE_1;_EINT();do{key11=w ;key_read();}while(1);}#pragma vector=PORT1_VECTOR__interrupt void P1_ISR(void){_DINT();P1IFG=0;P1IE=0;P1IES=0;Delayus(500);CLEAR();writechinese(0x80,"正在接收");// print_data();nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_STATUS,0x4e);//Reset_Rx_DSnRF24L01_Read_Rx_Payload(Rx_Buff,3);nRF24L01_Flush_RX_FIFO();print_data();IO_Init();Init_Port1();_EINT();} 上一頁(yè) 1 2 3 下一頁(yè)
評(píng)論