软件安装
本笔记以stm32f103c8
下载v5版本软件,最好是和视频教程里一样,要不然会遇到一大片的麻烦。。。
此外要下载stm32的标准库
新建工程
必须必须必须!!!!使用v5版本的keil5要不然视频的文件用不了会出现一大串的报错,本人亲自尝试,耗时一个晚上,最终重新下载低版本的keil5最终解决
example:
会出现以上三种错误,是因为keil5版本太高的原因
新建文件夹
文件夹里需新建三个文件夹:
User——存放主文件
conf.h配置库函数头文件的包含关系,it文件存放中断函数
libraries——存放标准库
start——存放启动文件
start 文件的选择:
添加路径
都需要手动添加
#include "stm32f10x.h" // Device header
int main(void)
{
while(1)
{
}
}
注意!!!!注意!!!!注意!!!!
最后一两行一定要空着 要不然会报错!!!!
寄存器点灯
#include "stm32f10x.h" // Device header
int main(void)
{
RCC->APB2ENR =0X00000010;
GPIOC->CRH =0x00300000;
GPIOC->ODR =0x00002000;
while(1)
{
}
}
标准库点灯
#include "stm32f10x.h" // Device header
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_13);
//GPIO_ResetBits(GPIOC,GPIO_Pin_13);
while(1)
{
}
}