32程序结构学习

初始化代码

复制代码
void LED_GPIO_Config(void)
{		
	/*定义一个GPIO_InitTypeDef类型的结构体*/
	GPIO_InitTypeDef GPIO_InitStructure;

	/*开启GPIOC的外设时钟*/
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); 

	/*选择要控制的GPIOC引脚*/															   
  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;	

	/*设置引脚模式为通用推挽输出*/
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   

	/*设置引脚速率为50MHz */   
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 

	/*调用库函数,初始化GPIOC*/
  	GPIO_Init(GPIOA, &GPIO_InitStructure);		  

	/* 关闭所有led灯	*/
	GPIO_SetBits(GPIOA, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5);	 
}

其中开外设时钟是容易遗漏的。

复制代码
/******************** (C) COPYRIGHT 2012 WildFire Team **************************
 * 文件名  :main.c
 * 描述    :按键测试函数,按键为扫描模式        
 * 实验平台:野火STM32开发板
 * 库版本  :ST3.5.0
 *
 * 作者    :wildfire team 
 * 论坛    :http://www.amobbs.com/forum-1008-1.html
 * 淘宝    :http://firestm32.taobao.com
**********************************************************************************/
#include "stm32f10x.h" 
#include "led.h"
#include "key.h"  

/*
 * 函数名:main
 * 描述  :主函数
 * 输入  :无
 * 输出  :无
 */
int main(void)
{	
	/* config the led */
	LED_GPIO_Config();
	LED_A3( ON );

	/*config key*/
	Key_GPIO_Config();	
	
	while(1)                            
	{	   
		if( Key_Scan(GPIOB,GPIO_Pin_5) == KEY_OFF  )
		{
			/*LED1反转*/
			GPIO_WriteBit(GPIOA, GPIO_Pin_3, 
				(BitAction)(1-(GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_3))));
		}   
	}
}


/******************* (C) COPYRIGHT 2012 WildFire Team *****END OF FILE************/

用key点灯功能正常。

相关推荐
QMCY_jason4 小时前
RK3588 usb摄像头 mipi摄像头 hdmi in 调试记录
单片机·嵌入式硬件
国科安芯4 小时前
四重证据,一条逻辑链:商业航天级微控制器MCU抗辐射验证方法学综述——以国科安芯AS32S601为例
人工智能·单片机·嵌入式硬件·mcu·安全·抗辐射
dadaobusi4 小时前
学习: PCIe 6.0 的 L0p
学习
燕落南枝6 小时前
CSS 学习:类型选择器与 AI 注释实战
css·人工智能·学习
玄芯散人7 小时前
【元婴·100】STM32启动流程:从上电到main()经历了什么
stm32·单片机·嵌入式硬件
恒锐丰科技林技术员9 小时前
EG3525S 推挽半桥 PWM 控制芯片解析与工程应用
经验分享·嵌入式硬件·硬件工程
Swilderrr10 小时前
论文精读:《Directory-Aware Query and Maintenance in Vector Databases》
笔记·学习
kkkkkkkkkk_Z10 小时前
新手自学嵌入式 | 学习日记:LCD显示原理、PWM控制、电容触摸屏(GT9147)驱动开发与项目实战
驱动开发·学习
科芯创展11 小时前
XZ5129:单节锂电池供电36V升压LED恒流驱动芯片设计解析
stm32·单片机·嵌入式硬件
恒锐丰科技林技术员11 小时前
EG44273 低侧单通道栅极驱动芯片解析
经验分享·嵌入式硬件·硬件工程