1 博客内容
博客内容基于STM32F103 RET6芯片,点亮PC3引脚LED灯,程序主要参考B站:STM32F103开发课程视频。
2 主程序(Main.c):
//================================================
// 名称: Main.c
// 作者: Morven_X
// 版本: 1.1
// 编制: 2021/01/12 23:50
// 更新: 2021/01/20 22:07
// 功能: 基于STM32F103 RET6芯片,点亮PC3引脚LED灯
// 简介: 初始编制使用结构体,更新增加寄存器操作(Keil 5.28)
// Email: morven_xie@163.com
//================================================
# include "stm32f10x.h"
# include "LED1.h"
int main(void)
{
LED_Init();
while(1)
{
GPIOC->ODR|=1<<3; //寄存器:输高,PC3设置高电平输出
// GPIO_SetBits(GPIOC, GPIO_Pin_3); //结构体,输出高,PC3设置高电平输出
}
}
3 LED灯头文件(LED1.h)
#ifndef _LED_H
#define _LED_H
void LED_Init(void);
#endif
4 LED灯程序(LED1.c)
# include "stm32f10x_rcc.h"
# include "stm32f10x_gpio.h"
# include "LED1.h"
void LED_Init(void)
{
RCC->APB2ENR|=1<<4; //使能PORTC时钟
GPIOC->CRL&=0XFFFF0FFF;
GPIOC->CRL|=0X00003000; //选择输出模式,最大速度50MHz,通用推挽输出
GPIOC->ODR|=0<<3; // 输出低,PC3设置低电平输出
}
//void LED_Init(void)
//{
// GPIO_InitTypeDef GPIO_InitStruct;
//
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能C口GPIO时钟
//
// GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP; //选择推挽输出
// GPIO_InitStruct.GPIO_Pin=GPIO_Pin_3; //指定引脚3
// GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; //设置输出速率50MHz//
// GPIO_Init(GPIOC,&GPIO_InitStruct); //初始化外设GPIOx寄存器
//}