stm32一点笔记

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引脚
  • 时钟引脚
  • 复位引脚
Created with Raphaël 2.2.0 开始 初始化 是否为真 End yes no
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值