Comprehensive Guide to Learning C Language for Microcontrollers

Comprehensive Guide to Learning C Language for Microcontrollers

Article Word Count: 7000 Practical Value: ⭐⭐⭐⭐⭐
Many people who want to learn microcontrollers ask me the first question: how can I learn microcontrollers well? Today, I will talk about how I started learning microcontrollers, how I got hands-on, and how I became proficient in this process.
First, let’s talk about microcontrollers. Generally, the MCS-51 microcontroller is widely used; it has a lot of documentation and a large user base, making the market quite big. From my personal experience, here’s how to learn microcontrollers faster.
Learning microcontrollers is a subject that emphasizes hands-on practice. You can’t just read books, but you must start by reading, as you need to understand the various functional registers of the microcontroller. To clarify, we use software to control the various functional registers of the microcontroller, which means controlling when the voltage levels on the microcontroller’s pins are high or low.
The changes in these high and low voltage levels control your system board, achieving the various functions we need. Regarding reading books, you only need to have a rough idea of what each pin of the microcontroller does and what functions it can achieve. The first and second times you may not understand everything, but that’s okay because you still lack practical sensory experience.
That’s why I always say that reading about microcontrollers for two or three days is sufficient. You can read five or six novels in a day, but for microcontrollers, two or three readings in two or three days will do; you don’t need to read carefully. I recommend one book: “New MCS-51 Microcontroller Application Design” published by Harbin Institute of Technology Press, authored by Zhang Yigang. Get a rough idea of the content of the book, and then practice; this is crucial.
If you don’t practice learning microcontrollers, it’s impossible to master it. There are two methods you can choose for practice: one method is to spend your own money to buy a microcontroller learning board. You don’t need a board with too many functions; for beginners, a board with many features will have many things you won’t need in your lifetime. I suggest having a board with a running light, digital tube, standalone keyboard, matrix keyboard, AD or DA (the principle is the same), LCD, and buzzer; that’s about enough. If you can proficiently apply what I’ve mentioned, you can say you have entered the world of microcontroller hardware, and the rest is just practicing circuit design and continuously accumulating experience.
Once you pass the first hurdle, the rest will be much easier; as the saying goes, the first step is the hardest. Method two: if there are experts in microcontrollers around you, ask them for help to set up a simple minimum system board.
For experts, making a microcontroller minimum system board only takes a minute, but it can be much harder for beginners because only by understanding the hardware can you use it proficiently. If you don’t have such an expert around you and can’t find someone to help, I recommend that you buy one yourself; after all, having one is much more convenient, and you can use it for small experiments related to microcontrollers later, saving you trouble.
Once you have a microcontroller learning board, you need to practice more. It’s best to have a computer; spend less time watching movies and playing games. Connect the learning board to the computer, open the debugging software, and sit in front of the computer. First, learn how to use the debugging software, then start with the simplest running light experiment. Once you can make those eight running lights flow according to your wishes, you have entered the field; you will find how fascinating microcontrollers are, and it’s so much fun. This isn’t just about learning knowledge; it’s about playing. When the program you write works as you intended, you’ll be happier than doing anything else, and you’ll get addicted, really.
People in electronics really become addicted. Then let the digital tube light up; once you’ve mastered these two tasks, you won’t be able to extricate yourself. You’ll start thinking about which career path you want to take.
This is how to practice. While writing programs, you will definitely encounter many problems. At this time, you can look up books or ask others. When you get answers, you will remember them for a lifetime. Knowledge must be applied to real-life situations to be effective. Think about it; after so many years in college, what have you learned in class? Is it just to be busy for the final exam? After scoring 90 points, you feel so happy, but when you return to school next semester, you’ve forgotten everything, right? What have you learned? But I tell you, once you learn microcontrollers, you will never forget them. Additionally, let’s talk about programming with assembly and C language. Many students take C language courses in their first or second year; I’ve also taken it. I know that at that time, it was all about multiplication and addition, calculating factorials, etc.
What’s the use of that? If you were asked to write a program for a microcontroller in C language, wouldn’t you be at a loss? We must be able to apply what is in the books. You can program microcontrollers in either C language or assembly language, but I recommend using C language as it is better. If you have a background in C language, it will be easier to learn; if not, you can learn C language while learning microcontrollers. C language is quite simple; it’s just a tool. I advise you to learn it well; you will definitely need it in the future. Otherwise, you will have to learn it later. It doesn’t matter if you know nothing about assembly, but if you know nothing about C language, you will face difficulties in the future.
Assembly code has high efficiency but is relatively difficult and verbose, especially when encountering algorithmic problems, which can be incredibly troublesome. Now the main frequency of microcontrollers is continuously increasing; we don’t need such high-efficiency code because we have high-frequency clocks. The ROM of microcontrollers is also continuously increasing, enough to accommodate any code you write in C language. C language materials are abundant and easy to find, and it has great portability. You only need to change an IO port to write a temperature sensor program, and it can be used anywhere, so I advise everyone to use C language.
In summary, as long as you have confidence, can stick to it, and have a strong will not to give up in the face of failure, learning microcontrollers can be an easy task.
Steps
1. Find a book to get a rough understanding of the microcontroller structure; just a general understanding is fine. You don’t need to understand everything; you are not writing a book. (3 days)
2. Find a learning board to practice writing programs; learning microcontrollers is all about programming practice. When you encounter difficulties, ask someone or check the book. (20 days)
3. Look for some small circuit materials online to practice designing peripheral circuits. After soldering, debug it yourself to familiarize yourself with the process. (10 days)
4. Completely design a circuit or product with your personal style; you will have become an expert.
Did you see that? With a little over a month of hard work, you can become an expert. I’ve said enough; whether you can learn it well depends on your effort.
My Learning Insights on Microcontrollers
Many people say that it’s best to learn assembly language first for microcontrollers. From my experience, I can tell you that this is absolutely unnecessary. Beginners should directly use C language for microcontroller programming; it saves time, is easier to learn, and progress will be fast. When you start learning microcontrollers, do not waste time trying to understand the internal structure of microcontrollers; this will only undermine your confidence. Once you learn programming, you will naturally master the internal structure step by step.
Practice in Learning Microcontrollers
Learning microcontrollers is heavily reliant on practice. To learn microcontrollers well, software programming is essential. However, being familiar with hardware is also very important for mastering microcontrollers.
How to learn hardware well? Hands-on practice is indispensable. We can enhance our understanding and proficient use of some chips by creating our own electronic projects. This way, we can gain more insight into the structure of the chips. I believe that once you complete your own electronic project, your level of microcontroller knowledge will qualitatively improve.
This is my insight into learning microcontrollers; I hope it helps enthusiasts learn microcontrollers well.
Using microcontrollers means understanding the hardware structure of microcontrollers and applying internal resources, learning how to initialize various functions in assembly or C language, and programming to achieve various functionalities.
Step 1: Using Digital I/O
Use button inputs to signal output levels with LEDs, which allows you to learn the digital I/O functions of the pins. When a button is pressed, an LED lights up; this demonstrates the functionality of combinational logic in digital circuits. Although simple, it helps you learn the general programming ideas of microcontrollers. For example, many registers must be set to initialize the pins for digital input and output. Every time you use a function of the microcontroller, you need to set the registers that control that function; this is a characteristic of microcontroller programming. Don’t be afraid of the complexity; all microcontrollers are like this.
Step 2: Using Timers
Once you learn to use timers, you can implement sequential circuits with microcontrollers. The functionality of sequential circuits is powerful and has many applications in industrial and household electrical device control. For instance, you can use a microcontroller to create a corridor light switch that turns on for 3 minutes after a button is pressed once, stays on continuously if the button is pressed twice in succession, and turns off if the button is pressed for more than 2 seconds.
Digital integrated circuits can implement sequential circuits, programmable logic devices (PLD) can implement sequential circuits, and programmable controllers (PLC) can also implement sequential circuits, but only microcontrollers make it the simplest and most cost-effective. Using timers is very important; logical time control is the foundation of microcontroller usage.
Step 3: Interrupts
The characteristic of microcontrollers is that a program executes repeatedly, and each instruction in the program requires a certain execution time. If the program does not reach a specific instruction, the action of that instruction will not occur, which can delay many rapid occurrences, such as the falling edge when a button is pressed.
To enable the microcontroller to respond to rapid actions during normal program execution, the interrupt function must be used. This function interrupts the normal running program of the microcontroller to handle quickly occurring actions, and after processing, it returns to execute the normal program.
The difficulty in using interrupt functions is knowing precisely when to allow or mask interrupts, which registers need to be set for a specific interrupt to take effect, what the program should do at the start of the interrupt, and what it should do after the interrupt is completed, etc.
Once you learn interrupts, you can write more complex structured programs that can monitor an event. Once the monitored event occurs, the program interrupts the current task to handle it. Of course, you can monitor multiple events. A vivid metaphor is that the interrupt function allows the microcontroller to eat from the bowl while keeping an eye on the pot.
If you master these three steps, it’s equivalent to having learned three moves of a martial art; you can barely defend yourself.
Step 4: RS232 Communication with PC
Microcontrollers all have USART interfaces, especially many models in the MSP430 series, which have two USART interfaces. The USART interface cannot be directly connected to the PC’s RS232 interface because their logic levels are different, requiring a MAX3232 chip for level conversion.
The use of USART interfaces is very important. This interface allows information exchange between the microcontroller and the PC. Although RS232 communication is not advanced, learning about interfaces is crucial. To use the USART interface correctly, one must learn about communication protocols, RS232 programming for PCs, and so on. Imagine how interesting it would be if the data displayed on the microcontroller experiment board appeared on the PC monitor, while the keyboard signals from the PC could be displayed on the microcontroller experiment board!
Step 5: Learn A/D Conversion
The MAP430 microcontroller has a multi-channel 12-bit A/D converter that allows the microcontroller to operate on analog signals, displaying and detecting voltage, current, and other signals. 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 the A/D conversion function is designing a voltmeter.
Step 6: Learn PCI, I2C Interfaces, and LCD Display Interfaces
These interfaces are important for connecting microcontrollers to external devices and expanding their functionality.
Step 7: Learn Comparison, Capture, and PWM Functions
These functions enable microcontrollers to control motors, detect speed signals, and implement motor speed control. If you master the above seven steps, you can design general application systems, equivalent to mastering ten moves of a martial art, enabling you to attack.
Step 8: Learn USB Interface, TCP/IP Interface, and Hardware & Software Design for Various Industrial Buses.
Learning USB interface, TCP/IP interface, and hardware & software design for various industrial buses is very important as it is the current direction of product development.
Up to this point, it is equivalent to having learned 15 moves of a martial art, but it is still not enough to be invincible. Even so, you are already a microcontroller expert!
Microcontroller’s “Super God Path”: Three Plans
First, microcontrollers are not omnipotent, but without microcontrollers, nothing can be done. From years ago to now, microcontrollers remain microcontrollers; their nature hasn’t changed much. They have simply returned from being seen as “mysterious,” “profitable,” and “interesting” to their true nature—this reflects the progress of society, becoming more reasonable and rational.
However, this return has gone to extremes, switching from one extreme to another. Conversely, the demand for this aspect is increasing; at least in our lifetimes, this “automation” process will continue. So why worry about not having a place to showcase your skills? Why worry about your salary being low or nonexistent?
I have been working with microcontrollers and my familiar industry for nearly ten years. I won’t boast about my level; whether it’s good or not, I can say I’m proud when I should be and humble when I need to learn. After all, microcontrollers are a system engineering project, and one doesn’t need to be familiar with all aspects precisely. To do well, I still say—it’s essential to integrate with the industry you are in; that’s the way to go.
Some people complain about the various aspects of microcontrollers in society; that is merely a phenomenon or surface issue, or it is just pure electronic development or supporting products facing more intense competition. Don’t think that just because you can code, doing some pure electronic work is impressive; that’s a misconception. Microcontroller system engineering is not so narrow.
If you can’t move beyond this narrow view, you will inevitably be one of those who complain. As I said earlier, microcontrollers are merely returning to their original form. Moreover, China lacks people who are in their 50s or 60s and still working with microcontrollers. Perhaps this is a process that emerging China needs to go through?
There is no such thing as the best profession; only the profession that suits you at the moment or for a certain period. Take microcontrollers, for me, the results of microcontroller work are merely components (except for pure electronic products). Because they are “components,” you need to provide corresponding physical dimensions, heat dissipation for the microcontroller system, installation conditions, and methods, etc., which need to align well with the environment provided by your upstream and downstream, rather than thinking that once your microcontroller functions are completed, your job is done, and everything is fine.
Just regarding the functions that microcontrollers need to achieve, if you can’t even implement them, what use do you have—this is just basic work. In fact, the environment provided by the upstream and downstream is a test for your design, and you may need to change several plans to achieve it better. Clearly, such an upstream and downstream environment is a great resource for you. However, some may overlook it, making it harder for you to become familiar with what you developed and its use and value in this industry, which is a great reference for your future development. Unlike C or C++ programmers, when they lack a platform to showcase their skills, they feel frustrated. In contrast, for microcontrollers, we can create a platform for ourselves to showcase and develop our skills.
I have said a lot, but I am just chatting and sharing my views; I hope it helps you a bit.
From my understanding, microcontrollers are quite “low-level” and “hardware-oriented”; there aren’t many complex data structures or tricky programming algorithms. We just need to understand and program from the perspective of how microcontrollers execute. A microcontroller can form an electronic system or just a smart node. There is not much complex knowledge to study because we are merely users of microcontrollers; don’t elevate yourself to the height of “research”; we only operate at the height of “application.”
Because we are at the “application” level, when we are familiar with and can precisely grasp the “use of microcontrollers,” we should focus more on the “application” and the “operating environment” of microcontrollers. There was once a brilliant person who used an Intel 8031 chip technical manual and internal manual to achieve applications you wouldn’t even think of on a microcontroller, but I believe that is unnecessary unless you want to develop on the 51 chip. After saying all this, if you are still just focused on microcontrollers for their own sake, I think you might be a little sad.
Familiarizing yourself with the upstream and downstream environments and conditions of microcontrollers is not a difficult task. I hope the things I understand can help newcomers and bring some thoughts to beginners; that would be enough.
Planning Level One:
Once you have a certain age and human resources, you can start your own business and become a so-called half-boss. However, saying it’s easy to be your own boss is easy, and saying it’s not easy is also not easy. I initially jumped in with such trepidation. I took on many projects, often with short cycles set by myself, usually spending the day maintaining previous projects and working until one or two in the morning to develop new ones.
There’s no need to mention the fatigue; sometimes I think I’m risking my life for money! My wife wasn’t too keen on me starting my own business, as I was doing well in my job. So, I told her that I might not be able to provide a stable income every month, but I guarantee that at the end of the year, my average monthly income will not be lower than it is now. Thus, I started on my own path. I am not afraid of hard work or suffering; I am not afraid of putting in effort without reward. What I fear is not being able to overcome my psychological barriers. Perhaps I have been lucky and smooth sailing all along? For my brothers and sisters working alongside me, you must overcome your psychological barriers and not worry too much about today’s gains and losses or the so-called “face” in certain situations.
At least we should use the “least cost” to pay our “tuition.” I don’t mind you laughing; I have paid a lot of “tuition.” A successful project is not about how good or strong your functions are, but how much profit your successful development has brought to your project party; that is true success, even if you only earned a little development fee.
When doing projects, don’t think too much about yourself; think from the perspective of the project party. They trust you enough to hand the project over to you, so you should consider it from their perspective—sometimes their requirements may be a bit excessive, but as the saying goes, ignorance is no excuse.
Planning Level Two:
Be a competent software and hardware electronic engineer. You don’t need to learn too much; just learn some basics. Don’t follow trends; that’s unnecessary. Sometimes you might learn something, but if you don’t have corresponding development tasks, you’ll only learn superficially. However, if you have a solid foundation, when you truly need it, picking it up again will be much quicker; it counts as a form of reserve.
But you should at least know one relatively narrow system, right? Don’t be embarrassed; I only know the 51 microcontroller. Let me talk about myself; I work in the industrial automation field related to machine tool equipment:
Proficient in 51, familiar with other microcontrollers, proficient in 51 assembly, proficient in CPLD, semi-proficient in C51 (only used for some human-machine interface work), and roughly familiar with FPGA (wanting to master my own 51 IP core).
  • Roughly familiar with ARM DSP, roughly familiar with ARM and DSP assembly, and have some understanding of C programming.
  • Proficient in 3D modeling software SOLIDWORKS (can design my own circuit board and mechanical equipment).
  • Roughly familiar with most machining processes.
  • Proficient in sheet metal and welding.
  • Familiar with solutions for CNC equipment and machine tools.
