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;
}
Previous article:Single chip microcomputer three key modes single click double click long press
Next article:Analysis of STM32 firmware library usage
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Europe's three largest chip giants re-examine their supply chains
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- Smart Micro MM32F103CxT6 Hardware IIC
- Looking for a solution to improve the micro-current amplifier circuit
- Encoder interface circuit design
- Two measurement methods for current detection resistor connection circuit
- Application of wireless remote control in raw material yard
- Balun Design
- Differences between MSP430F11x1 and MSP430F11x1A
- 【RT-Thread software package application works】Multi-function weather clock
- The difference between ISO10536, ISO15693 and ISO14443
- [Erha Image Recognition Artificial Intelligence Vision Sensor] 6. Identify motors and control their operation