How to learn microcontrollers? It's common to see people say they've been studying for months but haven't made much progress. Of course, learning speed varies depending on individual education levels and comprehension abilities, but I feel the most important factor is the learning method. A good learning method can make your efforts twice as effective. Here, I'll share my own method for learning microcontrollers.
01
Everything is difficult at the beginning.
Be brave and take the first step.
In the beginning, don't keep making excuses for yourself, saying things like you don't know how to create projects in KEIL or you don't have a project board. When you encounter difficulties, tackle them one by one. If you don't know how to create projects, learn that first. There are many tutorials online; just find one, take a look, and you'll understand after a few tries.
Then you can refer to other people's programs, it doesn't matter if you copy them. Write a very simple one, make it run, and first cultivate your own feeling, so that you know what it is like to write a program. Whether you write a large program or a small program, the steps you need to take are not much different. You always need to create a project, configure the project, create a program, add it to the project, write the code, compile it, generate the HEX, flash it into the microcontroller, and run it.
You must be familiar with this entire process. Personally, I think a learning board is essential; writing your program and running it to see the results will greatly improve your learning efficiency. As for a simulator, that depends on your individual needs. Microcontrollers emphasize both theory and practice; you can't learn by just reading books without hands-on experience.
02
Knowledge points can only be learned by applying them.
Put the ones you don't need aside for now.
This thick book is so overwhelming; by the time you finish learning the later parts, you'll probably have forgotten most of what you learned before. Therefore, it's best to apply it to actual programming, referring to the book only when you need it. There's no need to start from the first page and read the whole thing before writing code. For example, if you're writing a running light program, you don't need to look at interrupts; just focus on mastering the running light concept. This is about breaking the whole book down into smaller parts and absorbing the information bit by bit.
03
Don't just read about programming without writing it yourself.
You must write it yourself at least once.
In the beginning, when you know nothing, you can copy other people's programs, see what each line does, what its purpose is, and what the consequences are after running it. After you understand it, you need to write it yourself. You'll find that it's easy to understand other people's programs, but when it comes to writing your own, you can't write a single line. That's the difference. When you can write it yourself, it means you truly understand it.
04
Learn to master
Methods for debugging programs
Many people write programs, finish the code, run it, and get confused when the result isn't what they expected. Then they post the code on a forum, asking, "Why isn't my program running correctly?" and wait for others to analyze it for them. This is a very bad approach. They should learn to identify and solve problems themselves.
This requires learning debugging methods. For example, in KEIL, you can set breakpoints, examine register contents, and so on. These are all debugging tools. When you find that the program you wrote doesn't produce the results you expected, you can step through the code, set breakpoints, and trace the process, examining the contents of relevant registers to see if there are any deviations during program execution. Find the parts affecting the results and correct them. This process is very important; through debugging, you can learn knowledge that cannot be obtained from books.
05
Find a solution
More important than finding the code
Using a microcontroller to control peripheral devices to achieve our desired goals is one problem. The real challenge is writing a program to control the devices and make them operate as you want. To write a program, you must first find the solution approach. Learning to identify this solution approach is more important than finding the code itself.
Many people like to find other people's code, and some even copy the code directly into their own programs. This is not a learning attitude and will not help improve your programming skills.
I rarely look at other people's code; most of the time, I look at their thought process. A flowchart is best, but a textual explanation will suffice. Understanding someone's problem-solving approach from their code is extremely difficult, especially with large programs; it's incredibly tiring. So now I understand why I learned the importance of program flowcharts in school. Once you know how to solve a problem, the rest is simply arranging the code to complete it, which is no longer a problem.
06
Use your brain
Optimize the program using multiple methods
Think about how to achieve the same function using different methods. This is a process of practice and improvement. Once you solve a problem, think about whether you can achieve the same function in a different way, or whether you can make your code more concise and efficient. This process is one of progress. Much knowledge and experience cannot be gained simply by reading books; you need to practice, use your brain, and accumulate experience to improve your programming skills.
07
Looking at other people's code
Learn from other people's thinking
This is very useful in the early stages of learning. By looking at other people's code, especially code written by people with many years of programming experience, you can quickly improve your programming skills. At the same time, you can combine other people's programming techniques with your own ideas to write higher-level code and make progress. However, it is important to note that you must not turn learning into copying, and you should not think that you have learned it after copying. Doing so will only make you regress.
08
Try writing
Comprehensive application program
Starting with LED flashing, then moving on to dynamic scanning and interrupts, you can try writing a comprehensive application program like a clock. Don't underestimate a clock; writing a good one is not easy. It involves most of the knowledge of microcontrollers, such as button input (IO reading), dynamic scanning (IO output), and interrupts. How to coordinate the normal operation of each functional module is what programmers need to learn. When you write a single function, such as button input, you may feel it is easy.
Because your program doesn't do anything, it just reads the keystrokes. But when you mix it with other functions, ensuring each part works correctly throughout the program's operation is not as simple as writing a keystroke reader. Functional modules may interfere with each other. For example, you might need the digital tube to display data while simultaneously handling keystroke readings. Ensuring both parts work correctly is a coordination process. Once you have this coordination ability, you've entered the field.
Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964 ) . We apologize for any inconvenience.