学习STM8 关于数据类型的定义心得(更新)

来源:互联网 发布:哪个软件可以看韩剧 编辑:程序博客网 时间:2024/05/21 05:40

最近一直在学STM8  代码里面一直出现u8 * / u16等等 

类似

#include"stm8s.h"/*芯片唯一的ID地址 96位*/define UNIQUE_ID_START_ADDR  0x48CDu8 i;s16 temp;s8 t;u8 * pUniqueId;int main( void ){  return 0;}
一直不理解什么是u8 今天再网上好好的找找发现u8 是unsigned int 8的意思。如果是标准的C语言表达方式应该是

unsigned int 8

但是STM就变成了u8 一开始很郁闷不知道是什么意思。但是现在这样一想

volatile signed 32也就变成了

vs32 

说到底,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;typedef   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; typedef __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; typedef 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];
char kemu[10];
double mark;
}student;
这样就可以直接定义数据
student stu;
stu.name = '张三';
stu.kemu = '语文';
stu.mark = 97.5;

用起来也比较方便。

以上



2 0