class n) hit structure its 进行 开发板 tracking
1、led.c 的详细的代码:
初始化:首先进行时钟的打开,引脚的设置。port 速度设置,port 模式的设置
- /*----------------------------------------------------------*/
- #include "led.h"
- /* -------------------------------------------------------------------------
- 文件名称:led.c
- 描写叙述 :依据硬件连接配置LEDport,打开相应的寄存器
- ---------------------------------------------------------------------------*/
- 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;
- //port速度
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- //port模式。此为输出推挽模式
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- GPIO_Init(GPIOE,&GPIO_InitStructure);
- }
2、led.h 的头文件
led 的开关。翻转
- #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);
- #endif
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;
- }
- }
STM32 的 IO 配置点灯
来源: http://www.bubuko.com/infodetail-2147285.html