STM32笔记
标签(空格分隔): 未分类
—cheese steak jimmy’s
robin hood
#常用定义
##点亮LED灯
>GPIO_InitTypeDef GPIO_InitStructure[2];
>RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);//时钟 //enable外总线使能
>GPIO_InitStructure[0].GPIO_Pin=GPIO_Pin_13;//获取引脚
>GPIO_InitStructure[0].GPIO_Mode=GPIO_Mode_OUT;//输入输出状态
>GPIO_InitStructure[0].GPIO_OType=GPIO_OType_PP;//推挽
>GPIO_InitStructure[0].GPIO_PuPd=GPIO_PuPd_UP;//上拉
>GPIO_InitStructure[0].GPIO_Speed=GPIO_Speed_50MHz;//速度
>GPIO_Init(GPIOE,&GPIO_InitStructure[0]);//初始化
GPIO_SetBits(GPIOF,GPIO_Pin_9);//置位
GPIO_ResetBits(GPIOF,GPIO_Pin_9);//复位
d点亮一个灯 引脚pe13
##代码附录
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
>// GPIO_InitStructure[0].GPIO_Pin=GPIO_Pin_13;
// GPIO_InitStructure[0].GPIO_Mode=GPIO_Mode_OUT;
// GPIO_InitStructure[0].GPIO_OType=GPIO_OType_PP;
// GPIO_InitStructure[0].GPIO_PuPd=GPIO_PuPd_UP;
// GPIO_InitStructure[0].GPIO_Speed=GPIO_Speed_50MHz;
// GPIO_InitStructure[1].GPIO_Pin=GPIO_Pin_9;
// GPIO_InitStructure[1].GPIO_Mode=GPIO_Mode_OUT;
// GPIO_InitStructure[1].GPIO_OType=GPIO_OType_PP;
// GPIO_InitStructure[1].GPIO_PuPd=GPIO_PuPd_UP;
// GPIO_InitStructure[1].GPIO_Speed=GPIO_Speed_50MHz;
// GPIO_Init(GPIOE,&GPIO_InitStructure[0]);
// GPIO_Init(GPIOF,&GPIO_InitStructure[1]);
##关于gpio引脚设置的写法
// GPIO_InitTypeDef GPIO_InitStructure;
// GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14;//获取引脚
// GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//输入输出状态
// GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//推挽
// GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//上拉
// GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//速度
// GPIO_Init(GPIOE,&GPIO_InitStructure);//初始化
//
// GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;
// GPIO_Init(GPIOF,&GPIO_InitStructure);//初始化
##myport函数书写
#ifndef __myport_h
#define __myport_h
#include <stdio.h>
#include <stm32f4xx.h>
#define SPEEDONE GPIO_Speed_50MHz
void myport (GPIO_InitTypeDef *p,uint16_t tmp,uint8_t i,char type)
{
uint32_t A;
GPIO_TypeDef *B;
switch(type){
case 'A':
A=RCC_AHB1Periph_GPIOA;
B=GPIOA;
break;
case 'B':
A=RCC_AHB1Periph_GPIOB;
B=GPIOB;
break;
case 'C':
A=RCC_AHB1Periph_GPIOC;
B=GPIOC;
break;
case 'D':
A=RCC_AHB1Periph_GPIOD;
B=GPIOD;
break;
case 'E':
A=RCC_AHB1Periph_GPIOE;
B=GPIOE;
break;
case 'F':
A=RCC_AHB1Periph_GPIOF;
B=GPIOF;
break;
case 'G':
A=RCC_AHB1Periph_GPIOG;
B=GPIOG;
break;
}
RCC_AHB1PeriphClockCmd(A,ENABLE);
(*p).GPIO_Pin = tmp;
if(i==0)
{(*p).GPIO_Mode = GPIO_Mode_OUT;}
else {(*p).GPIO_Mode=GPIO_Mode_IN;}
(*p).GPIO_OType = GPIO_OType_PP;
(*p).GPIO_PuPd = GPIO_PuPd_UP;
(*p).GPIO_Speed = SPEEDONE;
GPIO_Init(B,p);
}
#endif
##引脚分类
- 电源引脚
- gpio引脚
- 时钟引脚
- 复位引脚