历史上的今天
今天是:2024年09月24日(星期二)
2020年09月24日 | STM32F4的IO设置测试
2020-09-24 来源:eefocus
环境:
主机: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 %drn", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
上一篇:STM32F103停机模式测试
史海拾趣
|
我的PIC单片机调试心得,给像我一样曾经苦苦寻觅的初学者一点启示 我是一位初学者,pic初学者,但是在单片机行当已经混迹多年了。说句实话,c开发环境都大同小异,只不过烧写和在线仿真大同小异。钻研了两天,收到了很多回应和启发。 下面应soso的请求,把最近的调试心得和大家分享 1、 先说说我要做的东西 说来 ...… 查看全部问答> |
|
看到了一篇学习笔记,觉得不错,转载来 来源:ouravr foxfox 入手Mini2440,根据优龙的代码,修改了LCD驱动,增加了中英文显示,另外增加了一个贪吃蛇的游戏。 MDK中国版例程服务包,里面有优龙的代码。 http://arm.embedinfo.com/down-li ...… 查看全部问答> |
|
Edge Detection Reference Design Introduction Video and image processing typically require very high computational power. Given the increasing processing demands, the parallel processing capabilities of Altera® programmable logic devices (PLDs) make them a ...… 查看全部问答> |
|
问题是这样的:从CPU过来的数据总线,接到FPGA了,FPGA后面又接了一个CPLD,等于说,FPGA既要将数据总线自己用,又要输出给CPLD用,该怎么实现了? 难题是数据总向是双向的不好办! 因为两片FPGA之间的连线资源较多,把它们之间的数据总结分为送 ...… 查看全部问答> |
|
请问各位大虾,现在我用ARM模块作了一个模块,需要计算机把它识别成一个人体学输入设备,该模块现在用的是windows ce系统,请问是否可以做一个驱动程序?大概应该怎么做?… 查看全部问答> |
|
从CWnd继承一个类CInputInfoWnd,在CInputInfoWnd用Create动态创建Edit控件m_editTest,此Edit控件上可以看到输入光标,但不能输入任何东西?… 查看全部问答> |
|
ESC月底在即,大量新品争相冒头。 ST的STM32L151/STM32L152该出门啦。 以下链接估计有人有兴趣:http://www.st.com/stonline/products/literature/bd/17350.pdf… 查看全部问答> |
|
这是一段MDK目录下的示例代码: /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Toggle Mode: TIM2CLK = 36 MHz, Prescaler = 0x2, ...… 查看全部问答> |




