当前位置:网站首页>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
}
边栏推荐
- 制作 .Img 镜像文件
- OSI、TCP/IP(A1)
- 数字签名技术简介
- C language: student management system based on sequence table, super detailed, all with notes, if you don't understand it after reading, please slap me.
- Kotlin foundation from introduction to advanced series explanation (basic chapter) keyword: suspend
- Good doctor consultation - Yu Chi - oral information
- 数仓搭建——ODS层
- General method of C language supporting yaml configuration file
- Introduction to the use of bit instruction in Rockwell AB PLC rslogix5000
- 数字化转型时代的企业数据新基建 | 爱分析报告
猜你喜欢

Interview question: what are the differences between ArrayList and LinkedList

Matlab提取论文插图中原始数据—Fig2Data工具

C language database: detailed description. Use the student management system to understand the operation of the database, which is simple and easy to understand.

Idea setting automatic package import and useless package deletion

kubernetes 部署 dashboard(可视化界面)

Navicat for MySQL installation tutorial

Use of crawler request library 2

kubernetes 部署 dashboard(可視化界面)

Sublime text 3 汉化+添加常用插件

为什么博途V17及以下的HMI面板不能与1500固件版本2.9或1200版本4.5 的CPU建立连接?
随机推荐
Source code installation and use of APIs IX
Polymer synthesis technology
HCIP第三天笔记
Form resume
Three usages of synchronized keywords in vernacular
出于数据安全考虑 荷兰教育部要求学校暂停使用Chrome浏览器
OSI、TCP/IP(A1)
General method of C language supporting yaml configuration file
SCM learning notes 1 -- data download and environment construction (based on Baiwen STM32F103 series tutorials)
IDEA设置 自动导包删无用包
Explanation and induction of polymer physics terms
HCIP第二天笔记
HCIP中的MGRE GRE OSPF过程
Navicat for MySQL installation tutorial
Kubernetes deployment dashboard (visual interface)
How to solve cnpm stuck during execution?
Sword finger offer frog jumps stairs
C语言力扣第53题之最大子数组和。动态规划与分治
数仓搭建——ODS层
OSPF(第五天笔记)