Home > other >  The embedded programming problem how to do, the most simple?
The embedded programming problem how to do, the most simple?

Time:10-12

Those who ask to embedded

CodePudding user response:

Circuit diagram?

Enclosed is a code, can be modified directly:

 void Init () 
{
SysTick_CLKSourceConfig (SysTick_CLKSource_HCLK_Div8);//select HCLK external clock/8
Fac_us=SystemCoreClock/8000000;//for 1/8 of the system clock, in fact it was count the number of 1 ussystick VAL minus
Fac_ms=(under-16) fac_us * 1000;//for each ms need the number of systick clock, namely every millisecond systick VAL minus the number of
}

Void delay (under-16 NMS)
{
U32 temp.
SysTick - & gt; The LOAD=(u32) NMS * fac_ms;//time load (SysTick - & gt; The LOAD of 24 bit)
SysTick - & gt; VAL=0 x00;//to empty counter
SysTick - & gt; CTRL |=SysTick_CTRL_ENABLE_Msk;//to count
Do
{
Temp=SysTick - & gt; CTRL;
} while ((temp& 0 x01) & amp; & ! (temp& (1 & lt; <16)));//waiting time arrived, see CTRL 16th (COUNTFLAG) is 1, see STRL 0 (ENABLE) 1
SysTick - & gt; CTRL&=~ SysTick_CTRL_ENABLE_Msk;//off the counter
SysTick - & gt; VAL=0 x00;//to empty counter
}


The main function of initialization GPIO, calls the Init () initialization, while (1) loop call delay (200), the direct control of the led flashing back,

CodePudding user response:

Of course, this is the way to directly by timer timing, also can be done through the way of interrupt,

Look at the link to blog: https://blog.csdn.net/qq_38410730/article/details/79843806
  • Related