LED

外设的基地址,STM32固件库,API函数

学会看数据手册调用数据

封装了好多寄存器

指针类型,指针运算符

宏定义放.h文件中

外设时钟的设置,开启端口时钟

低寄存器,输出模式

端口位设置/清除寄存器

运算

看数据手册的8.2GPIO寄存器描述

根据电路来写程序

程序的移植

帮助文档很重要(AD,STM32等)

下载福昕和UE

 

 

 

 

 初始化

#ifndef _led_H
#define _led_H


#endif        //不会报重复错误的错

移植直接改宏,定义宏,代码移植性

 

时序

点亮LED3

 main.c

#include "stm32f10x.h"
#include "led.h"


int main()
{
LED_Init();

while(1)
{
GPIO_ResetBits(LED_PORT,GPIO_Pin_2);//点亮LED3
}
}

LED.C

#include "led.h"


void LED_Init( )
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(LED_PORT_RCC,ENABLE);

GPIO_InitStructure.GPIO_Pin=LED_PIN;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(LED_PORT,&GPIO_InitStructure);

GPIO_SetBits(LED_PORT,LED_PIN);

}

LED.H

#ifndef _led_H
#define _led_H


#include "stm32f10x.h"

#define LED_PORT_RCC RCC_APB2Periph_GPIOC
#define LED_PIN (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7)
#define LED_PORT GPIOC

void LED_Init(void );

#endif

数码管随着点亮led灯,a到g亮一杠

原文地址:https://www.cnblogs.com/296389183yy/p/9284404.html