STM32 Getting Started Development--LED Module to Implement Marquee

Publisher:MysticDreamerLatest update time:2019-03-28 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Case description

Use the STM32F103ZE development board to control the LED lights to achieve the marquee phenomenon.

I am still learning embedded development, and the blog will be updated continuously, so stay tuned!


2. Development Environment

keil 5.14 + Windows 10 + FlyMcu

Reference: STM32 Reference Manual


3. Implementation principle

A. According to the hardware interface diagram:



From the interface diagram, we can see that the two LEDs on the development board are connected to the PB5 and PE5 interfaces respectively. That is, we can operate the register of the GPIO port to operate the controller of the GPIO port.



B. Initialize (enable) PB and PE ports. After searching the manual, we found that ports PB and PE are controlled by the third and sixth bits of the APB2ENR port respectively. We set this bit to 1, and keep other bits unchanged (|= operation).

APB2ENR: Peripheral Clock Enable Register



C. Configure GPIOx port




First, clear bits 20-23 corresponding to PB5 to 0, set to input mode, clear to 0 (&= operation)

Secondly, configure the GPIOB and GPIOE ports corresponding to the LED as push-pull output, that is, general push-pull output, that is, 00. The output mode speed is defined according to the actual situation. Here I use 50MHz, that is, 11. Since GPIOB_CRL is 32 bits, that is, bits 20-23 should be set to 0011 = 3, and the other bits remain unchanged.

The settings of PE5 port and PB5 port are the same.


led.c:

void led_init()

{

  // From the structure diagram, we can see that LED0 is connected to PB5 and LED1 is connected to PE5

//RCC_APB2ENR APB2 peripheral clock enable register

  RCC->APB2ENR |= 1<<3; // Set the third bit, even if IOPB is enabled

RCC->APB2ENR |= 1<<6; // Set the sixth bit, even if IOPE is enabled


//Port configuration low register GPIOx_CRL 32 bits

GPIOB->CRL &= 0XFF0FFFFF; // Set bits 23-20 to 0, i.e. set in input mode

GPIOB->CRL |= 0X00300000; // Set bits 23-22 to 00 Set bits 21-20 to 11

// Push-pull output, maximum speed 50MHz

// ODR port data output register

GPIOB->ODR = 1<<5; // Enable ODR5. Since the LED lights are connected to PB5 and PE5 respectively, the output should be from ODR5.



GPIOE->CRL &= 0XFF0FFFFF;

GPIOE->CRL |= 0X00300000;

GPIOE->ODR = 1<<5;

}

Keywords:STM32 Reference address:STM32 Getting Started Development--LED Module to Implement Marquee

Previous article:Single chip microcomputer three key modes single click double click long press
Next article:Analysis of STM32 firmware library usage

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号