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

📄 hal_cc2420db.h

📁 基于ATmega128的无线通信节点程序
💻 H
📖 第 1 页 / 共 2 页
字号:



/*******************************************************************************************************
 *******************************************************************************************************
 **************************                 CC2420 PIN ACCESS                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// CC2420 pin access

// Pin status
#define FIFO_IS_1       (!!(PINB & BM(FIFO)))
#define CCA_IS_1        (!!(PIND & BM(CCA)))
#define RESET_IS_1      (!!(PINA & BM(RESET_N)))
#define VREG_IS_1       (!!(PINA & BM(VREG_EN)))
#define FIFOP_IS_1      (!!(PINE & BM(FIFOP)))
#define SFD_IS_1        (!!(PIND & BM(SFD)))

// The CC2420 reset pin
#define SET_RESET_ACTIVE()    PORTA &= ~BM(RESET_N)
#define SET_RESET_INACTIVE()  PORTA |= BM(RESET_N)

// CC2420 voltage regulator enable pin
#define SET_VREG_ACTIVE()     PORTA |= BM(VREG_EN)
#define SET_VREG_INACTIVE()   PORTA &= ~BM(VREG_EN)
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   SERIAL PORTS                    **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// UART hardware flow control
/*#define CLR_RTS()                  (PORTD &= ~BM(UART1_RTS))
#define SET_RTS()                  (PORTD |= BM(UART1_RTS))

#define SET_CTS()                  (PORTD |= BM(UART1_CTS))
#define CLR_CTS()                  (PORTD &= ~BM(UART1_CTS))
*/
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               EXTERNAL INTERRUPTS                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Rising edge trigger for external interrupt 0 (FIFOP)
#define FIFOP_INT_INIT()            do { EICRA |= 0x10; CLEAR_FIFOP_INT(); } while (0)

// FIFOP on external interrupt 0

#define ENABLE_FIFOP_INT()          do { EIMSK |= 0x20;} while (0)
#define DISABLE_FIFOP_INT()         do { EIMSK &= ~0x20; } while (0)
#define CLEAR_FIFOP_INT()           do { EIFR = 0x20; } while (0)
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
// SFD interrupt on timer 1 capture pin
#define ENABLE_SFD_CAPTURE_INT()    do { TIMSK |= BM(TICIE1); } while (0)
#define DISABLE_SFD_CAPTURE_INT()   do { TIMSK &= ~BM(TICIE1); } while (0)
#define CLEAR_SFD_CAPTURE_INT()     do { TIFR = BM(ICF1); } while (0)
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
// Falling edge trigger for external interrupt 6 (joystick)
#define JOYSTICK_INT_INIT()         do { EICRA |= 0x40; } while (0)

// Joystick on external interrupt 6
#define ENABLE_JOYSTICK_INT()       do { EIMSK |= 0x30; } while (0)
#define DISABLE_JOYSTICK_INT()      do { EIMSK &= ~0x30; } while (0)
#define CLEAR_JOYSTICK_INT()        do { EIFR = 0x30; } while (0)
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                      BUTTONS                      **************************
 *******************************************************************************************************
 *******************************************************************************************************/

//-------------------------------------------------------------------------------------------------------
/*S2 button
#define BUTTON_PRESSED()           !(PINE & BM(BUTTON))

// Joystick
#define JOYSTICK_UP_PRESSED()       (PINE & BM(JOYSTICK_UP))
#define JOYSTICK_DOWN_PRESSED()     (PINF & BM(JOYSTICK_DOWN))
#define JOYSTICK_LEFT_PRESSED()     (PINF & BM(JOYSTICK_LEFT))
#define JOYSTICK_RIGHT_PRESSED()    (PINE & BM(JOYSTICK_RIGHT))
#define JOYSTICK_CENTER_PRESSED()   (PINE & BM(JOYSTICK_CENTER))*/
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                        LEDS                       **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// SET LED
#define SET_GLED()                  (PORTA &= ~BM(GLED))
#define SET_OLED()                  (PORTB &= ~BM(OLED))
#define SET_YLED()                  (PORTA &= ~BM(YLED))
#define SET_RLED()                  (PORTA &= ~BM(RLED))

// CLR LED
#define CLR_GLED()                  (PORTA |= BM(GLED))
#define CLR_OLED()                  (PORTB |= BM(OLED))
#define CLR_YLED()                  (PORTA |= BM(YLED))
#define CLR_RLED()                  (PORTA |= BM(RLED))

// Sets all leds simultaneously to display a 4-bit binary code
#define SET_LED_MASK(n) \
    do { \
        if (n & 0x01) SET_GLED(); else CLR_GLED(); \
        if (n & 0x02) SET_OLED(); else CLR_OLED(); \
        if (n & 0x04) SET_RLED(); else CLR_RLED(); \
        if (n & 0x08) SET_YLED(); else CLR_YLED(); \
    } while (0)
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               APPLICATION DEBUGGING               **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Controlled application crash (flashes the LEDs forever to indicate an error code)
#define EXCEPTION(n) \
    do { \
        DISABLE_GLOBAL_INT(); \
        SET_LED_MASK(n); \
        halWait(50000); \
        SET_LED_MASK(0); \
        halWait(50000); \
    } while (TRUE)
//-------------------------------------------------------------------------------------------------------


#endif

⌨️ 快捷键说明

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