EFM32之GPIO

设置系统时钟:

CMU_ClockSelectSet(cmuClock_HF,cmuSelect_HFXO);//32MHz

GPIO初始化:

void LED_Init(void)
{
     CMU_HFPRECLKEN0 |= (1<<6);//使能GPIO时钟
    GPIO->P[3].MODEL |= (4<<28);//将PD7设置成推挽输出
}

 

设置GPIO的触发寄存器:

void LED_Toggle(void)
{
    GPIO->P[3].DOUTTGL |= (1<<7);
}

 

延迟函数:

void Delay(uint32_t dlyTicks)
{
    uint32_t curTicks;
    curTicks = msTicks;
    while((msTicks-curTicks) < dlyTicks);
}

设置系统滴答时钟:

void systick_config(void)
{
    uint32_t temp;
    temp = CMU_ClockFreqGet(cmuClock_HF);
    SysTick_Config(temp/1000);
}

系统滴答时钟中断:

void SysTick_Handler(void)
{
    msTicks++;
}

主函数:

int main(void)

{

    CMU_ClockSelectSet(cmuClock_HF,cmuSelect_HFXO);//32MHz

    LED_Init();

    systick_config();

    while(1)

    {

        LED_Toggle();

        Delay(1000);//延时1s

    }

}


 

 

posted @ 2013-03-28 22:31  zpehome  阅读(1050)  评论(0编辑  收藏  举报