- /*
- ::按键控制
- PA8接LED,PE2接按键
- */
- #include"stm32f10x.h"
- void RCC_Configuration(void);
- void GPIO_Config(void);
- void Delay(__IO uint32_t nCount);
- int main()
- {
- RCC_Configuration(); //系统时钟配置|使能GPIO口
- GPIO_Config(); //LED控制配置
- while (1)
- {
- if(!GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2))
- {
- Delay(0x000FF);//延时防抖
- if(!GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2))
- {
- GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_8)));
- }
- }
- }
- }
- /****************************************************************************
- * 名 称:void GPIO_Config(void)
- * 功 能:GPIO初始化函数
- * 入口参数:无
- * 出口参数:无
- * 说 明:
- * 调用方法:无
- ****************************************************************************/
- void GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //配置LEDA8
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //配置按键PE2
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉输入
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- }
- /****************************************************************************
- * 名 称:void RCC_Configuration(void)
- * 功 能:系统时钟配置为72MHZ|使能GPIO口
- * 入口参数:无
- * 出口参数:无
- * 说 明:
- * 调用方法:无
- ****************************************************************************/
- void RCC_Configuration(void)
- {
- SystemInit();
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOE, ENABLE);//使能GPIO口
- }
- /****************************************************************************
- * 名 称:void Delay(__IO uint32_t nCount)
- * 功 能:延时函数
- * 入口参数:无
- * 出口参数:无
- * 说 明:
- * 调用方法:无
- ****************************************************************************/
- void Delay(__IO uint32_t nCount)
- {
- for(; nCount != 0; nCount--);
- }
|