STM32 IO configuration lighting

Publisher:真实幻想Latest update time:2019-03-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Specific code of led.c:



/*----------------------------------------------------------*/

#include "led.h"

 

/* -------------------------------------------------------------------------

File name: led.c

Description: Configure the LED port according to the hardware connection and open the corresponding register

---------------------------------------------------------------------------*/

void LED_Init(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

//Open the PB port clock

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

//Open the PE port clock

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);

//PB5, PE5 pin settings

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

//Port speed

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

//Port mode, this is output push-pull mode

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOB,&GPIO_InitStructure);

GPIO_Init(GPIOE,&GPIO_InitStructure);

}

Initialization: First, turn on the clock, set the pins, set the port speed, and set the port mode.

2. The header file of 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);

 

#endif

LED switch, flip

3. main.c function code



/*----------------------------------------------------------------------------------

File name: Control LED2 and LED3 to flash

Hardware platform: STM32F103 development board

Author: Qiushi

Firmware library: V3.5

-----------------------------------------------------------------------------------*/

/* Includes ------------------------------------------------------------------*/

#include "stm32f10x.h"

#include "led.h"

 

int main(void)

{

uint32_t i;


  LED_Heat();

LED2_ON;

LED3_OFF;

for(i=0; i < 0xffffff; i++)

  while (1)

  {

for(i = 0; i < 0xfffff;i++);

LED2_REV;

LED3_REV;

  }

}



When we use functions when writing code, we give priority to using function macros.

Keywords:STM32 Reference address:STM32 IO configuration lighting

Previous article:stm32 serial port lighting
Next article:STM32 Getting Started: Lighting

Recommended ReadingLatest update time:2024-11-23 02:49

STM32 jumps to hardware error interrupt (HardFault_Handle)
1. The error problem is that the data type is incorrect, which causes the step to never be executed and jumps to the hardware error interrupt; so the hardware interrupt can try to find the data type error. 2. Stack setting error will also jump to hardwarefault; 3. If HardFault_Handle is generated at an uncertain l
[Microcontroller]
Discussion on SystemInit() function of STM32
I only knew that systemInit was used to initialize the clock, but I didn't know how to initialize it, so I reorganized it. For details, refer to  STM32 study notes - SystemInit() function  This blog is very detailed, so I won’t go into details. ST recommends an 8M external crystal. Looking at the clock tree, you
[Microcontroller]
Discussion on SystemInit() function of STM32
STM32 implements one of the IAP functions
Recently, due to project requirements, we need to implement the online upgrade function of STM32, that is, IAP. I will first summarize the learning experience and the specific implementation of IAP in the past few days and share it with you. I hope it will be helpful to those who also implement IAP. At the end of the
[Microcontroller]
STM32 implements one of the IAP functions
Encrypting embedded code programs running on STM32
Purpose: Encrypt embedded code programs running on STM32 Compilation environment: IAR Embedded System for ARM5.5 1. STM32Flash organization The Flash of STM32 includes main memory (HD version, 512KB) + information block. The information block includes 2KB system memory (for system bootstrap startup code) a
[Microcontroller]
Encrypting embedded code programs running on STM32
LCD usage of FSMC of STM32
After two days of learning about LCD, I have a preliminary understanding of STM32's FSMC. Although I encountered some problems, I solved them one by one through unremitting efforts. Next, I will explain the problems you may encounter when using FSMC. I hope it will be helpful to everyone's study. 1. Port Configuratio
[Microcontroller]
STM32 serial port USART
USART is a standard interface that is very common in applications. 1. The main idea of ​​using peripheral devices in the STM32 firmware library In STM32, the configuration ideas of peripheral devices are relatively fixed. The first is to enable the relevant clocks. On the one hand, it is the clock of the device itself
[Microcontroller]
stm32DMA channel ADC channel
DMA: 1. When using DAC, when the converted analog signal is output through the IO port, why is the IO port also configured to input mode? PS: The stm32 manual defines that PA4 and PA5 are connected to DAC1 channel and DAC2 channel respectively; The use of DMA1 and DMA2 is also specified in the channel manual: How
[Microcontroller]
STM32 library function USART_SendData problem and solution
1. Problems and Phenomena There is no problem in using USART_SendData() function to send single characters non-continuously; when sending characters continuously (no delay between two characters), the sending buffer will overflow. If the amount of data sent is very small, the serial port will only send the last char
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号