当前位置:首页 > 单片机 > 单片机
[导读]STM32F10X.H1 #include "core_cm3.h"2 #include "system_stm32f10x.h"3 #include 45 /** @addtogroup Exported_types6 * @{7 */ 89 /*!< STM32F10x Standard Peripheral Library old types (maintained for legacy

STM32F10X.H



1 #include "core_cm3.h"

2 #include "system_stm32f10x.h"

3 #include

4

5 /** @addtogroup Exported_types

6 * @{

7 */

8

9 /*!< STM32F10x Standard Peripheral Library old types (maintained for legacy purpose) */

10 typedef int32_t s32;

11 typedef int16_t s16;

12 typedef int8_t s8;

13

14 typedef const int32_t sc32; /*!< Read Only */

15 typedef const int16_t sc16; /*!< Read Only */

16 typedef const int8_t sc8; /*!< Read Only */

17

18 typedef __IO int32_t vs32;

19 typedef __IO int16_t vs16;

20 typedef __IO int8_t vs8;

21

22 typedef __I int32_t vsc32; /*!< Read Only */

23 typedef __I int16_t vsc16; /*!< Read Only */

24 typedef __I int8_t vsc8; /*!< Read Only */

25

26 typedef uint32_t u32;

27 typedef uint16_t u16;

28 typedef uint8_t u8;

29

30 typedef const uint32_t uc32; /*!< Read Only */

31 typedef const uint16_t uc16; /*!< Read Only */

32 typedef const uint8_t uc8; /*!< Read Only */

33

34 typedef __IO uint32_t vu32;

35 typedef __IO uint16_t vu16;

36 typedef __IO uint8_t vu8;

37

38 typedef __I uint32_t vuc32; /*!< Read Only */

39 typedef __I uint16_t vuc16; /*!< Read Only */

40 typedef __I uint8_t vuc8; /*!< Read Only */

41

42 typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;

43

44 typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;

45 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))

46

47 typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;


源定义在#include


1 /*

2 * 'signed' is redundant below, except for 'signed char' and if

3 * the typedef is used to declare a bitfield.

4 */

5

6 /* 7.18.1.1 */

7

8 /* exact-width signed integer types */

9 typedef signed char int8_t;

10 typedef signed short int int16_t;

11 typedef signed int int32_t;

12 typedef signed __INT64 int64_t;

13

14 /* exact-width unsigned integer types */

15 typedef unsigned char uint8_t;

16 typedef unsigned short int uint16_t;

17 typedef unsigned int uint32_t;

18 typedef unsigned __INT64 uint64_t;

19

20 /* 7.18.1.2 */

21

22 /* smallest type of at least n bits */

23 /* minimum-width signed integer types */

24 typedef signed char int_least8_t;

25 typedef signed short int int_least16_t;

26 typedef signed int int_least32_t;

27 typedef signed __INT64 int_least64_t;

28

29 /* minimum-width unsigned integer types */

30 typedef unsigned char uint_least8_t;

31 typedef unsigned short int uint_least16_t;

32 typedef unsigned int uint_least32_t;

33 typedef unsigned __INT64 uint_least64_t;

34

35 /* 7.18.1.3 */

36

37 /* fastest minimum-width signed integer types */

38 typedef signed int int_fast8_t;

39 typedef signed int int_fast16_t;

40 typedef signed int int_fast32_t;

41 typedef signed __INT64 int_fast64_t;

42

43 /* fastest minimum-width unsigned integer types */

44 typedef unsigned int uint_fast8_t;

45 typedef unsigned int uint_fast16_t;

46 typedef unsigned int uint_fast32_t;

47 typedef unsigned __INT64 uint_fast64_t;

48

49 /* 7.18.1.4 integer types capable of holding object pointers */

50 #if __sizeof_ptr == 8

51 typedef signed __INT64 intptr_t;

52 typedef unsigned __INT64 uintptr_t;

53 #else

54 typedef signed int intptr_t;

55 typedef unsigned int uintptr_t;

56 #endif

57

58 /* 7.18.1.5 greatest-width integer types */

59 typedef signed __LONGLONG intmax_t;

60 typedef unsigned __LONGLONG uintmax_t;


由上述可知:


1、有符号整型

s8 占用1个byte,数据范围 -2^7 到 (2^7-1)

s16 占用2个byte,数据范围 -2^15 到 (2^15-1)

s32 占用 4个byte,数据范围 -2^31 到 (2^31-1)2^31 =2147483647

int64_t占用8个byte,数据范围 -2^63 到 (2^63-1) 2^63 =9223372036854775807ll

2、无符号整型

u8 占用1个byte, 数据范围 0 - 2^8

u16 占用2个byte, 数据范围 0 - 2^16

u32 占用4个byte, 数据范围 0 - 2^32 2^32 =4294967295

