Environment description: Keil + Proteus circuit simulation
First, create a project in Keil and create three files in the project. The file names are: "header file.c", "delay.c", and "delay.h"
Write the corresponding content in the header files .c, delay.c, and delay.h respectively: (Be careful not to insert the delay.h file into the project file)
1 #include2 #include"delay.h" 3 4 main() 5 { 6 while(1) 7 { 8 P1 = 0x00; 9 delay();10 P1 = 0xff;11 delay(); 12 }13 }
1 #include"delay.h"2 delay()3 {4 int x;5 for(x = 0;x < 250;x++)6;7 }
1 #ifndef _DELAY_H_2 #define _DELAY_H_3 delay();4 5 #endif
Set the directory for generating Hex files:
Click Rebuild all target files, and the generated effect is as follows:
Insert an 80C51 microcontroller chip into the Proteus simulation software, and then burn the newly generated Hex file into the chip:
The simulation results are as follows:
The entire process of writing an LED light program using modules has been introduced.
Kind tips:
1. Delay plays a delay role in the program.
2. The difference between #include
#include
#include "delay.h" is a custom function, stored in your new working directory
3. The main purpose of writing this article is not to introduce how to write a microcontroller program for turning an LED on and off, but to introduce the steps of writing programs using modules through this small program.
When I was writing C language, I only used a header file and a main function. At that time, I was thinking, if I do engineering projects in the future, do I have to write a very long C language file like this?
This problem has been bothering me for a long time, but it was solved today. In this way, a large project can be divided into several sub-modules, and then the modules can be tested one by one. Where there are problems, targeted debugging can be carried out, which improves the overall efficiency.
Previous article:How to tell how big a microcontroller program is
Next article:MCU external crystal and oscillation circuit
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
- Russia's revenge is too crazy! This organization has been unbanned, and the era of piracy is back...
- Problems with crystal oscillator circuits
- How to use TMS320DM8148 for object recognition?
- [RVB2601 Creative Application Development] Development Environment Construction and LED Flowing Light
- Transfer-【TWS headphones】Some you really don’t know
- Need help 24V 100mA working current sensorless built-in MOS three-phase brushless motor driver chip
- (A-Current Signal Detection Device) First Prize of Zhejiang Province_Hangzhou Dianzi University
- Is this what the 0 detection is like?
- IAR FOR 430 Failed to re-intialize A possible solution
- Design information for temperature monitoring system