学习STM8关于数据类型的定义⼼得(更新)
最近⼀直在学STM8 代码⾥⾯⼀直出现u8 * / u16等等
类似
#include"stm8s.h"
/*芯⽚唯⼀的ID地址 96位*/
define UNIQUE_ID_START_ADDR 0x48CD
u8 i;
s16 temp;
s8 t;
u8 * pUniqueId;
int main( void )
英语句子在线翻译{
return 0;
}
⼀直不理解什么是u8 今天再⽹上好好的找找发现u8 是unsigned int 8的意思。如果是标准的C语⾔表达⽅式应该是unsigned int 8
世界大学排名2020但是STM就变成了u8 ⼀开始很郁闷不知道是什么意思。但是现在这样⼀想
volatile signed 32也就变成了
vs32
how do you do 说到底,ST搞这么多花样嘛,也就是开发⼈员强⾏偷了个懒,结果搞得我们初学者头晕。不过怎么样变化都是基于标准C的。可以参考
//stdint.h 这⾥是C语⾔的标准表达⽅式
//第36⾏开始
typedef signed char int8_t; // 标准表达⽅式 signed char 等同于 int8_t;typedef signed short int int16_t;
typedef signed int int32_t;// 如果是在32位环境⾥,int代表4个字节32位typedef signed __int64 int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
typedef signed char int_least8_t;
typedef signed short int int_least16_t;
起立的英文
typedef signed int int_least32_t;
sobeautifultypedef signed __int64 int_least64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short int uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned __int64 uint_least64_t;
typedef signed int int_fast8_t;
typedef signed int int_fast16_t;
typedef signed int int_fast32_t;
typedef signed __int64 int_fast64_t;
typedef unsigned int uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;
typedef signed int intptr_t;
typedef unsigned int uintptr_t;
typedef signed __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
关于STM32 为了兼容旧版本的
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
我的青春岁月typedef const int32_t sc32;
typedef const int16_t sc16;
typedef const int8_t sc8;
typedef __IO int32_t vs32;
typedef __IO int16_t vs16;
typedef __IO int8_t vs8;
typedef __I int32_t vsc32;
typedef __I int16_t vsc16;
ordinary daytypedef __I int8_t vsc8;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef const uint32_t uc32;
typedef const uint16_t uc16;
parasitetypedef const uint8_t uc8;
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
typedef __I uint32_t vuc32;
typedef __I uint16_t vuc16;
typedef __I uint8_t vuc8;
可以作为参考理解。
以上
**修改下,更加容易理解的地⽅应该是在这⾥
/
*!< Signed integer types */
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
/*!< Unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
这⾥就能看出,int8_t 应该是 singed char 也就是说声明新的类型名来代替原有的类型名,这样的好处就是定义⼀种新的数据类型,这种类型⼜可以⽤来声明属于该类型的变量,⼤多数情况typedef⽤来定义⼀种结构体,因为原有数据类型不够⽤了。
有个例⼦
⾃定义数据类型
经常⽤来将结构定义成⼀个数据类型~如:typedef struct student{
char name[10];free 中国
wire transferchar kemu[10];
double mark;
}student;
这样就可以直接定义数据
student stu;
stu.name = '张三';
stu.kemu = '语⽂';
stu.mark = 97.5;
⽤起来也⽐较⽅便。
以上