#ifndef _DELAY1S_H_
#define _DELAY1S_H_
void delay1s(); //delay function
#endif
Again, we create a led_on.h, and the code content is as follows:
#ifndef _LED_ON_H_
#define _LED_ON_H_
void led_on(void);//Light flashes
#endif
The role is the same as delay1s.h. If you don't understand, you can look at the above explanation again.
Finally, we complete the three functions we mentioned above.
In the led_on() function, we used the definitions of some registers of the 51 MCU, so we have to include reg52.h, and we used the delay1s() function, so we have to include delay1s.h, so the code of the led_on.c file is as follows:
#include
#include “delay1s.h” //Note that there is no semicolon here
void led_on(void)
{
P0=0x00;
delay1s();
P0=0xff;
delay1s();
}
The code of the Main function is as follows:
#include
#include “delay1s.h”
#include “led_on.h”
void main()
{
led_on();
delay1s();
led_on();
}
In this function, in order to explain the definition of the structure #ifndef...#define...#endif again, you can remove this structure from all .h files, and then compile it to see the effect.
At this point, I believe everyone has a general understanding of this modular writing method. If we want to add new functions, such as adding a running light function, then we only need to add a led_circle.c and led_circle.h, and then follow the above steps to add it to the project. The rest of the program does not need to be changed. Obviously this is very convenient. In fact, the extern keyword can be used for function declarations. This type is the default in C language, so it is not necessary to write it.
Previous article:Playing with MCU, you and I are both rookies (continued 1)
Next article:Common Problems for C Language Beginners
Recommended ReadingLatest update time:2024-11-16 19:31
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
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
- AD sampling has been used for so long, it's time to get familiar with the internal structure
- Solution: Vivado cannot find the ILA core, or finds the ILA but there is no corresponding data line in the window
- There are posts everywhere. Why hang it on a tree?
- Many standards for automotive embedded systems
- DIY a car remotely controlled by WeChat
- C2000 MCU Boot Process Analysis - Taking TMS320F28069 as an Example
- Analysis and calculation of UART module register configuration in MSP430FR2311
- [New Year's Flavor Competition] + Show off your New Year's Eve dinner and experience ice and snow tourism in the north!
- In STM32F103RCT6, I use the state machine method to add buttons, but I don't want the buttons to work in a function.
- [2022 Digi-Key Innovation Design Competition] Revised version of 2-DOF pan-tilt robot control platform