stm32中的数据类型定义
扫描二维码
随时随地手机看文章
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);
注:强制类型转换时,得到一个所需要的中间变量,原来变量的类型未发生变化。