Delay function with Systick (System tick timer)
1.4 Registers
Systick->ctrl,--control and status registers
Systick->load,--Reload register
Systick->val,--Current value register
Systick->calib,--Calibration value Register
There are their respective descriptions: reference address: http://blog.csdn.net/marike1314/article/details/5673684
2.systick programming
Set the clock source (one is directly equal to the HCLK clock, one is the HCLK/8)
Kernel clock Systick->ctrl |= systick_clksource_hclk; 0x00000004
External clock source Systick->ctrl &= SYSTICK_CLKSOURCE_HCLK_DIV8;//0XFFFFFFFB
If the HCLK clock is 8M
void Delay_1us (U16 value)
{
Set Systick clock Source hclk=8m
systick->load=value*8; Time-load time is 8M 8 times 1us
systick->val=0x00; Empty counter
systick->ctrl=0x00000005; Set the clock source to HCLK (8M) and start the countdown 0x00000004|0x01
while (!) ( systick->ctrl& (1<<16)); The wait time arrives at Systick->ctrl's Countflag to arrive at 1 o'clock time (while expression 1 will always loop, jumping out of the loop for 0 o'clock)
systick->ctrl=0x00000004; Turn off counters
}
SysTick delay function