📄 rf_blink_led.c
字号:
#include "include.h"
//#include "lcd128_64.h"
#define PAYLOAD_SIZE 10
#define RF_CHANNEL 26
#define TX_PERIOD 50 // Packet sent each n'th cycle
#define FILL_BYTE 0xEE
static BYTE ledPeriod= 0x80; // LED blinking frequency
static UINT16 nRecv = 0; // Counting received packets
unsigned char recive=0;
void ledFlash(UINT16 duration, UINT16 period);
extern volatile BASIC_RF_SETTINGS rfSettings;
extern void halWait(UINT16 timeout);
extern void basicRfInit(BASIC_RF_RX_INFO *pRRI, UINT8 channel, WORD panId, WORD myAddr);
extern void basicRfReceiveOn(void);
extern BOOL basicRfSendPacket(BASIC_RF_TX_INFO *pRTI);
extern void EUSART_Init();
extern void sent_ch(unsigned char d);
//-------------------------------------------------------------------------------------------------------
// Basic RF transmission and reception structures
BASIC_RF_RX_INFO rfRxInfo;
BASIC_RF_TX_INFO rfTxInfo;
BYTE pTxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
BYTE pRxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI)
//
// DESCRIPTION:
// This function is a part of the basic RF library, but must be declared by the application. Once
// the application has turned on the receiver, using basicRfReceiveOn(), all incoming packets will
// be received by the FIFOP interrupt service routine. When finished, the ISR will call the
// basicRfReceivePacket() function. Please note that this function must return quickly, since the
// next received packet will overwrite the active BASIC_RF_RX_INFO structure (pointed to by pRRI).
//
// ARGUMENTS:
// BASIC_RF_RX_INFO *pRRI
// The reception structure, which contains all relevant info about the received packet.
//
// RETURN VALUE:
// BASIC_RF_RX_INFO*
// The pointer to the next BASIC_RF_RX_INFO structure to be used by the FIFOP ISR. If there is
// only one buffer, then return pRRI.
//-------------------------------------------------------------------------------------------------------
BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI) {
unsigned char i;
for(i=0;i<PAYLOAD_SIZE;i++)sent_ch(pRxBuffer[i]);
return pRRI;
} // basicRfReceivePacket
void port_init()
{
TRISA3=0;
TRISA5=0;
TRISB=0x0F;
TRISC0=0;
TRISC1=0;
TRISC2=0;
TRISC3=0;
TRISC4=1;
TRISC5=0;
ADCON1 = 0x0F;
}
void halSpiInit(void) {
// Initialize the SPI pins and directions
LATC3 = 1; // SCK
LATC5 = 1; // SDO
TRISC3 = 0; // SCK
TRISC4 = 1; // SDI
TRISC5 = 0; // SDO
// Initialize the SPI module
SSPSTAT = 0xc0;
SSPCON1 = 0x20;
SSPIF=0;
} // SpiInit
void ccp2_init()
{
IPEN=1;
GIEH=1;
GIEL=1;
CCP2IE=1;
CCP2IF=0;
CCP2IP=1;
CCP2CON = 0b00000101;
}
//-------------------------------------------------------------------------------------------------------
// int main (void)
//
// DESCRIPTION:
// Startup routine and main loop
//-------------------------------------------------------------------------------------------------------
void main (void) {
UINT8 n;
UINT32 iLoopCount;
// Initalize ports for communication with CC2420 and other peripheral units
port_init();
halSpiInit();
EUSART_Init();
ccp2_init();
//InitLcd();
// Wait for the user to select node address, and initialize for basic RF operation
halWait(1000);
//LoadICO();
basicRfInit(&rfRxInfo, RF_CHANNEL, 0x2420, 0x1234);
rfTxInfo.destAddr = 0x5678;
// Turn on RX mode
basicRfReceiveOn();
DLED3=1;
// The main loop:
while (TRUE)
{
DLED1=0;
DLED2=0;
if(recive)
{
DLED3=!DLED3;
recive=0;
if(pRxBuffer[0]==0x0f)DLED1=1;
if(pRxBuffer[0]==0xf0)DLED2=1;
halWait(6000);
}
}
} // main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -