历史上的今天
今天是:2024年11月19日(星期二)
2019年11月19日 | STM32初学笔记---延时函数及u16、u32、u8
2019-11-19 来源:eefocus
在编写流水灯程序时发现,和对之前用的51单片机所用的普通软件延时函数有所不同,51的普通软件延时函数我们一般是这样编写的:
#include #include #define uint unsigned int #define uchar unsigned char void delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); } 然而我们在对STM32利用库函数进行编程时采用此延时函数则完全行不通,而是采用下面的延时函数 #include "stm32f10x.h" void delay(u16 x) { u16 i=0; while(x--) { i=12000; while(i--); } } 可能也有一些博友和我一样在网上找了一些好用的代码,并顺便记了下来,这里也附带粘贴一些比较准确的软件延时函数 void delay_ms(u32 time) { u32i=8000*time; //数值自己定义,6000~9000 while(i--); } void delay_ms(u16 ms) { u32 temp; SysTick->LOAD= 9000*ms; SysTick->VAL=0X00;//清空计数器 SysTick->CTRL=0X01;//使能,减到零无动作,采用外部时钟源 do { temp=SysTick->CTRL;//读取当前倒计数值 }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达 SysTick->CTRL=0x00;//关闭计数器 SysTick->VAL=0X00; //清空计数器 } 微秒级延时 void delay_us(u32 time) { u32i=8*time; //数值自己定义6~9 while(i--); } void delay_us(u32 us) { u32 temp; SysTick->LOAD= 9*us; SysTick->VAL=0X00;//清空计数器 SysTick->CTRL=0X01;//使能,减到零无动作,采用外部时钟源 do { temp=SysTick->CTRL;//读取当前倒计数值 }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达 SysTick->CTRL=0x00;//关闭计数器 SysTick->VAL=0X00; //清空计数器 } “stdint.h” typedef signed char int8_t; typedef signedshort int int16_t; typedef signed int int32_t; typedef signed __INT64 int64_t; /* exact-widthunsigned integer types */ typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; typedef unsigned __INT64 uint64_t; typedef int32_t s32; typedef int16_t s16; typedef int8_t s8; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8;
史海拾趣
|
A flag to another clock domain If the signal that needs to cross the clock domains is just a pulse (i.e. it lasts just one clock cycle), we call it a \"flag\". The previous design usually doesn\'t work (the flag might be missed, ...… 查看全部问答> |
|
哪位用过ZLG7290这款芯片,我现在也在使用。 我想请教大家个问题:如何写驱动实现控制wince的系统菜单的?比如打开左下角的菜单,上下移动菜单,或者关闭任意程序等。谢谢… 查看全部问答> |
|
wince5.0 window media player 6.4 支持标准RTSP 要让wince5.0 window media player 6.4 支持标准RTSP,所以要写一个RTSP 的filter, 我的问题是,只要注册了这个rtsp的filter ,用media player6.4接收rtsp的流就会直接调用我这个RTSP 的filter? 还是还要修改注册表其他地方??… 查看全部问答> |
|
1、环氧树脂 Epoxy Resin 2、硅胶 Silicone 3、胶饼 Molding Compound 4、硅树脂 Hybrid 根据分子结构,环氧树脂大体上可分为五大类: 1、 缩水甘油醚类环氧树脂 2、 缩水甘油酯类环氧树脂 3、 缩水甘油胺 ...… 查看全部问答> |
|
今天又遭鄙视了,之前听说泰克的春季创新论坛扩展到15个城市,本想报名泰克创新论坛了解一哈功率测量、高精度功率分析、EMI诊断等方面的测试技术呢,网上资料虽然一大堆但面对面的教学让人更易接受,不懂还可以请教泰克的专家。但是,在巡展的15个 ...… 查看全部问答> |




