⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc2420example.c

📁 射频芯片cc2420的使用例程
💻 C
字号:
/*******************************************************************************************************
 一对运行此程序的节点之间建立起一个使用通道26的点对点的RF连接。
 使用下面的节点地址:
 * - PAN ID: 0x2420 (both nodes)                                                                       *
 * - Short address:                                                                                    *
 *		0x1234
 *		0x5678
 * INSTRUCTIONS:                                                                                       *
 * Data packets containing a 5-byte payload will be transmitted when the pot meter is turned, or S2 is *
 * held down. The first byte of the payload contains the pot meter value, which is used to control the *
 * PWM duty cycle on the receiving node. The other bytes are random (never initialized).               *
 *                                                                                                     *
 * LED indicators:                                                                                     *
 *     - Red:    Transmission failed (acknowledgment not received)                                     *
 *     - Yellow: Transmission OK (acknowledgment received)                                             *
 *     - Orange: Remote controlled dimmer															   *
 *     - Green:  Packet received                                                                       *
 *******************************************************************************************************/
#include "include.h"
BASIC_RF_RX_INFO rfRxInfo;
BASIC_RF_TX_INFO rfTxInfo;
BYTE pTxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
BYTE pRxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];

UINT8 temp9[16]={0x9,0x8,0x4,0xb,0xc,0x86,0xc,0x74,0x3,0xe5,0x4,0x69,0xf,0x8,0x5,0x0};

BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI) 
{
    // Adjust the led brightness
//    PWM0_SET_DUTY_CYCLE(pRRI->pPayload[0]);
    // Blink the green LED
    SET_RLED();SET_GLED();SET_YLED();
    halWait(10000);halWait(50000);halWait(50000);halWait(50000);
    CLR_RLED();CLR_GLED();CLR_YLED();
    halWait(10000);halWait(50000);halWait(50000);halWait(50000);

    //yENABLE_FIFOP_INT();
    // Continue using the (one and only) reception structure
    return pRRI;
} // basicRfReceivePacket

#pragma vector=INT7_vect
__interrupt void INT7_interrupt(void)
{
	//yDISABLE_FIFOP_INT();
	//yCLEAR_FIFOP_INT();
	DISABLE_GLOBAL_INT();
	
	SET_GLED();
	halWait(50000);halWait(50000);halWait(50000);halWait(50000);
	
	CLR_GLED();
	halWait(50000);halWait(50000);halWait(50000);halWait(50000);
	CC2420_FIFOP_ISP();
	
	ENABLE_GLOBAL_INT();
}

void main (void)
{
    UINT8 n;
/*
SFIOR |= BV(PUD);
  DDRD = 0xFF;
  while(1)
  {
  PORTD =  0;
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  PORTD = 0xff;
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  halWait(5000);halWait(5000);halWait(5000);halWait(5000);
  }
*/

    PORT_INIT();
    SPI_INIT();
    
    // Wait for the user to select node address, and initialize for basic RF operation
		//if (0) {
		if (1) {
			basicRfInit(&rfRxInfo, 16, 0x3000, 0x2111);
			rfTxInfo.destAddr = 0x6522;
		} else {
			basicRfInit(&rfRxInfo, 16, 0x3000, 0x6522);
			rfTxInfo.destAddr = 0x2111;
		}
	// Initalize common protocol parameters
    rfTxInfo.length = 16;
    rfTxInfo.ackRequest = TRUE;
    rfTxInfo.pPayload = pTxBuffer;
    rfRxInfo.pPayload = pRxBuffer;

    for (n = 0; n < 16; n++) 
	{
        pTxBuffer[n] = temp9[n] ; //y
    }

    // Turn on RX mode
    basicRfReceiveOn();

	// The main loop:
	while (TRUE) 
	{
	///*
    		if (basicRfSendPacket(&rfTxInfo)) 
			{
			    SET_YLED();
			    halWait(50000);halWait(50000);halWait(50000);halWait(50000);
			     
			    CLR_YLED();
			    halWait(50000);halWait(50000);halWait(50000);halWait(50000);
			} 
			else
			{
			    SET_RLED();
			    halWait(50000);halWait(50000);halWait(50000);halWait(50000);
			    CLR_RLED();
			    halWait(50000);halWait(50000);halWait(50000);halWait(50000);
			}
	//*/
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -