【MM32 eMiniBoard测评】+ SysTick秒计时器
[复制链接]
在MM32 eMiniBoard开发板的程序中,配有Systick的相关函数,将它与OLED屏相结合,就可实现一个秒计时器,其运行效果图所示。
运行效果图
Systick的相关函数如下:
void Systick_init()
{
if (SysTick_Config(RCC_GetSysClockFreq() / 1000)) {
// Capture error
while (1);
}
// Configure the SysTick handler priority
NVIC_SetPriority(SysTick_IRQn, 0x0);//SysTickinterrupt priority class set
}
void SysTick_Handler(void)
{
Counter++;
if(Counter >= 1000) {
Counter = 0;
s++;
LED1_TOGGLE();
LED2_TOGGLE();
LED3_TOGGLE();
LED4_TOGGLE();
}
}
实现秒计时器的主程序为:
s32 main(void)
{
Systick_init();
LED_Init();
APP_OLED_Init();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"MM32F0133 ",16);
OLED_ShowString(0,2,"SysTick test",16);
OLED_ShowString(0,4,"t = s",16);
while(1) {
OLED_ShowNum(32,4,s,2,16);
}
}
|