当前位置:网站首页>ARM架构与编程1--LED闪烁(基于百问网ARM架构与编程教程视频)
ARM架构与编程1--LED闪烁(基于百问网ARM架构与编程教程视频)
2022-07-23 05:43:00 【山、】
一、如何操作寄存器
1、访问内存
读出寄存器的值,修改,写回去。(操作复杂)
int * p;
int Val;
p = (0x40010C00 + 0x0C);
Val = *p;
Val |= (1<<3);
*p = Val;
2、访问寄存器
直接写寄存器。(操作简单)
int * p;
p = (0x40010C00 + 0x0C);
*p |= (1<<3);
二、谁来调用main函数
硬件复位后,程序第一步执行复位处理程序。

在复位处理程序中,首先执行SystemInit初始化函数,这个函数用户可以自己写,不是keil给封装的。然后调用main函数。
知道了main函数的调用过程,就可以自己编写系统的启动过程了。因为main函数是个C函数,所以需要用到栈空间,所以还要指定栈空间。

上图是官方启动文件中设置堆栈空间。

这个是自己编写的启动代码,在复位后,先执行__Vectors向量表,注册Reset_Handler函数,然后执行复位函数,在复位函数中,声明外部函数main,然后设置栈空间,最后跳转到main函数去执行函数。
栈空间可以在官方的手册中查找或者在keil中选择对应芯片之后查看。
三、实验代码
1、相关寄存器
开启时钟寄存器
因为是直接操作寄存器,所以不需要包含一堆头文件。直接操作对应寄存器即可。
开启外设时钟的实质是开启对应外设总线APB1和APB2的时钟使能寄存器RCC_APB2、1ENR的相关位。


系统若不进行进行时钟配置,则上电后默认系统时钟来源是HSI,8MHz。
引脚配置寄存器


GPIO引脚的模式配置寄存器有两个,一个是CRL、CRH分别是控制一组GPIO的低八位和高八位。比如GPIOB_CRL是引脚0-7的模式配置;GPIOB_CRH是8-15引脚的模式配置。

GPIOB_ODR是个32位寄存器,低16位有效,相关位置1则对应引脚输出高电平。
2、具体代码
1、定义指针指向具体寄存器
unsigned int * pAPB2En = ( unsigned int * )(0x40021000 + 0x18);
unsigned int * pGPIOCrl = ( unsigned int * )(0x40010C00 + 0);
unsigned int * pGPIOOdr = ( unsigned int * )(0x40010C00 + 0X0c);
2、通过配置寄存器
*pAPB2En |= (1<<3);//寄存器第3位置1,使能GPIOB时钟
*pGPIOCrl |= (1<<0);//寄存器第0位置1,设置GPIOB10MHz开漏输出
*pGPIOOdr |= (1<<0);//设置寄存器第0位置1,GPIOB_PIN0输出高电平,灯灭
3、LED闪烁
while(1)
{
delay();//延时
*pGPIOOdr &= ~(1<<0);//GPIOB_PIN0输出低电平,灯亮
delay();//延时
*pGPIOOdr |= (1<<0);//GPIOB_PIN0输出高电平,灯灭
}
边栏推荐
- CPC client installation tutorial
- 利用pycaret:低代码,自动化机器学习框架解决分类问题
- Circular queue
- With statement
- Modify the root password of MySQL
- Development and deployment of steel defect detection using paddlex yolov3 of propeller
- with语句
- Solution to schema verification failure in saving substantive examination request
- 数据分析(二)
- Ffmpeg audio coding
猜你喜欢

数据挖掘场景-发票虚开

使用飞桨的paddleX-yoloV3对钢材缺陷检测开发和部署

Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!

Definition and application of method

High level API of propeller to realize face key point detection

对.h5文件的迭代显示,h5py数据操作

pytorch与paddlepaddle对比——以DCGAN网络实现为例

Comparison between pytorch and paddlepaddle -- Taking the implementation of dcgan network as an example

Gartner research: how is China's digital development compared with the world level? Can high-performance computing dominate?

可能逃不了课了!如何使用paddleX来点人头?
随机推荐
Interpretation of yolov3 key code
UE4 solves the problem that the WebBrowser cannot play H.264
绿色数据中心“东数西算”全面启动
The data set needed to generate yolov3 from the existing voc207 data set, and the places that need to be modified to officially start the debugging program
Chaoslibrary · UE4 pit opening notes
保存实质审查请求书出现Schema校验失败的解决方法
Ninja startup process
论文解读:《提高N7-甲基鸟苷(m7G)位点预测性能的迭代特征表示方法》
实用卷积相关trick
VIO---Boundle Adjustment求解过程
生命科学领域下的医药研发通过什么技术?冷冻电镜?分子模拟?IND?
Rondom summary
论文解读:《基于预先训练的DNA载体和注意机制识别增强子-启动子与神经网络的相互作用》
Matplotlib Usage Summary
利用or-tools来求解路径规划问题(TSP)
Find the sum of numbers between 1 and 100 that cannot be divided by 3
NVIDIA NVIDIA released H100 GPU, and the water-cooled server is adapted on the road
LVGL8.1版本笔记
Vio --- boundary adjustment solution process
K核苷酸频率(KNF,k-nucleotide frequencies)或K-mer频率