uint64_t 占用8个byte, 数据范围 0 - 2^64 2^64 =18446744073709551615

3、浮点型

float ——4个byte,有符号型,可以表达负数/小数;Float 类型至少要能精确表示到小数点后6位。

double——8个byte,有符号型,可以表达负数/小数;Double 类型至少要能精确到小数点后 10 位。

二、不同数据类型混合运算

在C语言中,不同类型的数据间是可以混合运算的。在进行运算时,不同类型的数据要先转换成同一类型,然后进行运算。转换的规则如下:

注意:箭头的方向只表示数据类型级别的高低,由低向高转换,这个转换过程是一步到位的。

(三)数据类型转换规则

各类数据类型的转换,分为两种方式:隐式(编译软件自动完成),显式(程序强制转换)

隐式转换规则:

字符必须先转换为整数(C语言规定字符类型数据和整型数据之间可以通用)
short型转换为int型(同属于整型)
float型数据在运算时一律转换为双精度(double)型,以提高运算精度(同属于实型)
赋值时,一律是右部值转换为左部类型
[注]
当整型数据和双精度数据进行运算时,C先将整型数据转换成双精度型数据,再进行运算,结果为双精度类型数据
当字符型数据和实型数据进行运算时,C先将字符型数据转换成实型数据,然后进行计算,结果为实型数据

显式转换规则:

例:(int)(x+y);

注:强制类型转换时,得到一个所需要的中间变量,原来变量的类型未发生变化。


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

在嵌入式开发中,STM32的时钟系统因其灵活性和复杂性成为开发者关注的焦点。然而,看似简单的时钟配置背后,隐藏着诸多易被忽视的陷阱,轻则导致系统不稳定,重则引发硬件损坏。本文从时钟源选择、PLL配置、总线时钟分配等关键环...

关键字: STM32 时钟系统

在嵌入式系统开发中,STM32系列微控制器的内部温度传感器因其低成本、高集成度特性,广泛应用于设备自检、环境监测等场景。然而,受芯片工艺差异和电源噪声影响,其原始数据存在±1.5℃的固有误差。本文从硬件配置、校准算法、软...

关键字: STM32 温度传感器

在能源效率与智能化需求双重驱动下,AC-DC转换器的数字控制技术正经历从传统模拟方案向全数字架构的深刻变革。基于STM32微控制器的PFM(脉冲频率调制)+PWM(脉冲宽度调制)混合调制策略,结合动态电压调整(Dynam...

关键字: AC-DC STM32

当前智能家居产品需求不断增长 ,在这一背景下 ,对现有浇花装置缺陷进行了改进 ,设计出基于STM32单片机的全 自动家用浇花机器人。该设计主要由机械结构和控制系统构成 ,机械结构通过麦克纳姆轮底盘与喷洒装置的结合实现机器...

关键字: STM32 麦克纳姆轮 安全可靠 通过性强

用c++编程似乎是让你的Arduino项目起步的障碍吗?您想要一种更直观的微控制器编程方式吗?那你需要了解一下Visuino!这个图形化编程平台将复杂电子项目的创建变成了拖动和连接块的简单任务。在本文中,我们将带您完成使...

关键字: Visuino Arduino ESP32 STM32

基于STM32与LoRa技术的无线传感网络凭借其低功耗、广覆盖、抗干扰等特性,成为环境监测、工业自动化等场景的核心解决方案。然而,如何在复杂电磁环境中实现高效休眠调度与动态信道优化,成为提升网络能效与可靠性的关键挑战。本...

关键字: STM32 LoRa

在实时控制系统、高速通信协议处理及高精度数据采集等对时间敏感的应用场景中,中断响应延迟的优化直接决定了系统的可靠性与性能上限。STM32系列微控制器凭借其灵活的嵌套向量中断控制器(NVIC)、多通道直接内存访问(DMA)...

关键字: STM32 DMA

数字电源技术向高功率密度、高效率与高动态响应方向加速演进,STM32微控制器凭借其基于DSP库的算法加速能力与对LLC谐振变换器的精准控制架构,成为优化电源动态性能的核心平台。相较于传统模拟控制或通用型数字控制器,STM...

关键字: STM32 数字电源

STM32微控制器凭借其针对电机控制场景的深度优化,成为高精度、高可靠性驱动系统的核心选择。相较于通用型MCU,STM32在电机控制领域的核心优势集中体现在FOC(磁场定向控制)算法的硬件加速引擎与PWM死区时间的动态补...

关键字: STM32 电机控制

无线充电技术加速渗透消费电子与汽车电子领域,基于Qi协议的无线充电发射端开发成为智能设备能量补给的核心课题。传统模拟控制方案存在响应滞后、参数调整困难等问题,而基于STM32的数字PID控制结合FOD(Foreign O...

关键字: STM32 无线充电
关闭