短短的几个帖子就有网友跟进了,通过站内短信里问我,是不是可以使用st的固件库?我对st的固件库比较熟悉。在这里版主先不下结论,待版主通过实验一一比较两者的相同点与差异。
今天晚上首先带来的实验是systick实验,通过板载LED灯来验证。
实验目的:配置systick定时器与gpio驱动
实验方法:使用stm32f030的启动文件与固件库文件,配置systick定时器1ms中断一次,通过计数的方式让LED0灯闪烁频率为2Hz,LED1灯闪烁5Hz;
实验内容:
配置源代码如下:
void main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
bool LedStatus[2];
RCC_GetClocksFreq(&RCC_ClockFreq);
gCntLed[0] = 500;
gCntLed[1] = 100;
LedStatus[0] = false;
LedStatus[1] = false;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
/* Configure PC10 and PC11 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStructure);
if (SysTick_Config(48000)) //参数为系统时钟的向上溢出值,此配置为48000,即1ms中断一次
{
/* Capture error */
while (1);
}
while(1)
{
if(gCntLed[0] == 0)
{
if(LedStatus[0] == true)
{
GPIO_SetBits(GPIOF, GPIO_Pin_6);
LedStatus[0] = false;
}
else
{
GPIO_ResetBits(GPIOF, GPIO_Pin_6);
LedStatus[0] = true;
}
gCntLed[0] = 500;
}
if(gCntLed[1] == 0)
{
if(LedStatus[1] == true)
{
GPIO_SetBits(GPIOF, GPIO_Pin_7);
LedStatus[1] = false;
}
else
{
GPIO_ResetBits(GPIOF, GPIO_Pin_7);
LedStatus[1] = true;
}
gCntLed[1] = 100;
}
}
}
/**
* @brief SysTick_Handler的中断入口函数
* @param
* @retval
* @date 2014-11-23
* @note
*/
void SysTick_Handler(void)
{
if(gCntLed[0] > 0)
{
gCntLed[0]--;
}
else
{
gCntLed[0] = 0;
}
if(gCntLed[1] > 0)
{
gCntLed[1]--;
}
else
{
gCntLed[1] = 0;
}
}
实验结论:
目测两个棕色的LED灯一闪一闪滴~~
我要赚赏金
