The code is modified as follows:
#include "reg52.h" //This file defines some special function registers of the microcontroller
typedef unsigned int u16; //declare and define the data type
typedef unsigned char u8;
sbit led=P2^2; //Define the P2.2 port of the microcontroller as led
/*******************************************************************************
* Function name: delay
* Function : Delay function, when i=1, the delay is about 10us
*******************************************************************************/
void delay(u16 i)
{
while(i--);
}
/*******************************************************************************
* Function name: main
* Function : Main function
* Input: None
* Output : None
*******************************************************************************/
void main()
{
while(1)
{
led=0;
delay(50000); //About 450ms delay
led=1;
delay(50000); //About 450ms delay
}
}
Typedef is used in the code to declare and define data types. This is a syntax of C language, which is easy to understand. Here, u16 is used instead of unsigned int. In an 8-bit microcontroller, 16-bit data can be represented, which can represent numbers from 0 to 65535 (2^16-1). Similarly, u8 is used instead of unsigned char.
Add a delay function, which implements a self-decrementing infinite loop to achieve the purpose of delay. We will know later that this method is not recommended, but here it can roughly achieve a delay of about 5s for the LED to flash.
Previous article:Practical Analysis of 8051 MCU (Taking STC89C52RC as an Example) | 03 - LED Flowing Light
Next article:Practical Analysis of 8051 MCU (Taking STC89C52RC as an Example) | 01 - Lighting up an LED
Recommended ReadingLatest update time:2024-11-16 12:55
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- STC32G Series MCU Technical Reference Manual
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The Linux Foundation expects revenue to reach $177 million this year
- What does PAD mean in a circuit schematic?
- September 23 nexperia live broadcast review: Nexperia's efficient ESD solutions for connected car applications
- Knowledge of common op amp models
- These two methods make electric vehicles run farther in winter
- Voltage Follower
- Anlu SparkRoad Development Board Review (1) Development Board Hardware Overview
- C Data Structures
- 【ufun learning】isp download
- What is wireless charging? What are the benefits of a wireless charging setup?