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

📄 3.c

📁 cc2420 demo 3 with leds and speed control
💻 C
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                                   EJEMPLO 3 : Sem醘oro con velocidad                   *
 *      ***   + +   ***                                                                                *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 SEM罠ORO CON VELOCIDAD CONTROLADA

  Sem醘oro de 3 luces con incremento y decremento de velocidad.

  - Joystick central : encender.
  - Joystick izquierdo : apagar.
  - Joystick arriba : disminuir velocidad.
  - Joystick abajo : aumentar velocidad.
 *******************************************************************************************************
 * Compiler: AVR-GCC                                                                                   *
 * Target platform: CC2420DB (can easily be ported to other platforms)                                 *
 *******************************************************************************************************
 * Revision history:                                                                                   *
 * $Log: rf_blink_led.c,v $
 * Revision 1.5  2004/07/26 11:18:13  mbr
 * Changed PANID from 0xDEAD to 0x2420
 *
 * Revision 1.4  2004/04/05 08:25:52  mbr
 * Comments changed in header
 *
 * Revision 1.3  2004/03/30 14:58:27  mbr
 * Release for web
 *
 * 
 *
 *                                                                                                     *
 *
 *
 *******************************************************************************************************/
#include <include.h>


//-------------------------------------------------------------------------------------------------------
// 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];
int encender = 0;
int velocidad = 0;
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
//  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) {
	
	encender = pRRI->pPayload[0];
	velocidad = pRRI->pPayload[1];


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

} // basicRfReceivePacket




//-------------------------------------------------------------------------------------------------------
//	void main (void)
//
//	DESCRIPTION:
//		Startup routine and main loop
//-------------------------------------------------------------------------------------------------------
void main (void) {
     UINT8 n;

    // Initalize ports for communication with CC2420 and other peripheral units
    PORT_INIT();
    SPI_INIT();

    // Initialize PWM0 with a period of CLK/1024
    PWM0_INIT(TIMER_CLK_DIV1024);

    // Initialize and enable the ADC for reading the pot meter
    ADC_INIT();
    ADC_SET_CHANNEL(ADC_INPUT_0_POT_METER);
	ADC_ENABLE();

    // Wait for the user to select node address, and initialize for basic RF operation
    while (TRUE) {
		if (JOYSTICK_CENTER_PRESSED()) {
			basicRfInit(&rfRxInfo, 26, 0x2420, 0x1234);
			rfTxInfo.destAddr = 0x5678;
			break;
		} else if (JOYSTICK_UP_PRESSED() || JOYSTICK_DOWN_PRESSED() || JOYSTICK_LEFT_PRESSED() || JOYSTICK_RIGHT_PRESSED()) {
			basicRfInit(&rfRxInfo, 26, 0x2420, 0x5678);
			rfTxInfo.destAddr = 0x1234;
			break;
		}
	}

    // Initalize common protocol parameters
    rfTxInfo.length = 10;
    rfTxInfo.ackRequest = TRUE;
    rfTxInfo.pPayload = pTxBuffer;
    rfRxInfo.pPayload = pRxBuffer;



    for (n = 0; n < 10; n++) {
        pTxBuffer[n] = n;
    }

    // Turn on RX mode
    basicRfReceiveOn();

	// The main loop:
	while (TRUE) {
		
			if (JOYSTICK_CENTER_PRESSED()) {

			 pTxBuffer[0] = 1;
			 basicRfSendPacket(&rfTxInfo);

			}
			if (JOYSTICK_LEFT_PRESSED()) {

			 pTxBuffer[0] = 2;
			 basicRfSendPacket(&rfTxInfo);

			}
			if (JOYSTICK_UP_PRESSED()) {
			
			pTxBuffer[1]++;
			basicRfSendPacket(&rfTxInfo);

			}
			if (JOYSTICK_DOWN_PRESSED()) {

			pTxBuffer[1]--;
			basicRfSendPacket(&rfTxInfo);

			}
			while (JOYSTICK_UP_PRESSED() || JOYSTICK_DOWN_PRESSED()) {
				halRfWaitForCrystalOscillator();
			}
			
			

			while (encender == 1) {
					 SET_GLED();
					 	for (int j = 0;j<velocidad;j++) {
							for (int i = 0;i<10;i++ )  {
								halWait(100000000000);
							}
						}
					 CLR_GLED();
					 SET_YLED();
					 	for (int j = 0;j<velocidad/3;j++) {
							for (int i = 0;i<10;i++ )  {
								halWait(100000000000);
							}
						}
					 CLR_YLED();
					 SET_RLED();
					 	for (int j = 0;j<velocidad;j++) {
							for (int i = 0;i<10;i++ )  {
								halWait(100000000000);
							}
						}
					 CLR_RLED();

			}
			

		
    }
} // main

⌨️ 快捷键说明

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