timer.c

来自「ARM公司ATC培训的所有练习源码」· C语言 代码 · 共 33 行

C
33
字号
#include "timer.h"
#include "cortexm3.h"
#include "nvic.h"
#define MAGIC_VALUE 299999

#include <stdio.h>


void SysTick_init(void)
{
	int onems = ((NVIC.SysTick.Calibration) & 0x00ffffff);
	int reload = 999; /* Supposed to be once a second (999+1 ms)*/

	/* If the calibration value is non 0 then we can use it as a more accurate value for 1ms */
	if(onems != 0)
	{
		reload = ((onems+1) * 1000)-1;
	}
	/* *SysTickLoad = reload; */
	*SysTickLoad = MAGIC_VALUE; /* Found to be more realistic on ISSM */

#if defined SYSTICK_INTERRUPT
	*SysTickCtrl = SysTickEnable | SysTickInterrupt; /* Start, with interrupts enabled */
#else
	*SysTickCtrl = SysTickEnable; /* Start, with interrupts enabled */
#endif
}

void SysTickHandler(void)
{
	printf("SysTick interrupt.\n\r");
}

⌨️ 快捷键说明

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