For everyone, applying what you learn is key. In the past, I wanted to learn everything but didn’t excel at anything. When learning, I didn’t have a platform to apply what I learned; it was all for the sake of learning. But when you need to use it, picking it up again will be quick. Take ARM as an example; I worked hard when learning, from understanding its mechanism to implementation, and did many experiments, but now I rarely use it, leaving only some conceptual knowledge.
So there’s no need to be proficient in everything; just focus on one. For example, with the 51 microcontroller, from design to board production, procurement, soldering, and debugging into a finished product, if you think through the process and master it, what’s there to be afraid of? Even if you don’t get a high salary, you should still be offered a high annual income. You should understand the principle that “a boss is hard to find.”
Planning Level Three:
Be a qualified novice electronic engineer. For beginners, my advice is: don’t start with a five or ten-year plan; that doesn’t suit ordinary people. If we can make plans for the next year or two, you will have achieved something remarkable.
Every day is a new idea, every month brings changes, let alone every year. As long as you are working hard and doing things steadily, don’t make yourself too busy; give yourself half an hour each day to think about your “heart matters.” Master one thing, then branch out. In electronics, whether it’s ARM, DSP, or 51, they are all interconnected. Once you master one system, the others will also connect.
What’s scary is being half-knowledgeable in everything; that’s frustrating and sad!
Disclaimer: The content of this article is sourced from the internet, and the copyright belongs to the original author. If there are any copyright issues, please contact for deletion.
-END-
Comprehensive Guide to Learning C Language for Microcontrollers

1

Super Comprehensive Embedded IoT System Hardware and Software Basics Compilation……

2

Hot Discussions on Zhihu | Is C++ Useful in Embedded Development?

3

How to Improve Your Technical Skills Working in Embedded Systems at a Small Company?

Comprehensive Guide to Learning C Language for Microcontrollers
Comprehensive Guide to Learning C Language for Microcontrollers

Comprehensive Guide to Learning C Language for Microcontrollers

Comprehensive Guide to Learning C Language for Microcontrollers
Every day, the little creator works hard to produce electricity,
[Share, Like, Follow] Can I have a duck?Comprehensive Guide to Learning C Language for Microcontrollers

Leave a Comment