[NUCLEO-F031K6试用]MDK寄存器版:2、1Hz指示灯
- UID
- 1066743
|
[NUCLEO-F031K6试用]MDK寄存器版:2、1Hz指示灯
代码如下:
main.c
#include "stm32f0xx.h"#include "sys.h"#include "systick.h"#include "led.h"int main(void){ SystemCoreClockConfigure(); SystemCoreClockUpdate(); systick_init(); led_init(); while(1) {// GPIOB->BSRR = 0x1 << 3;// GPIOB->BRR = 0x1 << 3; }}
systick.c
#include "systick.h"static int tim = 0;int systick_init(void){ SysTick_Config(SystemCoreClock / 1000); return 0;}void SysTick_Handler(void){ static int tt = 0; if(tim++ - tt > 500) { tt = tim; GPIOB->BSRR = ((GPIOB->ODR & (1 << 3)) > 0) ? (0x1 << 19) : (0x1 << 3); }} |
|
|
|
|
|