您现在的位置: 主页 > MCU > 单片机技术应用 > STM32F4的IO设置测试 -
本文所属标签:
为本文创立个标签吧:

STM32F4的IO设置测试 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-06 

[导读]环境:主机:WIN7开发环境:MDK4.72MCU:STM32F407VGT6说明:目标板上有一个LED,有一个按键,按键实现LED状态翻转.LED:PE2,低电平亮,高电平灯灭按键:PC13,低电平按下,高电平松开源代码:main.c/**************************

环境:

本文引用地址: http://www.21ic.com/app/mcu/201808/783959.htm

主机:WIN7

开发环境:MDK4.72

MCU:STM32F407VGT6


说明:

目标板上有一个LED,有一个按键,按键实现LED状态翻转.


LED:PE2,低电平亮,高电平灯灭

按键:PC13,低电平按下,高电平松开


源代码:

main.c


/*********************************************************************

*主文件

*(c)copyright2014,jdh

*AllRightReserved

*新建日期:2014/3/25byjdh

**********************************************************************/

/*********************************************************************

*头文件

**********************************************************************/

#include"main.h"

#include"stm32f4xx_rcc.h"

#include"stm32f4xx_gpio.h"

/*********************************************************************

*全局变量

**********************************************************************/

static__IOuint32_tTimingDelay;

/*********************************************************************

*函数定义

**********************************************************************/

voidDelay(__IOuint32_tnTime);

/*********************************************************************

*函数

**********************************************************************/

intmain(void)

{

//定义IO初始化结构体

GPIO_InitTypeDefGPIO_InitStructure;

//系统时钟:1ms滴答1次

if(SysTick_Config(SystemCoreClock/1000))

{

while(1);

}

//设置LED的IO口

//初始化时钟

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);

//管脚模式:输出口

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;

//类型:推挽模式

GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;

//上拉下拉设置:不使能

GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;

//IO口速度

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;

//管脚指定

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;

//初始化

GPIO_Init(GPIOE,&GPIO_InitStructure);

//设置按键的IO口

//初始化时钟

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);

//管脚模式:输出口

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;

//类型:推挽模式

GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;

//上拉下拉设置:不使能

GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;

//IO口速度

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;

//管脚指定

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;

//初始化

GPIO_Init(GPIOC,&GPIO_InitStructure);

while(1)

{

//GPIO_SetBits(GPIOE,GPIO_Pin_2);

//Delay(500);

//GPIO_ResetBits(GPIOE,GPIO_Pin_2);

//Delay(500);

//按键检测

if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)==0)

{

GPIO_ToggleBits(GPIOE,GPIO_Pin_2);

Delay(500);

}

}

}

/**

*@briefInsertsadelaytime.

*@paramnTime:specifiesthedelaytimelength,inmilliseconds.

*@retvalNone

*/

voidDelay(__IOuint32_tnTime)

{

TimingDelay=nTime;

while(TimingDelay!=0);

}

/**

*@briefDecrementstheTimingDelayvariable.

*@paramNone

*@retvalNone

*/

voidTimingDelay_Decrement(void)

{

if(TimingDelay!=0x00)

{

TimingDelay--;

}

}

#ifdefUSE_FULL_ASSERT

/**

*@briefReportsthenameofthesourcefileandthesourcelinenumber

*wheretheassert_paramerrorhasoccurred.

*@paramfile:pointertothesourcefilename

*@paramline:assert_paramerrorlinesourcenumber

*@retvalNone

*/

voidassert_failed(uint8_t*file,uint32_tline)

{

/*Usercanaddhisownimplementationtoreportthefilenameandlinenumber,

ex:printf("Wrongparametersvalue:file%sonline%drn",file,line)*/

/*Infiniteloop*/

while(1)

{

}

}

#endif

/**

*@}

*/

/**

*@}

*/

/*******************(C)COPYRIGHT2011STMicroelectronics*****ENDOFFILE****/






              查看评论 回复



嵌入式交流网主页 > MCU > 单片机技术应用 > STM32F4的IO设置测试 -
 

"STM32F4的IO设置测试 -"的相关文章

网站地图

围观()