nRF2401RX.c
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:23k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. //-----------------------------------------------------------------------------
  2. // nRF2401RX.c
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2007 Vson Technology, Inc.
  5. // http://www.usbmcu.com
  6. //
  7. // Program Description:
  8. //
  9. //
  10. //
  11. //
  12. //
  13. // MCU:            C8051F347
  14. // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  15. //                 Silicon Laboratories IDE version 2.6
  16. // Command Line:   
  17. // Project Name:   TR1000
  18. //
  19. //
  20. // Release 1.0
  21. //    -All changes by Brin
  22. //    -24 JUL 2007
  23. //
  24. // 2007.10.19更改 1. 丢弃包序相同的数据——》丢弃ID相同且包序号相同的数据(建1K缓冲区存 ID号 包序号)
  25. // 
  26. #include "Include_H.h"
  27. #define _RF_PADLOAD_TEST_
  28. void nRF2401Configuration(void)
  29. {
  30.  unsigned char i;
  31.  /*==================================================*/
  32.  //config channeal 1
  33.  /*==================================================*/
  34.  //Configuration initial
  35.  //BS CONFIG_PORT,PWR_UP //
  36.  sbitRfCE1 = 0;
  37.  sbitRfCS1 = 0;//BC CONFIG_PORT,CS //CE==1
  38.  sbitRfCLK1 = 0;//BC CONFIG_PORT,CLK
  39.  sbitRfData1 = 0;//BC CONFIG_PORT,DIN
  40.  //Configuration initial end
  41.  sbitRfCS1 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
  42. //CALL Delay_5us //Tcs2data min. 5us
  43.  for (i = 0; i < 20; i++);    // Wait 5us 
  44.  Channel1Write8bitData(RF_CONFIG_DATA14);
  45.  Channel1Write8bitData(RF_CONFIG_DATA13);
  46.  Channel1Write8bitData(RF_CONFIG_DATA12);
  47.  Channel1Write8bitData(RF_CONFIG_DATA11);
  48.  Channel1Write8bitData(RF_CONFIG_DATA10);
  49.  Channel1Write8bitData(RF_CONFIG_DATA9);
  50.  Channel1Write8bitData(RF_CONFIG_DATA8);
  51.  Channel1Write8bitData(RF_CONFIG_DATA7);
  52.  Channel1Write8bitData(RF_CONFIG_DATA6);
  53.  Channel1Write8bitData(RF_CONFIG_DATA5);
  54.  Channel1Write8bitData(RF_CONFIG_DATA4);
  55.  Channel1Write8bitData(RF_CONFIG_DATA3);
  56.  Channel1Write8bitData(RF_CONFIG_DATA2);
  57.  Channel1Write8bitData(RF_CONFIG_DATA1);
  58.  Channel1Write8bitData(gaucRfConfigData0[0]);//(RF_CONFIG_DATA00);
  59.  
  60.  for (i = 0; i < 20; i++);    // Wait 5us
  61.  sbitRfCS1 = 0;  //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
  62.  sbitRfData1 = 0; //BC CONFIG_PORT,DIN //Remain low
  63.  sbitRfCE1 = 1; //BS CONFIG_PORT,CE
  64.  for (i = 0; i < 200; i++);    // Wait 5us
  65.   
  66. /*==================================================*/
  67. //config channeal 2
  68. /*==================================================*/
  69.  
  70.  //Configuration initial
  71.  //BS CONFIG_PORT,PWR_UP //
  72.  sbitRfCE2 = 0;
  73.  sbitRfCS2 = 0;//BC CONFIG_PORT,CS //CE==1
  74.  sbitRfCLK2 = 0;//BC CONFIG_PORT,CLK
  75.  sbitRfData2 = 0;//BC CONFIG_PORT,DIN
  76.  //Configuration initial end
  77.  sbitRfCS2 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
  78. //CALL Delay_5us //Tcs2data min. 5us
  79.  for (i = 0; i < 20; i++);    // Wait 5us 
  80.  Channel2Write8bitData(RF_CONFIG_DATA14);
  81.  Channel2Write8bitData(RF_CONFIG_DATA13);
  82.  Channel2Write8bitData(RF_CONFIG_DATA12);
  83.  Channel2Write8bitData(RF_CONFIG_DATA11);
  84.  Channel2Write8bitData(RF_CONFIG_DATA10);
  85.  Channel2Write8bitData(RF_CONFIG_DATA9);
  86.  Channel2Write8bitData(RF_CONFIG_DATA8);
  87.  Channel2Write8bitData(RF_CONFIG_DATA7);
  88.  Channel2Write8bitData(RF_CONFIG_DATA6);
  89.  Channel2Write8bitData(RF_CONFIG_DATA5);
  90.  Channel2Write8bitData(RF_CONFIG_DATA4);
  91.  Channel2Write8bitData(RF_CONFIG_DATA3);
  92.  Channel2Write8bitData(RF_CONFIG_DATA2);
  93.  Channel2Write8bitData(RF_CONFIG_DATA1);
  94.  Channel2Write8bitData(gaucRfConfigData0[1]);//(RF_CONFIG_DATA00);
  95.  
  96.  for (i = 0; i < 20; i++);    // Wait 5us
  97.  sbitRfCS2 = 0;  //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
  98.  sbitRfData2 = 0; //BC CONFIG_PORT,DIN //Remain low
  99.  sbitRfCE2 = 1; //BS CONFIG_PORT,CE
  100. //***********************************************************
  101.  for (i = 0; i < 200; i++);    // Wait 5us
  102. /*==================================================*/
  103. //config channeal 3
  104. /*==================================================*/
  105.  //Configuration initial
  106.  //BS CONFIG_PORT,PWR_UP //
  107.  sbitRfCE3 = 0;
  108.  sbitRfCS3 = 0;//BC CONFIG_PORT,CS //CE==1
  109.  sbitRfCLK3 = 0;//BC CONFIG_PORT,CLK
  110.  sbitRfData3 = 0;//BC CONFIG_PORT,DIN
  111.  //Configuration initial end
  112.  sbitRfCS3 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
  113. //CALL Delay_5us //Tcs2data min. 5us
  114.  for (i = 0; i < 20; i++);    // Wait 5us 
  115.  Channel3Write8bitData(RF_CONFIG_DATA14);
  116.  Channel3Write8bitData(RF_CONFIG_DATA13);
  117.  Channel3Write8bitData(RF_CONFIG_DATA12);
  118.  Channel3Write8bitData(RF_CONFIG_DATA11);
  119.  Channel3Write8bitData(RF_CONFIG_DATA10);
  120.  Channel3Write8bitData(RF_CONFIG_DATA9);
  121.  Channel3Write8bitData(RF_CONFIG_DATA8);
  122.  Channel3Write8bitData(RF_CONFIG_DATA7);
  123.  Channel3Write8bitData(RF_CONFIG_DATA6);
  124.  Channel3Write8bitData(RF_CONFIG_DATA5);
  125.  Channel3Write8bitData(RF_CONFIG_DATA4);
  126.  Channel3Write8bitData(RF_CONFIG_DATA3);
  127.  Channel3Write8bitData(RF_CONFIG_DATA2);
  128.  Channel3Write8bitData(RF_CONFIG_DATA1);
  129.  Channel3Write8bitData(gaucRfConfigData0[2]);//(RF_CONFIG_DATA00);
  130.  
  131.  for (i = 0; i < 20; i++);    // Wait 5us
  132.  sbitRfCS3 = 0;  //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
  133.  sbitRfData3 = 0; //BC CONFIG_PORT,DIN //Remain low
  134.  sbitRfCE3 = 1; //BS CONFIG_PORT,CE
  135. //***********************************************************
  136.  for (i = 0; i < 200; i++);    // Wait 5us
  137. /*==================================================*/
  138. //config channeal 4
  139. /*==================================================*/
  140.  //Configuration initial
  141.  //BS CONFIG_PORT,PWR_UP //
  142.  sbitRfCE4 = 0;
  143.  sbitRfCS4 = 0;//BC CONFIG_PORT,CS //CE==1
  144.  sbitRfCLK4 = 0;//BC CONFIG_PORT,CLK
  145.  sbitRfData4 = 0;//BC CONFIG_PORT,DIN
  146.  //Configuration initial end
  147.  sbitRfCS4 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
  148. //CALL Delay_5us //Tcs2data min. 5us
  149.  for (i = 0; i < 20; i++);    // Wait 5us 
  150.  Channel4Write8bitData(RF_CONFIG_DATA14);
  151.  Channel4Write8bitData(RF_CONFIG_DATA13);
  152.  Channel4Write8bitData(RF_CONFIG_DATA12);
  153.  Channel4Write8bitData(RF_CONFIG_DATA11);
  154.  Channel4Write8bitData(RF_CONFIG_DATA10);
  155.  Channel4Write8bitData(RF_CONFIG_DATA9);
  156.  Channel4Write8bitData(RF_CONFIG_DATA8);
  157.  Channel4Write8bitData(RF_CONFIG_DATA7);
  158.  Channel4Write8bitData(RF_CONFIG_DATA6);
  159.  Channel4Write8bitData(RF_CONFIG_DATA5);
  160.  Channel4Write8bitData(RF_CONFIG_DATA4);
  161.  Channel4Write8bitData(RF_CONFIG_DATA3);
  162.  Channel4Write8bitData(RF_CONFIG_DATA2);
  163.  Channel4Write8bitData(RF_CONFIG_DATA1);
  164.  Channel4Write8bitData(gaucRfConfigData0[3]);//(RF_CONFIG_DATA00);
  165.  
  166.  for (i = 0; i < 20; i++);    // Wait 5us
  167.  sbitRfCS4 = 0;  //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
  168.  sbitRfData4 = 0; //BC CONFIG_PORT,DIN //Remain low
  169.  sbitRfCE4 = 1; //BS CONFIG_PORT,CE
  170. //***********************************************************
  171. }
  172. //====================================================
  173. //====================================================
  174. //Low for ready Data High for Write Data
  175. //时序 Low  8 LowHigh Low
  176. void Channel1Write8bitData(unsigned char ucWriteData)
  177. {
  178.      unsigned char ucGeneralCount=0;
  179.      unsigned char i;
  180.      //__disable_interrupt();
  181.      
  182.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  183.      {
  184.         sbitRfCLK1 = 0;
  185.         for (i = 0; i < 1; i++);    // Wait 0.5us
  186.         if ((ucWriteData & BIT7) == BIT7)
  187.           {sbitRfData1 = 1;} //set   DATA bit
  188.         else
  189.           {sbitRfData1 = 0;} //reset DATA bit
  190.         for (i = 0; i < 1; i++);    // Wait 0.5us
  191.         sbitRfCLK1 = 1;
  192.         for (i = 0; i < 2; i++);    // Wait 1us
  193.         ucWriteData=ucWriteData<<1;  //MSB   
  194.      }
  195.      sbitRfCLK1 = 0;// for last low
  196.      //sbitRfData1 = 0;
  197.      //_EINT();                             //enable interrupt   
  198. }
  199. //====================================================
  200. //====================================================
  201. //Low for ready Data High for Write Data
  202. //时序 Low  8 LowHigh Low
  203. void Channel2Write8bitData(unsigned char ucWriteData)
  204. {
  205.      unsigned char ucGeneralCount=0;
  206.      unsigned char i;
  207.      //__disable_interrupt();
  208.      
  209.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  210.      {
  211.         sbitRfCLK2 = 0;
  212.         for (i = 0; i < 1; i++);    // Wait 0.5us
  213.         if ((ucWriteData & BIT7) == BIT7)
  214.           {sbitRfData2 = 1;} //set   DATA bit
  215.         else
  216.           {sbitRfData2 = 0;} //reset DATA bit
  217.         for (i = 0; i < 1; i++);    // Wait 0.5us
  218.         sbitRfCLK2 = 1;
  219.         for (i = 0; i < 2; i++);    // Wait 1us
  220.         ucWriteData=ucWriteData<<1;  //MSB   
  221.      }
  222.      sbitRfCLK2 = 0;// for last low
  223.      //sbitRfData2 = 0;
  224.      //_EINT();                             //enable interrupt   
  225. }
  226. //====================================================
  227. //====================================================
  228. //Low for ready Data High for Write Data
  229. //时序 Low  8 LowHigh Low
  230. void Channel3Write8bitData(unsigned char ucWriteData)
  231. {
  232.      unsigned char ucGeneralCount=0;
  233.      unsigned char i;
  234.      //__disable_interrupt();
  235.      
  236.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  237.      {
  238.         sbitRfCLK3 = 0;
  239.         for (i = 0; i < 1; i++);    // Wait 0.5us
  240.         if ((ucWriteData & BIT7) == BIT7)
  241.           {sbitRfData3 = 1;} //set   DATA bit
  242.         else
  243.           {sbitRfData3 = 0;} //reset DATA bit
  244.         for (i = 0; i < 1; i++);    // Wait 0.5us
  245.         sbitRfCLK3 = 1;
  246.         for (i = 0; i < 2; i++);    // Wait 1us
  247.         ucWriteData=ucWriteData<<1;  //MSB   
  248.      }
  249.      sbitRfCLK3 = 0;// for last low
  250.      //sbitRfData3 = 0;
  251.      //_EINT();                             //enable interrupt   
  252. }
  253. //====================================================
  254. //====================================================
  255. //Low for ready Data High for Write Data
  256. //时序 Low  8 LowHigh Low
  257. void Channel4Write8bitData(unsigned char ucWriteData)
  258. {
  259.      unsigned char ucGeneralCount=0;
  260.      unsigned char i;
  261.      //__disable_interrupt();
  262.      
  263.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  264.      {
  265.         sbitRfCLK4 = 0;
  266.         for (i = 0; i < 1; i++);    // Wait 0.5us
  267.         if ((ucWriteData & BIT7) == BIT7)
  268.           {sbitRfData4 = 1;} //set   DATA bit
  269.         else
  270.           {sbitRfData4 = 0;} //reset DATA bit
  271.         for (i = 0; i < 1; i++);    // Wait 0.5us
  272.         sbitRfCLK4 = 1;
  273.         for (i = 0; i < 2; i++);    // Wait 1us
  274.         ucWriteData=ucWriteData<<1;  //MSB   
  275.      }
  276.      sbitRfCLK4 = 0;// for last low
  277.      //sbitRfData4 = 0;
  278.      //_EINT();                             //enable interrupt   
  279. }
  280. //============================================================================================
  281. //
  282. //============================================================================================
  283. bit nRF2401RxData(void)
  284. {
  285.  unsigned char i;
  286. // unsigned int j;
  287.  bit bitReceivedDataFlag = 0;
  288.  //ShockBurst TX initial
  289.  //sbitRfCE1 = 1;
  290.  //sbitRfCS1 = 0;//BC CONFIG_PORT,CS
  291.  //sbitRfCLK1 = 0;//BC CONFIG_PORT,CLK
  292.  //sbitRfData1 = 0;//BC CONFIG_PORT,DIN
  293.  //ShockBurst TX initial end
  294.  //for (i = 0; i < 20; i++);    // Wait 5us //Tce2data min. 5us
  295. for (i = 0; i < 1; i++)
  296. {
  297. //==================================================================
  298. //Channel 1
  299. //==================================================================
  300. // for (i = 0; i < 1; i++)
  301. // {
  302.    //if ( (sbitRfDR1 == 1) | (sbitRfDR2 == 1) | (sbitRfDR3 == 1) | (sbitRfDR4 == 1) )
  303.    if (sbitRfDR1 == 1)//(bitReceivedDataFlag == 0)//(sbitRfDR1 == 1)
  304.    {
  305.       
  306.   sbitLED = 0;
  307.   //Receive_data_start:
  308.       
  309.   //DelayMs(5);
  310.       /*
  311.   for (j = 0; j < 20000; j++)    // Wait 5us
  312.   {
  313.     for (i = 0; i < 200; i++)
  314.      {;}
  315.   }
  316.   */
  317.   //StartTimer2(10); //200ms //收到数据,启动计时200ms 
  318.   //StartTimer2(20); //200ms //收到数据,启动计时200ms //modify at 2007.11.19
  319.   StartTimer2(40); //200ms //收到数据,启动计时200ms //modify at 2007.11.30
  320.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel1Read8bitData();
  321.   
  322.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel1Read8bitData();
  323.   
  324.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel1Read8bitData();
  325.   
  326.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel1Read8bitData();
  327.   
  328.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel1Read8bitData();
  329.   
  330.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel1Read8bitData();
  331.       
  332.     gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel1Read8bitData();
  333.     
  334.     #ifndef  _RF_PADLOAD_TEST_
  335.     //#define _RF_PADLOAD_TEST_
  336.     gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel1Read8bitData();
  337.     
  338.     gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel1Read8bitData();
  339.     
  340.     #endif
  341.     
  342.       //#ifndef  _USB_REQUEST_H
  343.       //Channel1Read8bitData();
  344.       
  345.       
  346.   while( sbitRfDR1 == 1 )
  347.   {
  348.     ;
  349.   }
  350.   
  351.       sbitLED = 1;
  352.       //DelayMs(100);
  353.       bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
  354.     
  355.  
  356. }//if
  357.        
  358. if (bitReceivedDataFlag == 1)
  359.    break;
  360.  //}//for
  361. /*
  362. //==================================================================
  363. //Channel 2
  364. //==================================================================
  365.  //for (i = 0; i < 1; i++)
  366.  //{
  367.    if (sbitRfDR2 == 1)
  368.    {
  369.       sbitLED = 0;
  370.   //Receive_data_start:
  371.       
  372.   DelayMs(5);
  373.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel2Read8bitData();
  374.   
  375.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel2Read8bitData();
  376.   
  377.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel2Read8bitData();
  378.   
  379.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel2Read8bitData();
  380.   
  381.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel2Read8bitData();
  382.   
  383.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel2Read8bitData();
  384.   
  385.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel2Read8bitData();
  386.       
  387.       #ifndef  _RF_PADLOAD_TEST_
  388.       
  389.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel2Read8bitData();
  390.   
  391.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel2Read8bitData();
  392.       
  393.       #endif
  394.       
  395.   while( sbitRfDR2 == 1 )
  396.   {
  397.     ;
  398.   }
  399.   
  400.       sbitLED = 1;
  401.       //DelayMs(100);
  402.       bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
  403.     
  404.  
  405. }//if
  406.     
  407. if (bitReceivedDataFlag == 1)
  408.    break;
  409.  //}//for
  410.  //DelayMs(1);
  411. //=========================================================================
  412. //Channel 3
  413. //=========================================================================
  414. // for (i = 0; i < 1; i++)
  415. // {
  416.    if (sbitRfDR3 == 1)//(bitReceivedDataFlag == 0)//
  417.    {
  418.       sbitLED = 0;
  419.   //Receive_data_start:
  420.       
  421.   DelayMs(5);
  422.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel3Read8bitData();
  423.   
  424.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel3Read8bitData();
  425.   
  426.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel3Read8bitData();
  427.   
  428.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel3Read8bitData();
  429.   
  430.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel3Read8bitData();
  431.   
  432.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel3Read8bitData();
  433.   
  434.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel3Read8bitData();
  435.       
  436.       #ifndef  _RF_PADLOAD_TEST_
  437.       
  438.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel3Read8bitData();
  439.   
  440.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel3Read8bitData();
  441.       
  442.       #endif
  443.       
  444.   while( sbitRfDR3 == 1 )
  445.   {
  446.     ;
  447.   }
  448.   
  449.       sbitLED = 1;
  450.       //DelayMs(100);
  451.       bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
  452.     
  453.  
  454. }//if
  455.     if (bitReceivedDataFlag == 1)
  456.    break;
  457. // }//for
  458. //=========================================================================
  459. //Channel 4
  460. //=========================================================================
  461. // for (i = 0; i < 1; i++)
  462. // {
  463.    if (sbitRfDR4 == 1)
  464.    {
  465.       sbitLED = 0;
  466.   //Receive_data_start:
  467.       
  468.   DelayMs(5);
  469.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel4Read8bitData();
  470.   
  471.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel4Read8bitData();
  472.   
  473.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel4Read8bitData();
  474.   
  475.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel4Read8bitData();
  476.   
  477.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel4Read8bitData();
  478.   
  479.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel4Read8bitData();
  480.   
  481.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel4Read8bitData();
  482.       
  483.       #ifndef  _RF_PADLOAD_TEST_
  484.       
  485.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel4Read8bitData();
  486.   
  487.       gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel4Read8bitData();
  488.       
  489.       #endif
  490.       
  491.   while( sbitRfDR4 == 1 )
  492.   {
  493.     ;
  494.   }
  495.   
  496.       sbitLED = 1;
  497.       //DelayMs(100);
  498.       bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
  499.     
  500.  
  501. }//if
  502.     
  503.   
  504.     
  505. if (bitReceivedDataFlag == 1)
  506.    break;
  507.  //}//for
  508. */ 
  509. }//for
  510. //=============================================================================================
  511.  
  512.  if (bitReceivedDataFlag == 1)
  513.    { 
  514.      //数据格式:地址2,地址1,地址0,数据3,数据2,数据1,数据0 地址2最高位bit7--0:学生机 1:教师机
  515.  if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
  516.    {
  517.      //1:教师机
  518.  if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] & BIT7) == BIT7)
  519.          M_State = TX_TEACHER_KEY_DATA_TO_HOST_STATUS;
  520.  else 
  521.          M_State = TX_TOUCHPAD_DATA_TO_HOST_STATUS;
  522.         }
  523.       else
  524.     {
  525.   //0:学生机
  526.           
  527.       //数据3 bit7--1:有后续包 0:最后一包 bit6--1:考试数据 0:按键数据
  528.   if ( (gaucRxDataFromRfBuffer[5] & BIT6) == BIT6 )
  529.     {
  530.       M_State = TX_STUDENT_EXAM_DATA_TO_HOST_STATUS;
  531.     }
  532.   else
  533.     {
  534.   M_State = TX_STUDENT_KEY_DATA_TO_HOST_STATUS;
  535.     }
  536.   
  537. }
  538.     }
  539.  return bitReceivedDataFlag;
  540. }
  541. //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
  542. //CLK时序: Low 8个HighLow Low 
  543. unsigned char Channel1Read8bitData(void)
  544. {
  545.      unsigned char ucGeneralCount=0;
  546.      unsigned char ucReadData=0;
  547.      unsigned char i;
  548.  //unsigned char j=0;
  549.      //__disable_interrupt();
  550.      sbitRfCLK1 = 0;
  551.      //j = P2MDOUT;
  552.  //j = P2;
  553.  //j = P0;
  554.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  555.      {
  556.         
  557.         ucReadData = ucReadData<<1;//MSB
  558.         sbitRfCLK1 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
  559.         for (i = 0; i < 1; i++);    // Wait 2.5us
  560.         if (sbitRfData1 == 1)
  561.           {ucReadData |= BIT0;} //bit 1
  562.         else
  563.           {ucReadData &= ~BIT0;} // bit is 0
  564.         //for (i = 0; i < 1; i++);    // Wait 2.5us  
  565.         for (i = 0; i < 1; i++);    // Wait 2.5us
  566.     sbitRfCLK1 = 0;
  567.         for (i = 0; i < 2; i++);    // Wait 2.5us
  568.       }
  569.  return ucReadData;
  570. }
  571. /*
  572. //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
  573. //CLK时序: Low 8个HighLow Low 
  574. unsigned char Channel2Read8bitData(void)
  575. {
  576.      unsigned char ucGeneralCount=0;
  577.      unsigned char ucReadData=0;
  578.      unsigned char i;
  579.  //unsigned char j=0;
  580.      //__disable_interrupt();
  581.      sbitRfCLK2 = 0;
  582.      //j = P2MDOUT;
  583.  //j = P2;
  584.  //j = P0;
  585.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  586.      {
  587.         
  588.         ucReadData=ucReadData<<1;//MSB
  589.         sbitRfCLK2 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
  590.         for (i = 0; i < 1; i++);    // Wait 2.5us
  591.         if (sbitRfData2 == 1)
  592.           {ucReadData |= BIT0;} //bit 1
  593.         else
  594.           {ucReadData &= ~BIT0;} // bit is 0
  595.         //for (i = 0; i < 1; i++);    // Wait 2.5us  
  596.         for (i = 0; i < 1; i++);    // Wait 2.5us
  597. sbitRfCLK2 = 0;
  598.         for (i = 0; i < 2; i++);    // Wait 2.5us
  599.       }
  600.  return ucReadData;
  601. }
  602. //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
  603. //CLK时序: Low 8个HighLow Low 
  604. unsigned char Channel3Read8bitData(void)
  605. {
  606.      unsigned char ucGeneralCount=0;
  607.      unsigned char ucReadData=0;
  608.      unsigned char i;
  609.  //unsigned char j=0;
  610.      //__disable_interrupt();
  611.      sbitRfCLK3 = 0;
  612.      //j = P2MDOUT;
  613.  //j = P2;
  614.  //j = P0;
  615.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  616.      {
  617.         
  618.         ucReadData=ucReadData<<1;//MSB
  619.         sbitRfCLK3 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
  620.         for (i = 0; i < 1; i++);    // Wait 2.5us
  621.         if (sbitRfData3 == 1)
  622.           {ucReadData |= BIT0;} //bit 1
  623.         else
  624.           {ucReadData &= ~BIT0;} // bit is 0
  625.         //for (i = 0; i < 1; i++);    // Wait 2.5us  
  626.         for (i = 0; i < 1; i++);    // Wait 2.5us
  627. sbitRfCLK3 = 0;
  628.         for (i = 0; i < 2; i++);    // Wait 2.5us
  629.       }
  630.  return ucReadData;
  631. }
  632. //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
  633. //CLK时序: Low 8个HighLow Low 
  634. unsigned char Channel4Read8bitData(void)
  635. {
  636.      unsigned char ucGeneralCount=0;
  637.      unsigned char ucReadData=0;
  638.      unsigned char i;
  639.  //unsigned char j=0;
  640.      //__disable_interrupt();
  641.      sbitRfCLK4 = 0;
  642.      //j = P2MDOUT;
  643.  //j = P2;
  644.  //j = P0;
  645.      for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
  646.      {
  647.         
  648.         ucReadData=ucReadData<<1;//MSB
  649.         sbitRfCLK4 = 1;// ;Time Hold min.500ns
  650.         for (i = 0; i < 1; i++);    // Wait 2.5us
  651.         if (sbitRfData4 == 1)
  652.           {ucReadData |= BIT0;} //bit 1
  653.         else
  654.           {ucReadData &= ~BIT0;} // bit is 0
  655.         //for (i = 0; i < 1; i++);    // Wait 2.5us  
  656.         for (i = 0; i < 1; i++);    // Wait 2.5us
  657. sbitRfCLK4 = 0;
  658.         for (i = 0; i < 2; i++);    // Wait 2.5us
  659.       }
  660.  return ucReadData;
  661. }
  662. */
  663. //-----------------------------------------------------------------------------
  664. // End Of File
  665. //-----------------------------------------------------------------------------