实验目的:中断方式按键(PA0)实现流水灯,每个灯之间的切换时延是2秒。
1.在文件stm32f4xx.h中找到STM32F40_41xxx系列HSE_VALUE(L144)改为8000000
在文件system_stm32f4xx.c中修改STMF40_41xxx系列
PLL_M=8 L371
PLL_N=336 L401
PLL_P=2 L403
systick.c
#include "stm32f4xx.h"
#include <stdint.h>
#define rSysTickCtrl *((volatile unsigned long*)0xE000E010)
static uint32_t systicknum = 0;
//定时器中断函数
void SysTick_Handler(void)
{
if(systicknum != 0)
{
systicknum--;
}
}
void delay_ms(uint32_t m)
{
systicknum = m;
SysTick_Config(SystemCoreClock/1000);
NVIC_SetPriority(SysTick_IRQn, 0);
while(systicknum != 0);
rSysTickCtrl &= ~(1 << 0) ; // bit0 -> 0 disable SysTick
}
void delay_us(uint32_t u)
{
systicknum = u;
SysTick_Config(SystemCoreClock/1000000);
//NVIC_SetPriority(SysTick_IRQn, 1);
while(systicknum != 0);
rSysTickCtrl &= ~(1 << 0) ; // bit0 -> 0 disable SysTick
}
rj_led.c
#include "rj_led.h"
#include "systick.h"
void