这篇文章主要是代码分享,以及简单解析。
对代码哪里不理解的,欢迎找我讨论哈。
和上篇代码结构不一样的地方是多文件和分模块,使得工程更加有条理。
这篇文章主要是单片机引脚的输出操作,和PID的那篇文章高度重合,原因是这就是最基础的底层。
文件目录
- 02_LCD12864 (这个是项目名)
- button.c
- button.h
- GPIO.h
- button_cfg.c
- button_cfg.h
- Game.c
- Game.h
- button.h
- LCD12864.h
- GPIO.c
- Reg.h
- GPIO.h
- LCD12864.c
- GPIO.h
- LCD12864.h
- LCD12864_cfg.h
- main.c
- Systick.h
- RCC.h
- LCD12864.h
- button.h
- Game.h
- RCC.c
- RCC.h
- start.s
- Systick.c
- Reg.h
- Systick.h
- button.c
STM32F103最简短的启动文件
这部分代码在PID电机调速那篇文章已经分享过了,所以不做过多赘述。
只实现了中断向量表中的复位向量和SysTick向量。
MODULE ?cstartup
SECTION CSTACK:DATA:NOROOT(3)
SECTION .intvec:CODE:NOROOT(2)
EXTERN __iar_program_start
EXTERN SysTick_Handler
PUBLIC __vector_table
DATA
__vector_table
DCD sfe(CSTACK)
DCD Reset_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD NMI_Handler
DCD SysTick_Handler
THUMB
PUBWEAK Reset_Handler
SECTION .text:CODE:REORDER:NOROOT(2)
Reset_Handler
LDR R0,=__iar_program_start
BX R0
PUBWEAK NMI_Handler
SECTION .text:CODE:REORDER:NOROOT(1)
NMI_Handler
B NMI_Handler
END
Reg.h文件内容
这部分代码在PID电机调速那篇文章已经分享过了,所以不做过多赘述。
只是单独形成了一个文件。
这部分都是寄存器结构体定义和寄存器指针宏定义。对于刚从51转到arm芯片的新手同学看着可能有点困难,这也是一个C语言知识点,typedef关键字的典型用法,但是你要理解并会用,51因为内存地址空间太小,所以很少这么用,arm芯片都是32位的地址空间,相对来说就可以称之为海量。
#ifndef __REG_H_
#define __REG_H_
#include "stdint.h"
typedef struct
{
volatile uint32_t CTRL;
volatile uint32_t LOAD;
volatile uint32_t VAL;
volatile uint32_t CALIB;
}SysTick_Def;
typedef struct
{
volatile uint32_t CR;
volatile uint32_t CFCR;
volatile uint32_t CIR;
volatile uint32_t APB2RSTR;
volatile uint32_t APB1RSTR;
volatile uint32_t AHBENR;
volatile uint32_t APB2ENR;
volatile uint32_t APB1ENR;
volatile uint32_t BDCR;
volatile uint32_t CSR;
}RCC_TypeDef;
typedef struct
{
volatile uint32_t CRL;
volatile uint32_t CRH;
volatile uint32_t IDR;
volatile uint32_t ODR;
volatile uint32_t BSRR;
volatile uint32_t BRR;
volatile uint32_t