⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2401.c

📁 2.4G无线数传模块nrf2401的c51程序
💻 C
字号:
#include <reg51.h>
sbit PWR_UP = P3^4; 
sbit CE  = P1^0; 
sbit CS  = P1^2; 
sbit DR1 = P3^0; 
sbit CLK = P1^3; 
sbit DATA = P3^1; 
sbit led = P2^0; 
void delay( int dly); 
void clock(void);
void Recieve(void)
{
      int i=0;
      unsigned int temp=0x00;
    PWR_UP = 1;
    CE = 0 ;
    CS = 0;    
    delay(2);
    CE=1;
    delay(2);
      DR1=1;
      DATA=1;
      while(1)
      {temp=0x00;
           if(DR1==1)
           {
           for(i=0;i<8;i++)
          {
              temp=temp << 1;
              clock();
                if(DATA)
                  temp=temp | 0x01;
            }
			P0=temp;
            }
			delay(1);
			
      }

}
void clock(void)
{                                       
CLK=0;
  delay(2);
CLK=1;
  delay(1);
}

void delay( int dly) 
{
  int count;   
  while(dly != 0) 
  {
     count=1;
    while(count>0)   
      count--;     
  dly--; 
}       
}                              
void configuration(void)
{
    int i,j;
      int temp=0x00;
      int config_word[18];
      config_word[0]=0x8e;
      config_word[1]=0x08;
      config_word[2]=0x1c;
      config_word[3]=0x08;
      config_word[4]=0x08;
      config_word[5]=0xCC;   /* */
      config_word[6]=0xCC;
      config_word[7]=0xCC;
      config_word[8]=0xCC;   /**/
      config_word[9]=0xE7;
      config_word[10]=0xCC;
      config_word[11]=0xCC;
      config_word[12]=0xCC;
      config_word[13]=0xCC;       
      config_word[14]=0xE7;
      config_word[15]=0x21;
      config_word[16]=0x6f;       
      config_word[17]=0x05;
    PWR_UP=0;
    CS=0;
    CE=0;
    PWR_UP=1;
     delay(10);
      CS=1;
      delay(2);
      for(i=0;i<18;i++)
      {
        temp= config_word[i];
           for(j=0;j<8;j++)
           {
              if(temp&0x80)
              DATA=1;
              else
              DATA=0;
              delay(1);
              clock();
              delay(1);
              temp=temp << 1;
           }


      }
        CS=0;
      delay(1);
}
main()
{int i;
configuration();    
  delay(1); 
Recieve();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -