总的来说必须要完成两个:
- 1.设置时钟
- 2.设置模式
- 3.进行初始化
(以插在GPIOA 1、2口为例)
(LED.c)
#include "stm32f10x.h" // Device header
void LED_Init(void)
{
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA,ENABLE);//设置时钟
GPIO_InitTypeDef GPIO_InitStructure;//设置模式
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP ;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1 |GPIO_Pin_2 ;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
(LED.h)
#ifndef __LED_H //LED前面是两个下划线
#define __LED_H
void LED_Init(void);
#endif
//<-(这里一定要是空一行!)
小tip : 对于注释中的函数,可以用ctrl + f查找其定义哦!
1283

被折叠的 条评论
为什么被折叠?



