Learning to use a microcontroller is to understand the microcontroller hardware structure and the application of internal resources, learn the initialization settings of various functions in assembly or C language, and program the realization of various functions. The following are some of my experiences:
Step 1: Use of digital I/O
Use buttons to input signals and light-emitting diodes to display output levels, so that you can learn the digital I/O function of the pins. After pressing a button, a certain light-emitting diode lights up. This is the function of combinational logic in digital circuits. Although it is very simple, you can learn general microcontroller programming ideas. For example, many registers must be set to initialize the pins so that the pins have digital input and output functions. Every time a function of the microcontroller is used, the register that controls the function must be set. This is the characteristic of microcontroller programming. Don't be afraid of trouble. All microcontrollers are like this. It should be noted that two functions use the same group of I/O ports. For example, the LCD and LED routines all use the PB group. If the two are combined, there will be conflicts and the expected effect cannot be achieved. It is recommended that different modules use different IO ports.
Step 2: Use of timer
Once you learn how to use the timer, you can use a single-chip microcomputer to implement a sequential circuit. The function of the sequential circuit is powerful and has many applications in the control of industrial and household electrical equipment. For example, a single-chip microcomputer can be used to implement a corridor light switch with a button. After the button is pressed once, the light will automatically turn off after 3 minutes. When the button is pressed twice in succession, the light will always be on. When the button is pressed for more than 2 seconds, the light will turn off. Digital integrated circuits can implement sequential circuits, programmable logic devices (PLDs) can implement sequential circuits, and programmable controllers (PLCs) can also implement sequential circuits, but only single-chip microcomputers are the simplest and the lowest cost.
The use of timers is very important. Logic plus time control is the basis for the use of single-chip microcomputers.
Step 3: Interrupts
The characteristic of a single-chip microcomputer is that a program is repeatedly executed. The execution of each instruction in the program requires a certain execution time. If the program does not execute a certain instruction, the action of the instruction will not occur, which will delay many fast-moving things, such as the falling edge when a button is pressed. In order to make the MCU respond to fast actions during the normal operation of the program, the interrupt function of the MCU must be used. This function is that after the fast action occurs, the MCU interrupts the normal operation of the program, processes the fast action, and returns to execute the normal program after the processing is completed.
The difficulty in using the interrupt function is that it is necessary to accurately know when the interrupt is not allowed to occur (shield interrupt) and when the interrupt is allowed to occur (open interrupt), which registers need to be set to make a certain interrupt work, what the program should do when the interrupt starts, what the program should do after the interrupt is completed, etc. After learning the interrupt, you can compile a more complex program. Such a program can do one thing and monitor one thing. Once the monitored thing happens, it interrupts the thing being done and processes the monitored thing. Of course, it can also monitor multiple things. Figuratively speaking, the interrupt function enables the MCU to have the function of eating from the bowl and watching the pot. Learning the above three steps is equivalent to the martial arts of the Eighteen Dragon Palms. If you have learned three palms, you can barely protect yourself.
Step 4: RS232 communication with the PC.
The MCU has a USART interface, especially many models in the stm8 series, which have two USART interfaces. The USART interface cannot be directly connected to the RS232 interface of the PC. The logic levels between them are different, and a stm8s105c6 chip is needed for level conversion. The use of the USART interface is very important. Through this interface, the microcontroller and the PC can exchange information. Although RS232 communication is not advanced, it is very important to learn the interface. To use the USART interface correctly, you need to learn the communication protocol, the RS232 interface programming of the PC, and so on. Imagine that the data on the microcontroller experimental board is displayed on the PC monitor, and the keyboard signal of the PC can be displayed on the microcontroller experimental board. How interesting it will be!
Step 5: Learn A/D conversion
The stm8 microcontroller has a multi-channel 12-bit A/D converter. Through these A/D converters, the microcontroller can operate analog quantities, display and detect voltage, current and other signals. When learning, pay attention to the concepts of analog ground and digital ground, reference voltage, sampling time, conversion rate, conversion error, etc. A simple example of using the A/D conversion function is to design a voltmeter.
Step 6: Learn
the use of PCI, I2C interface and LCD interface. These interfaces can make it easier for the microcontroller to connect to external devices, which is very important in expanding the functions of the microcontroller.
Step 7: Learn the comparison, capture and PWM functions.
These functions can enable the microcontroller to control the motor, detect the speed signal, and realize the control functions such as the motor speed regulator. If you have learned all the above seven steps, you can design a general application system, which is equivalent to learning the 10 moves of the 18th Palm of the Dragon, and you can attack.
Step 8: Learn the hardware and software design of the USB
interface, TCP/IP interface, and various industrial buses. Learning the hardware and software design of the USB interface, TCP/IP interface, and various industrial buses is very important because it is the development direction of current product development.
So far, it is equivalent to learning 15 moves of the 18th Palm of the Dragon, but it is not yet the realm of being invincible. Even so, it is still a microcontroller hero.
Previous article:Principle and function of single chip microcomputer crystal oscillator circuit
Next article:Detailed explanation of the connection between RXD and TXD of microcontroller serial communication
- Popular Resources
- Popular amplifiers
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- MSP430F6638 baud rate setting
- KiCAD released a new version - 5.1.10
- 2020 National College Student Electronics Contest Test Questions
- High voltage and small size: the latest technology trends of Nichicon's drive film capacitors
- [Chip] Interesting chips, interesting engineer souls
- Serial communication
- TMS320C6678DSP SRIO channel and frequency settings
- Should 5G be blamed for cheating in the college entrance examination?
- How to use DRV8703-Q1
- Installation and use of saleae logic analyzer