STM32的IO配置点灯
2015-08-16 23:10
357 查看
1、led.c的具体的代码:
2、led.h的头文件
3、main.c函数代码
我们写代码的时候使用函数的时候,优先使用函数宏。
/*----------------------------------------------------------*/ #include "led.h" /* ------------------------------------------------------------------------- 文件名:led.c 描述 :根据硬件连接配置LED端口,打开对应的寄存器 ---------------------------------------------------------------------------*/ void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; //打开PB口时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //打开PE口时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); //PB5,PE5引脚设置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //端口速度 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //端口模式,此为输出推挽模式 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_Init(GPIOE,&GPIO_InitStructure); }初始化:首先进行时钟的打开,引脚的设置,端口速度设置,端口模式的设置
2、led.h的头文件
#ifndef __LED_H #define __LED_H #include "stm32f10x.h" #define LED2_OFF GPIO_SetBits(GPIOE,GPIO_Pin_5) #define LED2_ON GPIO_ResetBits(GPIOE,GPIO_Pin_5) #define LED2_REV GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_5)))) #define LED3_OFF GPIO_SetBits(GPIOB,GPIO_Pin_5) #define LED3_ON GPIO_ResetBits(GPIOB,GPIO_Pin_5) #define LED3_REV GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)))) void LED_Init(void); #endifled的开关,翻转
3、main.c函数代码
/*---------------------------------------------------------------------------------- 文件名称:控制LED2,LED3闪烁 硬件平台:STM32F103 开发板 作者 :求是 固件库 :V3.5 -----------------------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" #include "led.h" int main(void) { uint32_t i; <span style="white-space:pre"> </span>LED_Init(); LED2_ON; LED3_OFF; for(i=0; i < 0xffffff; i++) while (1) { for(i = 0; i < 0xfffff;i++); LED2_REV; LED3_REV; } }
我们写代码的时候使用函数的时候,优先使用函数宏。
相关文章推荐
- python去掉html标签
- 清理Android项目中没用的资源
- @property关键字和几个描述符号(不全,待补充)
- DHCP Snooping简介
- 实现线程串行执行
- ubuntu 14.04 任务栏无法显示时间
- Android本地数据存储复习
- WPF中的右键菜单ContextMenu
- 第一百三十六天 how can I坚持
- Leetcode 7 Reverse Integer
- 《Python简明教程》总结
- C/C++编译链接过程详解
- 《Python简明教程》总结
- 前端开发推荐网址
- 优秀博客链接
- 归并排序的C++实现
- ECNU 1624 求交集多边形面积
- 感想。
- 3
- 第86讲:Scala中For表达式的生成器、定义和过滤器