当前位置:网站首页>基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
2022-06-25 04:01:00 【网易独家音乐人Mike Zhou】
基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
#include "ADuCM4050.h"
#include "stm32f4xx.h"
void delay_ms(unsigned int ms)
{
while(ms--)
{
SysTick->CTRL = 0; // Disable SysTick ¹Ø±Õϵͳ¶¨Ê±Æ÷
SysTick->LOAD = 52000000/1000-1; // Count from 255 to 0 (256 cycles) ÔØÈë¼ÆÊýÖµ ¶¨Ê±Æ÷´ÓÕâ¸öÖµ¿ªÊ¼¼ÆÊý
SysTick->VAL = 0; // Clear current value as well as count flag Çå¿Õ¼ÆÊýÖµµ½´ï0ºóµÄ±ê¼Ç
SysTick->CTRL = 5; // Enable SysTick timer with processor clock ʹÄÜ52MHzµÄϵͳ¶¨Ê±Æ÷
while ((SysTick->CTRL & 0x00010000)==0);// Wait until count flag is set µÈ´ý
}
SysTick->CTRL = 0; // Disable SysTick ¹Ø±Õϵͳ¶¨Ê±Æ÷
}
void delay_us(unsigned int us)
{
while(us--)
{
SysTick->CTRL = 0; // Disable SysTick ¹Ø±Õϵͳ¶¨Ê±Æ÷
SysTick->LOAD = 52000000/1000/1000-1; // Count from 255 to 0 (256 cycles) ÔØÈë¼ÆÊýÖµ ¶¨Ê±Æ÷´ÓÕâ¸öÖµ¿ªÊ¼¼ÆÊý
SysTick->VAL = 0; // Clear current value as well as count flag Çå¿Õ¼ÆÊýÖµµ½´ï0ºóµÄ±ê¼Ç
SysTick->CTRL = 5; // Enable SysTick timer with processor clock ʹÄÜ52MHzµÄϵͳ¶¨Ê±Æ÷
while ((SysTick->CTRL & 0x00010000)==0);// Wait until count flag is set µÈ´ý
}
SysTick->CTRL = 0; // Disable SysTick ¹Ø±Õϵͳ¶¨Ê±Æ÷
}
其中的52000000表示芯片的系统定时器频率 32系列一般为外部定时器频率的两倍
边栏推荐
猜你喜欢

WPF 使用 MAUI 的自绘制逻辑

Paper notes: multi label learning ESMC (I don't understand it, but I haven't written it yet, so I'll put it here for a place temporarily)

Leader: who can use redis expired monitoring to close orders and get out of here!

第九章 APP项目测试(2) 测试工具

js的sort()函数

【无标题】

JS, BOM, DOM (VI)

我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶

dotnet-exec 0.4.0 released

Record the problem of C # print size once
随机推荐
GBASE 8s存儲過程語法結構
Codeforces Round #802 (Div. 2) C D
JS' sort() function
台式电脑连不上wifi怎么办
Use text analysis to identify the main gender in a text
【无标题】
CTF_ Web: basic 12 questions WP of attack and defense world novice zone
SOC验证环境的启动方式
计算学生成绩等级(虚函数和多态)
CTF_ Web: Advanced questions of attack and defense world expert zone WP (15-18)
成功解决:selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from
Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from
本轮压力测试下,DeFi协议们表现如何?
Office macro virus bounce shell experiment
坐标系左乘右乘
GBASE 8s 索引R树
《牛客刷verilog》Part I Verilog快速入门
Wechat likes to pay attention to the solution of invalid automatic reply
js的call()和apply()
Unity Quad culls shaders with back faces and transparent parts