STM32F4的IO设置测试
2014-03-25 11:49
274 查看
STM32F4的IO设置测试
本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.
环境:
主机:WIN7
开发环境:MDK4.72
MCU:STM32F407VGT6
说明:
目标板上有一个LED,有一个按键,按键实现LED状态翻转.
LED:PE2,低电平亮,高电平灯灭
按键:PC13,低电平按下,高电平松开
源代码:
main.c
本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.
环境:
主机:WIN7
开发环境:MDK4.72
MCU:STM32F407VGT6
说明:
目标板上有一个LED,有一个按键,按键实现LED状态翻转.
LED:PE2,低电平亮,高电平灯灭
按键:PC13,低电平按下,高电平松开
源代码:
main.c
/********************************************************************* * 主文件 * (c)copyright 2014,jdh * All Right Reserved *新建日期:2014/3/25 by jdh **********************************************************************/ /********************************************************************* * 头文件 **********************************************************************/ #include "main.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_gpio.h" /********************************************************************* * 全局变量 **********************************************************************/ static __IO uint32_t TimingDelay; /********************************************************************* * 函数定义 **********************************************************************/ void Delay(__IO uint32_t nTime); /********************************************************************* * 函数 **********************************************************************/ int main(void) { //定义IO初始化结构体 GPIO_InitTypeDef GPIO_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); } } } /** * @brief Inserts a delay time. * @param nTime: specifies the delay time length, in milliseconds. * @retval None */ void Delay(__IO uint32_t nTime) { TimingDelay = nTime; while(TimingDelay != 0); } /** * @brief Decrements the TimingDelay variable. * @param None * @retval None */ void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) { TimingDelay--; } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
相关文章推荐
- Xcode升级5.1 iOS升级7.1无法真机调试
- 如何查询不重复字段记录
- SpringMVC控制器设值原理分析(ModelAndView的值通过HttpServletRequest直接取到的原因)
- ios--md5加密
- 如何捕获和分析 JavaScript Error
- ubuntu 修改root密码
- html制作的日历
- MapReduce优化----几点根本设置
- 000
- 一、Linux学习笔记:虚拟机设置中的各种网络连接方式详解
- 官方论坛的帖子 How about use "armeabi-v7a" as default ABI on Android for template? ABI 是啥?
- 让文字具有3D效果
- HOG特征向量的维数
- vc 操作word 指定位置读写,拆分表格!
- 第四周作业------第三题
- 0day汇编shellcode有基础疑问
- Ubuntu 12.04 安装Chrome步骤
- python特性介绍
- 有权重参考价值:站长平台搞了个2014网站运势神测
- maven仓库管理器Nexus