Eight Essential Steps to Learning Microcontrollers

Eight Essential Steps to Learning Microcontrollers

Learning to use microcontrollers involves understanding the hardware structure of the microcontroller and the application of its internal resources, as well as learning various initialization settings for functions in assembly or C language, and programming to implement various functionalities. Here are some of my experiences:

Step 1: Using Digital I/O

Using button inputs to signal, and LEDs to display output levels, allows you to learn the digital I/O functionality of the pins. When a button is pressed, an LED lights up, demonstrating the functionality of combinational logic in digital circuits. Although simple, this teaches the general programming concepts of microcontrollers, such as the necessity of setting many registers to initialize the pins for digital input and output functionalities. Each time you use a function of the microcontroller, you must configure the registers controlling that function; this is a characteristic of microcontroller programming. Do not be afraid of the complexity; all microcontrollers operate this way. Note that two functions may use the same group of I/O ports, such as the LCD and LED routines both using the PB group. If combined, they may conflict and not achieve the desired effect; it is advisable to use different I/O ports for different modules.

Step 2: Using Timers

Learning to use timers allows you to implement sequential circuits with microcontrollers. The functionality of sequential circuits is powerful and has many applications in industrial and home electrical device control. For example, a microcontroller can implement a corridor light switch with a single button, where the light stays on for 3 minutes after the button is pressed once, remains on when pressed twice, and turns off if pressed for more than 2 seconds. Digital integrated circuits can implement sequential circuits, programmable logic devices (PLD) can implement sequential circuits, and programmable logic controllers (PLC) can also implement sequential circuits, but only microcontrollers do it most simply and at the lowest cost.

Using timers is very important; logic combined with time control is the foundation of microcontroller usage.

Step 3: Interrupts

A characteristic of microcontrollers is that a program executes repeatedly, and each instruction in the program requires a specific execution time. If the program does not execute a certain instruction, the action of that instruction will not occur, which can delay many rapid events, such as the falling edge when a button is pressed. To enable the microcontroller to respond to rapid actions during normal program execution, you must use the interrupt function. This function interrupts the normal running program of the microcontroller when a rapid action occurs, processes the rapid event, and then returns to executing the normal program.

The difficulty in using interrupts is knowing precisely when interrupts should not occur (masking interrupts), when they should be allowed (enabling interrupts), which registers need to be set for a certain interrupt to work, what the program should do at the start of an interrupt, and what it should do after the interrupt is completed, etc. Once you learn interrupts, you can program more complex structured programs that can monitor one thing while doing another. Once the monitored event occurs, the program interrupts what it is currently doing to handle the monitored event. Of course, you can also monitor multiple events. A metaphor for this is that the interrupt function allows the microcontroller to ‘eat from the bowl while watching the pot.’ Learning these first three steps is akin to mastering three techniques of the Eighteen Dragon-Subduing Palms; you can barely protect yourself.

Step 4: Communicating with a PC via RS232

Microcontrollers all have USART interfaces, particularly many models in the STM8 series, which have two USART interfaces. The USART interface cannot be directly connected to the RS232 interface of a PC due to differing logic levels; a STM8S105C6 chip is needed for level conversion. Using the USART interface is very important, as it allows information exchange between the microcontroller and the PC. Although RS232 communication is not advanced, it is crucial for learning about interfaces. Proper use of the USART interface requires understanding communication protocols, RS232 programming for PCs, and other related knowledge. Imagine how interesting it would be if the data displayed on the microcontroller’s experiment board could be shown on the PC monitor, while signals from the PC’s keyboard could be displayed on the microcontroller’s experiment board!

Step 5: Learning A/D Conversion

The STM8 microcontroller comes with multi-channel 12-bit A/D converters, allowing the microcontroller to operate on analog quantities and display and detect signals such as voltage and current. When learning, pay attention to concepts such as analog ground vs. digital ground, reference voltage, sampling time, conversion rate, and conversion error. A simple example of using A/D conversion functionality is designing a voltmeter.

Step 6: Learning PCI, I2C Interfaces, and LCD Interfaces

The use of these interfaces makes it easier for microcontrollers to connect to external devices, which is very important for expanding microcontroller functionalities.

Step 7: Learning Compare, Capture, and PWM Functions

These functions allow the microcontroller to control motors, detect speed signals, and implement motor speed controllers. If you master these seven steps, you can design general application systems, equivalent to learning ten techniques of the Eighteen Dragon-Subduing Palms, allowing you to strike back.

Step 8: Learning USB Interface, TCP/IP Interface, and Hardware and Software Design for Various Industrial Buses
Learning USB interfaces, TCP/IP interfaces, and hardware and software design for various industrial buses is very important, as this is the current trend in product development.

So far, this is equivalent to having learned 15 techniques of the Eighteen Dragon-Subduing Palms, but still not at the level of being invincible. Even so, you can be considered a microcontroller master.

Article sourced from: Microcontroller

Let’s share microcontroller learning experiences together!

Click to read the original text,and learn microcontroller tutorials for free

↓↓↓

Leave a Comment