历史上的今天
今天是:2024年11月18日(星期一)
2019年11月18日 | stm32数据类型
2019-11-18 来源:eefocus
stm32编程过程经常定义变量类型,经常担心数据运算过程中 超过变量类型范围。因为在编程过程中,不同的CPU,其数据类型的意义各不相同,所以一定要注意相应变量数据类型的定义和转换,否则在计算中可能会出现不确定的错误。所以下面列出常见数据类型:
一、C语言数据类型
stm32使用的数据类型定义在 stm32f30x.h中
This file contains all the peripheral registers definitions, bits
* definitions and memory mapping for STM32F30x devices.
整型定义:
#include "core_cm4.h" /* Cortex-M4 processor and core peripherals */
#include "system_stm32f4xx.h"
#include /** @addtogroup Exported_types * @{ */ /*!< STM32F10x Standard Peripheral Library old types (maintained for legacy purpose) */ typedef int32_t s32; typedef int16_t s16; typedef int8_t s8; typedef const int32_t sc32; /*!< Read Only */ typedef const int16_t sc16; /*!< Read Only */ typedef const int8_t sc8; /*!< Read Only */ typedef __IO int32_t vs32; typedef __IO int16_t vs16; typedef __IO int8_t vs8; typedef __I int32_t vsc32; /*!< Read Only */ typedef __I int16_t vsc16; /*!< Read Only */ typedef __I int8_t vsc8; /*!< Read Only */ typedef uint32_t u32; /*常用类型*/ typedef uint16_t u16; typedef uint8_t u8; typedef const uint32_t uc32; /*!< Read Only */ typedef const uint16_t uc16; /*!< Read Only */ typedef const uint8_t uc8; /*!< Read Only */ typedef __IO uint32_t vu32; typedef __IO uint16_t vu16; typedef __IO uint8_t vu8; typedef __I uint32_t vuc32; /*!< Read Only */ typedef __I uint16_t vuc16; /*!< Read Only */ typedef __I uint8_t vuc8; /*!< Read Only */ 浮点型: #if !defined(__STRICT_ANSI__) || defined(__USE_C99_MATH) /* C99 additions */ typedef float float_t; typedef double double_t; 注:还有float 浮点型 编译器中不能看到其定义(估计已编译了)。 而uint32_t 、uint16_t、uint8_t在哪里定义?在stdint.h文件中,详见下面: /* exact-width signed integer types */ typedef signed char int8_t; typedef signed short int int16_t; typedef signed int int32_t; typedef signed __int64 int64_t; /* exact-width unsigned integer types */ typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; /* minimum values of exact-width signed integer types */ #define INT8_MIN -128 /* s8 占用1个byte,数据范围 -2^7 到 (2^7-1) */ #define INT16_MIN -32768 /* s16 占用2个byte,数据范围 -2^15 到 (2^15-1) */ #define INT32_MIN (~0x7fffffff) /* -2147483648 is unsigned s32 占用 4个byte,数据范围 -2^31 到 (2^31-1) */ #define INT64_MIN __ESCAPE__(~0x7fffffffffffffffll) /* -9223372036854775808 is unsigned int64_t占用8个byte,数据范围 -2^63 到 (2^63-1) */ /* maximum values of exact-width signed integer types */ #define INT8_MAX 127 #define INT16_MAX 32767 #define INT32_MAX 2147483647 #define INT64_MAX __ESCAPE__(9223372036854775807ll) /* maximum values of exact-width unsigned integer types */ #define UINT8_MAX 255 /* u8 占用1个byte, 数据范围 0 - 2^8*/ #define UINT16_MAX 65535 /* u16 占用2个byte, 数据范围 0 - 2^16*/ #define UINT32_MAX 4294967295u /* u32 占用4个byte, 数据范围 0 - 2^32*/ #define UINT64_MAX __ESCAPE__(18446744073709551615ull) 由上述可知: 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 位。
上一篇:stm32f0_GPIO
下一篇:stm32f4xx 加密
史海拾趣
|
让家电智能人声化设计不再为难——WTV语音芯片帮你提升产品性能 本帖最后由 jameswangsynnex 于 2015-3-3 20:00 编辑 关键词:语音芯片,语音IC,WTV芯片,家电控制 语音芯片,采用数码电子技术将纯的无任何机械的半导体集成电路(IC)去完成语音信号的存储和还原,这样一类经过存储而还原播放的语言、声 ...… 查看全部问答> |
|
摘要:针对传统分布式温度监测系统的布线问题,提出了利用ZigBee无线网络技术实现分布式温度检测系统的实现方案。该方案通过基于ZigBee技术的无线收发微处理器CC2430以及协调器节点、传感器节点的硬件设计和软件的设计流程,成功组建了一个大范围的 ...… 查看全部问答> |
|
任职条件: 大学嵌入式、计算机、电子专业本科学历。研究生、有工作经验者、有嵌入式相关证书者优先。 英语四级以上,六级以上者优先。 精通嵌入式C语言,熟练掌握嵌入式系统架构、原理。 热爱本职工作,具有较强的团队合作精神。 诚实、 ...… 查看全部问答> |
|
linux内核完全剖析 基于0.12内核 赵炯 的 200901的 txt doc pdf 的下载版本地址 谁有就给个链接吧 谢谢了哈 嘿嘿… 查看全部问答> |
|
本帖最后由 jameswangsynnex 于 2015-3-3 20:03 编辑 中国首条年产3万平方米石墨烯薄膜生产线投产暨石墨烯手机触摸屏新品发布会在常州市江南石墨烯研究院举行。 石墨烯自2004年被发现,由于其各种电学、热学、机械(行情 专区)性能已 ...… 查看全部问答> |
|
本帖最后由 辛昕 于 2014-12-4 00:04 编辑 这算是前面 那个 Contiki系列的续编。不过,相对来说,我觉得它比较独立。 一直以来,用GCC编程是我的习惯,只不过,那也仅限于PC上的程序。而一 ...… 查看全部问答> |
|
EEWORLD大学堂----Atmel SAM D21 USB接口模块(二) Atmel SAM D21 USB接口模块(二):https://training.eeworld.com.cn/course/19?SAM D21 USB模块介绍、特点和注意事项,USB host MSC bootloader流程。… 查看全部问答> |




