当有按键的时候,将 TxPayloadBuffer[]的数据发送出去
SW1_Data_ADDR |= SW1_MASK; // Write a 1 so we can read the switch
if (!(SW1_Data_ADDR & SW1_MASK))
{
// Transmit a packet when the "Switch 1" button is pressed.
nRED_LED_Data_ADDR &= ~nRED_LED_MASK; // Red LED On
Delay(DELAY_COUNT); // Give the user a chance to see the LED.
// This also guarantees the receiver has been running for at least 1ms.
// Stop receiving so that we can transmit
RadioAbort();
RadioSetPtr(TxPayloadBuffer); // Set the transmit buffer
RadioBlockingTransmit(0, PAYLOAD_LENGTH); // Send it
++TransmittedCount;
nRED_LED_Data_ADDR |= nRED_LED_MASK; // Red LED Off
// Wait for user to release the "Switch 1" button.
SW1_Data_ADDR |= SW1_MASK; // Write a 1 so we can read the switch
while(!(SW1_Data_ADDR & SW1_MASK));
RadioSetPtr(RxPayloadBuffer); // Set the receive buffer
RadioStartReceive(); // Restart the receiver
Delay(SWITCH_DEBOUCE); // Debounce switch
}
if (RxState & RADIO_COMPLETE)
{
ReceivedPayloadSize = RadioEndReceive();
if (!(RxState & RADIO_ERROR))
{
if (ReceivedPayloadSize == PAYLOAD_LENGTH)
{
// Successfully received a packet
++ReceivedCount;
// Give the user feedback a packet has been received
nGREEN_LED_Data_ADDR &= ~nGREEN_LED_MASK; // Green LED On
Delay(DELAY_COUNT); // Give the user a chance to see the LED
nGREEN_LED_Data_ADDR |= nGREEN_LED_MASK; // Green LED Off
}
// else drop Packet. Not the correct length
}
else
{
// Packet received with an error.
}
// Restart the receive operation
RadioStartReceive();
}