Home > other >  consult
consult

Time:09-21

How to realize the interval of 1 second delay function?
Void Delay (uint32_t count)
{
for(; The count!=0; The count -);
}

Delay ();
The above should fill in brackets?
You can answer it for me? Or give me information,
Thank you,

CodePudding user response:

A lot of singlechip routines have ms delay function, 1000 ms is a second,
This is stm32f103 routines,
Delay_ms (300);//delay 300 ms
Void delay_ms (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)));//wait time
SysTick - & gt; CTRL&=~ SysTick_CTRL_ENABLE_Msk;//off the counter
SysTick - & gt; VAL=0 x00;//to empty counter
}

CodePudding user response:

reference 1st floor xuyaqi029 response:
a lot of singlechip routines have ms delay function, 1000 ms is a second,
This is stm32f103 routines,
Delay_ms (300);//delay 300 ms
Void delay_ms (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)));//wait time
SysTick - & gt; CTRL&=~ SysTick_CTRL_ENABLE_Msk;//off the counter
SysTick - & gt; VAL=0 x00;//to empty counter
}

This Sys Tick timer delay temporarily is beyond my ability range, simple?

CodePudding user response:

Test and operation, according to the assembly code a cycle of the machine cycle count on the number of instructions (such as N), according to several clock chip that is a machine cycle (such as M, ordinary 51 chip is 12, single cycle, 51 chip to 1), assuming that clock cycles for T=1/crystal frequency Fosc), then, fill in parentheses value of 1/(N * M * T)

CodePudding user response:

reference worldy reply: 3/f
debugging operation, according to the instructions of assembly code number a cycle of the machine cycle number (N), according to several clock chip that is a machine cycle (such as M, ordinary 51 chip is 12, single cycle, 51 chip to 1), assuming that clock cycles for T=1/crystal frequency Fosc), then, fill in parentheses value of 1/(N * M * T)

I studied STM32C8T6,

CodePudding user response:

The STM32 more support online debugging, connected to the JTAG or STTAG can on-line debugging

CodePudding user response:

Need to see the CPU cycles and compiled the assembly of the execution of CPU cycles,

CodePudding user response:

refer to the original poster small white love learning response:
how to realize the interval of 1 second delay function?
Void Delay (uint32_t count)
{
for(; The count!=0; The count -);
}

Delay ();
The above should fill in brackets?
You can answer it for me? Or give me information,
Thank you,

Do not recommend using delay function delay one second, the second CPU be preempted, but what did live, use timer interrupt is not more efficient