当前位置:网站首页>基于STM32的编写
基于STM32的编写
2022-06-28 01:03:00 【m0_61811389】
一、在Keil环境下创建新项目
1.新建项目
点击project,选择New uVision Project创建项目,命名项目并保存

![]()
选择芯片:STM32F103VE,点击OK

然后CMSIS中选择CORE,在Device下选择Startup,选完后点OK

2.添加源文件
在刚才的目录下右击Source Group 1,选择Add New Item to Group 'Source Group 1'...
选择文件的类型,点击Asm Files(.s)添加汇编文件,输入文件名然后点击Add

点击Source Group 1查看text.s
二、代码编写,编译与调试
1.代码编写
在text.s中添加代码
AREA MYDATA, DATA
AREA MYCODE, CODE
ENTRY
EXPORT __main
__main
MOV R0, #10
MOV R1, #11
MOV R2, #12
MOV R3, #13
;LDR R0, =func01
BL func01
;LDR R1, =func02
BL func02
BL func03
LDR LR, =func01
LDR PC, =func03
B .
func01
MOV R5, #05
BX LR
func02
MOV R6, #06
BX LR
func03
MOV R7, #07
MOV R8, #08
BX LR
进行初始设置,点击Options for Target

在Output界面下,勾选 Create HEX File,才能生成 hex 文件

在 Debug界面下,勾选 Use Simulator

我们需要修改Dialog和右侧Parameter如下图

调试运行,结果符合预期,寄存器的值和程序设置一致,具体如下图所示:

三、分析生成的HEX文件
用记事本打开hex文件,是一串十六进制字符

1.扩展线性地址记录
扩展线性地址记录(hex 文件的第一排十六进制)也叫作 32 位地址记录或 HEX386 记录
这些记录包含数据地址的高 16 位
扩展线性地址记录总是有两个数据字节,外观如下(这里我通过标记方便对应原始数据):
:020000040800F2

当一个扩展线性地址记录被读取,存储于数据域的扩展线性地址被保存,它被应用于从 Intel HEX 文件读取来的随后的记录。线性地址保持有效,直到它被另外一个扩展地址记录所改变。通过把记录当中的地址域与被移位的来自扩展线性地址记录的地址数据相加获得数据记录的绝对存储器地址。
2.数据部分
Intel HEX 由任意数量的十六进制记录组成。每个记录包含 5 个域,它们按一定格式排列::llaaaatt[dd...]cc。每一组字母对应一个不同的域,每一个字母对应一个十六进制编码的数字。每一个域由至少两个十六进制编码数字组成,它们构成一个字节,就像以下描述的那样::llaaaatt[dd…]cc

3.文件尾部
在文件的最后一排,是一个文件的结束标志:
:00000001FF

参考文献:(3条消息) Keil环境下创建STM32汇编语言工程并分析HEX文件内容_m0_58414679的博客-CSDN博客
边栏推荐
- "Dadao Zhichuang" won a ten million prea+ round of financing and launched a technology consumption robot
- Teach you how to realize pynq-z2 bar code recognition
- 【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
- [today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born
- 畢業總結
- Solutions to st link USB communication error
- Starting sequence of Turing machine
- Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance
- How to systematically learn LabVIEW?
- The graduation season is coming, and the number of college graduates in 2022 has exceeded 10 million for the first time
猜你喜欢

【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
![[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown](/img/6e/f0e71bb941d5940dbf6d51b812b52e.png)
[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown

Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法

How to realize red, green and yellow traffic lights in ros+gazebo?

【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线

Flask基础:模板渲染+模板过滤使用+控制语句

数仓的字符截取三胞胎:substrb、substr、substring
![[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born](/img/af/1faf1df4262940e73104ed2880f08d.png)
[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born

【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用

如何开启多语言文本建议?Win11打开多语言文本建议的方法
随机推荐
Keil "St link USB communication error" solution
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
如何判断线程池已经执行完所有任务了?
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
"Dadao Zhichuang" won a ten million prea+ round of financing and launched a technology consumption robot
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
SQL reported an unusual error, which confused the new interns
MySQL优化小技巧
11 timers for STM32F103
【历史上的今天】6 月 6 日:世界 IPv6 启动纪念日;《俄罗斯方块》发布;小红书成立
Win11无法使用动态壁纸怎么办?Win11用不了动态壁纸的解决方法
如何系统学习LabVIEW?
【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
Opencv -- Hough transform and some problems encountered
MFC常用 当前路径
榜单首发——前装搭载率站上10%大关,数字钥匙方案供应商TOP10
SQL injection bypass (V)
抓包整理外篇fiddler————了解工具栏[一]
Skills in schematic merging
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established
