void main() { UART_init(); //================NRF905初始化 CSN=1; // Spi disable SCK=0; // Spi clock line init high DR=1; // Init DR for input AM=1; // Init AM for input PWR_UP=1; // nRF905 power on TRX_CE=0; // Set nRF905 in standby mode TX_EN=0; // set radio in Rx mode //================ Config905(); // Config nRF905 module LED2=CD; TxBuf[0] = 1; TxBuf[1] = 1; TxBuf[2] = 1; TxBuf[3] = 1; SetTxMode(); // Set Tx Mode TxPacket(); // Transmit Tx buffer data LED1 = 0; Delay(500); // delay for led light LED1 =1; TxBuf[0] = 0xff; TxBuf[1] = 0xff; TxBuf[2] = 0xff; TxBuf[3] = 0xff; // led close SetRxMode(); // Set nRF905 in Rx mode while(1) { if(RECEIVR_buffer=='l'||RECEIVR_buffer=='r'||RECEIVR_buffer=='f'||RECEIVR_buffer=='b'||KEY1==0) //if(KEY1 ==0 ) { LED1 = 0; TxBuf[0] = RECEIVR_buffer ; COM_send(RECEIVR_buffer); //===============NRF905发送相应的按键 SetTxMode(); // Set Tx Mode TxPacket(); // Transmit Tx buffer data //TxBuf[0] = 0xff; //TxBuf[1] = 0xff; SetRxMode(); // Set nRF905 in Rx mode Delay(500); LED1 = 1; } //=====================等待NRF905接收 if (DR) // If recive data ready... 数据准备就绪 RxPacket(); // ... recive data } }
void NRF24L01_Init(void) { SPI1_Init(); NRF24L01_Check(); SetRxMode(); }
// returns FALSE on END command, TRUE otherwise bool tScriptState::ExecuteCommand(tCommand& cmd) { bool bContinue = TRUE; switch(cmd.cmdId) { case cmdLabel: break; case cmdGoto: { ULONG step; const tParameter *pParam = cmd.params.GetAt(0); if (!FindLabelByName(*pParam, &step)) { FailCase("Can't find label %s", (LPCSTR)pParam->String()); } else { currentCommandIndex = step; } } break; case cmdIf: { bool bTrue = EvaluateCondition(cmd.params[0]->String()); if (!bTrue) { currentCommandIndex = cmd.elseStepForIf; } } break; case cmdEnd: bContinue = FALSE; break; case cmdSet: { ULONG data; ULONG value = cmd.params[1]->Value(); if (!GetVariable(cmd.params[0]->String(), data) || data != value) { data = value; SetVariable(cmd.params[0]->String(), data); } } break; case cmdAdd: { ULONG data; if (GetVariable(cmd.params[0]->String(), data)) { data += cmd.params[1]->Value(); SetVariable(cmd.params[0]->String(), data); } else { FailCase("Can't add %s", cmd.params[0]->String()); } } break; case cmdPrepare: { ULONG data; if (GetVariable("use_merged_buffers", data)) bUseMergedBuffers = !!data; if (GetVariable("use_published_events", data)) bUsePublishedIndices = !!data; if (GetVariable("use_msix", data)) bMSIXUsed = !!data; SimulationPrepare(); } break; case cmdTxAsync: { bAsyncTransmit = !!cmd.params[0]->Value(); } break; case cmdSend: { AddTxBuffers(cmd.params[0]->Value(), cmd.params[1]->Value()); } break; case cmdTxComplete: { CompleteTx((int)cmd.params[0]->Value()); } break; case cmdTxGet: { GetTxBuffer(cmd.params[0]->Value()); } break; case cmdRxReturn: { ReturnRxBuffer(cmd.params[0]->Value()); } break; case cmdRxReceive: { RxReceivePacket((UCHAR)cmd.params[0]->Value()); } break; case cmdDataGet: { UCHAR offset, val, res; offset = (UCHAR)cmd.params[0]->Value(); val = (UCHAR)cmd.params[1]->Value(); res = GetDeviceData(offset); if (res != val) { FailCase("cmdDataGet(%d) = %d, expected %d", offset, res, val); } } break; case cmdDataSet: { UCHAR offset, val; offset = (UCHAR)cmd.params[0]->Value(); val = (UCHAR)cmd.params[1]->Value(); SetDeviceData(offset, val); } break; case cmdRxRestart: { BOOLEAN bExpected = (BOOLEAN)cmd.params[0]->Value(); BOOLEAN b = RxRestart(); if (b != bExpected) { FailCase("RxRestart: %d, expected %d", b, bExpected); } } break; case cmdTxRestart: { BOOLEAN bExpected = (BOOLEAN)cmd.params[0]->Value(); BOOLEAN b = TxRestart(); if (b != bExpected) { FailCase("TxRestart: %d, expected %d", b, bExpected); } } break; case cmdTxEnableInterrupt: { TxEnableInterrupt(); } break; case cmdTxDisableInterrupt: { TxDisableInterrupt(); } break; case cmdRxEnableInterrupt: { RxEnableInterrupt(); } break; case cmdRxDisableInterrupt: { RxDisableInterrupt(); } break; case cmdRxGet: { ULONG len; GetRxBuffer(&len); } break; case cmdControlRxMode: { SetRxMode((UCHAR)cmd.params[0]->Value(), cmd.params[1]->Value() != 0); } break; case cmdControlVlanAdd: { USHORT us = (USHORT)cmd.params[0]->Value(); VlansAdd(&us, 1); } break; case cmdControlVlanDel: { USHORT us = (USHORT)cmd.params[0]->Value(); VlansDel(&us, 1); } break; case cmdControlMacTable: { SetMacAddresses(cmd.params[0]->Value()); } default: result = 1; break; } return bContinue; }