stm32 數據類型的定義(常用的U8,U16,U32到底代表什麼)

在Keil MDK 開發環境裏,比如一個 無符號32位整形數據會有很多種表示方法:

1,unsigned int 32 (C語言標準表達方法)

2,uint32_t ;

3 ,u32;

這三種方式都是在表達同一個意思,可爲什麼ST的開發人員要搞的這麼亂呢?

還有其他好多你可能看起來很陌生 ,很不好理解的表達方式,

如:_IO int32_t 他等同於vs32(這個你同樣很陌生),不過他還等同於 volatile int32_t, 還等同於 volatile signed int 32;

最後這種表達方式纔是C語言的標準表達方式,夠亂吧,能把初學者弄的暈頭轉向。

u8,u16,u32都是unsigned char類型,不過u8是一個字節的,u16是2字節,u32是4字節 typed.

u8 是 unsigned char

u16 是 unsigned short

u32 是 unsigned int

u8 最大255 u16最大65535 就這個意思u8 a=255 a+1=0 u16 b=255 b+1=256

其實ST 搞這麼多花樣,無非是想開發人員在寫代碼時定義數據類型能少寫幾個符號,然後又因爲前後版本升級,爲了兼容舊版本(主要是V2.0)纔會出現這麼多表示方法。不管他怎麼換,都是基於標準C來的,看清楚以下幾個文件你就OK了:

core_cm3.h ;stm32f10x.h; stdint.h; 其中每個文件大概作用如下:

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;

core_cm3.h 文件主要針對動態 靜態 變量修飾符做出類型擴展

#ifdef __cplusplus

#define __I volatile

#else

#define __I volatile const

#endif

#define __O volatile

#define __IO volatile

stm32f10x.h 這個文件主要是爲了兼容舊版本吧

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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章