file-type

Systick定时器在单片机中的高效应用

下载需积分: 9 | 453KB | 更新于2025-01-20 | 68 浏览量 | 1 下载量 举报 收藏
download 立即下载
标题:"systick时钟基线运用" 描述:"工程化,定制化你的单片机代码,时至今日,依旧看到很多小伙伴们放着单片机里的定时器不用,动辄delay1s(); delay500ms();虽然简单粗暴,但是其实是很不妥当的。还有很多需要按键的程序,动不动就“while(k1==0);”的等按键松开,这样的代码只是“为了满足某个功能“而设计的代码,而非”为了保证产品的质量“而设计的代码。我们应该时刻考虑“如果这用户不按我的标准操作来搞我的产品,我该怎么写程序?”,而不是”只要客户乖乖听我的,这样做是没问题的,就行了;出了问题都是他乱搞,跟我有个毛关系”,后面的思维是典型的只顾自己爽的思维,我们应当想方设法的提高产品的可靠度。本程序利用systick定时器用作时钟基线实现多个定时器功能" 标签:"stm32 systick 时钟基线 多任务" 文件名称:"systick时钟基线运用" 在深入探讨文件内容之前,需要对标题和描述中提及的知识点进行详细说明。 首先,systick定时器是ARM Cortex-M系列处理器内核中的一个系统定时器,它是一个简单的24位倒计数器,常用于生成周期性的中断,非常适合用于操作系统的节拍器或者裸机编程中的时间基准。在嵌入式系统开发中,systick定时器的正确使用对于保证程序的稳定性和可靠性至关重要。 描述中提到了工程化和定制化单片机代码的重要性。在嵌入式开发中,仅仅使用简单的延迟函数(如delay1s())是不够的,这不仅会影响程序的响应性,还可能导致资源的浪费和系统性能的下降。更为合理的方法是利用systick定时器作为时钟基线,通过它来实现定时器功能,这样可以更有效地管理时间资源,提高代码的效率和可维护性。 描述中还强调了编程时应考虑的健壮性和可靠性问题。在实际应用中,用户可能并不会按照开发者的预期去操作设备,因此代码需要能够适应各种非预期的使用场景。例如,使用简单的while循环等待按键释放是不够的,这可能导致程序在某些情况下无法正确响应用户操作。正确的做法应该是利用中断或者更高级的定时器功能来处理按键事件,这样可以避免阻塞CPU,提高程序的响应速度和可靠性。 在嵌入式系统中,多任务的实现也是一个常见的需求。描述中提到的使用systick实现多个定时器功能,实际上就是在讨论如何在一个单核处理器上实现类似多任务的效果。通过合理安排任务的执行和时间管理,可以让多个任务看起来像是并行运行的。 最后,标签中提到的stm32是STMicroelectronics公司生产的一系列32位ARM Cortex-M微控制器,广泛应用于各种嵌入式系统和物联网设备。由于stm32系列微控制器通常搭载了systick定时器,因此这个资源可能是为stm32开发的代码或者讨论如何在stm32平台上使用systick定时器。 通过以上内容,我们可以得知这个压缩文件可能包含以下知识点: 1. systick定时器的工作原理和编程方法。 2. 如何利用systick定时器作为时钟基线来设计和实现定时器功能。 3. 嵌入式系统中代码工程化和定制化的方法和重要性。 4. 提高嵌入式系统可靠性的编程思维和实践。 5. 如何在单核处理器上模拟实现多任务处理。 6. STM32微控制器的systick定时器应用实例和编程技巧。 这些知识点对于嵌入式系统开发者来说是基础且重要的,掌握它们有助于开发出性能更优、更稳定的嵌入式软件产品。

相关推荐

filetype

Rebuild started: Project: display *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MCUSTM32\ARM\ARMCC\Bin' Rebuild target 'display' Note: source file '..\CORE\system_stm32f10x.c' - object file renamed from '.\Objects\system_stm32f10x.o' to '.\Objects\system_stm32f10x_1.o'. compiling stm32f10x_it.c... compiling main.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\USER\main.h(7): error: #5: cannot open source input file "systick.h": No such file or directory #include "systick.h" ..\USER\main.c: 2 warnings, 1 error compiling system_stm32f10x.c... assembling startup_stm32f10x_md.s... compiling stm32f10x_rcc.c... compiling core_cm3.c... compiling display.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\APP\display.c: 1 warning, 0 errors compiling stm32f10x_gpio.c... compiling misc.c... compiling timer.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(23): warning: #1-D: last line of file ends without a newline #endif /* __MAIN_H */ ..\USER\main.h(7): error: #5: cannot open source input file "systick.h": No such file or directory #include "systick.h" ..\APP\timer.c: 2 warnings, 1 error compiling key.c... ..\APP\display.h(26): warning: #1-D: last line of file ends without a newline #endif /* __DISPLAY_H */ ..\USER\main.h(7): error: #5: cannot open source input file "systick.h": No such file or directory #include "systick.h" ..\APP\key.c: 1 warning, 1 error compiling systick_delay.c... compiling stm32f10x_tim.c... ".\Objects\display.axf" - 3 Error(s), 6 Warning(s). Target not created. Build Time Elapsed: 00:00:02

filetype

15:34:49 **** Incremental Build of configuration Debug for project ov2640 **** make -j20 all arm-none-eabi-gcc "../Core/ov2460/SysTick.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/ov2460/SysTick.d" -MT"Core/ov2460/SysTick.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/ov2460/SysTick.o" ../Core/ov2460/SysTick.c: In function 'SysTick_Init': ../Core/ov2460/SysTick.c:12:9: warning: implicit declaration of function 'SysTick_CLKSourceConfig'; did you mean 'HAL_SYSTICK_CLKSourceConfig'? [-Wimplicit-function-declaration] 12 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); | ^~~~~~~~~~~~~~~~~~~~~~~ | HAL_SYSTICK_CLKSourceConfig ../Core/ov2460/SysTick.c:12:33: error: 'SysTick_CLKSource_HCLK_Div8' undeclared (first use in this function); did you mean 'SYSTICK_CLKSOURCE_HCLK_DIV8'? 12 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ | SYSTICK_CLKSOURCE_HCLK_DIV8 ../Core/ov2460/SysTick.c:12:33: note: each undeclared identifier is reported only once for each function it appears in make: *** [Core/ov2460/subdir.mk:28: Core/ov2460/SysTick.o] Error 1 "make -j20 all" terminated with exit code 2. Build might be incomplete. 15:34:49 Build Failed. 2 errors, 1 warnings. (took 185ms)

「已注销」
  • 粉丝: 0
上传资源 快速赚钱