基于MSP430單片機(jī)驅(qū)動(dòng)NRF24L01無線模塊發(fā)送C語言程序 作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對(duì)面交流海量資料庫查詢 收藏 //void nRF24L01_TX_MODE(void){nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_CONFIG,0x5e);//Reflect TX_DRnRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_EN_AA,0x00);////Disable auto_acknowledgment,6 pipesnRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_EN_RXADDR,0x01);//Enabled RX Addresses.Enable data pipe 0nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_SETUP_AW,0x03);//RX/TX Address field width 5 bytes.nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_SETUP_RETR,0x00);//Re-Transmit disabled.nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_RF_CH,0x02);//RF Channel.nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_RF_SETUP,0x06);//Air Data Rate 1Mbps.RF_PWR:0dBm.LNA Gain 0.nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_RX_PW_P0,0x05);//Pipe0 1 Bytes Payload.nRF24L01SpiWriteReg(nRF24L01_W_REGISTER+nRF24L01_STATUS,0x2e);//Reset_Tx_DS}/******************************************************************************************************************///以下是液晶屏顯示程序void Write_command(uchar x){uchar b,i=0;Delayus(3);b=x;LCD_CS_1; //cs=1;LCD_D_1; //data=1;for(i=0;i<5;i++) //5 個(gè)連續(xù)1 11111{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} LCD_CLK_0; //clk=0LCD_D_0; //data=0;for(i=0;i<3;i++) //RS,RW,0 Rs="Rw"=0 //寫命令{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} ////////////////////////////////////上面是發(fā)送一個(gè)完整的啟動(dòng)數(shù)據(jù)11111000for(i=0;i<4;i++) //發(fā)送高4位{if((x&0x80)?1:0) //1LCD_D_1; //data=1;elseLCD_D_0; //data=0;LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1x=x<<1;}LCD_D_0; //data=0;for(i=0;i<4;i++) //RS,RW,0 發(fā)送4個(gè)0;{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} ////////////////////////////////////////////// for(i=0;i<4;i++) //發(fā)送低4位{if((b&0x08)?1:0) //1LCD_D_1; //data=1;elseLCD_D_0; //data=0;LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1b=b<<1;}LCD_D_0; //data=0;for(i=0;i<4;i++) //RS,RW,0 發(fā)送4個(gè)0;{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} LCD_CS_1; //cs=1;Delayus(15);}void Write_data(uchar x){uchar b,i=0;Delayus(3);b=x;LCD_CS_1; //cs=1;LCD_D_1; //data=1;for(i=0;i<5;i++) //5 個(gè)連續(xù)1 11111{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} LCD_CLK_0; //clk=0 //RW=0LCD_D_0; //data=0;LCD_CLK_1; //clk=1LCD_CLK_0; //clk=0 //RS=1LCD_D_1; //data=0;LCD_CLK_1; //clk=1LCD_CLK_0; //clk=0 //0LCD_D_0; //data=0;LCD_CLK_1; //clk=1////////////////////////////////////上面是發(fā)送一個(gè)完整的啟動(dòng)數(shù)據(jù)11111010for(i=0;i<4;i++) //發(fā)送高4位{if((x&0x80)?1:0) //1LCD_D_1; //data=1;elseLCD_D_0; //data=0;LCD_CLK_0; //clk=0LCD_CLK_1; //clk=1x=x<<1;}LCD_D_0; //data=0;for(i=0;i<4;i++) //RS,RW,0 發(fā)送4個(gè)0;{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} ////////////////////////////////////////////// for(i=0;i<4;i++) //發(fā)送低4位{if((b&0x08)?1:0) //1LCD_D_1; //data=1;elseLCD_D_0; //data=0;LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1b=b<<1;}LCD_D_0; //data=0;for(i=0;i<4;i++) //RS,RW,0 發(fā)送4個(gè)0;{LCD_CLK_0; //clk=0LCD_CLK_1; ; //clk=1} LCD_CS_1; //cs=1;Delayus(15);}void CLEAR(){Write_command(0x30);Write_command(0x01);Write_command(0x34);Write_command(0x30);}void drclear(void){//以下是清繪畫RAMuchar i,j;Write_command(0x34);for(j=0;j<32;j++){for(i=0;i<32;i++){tu[i][j]=0x00;}} for(j=0;j<32;j++){for(i=0;i<16;i++){tu[i][j]=0x00;Write_command(0x80+j); //設(shè)定垂直坐標(biāo)Write_command(0x80+i); //設(shè)定水平坐標(biāo)Write_data(0x00); //放入數(shù)據(jù)高字節(jié)Write_data(0x00); //放入數(shù)據(jù)低字節(jié)}} }void LCD_Init(){LCD_RST_0; //rst=0Delayus(100);LCD_RST_1; //rst=1Delayus(100);Write_command(0x30);Delayus(20);Write_command(0x30);Delayus(20);Write_command(0x30);Write_command(0x30);//--------------Write_command(0x0c);//Write_command(0x0C);Delayus(10);Write_command(0x01);Delayus(20);Write_command(0x06);/*//以下是清繪畫RAMuchar i,j;Write_command(0x34);for(j=0;j<32;j++){for(i=0;i<16;i++){Write_command(0x80+j); //設(shè)定垂直坐標(biāo)Write_command(0x80+i); //設(shè)定水平坐標(biāo)Write_data(0x00); //放入數(shù)據(jù)高字節(jié)Write_data(0x00); //放入數(shù)據(jù)低字節(jié)}} */}void writechar(uchar x, uint chinese){Write_command(0x30);Write_command(x);Write_data(chinese);}void writechinese(uchar x,const char *p){uint i;i=strlen(p);Write_command(x);for(;i;i--)Write_data(*(p++)); }void hexdisp(uchar f1){Write_data(0+f1+7*(f1/10));}void hex4(uint f2){uchar f1;f1=(f2&0xf000)>>12;hexdisp(f1);f1=(f2&0x0f00)>>8;hexdisp(f1);f1=(f2&0xf0)>>4;hexdisp(f1);f1=f2&0x0f;hexdisp(f1);}void liney(uchar x,uchar y,uchar l) //在(x,y)向下開始顯示長度為l(<=16)的豎線{uchar l1,i;uint x1=0x00,x2=0x00,ix=x/16;l1=x-ix*16;if (l1<8){x1=0x80>>l1;}else{x2=0x80>>(l1-8);}for (i=0;i>(l1+l2);x1=x1<>l1;x2=0xff<>(l2+l1-8);x2=x2<>l1;x2=0xff;}else{l2=l1-8;x1=0x00;x2=0xff>>l2;}if(l+l1<=24){l2=24-l-l1;x3=0xff<0;k--){c^=a&0x0001; //奇偶校驗(yàn)a=a>>1;}buffer=buffer|c;return buffer;} 上一頁 1 2 3 下一頁
評(píng)論