nRF2401RX.c
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:23k
- //-----------------------------------------------------------------------------
- // nRF2401RX.c
- //-----------------------------------------------------------------------------
- // Copyright 2007 Vson Technology, Inc.
- // http://www.usbmcu.com
- //
- // Program Description:
- //
- //
- //
- //
- //
- // MCU: C8051F347
- // Tool chain: Keil C51 7.50 / Keil EVAL C51
- // Silicon Laboratories IDE version 2.6
- // Command Line:
- // Project Name: TR1000
- //
- //
- // Release 1.0
- // -All changes by Brin
- // -24 JUL 2007
- //
- // 2007.10.19更改 1. 丢弃包序相同的数据——》丢弃ID相同且包序号相同的数据(建1K缓冲区存 ID号 包序号)
- //
- #include "Include_H.h"
- #define _RF_PADLOAD_TEST_
- void nRF2401Configuration(void)
- {
- unsigned char i;
- /*==================================================*/
- //config channeal 1
- /*==================================================*/
- //Configuration initial
- //BS CONFIG_PORT,PWR_UP //
- sbitRfCE1 = 0;
- sbitRfCS1 = 0;//BC CONFIG_PORT,CS //CE==1
- sbitRfCLK1 = 0;//BC CONFIG_PORT,CLK
- sbitRfData1 = 0;//BC CONFIG_PORT,DIN
- //Configuration initial end
- sbitRfCS1 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
- //CALL Delay_5us //Tcs2data min. 5us
- for (i = 0; i < 20; i++); // Wait 5us
- Channel1Write8bitData(RF_CONFIG_DATA14);
- Channel1Write8bitData(RF_CONFIG_DATA13);
- Channel1Write8bitData(RF_CONFIG_DATA12);
- Channel1Write8bitData(RF_CONFIG_DATA11);
- Channel1Write8bitData(RF_CONFIG_DATA10);
- Channel1Write8bitData(RF_CONFIG_DATA9);
- Channel1Write8bitData(RF_CONFIG_DATA8);
- Channel1Write8bitData(RF_CONFIG_DATA7);
- Channel1Write8bitData(RF_CONFIG_DATA6);
- Channel1Write8bitData(RF_CONFIG_DATA5);
- Channel1Write8bitData(RF_CONFIG_DATA4);
- Channel1Write8bitData(RF_CONFIG_DATA3);
- Channel1Write8bitData(RF_CONFIG_DATA2);
- Channel1Write8bitData(RF_CONFIG_DATA1);
- Channel1Write8bitData(gaucRfConfigData0[0]);//(RF_CONFIG_DATA00);
-
- for (i = 0; i < 20; i++); // Wait 5us
- sbitRfCS1 = 0; //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
- sbitRfData1 = 0; //BC CONFIG_PORT,DIN //Remain low
- sbitRfCE1 = 1; //BS CONFIG_PORT,CE
- for (i = 0; i < 200; i++); // Wait 5us
-
- /*==================================================*/
- //config channeal 2
- /*==================================================*/
-
- //Configuration initial
- //BS CONFIG_PORT,PWR_UP //
- sbitRfCE2 = 0;
- sbitRfCS2 = 0;//BC CONFIG_PORT,CS //CE==1
- sbitRfCLK2 = 0;//BC CONFIG_PORT,CLK
- sbitRfData2 = 0;//BC CONFIG_PORT,DIN
- //Configuration initial end
- sbitRfCS2 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
- //CALL Delay_5us //Tcs2data min. 5us
- for (i = 0; i < 20; i++); // Wait 5us
- Channel2Write8bitData(RF_CONFIG_DATA14);
- Channel2Write8bitData(RF_CONFIG_DATA13);
- Channel2Write8bitData(RF_CONFIG_DATA12);
- Channel2Write8bitData(RF_CONFIG_DATA11);
- Channel2Write8bitData(RF_CONFIG_DATA10);
- Channel2Write8bitData(RF_CONFIG_DATA9);
- Channel2Write8bitData(RF_CONFIG_DATA8);
- Channel2Write8bitData(RF_CONFIG_DATA7);
- Channel2Write8bitData(RF_CONFIG_DATA6);
- Channel2Write8bitData(RF_CONFIG_DATA5);
- Channel2Write8bitData(RF_CONFIG_DATA4);
- Channel2Write8bitData(RF_CONFIG_DATA3);
- Channel2Write8bitData(RF_CONFIG_DATA2);
- Channel2Write8bitData(RF_CONFIG_DATA1);
- Channel2Write8bitData(gaucRfConfigData0[1]);//(RF_CONFIG_DATA00);
-
- for (i = 0; i < 20; i++); // Wait 5us
- sbitRfCS2 = 0; //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
- sbitRfData2 = 0; //BC CONFIG_PORT,DIN //Remain low
- sbitRfCE2 = 1; //BS CONFIG_PORT,CE
-
- //***********************************************************
- for (i = 0; i < 200; i++); // Wait 5us
- /*==================================================*/
- //config channeal 3
- /*==================================================*/
- //Configuration initial
- //BS CONFIG_PORT,PWR_UP //
- sbitRfCE3 = 0;
- sbitRfCS3 = 0;//BC CONFIG_PORT,CS //CE==1
- sbitRfCLK3 = 0;//BC CONFIG_PORT,CLK
- sbitRfData3 = 0;//BC CONFIG_PORT,DIN
- //Configuration initial end
- sbitRfCS3 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
- //CALL Delay_5us //Tcs2data min. 5us
- for (i = 0; i < 20; i++); // Wait 5us
- Channel3Write8bitData(RF_CONFIG_DATA14);
- Channel3Write8bitData(RF_CONFIG_DATA13);
- Channel3Write8bitData(RF_CONFIG_DATA12);
- Channel3Write8bitData(RF_CONFIG_DATA11);
- Channel3Write8bitData(RF_CONFIG_DATA10);
- Channel3Write8bitData(RF_CONFIG_DATA9);
- Channel3Write8bitData(RF_CONFIG_DATA8);
- Channel3Write8bitData(RF_CONFIG_DATA7);
- Channel3Write8bitData(RF_CONFIG_DATA6);
- Channel3Write8bitData(RF_CONFIG_DATA5);
- Channel3Write8bitData(RF_CONFIG_DATA4);
- Channel3Write8bitData(RF_CONFIG_DATA3);
- Channel3Write8bitData(RF_CONFIG_DATA2);
- Channel3Write8bitData(RF_CONFIG_DATA1);
- Channel3Write8bitData(gaucRfConfigData0[2]);//(RF_CONFIG_DATA00);
-
- for (i = 0; i < 20; i++); // Wait 5us
- sbitRfCS3 = 0; //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
- sbitRfData3 = 0; //BC CONFIG_PORT,DIN //Remain low
- sbitRfCE3 = 1; //BS CONFIG_PORT,CE
-
- //***********************************************************
- for (i = 0; i < 200; i++); // Wait 5us
- /*==================================================*/
- //config channeal 4
- /*==================================================*/
- //Configuration initial
- //BS CONFIG_PORT,PWR_UP //
- sbitRfCE4 = 0;
- sbitRfCS4 = 0;//BC CONFIG_PORT,CS //CE==1
- sbitRfCLK4 = 0;//BC CONFIG_PORT,CLK
- sbitRfData4 = 0;//BC CONFIG_PORT,DIN
- //Configuration initial end
- sbitRfCS4 = 1;//BS CONFIG_PORT,CS //entry configuration mode ce==0
- //CALL Delay_5us //Tcs2data min. 5us
- for (i = 0; i < 20; i++); // Wait 5us
- Channel4Write8bitData(RF_CONFIG_DATA14);
- Channel4Write8bitData(RF_CONFIG_DATA13);
- Channel4Write8bitData(RF_CONFIG_DATA12);
- Channel4Write8bitData(RF_CONFIG_DATA11);
- Channel4Write8bitData(RF_CONFIG_DATA10);
- Channel4Write8bitData(RF_CONFIG_DATA9);
- Channel4Write8bitData(RF_CONFIG_DATA8);
- Channel4Write8bitData(RF_CONFIG_DATA7);
- Channel4Write8bitData(RF_CONFIG_DATA6);
- Channel4Write8bitData(RF_CONFIG_DATA5);
- Channel4Write8bitData(RF_CONFIG_DATA4);
- Channel4Write8bitData(RF_CONFIG_DATA3);
- Channel4Write8bitData(RF_CONFIG_DATA2);
- Channel4Write8bitData(RF_CONFIG_DATA1);
- Channel4Write8bitData(gaucRfConfigData0[3]);//(RF_CONFIG_DATA00);
-
- for (i = 0; i < 20; i++); // Wait 5us
- sbitRfCS4 = 0; //BC CONFIG_PORT,CS //After finish configuration mode,Entry stanby mode
- sbitRfData4 = 0; //BC CONFIG_PORT,DIN //Remain low
- sbitRfCE4 = 1; //BS CONFIG_PORT,CE
-
- //***********************************************************
- }
- //====================================================
- //====================================================
- //Low for ready Data High for Write Data
- //时序 Low 8 LowHigh Low
- void Channel1Write8bitData(unsigned char ucWriteData)
- {
- unsigned char ucGeneralCount=0;
- unsigned char i;
- //__disable_interrupt();
-
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- sbitRfCLK1 = 0;
- for (i = 0; i < 1; i++); // Wait 0.5us
- if ((ucWriteData & BIT7) == BIT7)
- {sbitRfData1 = 1;} //set DATA bit
- else
- {sbitRfData1 = 0;} //reset DATA bit
- for (i = 0; i < 1; i++); // Wait 0.5us
- sbitRfCLK1 = 1;
- for (i = 0; i < 2; i++); // Wait 1us
- ucWriteData=ucWriteData<<1; //MSB
- }
- sbitRfCLK1 = 0;// for last low
- //sbitRfData1 = 0;
- //_EINT(); //enable interrupt
- }
- //====================================================
- //====================================================
- //Low for ready Data High for Write Data
- //时序 Low 8 LowHigh Low
- void Channel2Write8bitData(unsigned char ucWriteData)
- {
- unsigned char ucGeneralCount=0;
- unsigned char i;
- //__disable_interrupt();
-
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- sbitRfCLK2 = 0;
- for (i = 0; i < 1; i++); // Wait 0.5us
- if ((ucWriteData & BIT7) == BIT7)
- {sbitRfData2 = 1;} //set DATA bit
- else
- {sbitRfData2 = 0;} //reset DATA bit
- for (i = 0; i < 1; i++); // Wait 0.5us
- sbitRfCLK2 = 1;
- for (i = 0; i < 2; i++); // Wait 1us
- ucWriteData=ucWriteData<<1; //MSB
- }
- sbitRfCLK2 = 0;// for last low
- //sbitRfData2 = 0;
- //_EINT(); //enable interrupt
- }
- //====================================================
- //====================================================
- //Low for ready Data High for Write Data
- //时序 Low 8 LowHigh Low
- void Channel3Write8bitData(unsigned char ucWriteData)
- {
- unsigned char ucGeneralCount=0;
- unsigned char i;
- //__disable_interrupt();
-
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- sbitRfCLK3 = 0;
- for (i = 0; i < 1; i++); // Wait 0.5us
- if ((ucWriteData & BIT7) == BIT7)
- {sbitRfData3 = 1;} //set DATA bit
- else
- {sbitRfData3 = 0;} //reset DATA bit
- for (i = 0; i < 1; i++); // Wait 0.5us
- sbitRfCLK3 = 1;
- for (i = 0; i < 2; i++); // Wait 1us
- ucWriteData=ucWriteData<<1; //MSB
- }
- sbitRfCLK3 = 0;// for last low
- //sbitRfData3 = 0;
- //_EINT(); //enable interrupt
- }
- //====================================================
- //====================================================
- //Low for ready Data High for Write Data
- //时序 Low 8 LowHigh Low
- void Channel4Write8bitData(unsigned char ucWriteData)
- {
- unsigned char ucGeneralCount=0;
- unsigned char i;
- //__disable_interrupt();
-
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- sbitRfCLK4 = 0;
- for (i = 0; i < 1; i++); // Wait 0.5us
- if ((ucWriteData & BIT7) == BIT7)
- {sbitRfData4 = 1;} //set DATA bit
- else
- {sbitRfData4 = 0;} //reset DATA bit
- for (i = 0; i < 1; i++); // Wait 0.5us
- sbitRfCLK4 = 1;
- for (i = 0; i < 2; i++); // Wait 1us
- ucWriteData=ucWriteData<<1; //MSB
- }
- sbitRfCLK4 = 0;// for last low
- //sbitRfData4 = 0;
- //_EINT(); //enable interrupt
- }
- //============================================================================================
- //
- //============================================================================================
- bit nRF2401RxData(void)
- {
- unsigned char i;
- // unsigned int j;
- bit bitReceivedDataFlag = 0;
- //ShockBurst TX initial
- //sbitRfCE1 = 1;
- //sbitRfCS1 = 0;//BC CONFIG_PORT,CS
- //sbitRfCLK1 = 0;//BC CONFIG_PORT,CLK
- //sbitRfData1 = 0;//BC CONFIG_PORT,DIN
- //ShockBurst TX initial end
- //for (i = 0; i < 20; i++); // Wait 5us //Tce2data min. 5us
- for (i = 0; i < 1; i++)
- {
- //==================================================================
- //Channel 1
- //==================================================================
- // for (i = 0; i < 1; i++)
- // {
- //if ( (sbitRfDR1 == 1) | (sbitRfDR2 == 1) | (sbitRfDR3 == 1) | (sbitRfDR4 == 1) )
- if (sbitRfDR1 == 1)//(bitReceivedDataFlag == 0)//(sbitRfDR1 == 1)
- {
-
- sbitLED = 0;
- //Receive_data_start:
-
- //DelayMs(5);
- /*
- for (j = 0; j < 20000; j++) // Wait 5us
- {
- for (i = 0; i < 200; i++)
- {;}
- }
- */
- //StartTimer2(10); //200ms //收到数据,启动计时200ms
- //StartTimer2(20); //200ms //收到数据,启动计时200ms //modify at 2007.11.19
- StartTimer2(40); //200ms //收到数据,启动计时200ms //modify at 2007.11.30
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel1Read8bitData();
-
- #ifndef _RF_PADLOAD_TEST_
- //#define _RF_PADLOAD_TEST_
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel1Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel1Read8bitData();
-
- #endif
-
- //#ifndef _USB_REQUEST_H
- //Channel1Read8bitData();
-
-
- while( sbitRfDR1 == 1 )
- {
- ;
- }
-
- sbitLED = 1;
- //DelayMs(100);
- bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
-
-
- }//if
-
- if (bitReceivedDataFlag == 1)
- break;
- //}//for
- /*
- //==================================================================
- //Channel 2
- //==================================================================
- //for (i = 0; i < 1; i++)
- //{
- if (sbitRfDR2 == 1)
- {
- sbitLED = 0;
- //Receive_data_start:
-
- DelayMs(5);
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel2Read8bitData();
-
- #ifndef _RF_PADLOAD_TEST_
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel2Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel2Read8bitData();
-
- #endif
-
- while( sbitRfDR2 == 1 )
- {
- ;
- }
-
- sbitLED = 1;
- //DelayMs(100);
- bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
-
-
- }//if
-
- if (bitReceivedDataFlag == 1)
- break;
- //}//for
- //DelayMs(1);
- //=========================================================================
- //Channel 3
- //=========================================================================
- // for (i = 0; i < 1; i++)
- // {
- if (sbitRfDR3 == 1)//(bitReceivedDataFlag == 0)//
- {
- sbitLED = 0;
- //Receive_data_start:
-
- DelayMs(5);
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel3Read8bitData();
-
- #ifndef _RF_PADLOAD_TEST_
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel3Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel3Read8bitData();
-
- #endif
-
- while( sbitRfDR3 == 1 )
- {
- ;
- }
-
- sbitLED = 1;
- //DelayMs(100);
- bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
-
-
- }//if
- if (bitReceivedDataFlag == 1)
- break;
- // }//for
- //=========================================================================
- //Channel 4
- //=========================================================================
- // for (i = 0; i < 1; i++)
- // {
- if (sbitRfDR4 == 1)
- {
- sbitLED = 0;
- //Receive_data_start:
-
- DelayMs(5);
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 1] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 2] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 4] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 5] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 6] = Channel4Read8bitData();
-
- #ifndef _RF_PADLOAD_TEST_
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 7] = Channel4Read8bitData();
-
- gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 8] = Channel4Read8bitData();
-
- #endif
-
- while( sbitRfDR4 == 1 )
- {
- ;
- }
-
- sbitLED = 1;
- //DelayMs(100);
- bitReceivedDataFlag = 1; //Set flag for quit the Check Circle
-
-
- }//if
-
-
-
- if (bitReceivedDataFlag == 1)
- break;
- //}//for
- */
- }//for
- //=============================================================================================
-
- if (bitReceivedDataFlag == 1)
- {
- //数据格式:地址2,地址1,地址0,数据3,数据2,数据1,数据0 地址2最高位bit7--0:学生机 1:教师机
- if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- {
- //1:教师机
- if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 3] & BIT7) == BIT7)
- M_State = TX_TEACHER_KEY_DATA_TO_HOST_STATUS;
- else
- M_State = TX_TOUCHPAD_DATA_TO_HOST_STATUS;
- }
- else
- {
- //0:学生机
-
- //数据3 bit7--1:有后续包 0:最后一包 bit6--1:考试数据 0:按键数据
- if ( (gaucRxDataFromRfBuffer[5] & BIT6) == BIT6 )
- {
- M_State = TX_STUDENT_EXAM_DATA_TO_HOST_STATUS;
- }
- else
- {
- M_State = TX_STUDENT_KEY_DATA_TO_HOST_STATUS;
- }
-
- }
- }
- return bitReceivedDataFlag;
- }
- //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
- //CLK时序: Low 8个HighLow Low
- unsigned char Channel1Read8bitData(void)
- {
- unsigned char ucGeneralCount=0;
- unsigned char ucReadData=0;
- unsigned char i;
- //unsigned char j=0;
- //__disable_interrupt();
- sbitRfCLK1 = 0;
- //j = P2MDOUT;
- //j = P2;
- //j = P0;
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
-
- ucReadData = ucReadData<<1;//MSB
-
-
- sbitRfCLK1 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
- for (i = 0; i < 1; i++); // Wait 2.5us
- if (sbitRfData1 == 1)
- {ucReadData |= BIT0;} //bit 1
- else
- {ucReadData &= ~BIT0;} // bit is 0
- //for (i = 0; i < 1; i++); // Wait 2.5us
- for (i = 0; i < 1; i++); // Wait 2.5us
-
- sbitRfCLK1 = 0;
- for (i = 0; i < 2; i++); // Wait 2.5us
-
- }
- return ucReadData;
- }
- /*
- //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
- //CLK时序: Low 8个HighLow Low
- unsigned char Channel2Read8bitData(void)
- {
- unsigned char ucGeneralCount=0;
- unsigned char ucReadData=0;
- unsigned char i;
- //unsigned char j=0;
- //__disable_interrupt();
- sbitRfCLK2 = 0;
- //j = P2MDOUT;
- //j = P2;
- //j = P0;
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
-
- ucReadData=ucReadData<<1;//MSB
-
-
- sbitRfCLK2 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
- for (i = 0; i < 1; i++); // Wait 2.5us
- if (sbitRfData2 == 1)
- {ucReadData |= BIT0;} //bit 1
- else
- {ucReadData &= ~BIT0;} // bit is 0
- //for (i = 0; i < 1; i++); // Wait 2.5us
- for (i = 0; i < 1; i++); // Wait 2.5us
-
- sbitRfCLK2 = 0;
- for (i = 0; i < 2; i++); // Wait 2.5us
-
- }
- return ucReadData;
- }
- //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
- //CLK时序: Low 8个HighLow Low
- unsigned char Channel3Read8bitData(void)
- {
- unsigned char ucGeneralCount=0;
- unsigned char ucReadData=0;
- unsigned char i;
- //unsigned char j=0;
- //__disable_interrupt();
- sbitRfCLK3 = 0;
- //j = P2MDOUT;
- //j = P2;
- //j = P0;
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
-
- ucReadData=ucReadData<<1;//MSB
-
-
- sbitRfCLK3 = 1;//BS CONFIG_PORT,CLK ;Time Hold min.500ns
- for (i = 0; i < 1; i++); // Wait 2.5us
- if (sbitRfData3 == 1)
- {ucReadData |= BIT0;} //bit 1
- else
- {ucReadData &= ~BIT0;} // bit is 0
- //for (i = 0; i < 1; i++); // Wait 2.5us
- for (i = 0; i < 1; i++); // Wait 2.5us
-
- sbitRfCLK3 = 0;
- for (i = 0; i < 2; i++); // Wait 2.5us
-
- }
- return ucReadData;
- }
- //nRF2401 ready Data when CLK is Low; Mcu read data when CLK is high
- //CLK时序: Low 8个HighLow Low
- unsigned char Channel4Read8bitData(void)
- {
- unsigned char ucGeneralCount=0;
- unsigned char ucReadData=0;
- unsigned char i;
- //unsigned char j=0;
- //__disable_interrupt();
- sbitRfCLK4 = 0;
- //j = P2MDOUT;
- //j = P2;
- //j = P0;
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
-
- ucReadData=ucReadData<<1;//MSB
-
-
- sbitRfCLK4 = 1;// ;Time Hold min.500ns
- for (i = 0; i < 1; i++); // Wait 2.5us
- if (sbitRfData4 == 1)
- {ucReadData |= BIT0;} //bit 1
- else
- {ucReadData &= ~BIT0;} // bit is 0
- //for (i = 0; i < 1; i++); // Wait 2.5us
- for (i = 0; i < 1; i++); // Wait 2.5us
-
- sbitRfCLK4 = 0;
- for (i = 0; i < 2; i++); // Wait 2.5us
-
- }
- return ucReadData;
- }
- */
- //-----------------------------------------------------------------------------
- // End Of File
- //-----------------------------------------------------------------------------