1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include "stm32f10x.h"
static u32 fac_us; static u32 fac_ms;
void Sysdelay_init(void) { SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); fac_us = SystemCoreClock / 8000000; fac_ms = fac_us * 1000; }
void Sysdelay_us(u32 nus) { u32 temp; SysTick->LOAD = nus * fac_us; SysTick->VAL |= 0x00; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; do { temp = SysTick->CTRL; }while(temp & 0x01 && !(temp & (1 << 16))); SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; SysTick->VAL |= 0x00; }
void Sysdelay_ms(u32 nms) { u32 temp; SysTick->LOAD = nms * fac_ms; SysTick->VAL |= 0x00; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; do { temp = SysTick->CTRL; }while(temp & 0x01 && !(temp & (1 << 16))); SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; SysTick->VAL |= 0x00; }
|