STM32 learning experience six: C-related language learning and reading register address mapping name

Record it, to facilitate future ~ read
main elements:
1) used to explain the C language;
2) Address Register name mapping interpretation.
Official information: "the STM32 Chinese Reference Manual V10" Chapter 8 General and multiplexing functions IO (GPIO and AFIO)
1. Common C language
1.1 Operation: Six-bit operation Operator
1) bitwise AND: &
Example: 1011 & 0010 = 0010
2) bitwise oR: |
Example: 1011 | 0010 = 1011
. 3) or bitwise XOR: ^
Example: 1011 ^ 0010 = 1001
4) Invert: -
Example: - 1011 = 0100
5) left: <<
Example : 0110 << 1 = 1100 is
6) to the right: >>
Example: 1 = 0110 >> 0011
7) a combination of: bitwise and after the assignment: & =

GPIOA->CRL&=0XFFFFFF0F;      //将第4-7位清0
GPIOA->CRL|=0X00000040;  //设置相应位的值,不改变其他位的值

1.2 Image define macros
define the C language preprocessor for macro definition, can improve the readability of source code to facilitate programming.
Common format:
#define identifier string
identifier defined as a macro name. String can be a constant expression, format string.
example:

#define SYSCLK_FREQ_72MHz 72000000

72000000 SYSCLK_FREQ_72MHz definition identifier value.
1.3 ifdef conditional compilation
microcontroller program development process, often encounter a situation when certain conditions are satisfied for a set of statements to be compiled, and when the conditions are not met another group of statements is compiled. The most common form of conditional compilation command:
#ifdef identifier
block. 1
#else
block 2
#endif
Example:

#ifdef STM32F10X_HD
//大容量芯片需要的一些变量定义
#end

1.4 extern variable declared
before the C language can be placed in the extern variable or function to indicate defined variables or functions in other files, look for hints to the compiler encounters defined in other modules in this variable and function. Extern variable can be declared for many times, but only once defined .

1.5 typedef alias type
defines a type of alias, rather than a simple macro substitution. Pointer type may be used as a statement that a plurality of objects.
unsigned char uint8_t typedef;
typedef unsigned int Short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned uint64_t the __int64;

1.6 structure: configuration type
Struct structure name {
member list 1;
member variable 2;
. . .
} Variable name list;

you can define variables at the time stated structure can also be defined later affirmed that the method is:
Struct structure name structure variables list;
effect: the same type can be an array, you can use different types of tissue structure.
Scalable structure.
example:

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)

Static 1.7
static local variables declared in the static storage area.
It is at the end of the function call, will not be released, the value will always remain.
So declared static local variable, with memory function.
2. MDK name in the register address mapping analysis of
the concept: for MCU, all the underlying configuration, end-all configuration registers .
STM32 operation :
GPIOA-> ODR = 0x00000000;
the problem: the value 0x00000000 is how to register address assignment ODR GPIOA's? That GPIOA-> ODR this writing, is how mapping GPIOA the ODR register address up? I understand this chart below can understand.
Here Insert Picture Description
Knowledge :
1) Learning C language commonly used functions;
2) Learn name mapping register address, refer STM32 learning experience five: GPIO Experiment - based on the bit operation .

Published 24 original articles · won praise 2 · Views 4127

Guess you like

Origin blog.csdn.net/Leisure_ksj/article/details/105155462