The rapid development of the C programming language required STM32 review

1. Bit Operation
C supports the following six kinds of language bitwise operators
&: Bitwise AND.
|:. Bitwise or
. ^: Bitwise exclusive-or
. -: negated
. <<: Left
>>: left.
Note : operator does not include the small dots left corner, please ignore small point

2.define macro definitions
define the C language preprocessor thereof, can improve the readability of source code to facilitate programming.
Common format: #define identifier string

3.ifdef conditions

					#ifdef 标识符
					程序段1
					#else
					程序段2
					#endif

His role is: When the identifier has been defined (usually defined by #define command), then compiled the program segment 1, otherwise block 2 to be compiled.
NOTE: wherein #else Block 2 can not

Another form

#if 标识符 
程序段1
#endif  

If the identifier is already defined, then the execution of the block 1

4.extern declare variables

Extern variable can be placed before or function, represents a variable or function is defined in another file, look for hints to the compiler encounters defined in other modules in this variable and function.

Note: extern variable can be declared many times, but only once defined.
Here Insert Picture Description
The structure
declaration format structure type

格式:
struct 结构体名
{
	成员列表;
}变量名列表;

实例:
struct _GPIO
{
	int TMODER;
	int Tser;
}
**注:变量名列表结构体声明的结构体变量,可不写,以后再定义**
例如:struct _GPIO  age,number;//就定义了两个结构体变量age和number

After defining the structure variable reference method is variable structure member

例如我们上面定义了的age结构体变量,我要输出他的成员变量Tser
那么应该写为
printf("%d",age.Tser);//也就是 结构体变量名.成员变量名,没什么特殊的

Pointer variable definition of the structure

依然基于上面的_GPIO结构体
定义结构体指针变量:struct _GPIO  *age;
是的,只是结构体变量名前面加了*,但是要访问结构体变量成员时应该这样写
printf("%d",age->Tser);

6.typedef type alias

typedef is used to create a new type for the existing name, or become a type alias to simplify the custom variable. Alias ​​is the type most typedef enum type and definition of the structure used in the keil5.

struct _GPIO
{
	__IO uint32_TMODER;
	__IO uint32_Tser;
	......
}
此时我们定义一个上面的结构体应该这样定义
struct _GPIO age;


但是我们使用typedeftypedef  struct 
{
	__IO uint32_TMODER;
	__IO uint32_Tser;
	......
}GPIO
此时我们定义一个上面的结构体可以这样
GPIO age;
此时我们就定义了一个叫age的结构体变量
Published 11 original articles · won praise 4 · Views 1409

Guess you like

Origin blog.csdn.net/OXOXOX6/article/details/104539833