博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
STM32F4的IO设置测试
阅读量:3946 次
发布时间:2019-05-24

本文共 3571 字,大约阅读时间需要 11 分钟。

               

STM32F4的IO设置测试

本文博客链接:,作者: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****/

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!

你可能感兴趣的文章
凡事必定不少于三个以上的解决方法
查看>>
带团队的点滴心经
查看>>
五种力量让你如虎添翼
查看>>
你害怕创新吗
查看>>
创新服务的七要素
查看>>
虚伪的奉承也有效
查看>>
蒂姆·库克的五项核心领导力
查看>>
你为何没有成为领导者
查看>>
一切悲剧都源于不当激励
查看>>
别把用户的高期望混同于好体验
查看>>
动机和机会:推动商业发展的引擎
查看>>
4个信号表明你是一个失败的领导
查看>>
成功谈判 你需要几个锦囊?
查看>>
一个人的宽度决定了他的高度
查看>>
善于拜访是另一种经营智慧
查看>>
打造新老员工双赢机制变对立为统一
查看>>
企业如何避免用错人
查看>>
打掉苹果“无与伦比”的傲慢(人民时评)
查看>>
Creating an Android Project
查看>>
Running Your App (android)
查看>>