当前位置:网站首页>Arm architecture and programming 1 -- LED flashing (based on Baiwen arm architecture and programming tutorial video)
Arm architecture and programming 1 -- LED flashing (based on Baiwen arm architecture and programming tutorial video)
2022-07-24 01:22:00 【Mountains】
One 、 How to operate registers
1、 Access memory
Read the value of the register , modify , Write back .( The operation is complicated )
int * p;
int Val;
p = (0x40010C00 + 0x0C);
Val = *p;
Val |= (1<<3);
*p = Val;
2、 Access registers
Write directly to the register .( It's easy to operate )
int * p;
p = (0x40010C00 + 0x0C);
*p |= (1<<3);
Two 、 Who will call main function
After hardware reset , The first step of the program is to execute the reset processing program .

In the reset handler , First, execute SystemInit Initialization function , Users can write this function by themselves , No keil To encapsulate . And then call main function .
got it main Calling procedure of function , You can write the startup process of the system by yourself . because main The function is a C function , So you need stack space , So also specify the stack space .

The above figure shows the stack space set in the official startup file .

This is the startup code written by myself , After reset , Execute first __Vectors Vector table , register Reset_Handler function , Then execute the reset function , In the reset function , Declare external functions main, Then set the stack space , Finally jump to main Function to execute function .
Stack space can be found in the official manual or in keil Select the corresponding chip in and check .
3、 ... and 、 Experimental code
1、 Related registers
Turn on the clock register
Because it is a direct operation register , So there is no need to include a pile of header files . Directly operate the corresponding register .
The essence of turning on the peripheral clock is to turn on the corresponding peripheral bus APB1 and APB2 Clock enable register RCC_APB2、1ENR Correlation bit of .


If the system does not configure the clock , The default system clock source after power on is HSI,8MHz.
Pin configuration register


GPIO There are two mode configuration registers of the pin , One is CRL、CRH Control a group GPIO The lower eight and the higher eight . such as GPIOB_CRL It's pins 0-7 Mode configuration ;GPIOB_CRH yes 8-15 Mode configuration of pins .

GPIOB_ODR It's a 32 Bit register , low 16 Bit effective , Relevant location 1 Then the corresponding pin outputs high level .
2、 Specific code
1、 Define a pointer to a specific register
unsigned int * pAPB2En = ( unsigned int * )(0x40021000 + 0x18);
unsigned int * pGPIOCrl = ( unsigned int * )(0x40010C00 + 0);
unsigned int * pGPIOOdr = ( unsigned int * )(0x40010C00 + 0X0c);
2、 By configuring registers
*pAPB2En |= (1<<3);// Register No 3 Location 1, Can make GPIOB The clock
*pGPIOCrl |= (1<<0);// Register No 0 Location 1, Set up GPIOB10MHz Open drain output
*pGPIOOdr |= (1<<0);// Set register number 0 Location 1,GPIOB_PIN0 Output high level , The light goes out
3、LED flashing
while(1)
{
delay();// Time delay
*pGPIOOdr &= ~(1<<0);//GPIOB_PIN0 Output low level , Light on
delay();// Time delay
*pGPIOOdr |= (1<<0);//GPIOB_PIN0 Output high level , The light goes out
}
边栏推荐
- Thread pool summary
- A little understanding of encoder
- Bubble sort, quick sort
- 小熊派简介和环境搭建
- Source code installation and use of APIs IX
- [reply] about the fact that I chose the wrong technology at the wrong time
- Interview question: what are the differences between ArrayList and LinkedList
- 面试题之:ArrayList和LinkedList有哪些区别
- Basic exercises of C language for beginners
- HCIP第七天笔记
猜你喜欢

Polymer synthesis technology

MGRE experiment

HCIP中OSPF详解

HCIP第六天_特殊区域综合实验

OSI open system interconnection model and tcp/ip model

Determination of host byte order

2022全球开发者薪资曝光:中国排第19名,平均年薪23,790美元
For data security reasons, the Dutch Ministry of Education asked schools to suspend the use of Chrome browser

HCIP第五天笔记

Prometheus operator user guide notes
随机推荐
Hot 100 depth first
Vessel Segmentation in Retinal Image Based on Retina-GAN
HCIP第三天笔记
Understanding of flexible array in C language
HCIP第五天笔记
Deep understanding of collaborative process
OSI、TCP/IP(A1)
128. Longest continuous sequence
HCIP第十二天笔记
OSPF(第六天笔记)
Notes: binary tree pruning (recursion, iteration)
Create database table db.create in flask project_ all()
High voltage technology test questions and answers
HCIP第四天笔记
MGRE experiment
C language: explain in detail the two local communication methods based on TCP and UDP
罗克韦尔AB PLC RSLogix5000中的位指令使用方法介绍
SQL CASE 多条件用法
Idea compiler sets the separation line between methods
HCIP第一天笔记