其实这篇的1Hz灯,就是在上一篇的基础上添加了SysTick滴答时钟。
main.c代码如下#include "MK64F12.h"
#include "../driver/inc/led.h"
#include "../driver/inc/systick.h"
int main(void)
{
led_init();
systick_init();
while(1)
{
// PTB->PSOR = 1 << 22;
// PTB->PCOR = 1 << 22;
}
}
systick.c代码如下
#include "../inc/systick.h"
static int tim = 0;
int
systick_init(void)
{
SysTick_Config(SystemCoreClock / 1000);
return 0;
}
void SysTick_Handler()
{
static int tt = 0;
if(tim++ - tt > 500)
{
tt = tim;
PTB->PTOR |= 1 << 22;
}
}
|