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

📄 hal_mcu.c

📁 msp430与cc2500无线收发器通讯的底层硬件配置
💻 C
字号:
/******************************************************************************
    Filename: hal_mcu.c

    Copyright 2007 Texas Instruments, Inc.
******************************************************************************/

#include "hal_types.h"
#include "hal_defs.h"
#include "hal_board.h"
#include "hal_mcu.h"



//----------------------------------------------------------------------------------
//  void halMcuInit(void)
//
//  DESCRIPTION:
//    Turn off watchdog and set up system clock. 
//----------------------------------------------------------------------------------
void halMcuInit(void)
{
    uint8 i;
    // Stop watchdog
    WDTCTL = WDTPW + WDTHOLD;

    // Set up clock system on MCU to fit your system
    
    BCSCTL1&=~XT2OFF;//turn on the oscillator XT2
    do
    {
       IFG1&=~OFIFG;
       for(i=0xFF;i>0;i--);
    }
    while((IFG1&OFIFG));
    BCSCTL2 |=SELM1;        // MCLK = XT2,SMCLK = DCO
    DCOCTL = DCO0+DCO1+DCO2;// Max DCO
    BCSCTL1 =RSEL0+RSEL1+RSEL2; // XT2on, max RSEL
    // Target specific implementation
}


//-----------------------------------------------------------------------------
//  void halMcuWaitUs(uint16 usec)
//
//  DESCRIPTION:
//    Busy wait function. Waits the specified number of microseconds. Use
//    assumptions about number of clock cycles needed for the various instructions.
//    The duration of one cycle depends on the system clock. In this TEMPLATE HAL,
//    system clock is 1 MHz, thus 1 cycles per usec.
//
//    NB! This function is highly dependent on architecture and compiler!
//-----------------------------------------------------------------------------
void halMcuWaitUs(uint16 usec) // 5 cycles for calling
{
    // In this example, the least we can wait is 12 usec:
    // ~1 us for call, 1 us for first compare and 1 us for return

    while(usec > 12)      // 2 cycles for compare
    {                     // 2 cycles for jump
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        usec -= 10;       // 1 cycles for optimized decrement
    }
}  // 4 cycles for returning 
//for 8MHz crystal,at lest wait 2us


//-----------------------------------------------------------------------------
//  void halMcuSetLowPowerMode(uint8 mode)
//
//  DESCRIPTION:
//    Sets the MCU in a low power mode. Will turn global interrupts on at
//    the same time as entering the LPM mode. The MCU must be waken from
//    an interrupt (status register on stack must be modified).
//-----------------------------------------------------------------------------
void halMcuSetLowPowerMode(uint8 mode)
{
    switch (mode)
    {
        case HAL_MCU_LPM_0:
            __low_power_mode_0();
            break;
        case HAL_MCU_LPM_1:
            __low_power_mode_1();
            break;
        case HAL_MCU_LPM_2:
            __low_power_mode_2();
            break;
        case HAL_MCU_LPM_3:
            __low_power_mode_3();
            break;
        case HAL_MCU_LPM_4:
            __low_power_mode_4();
            break;
    }
}

⌨️ 快捷键说明

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