Mastering Microcontrollers: A Comprehensive Guide

1. Introduction Many beginners in microcontrollers often ask me, “I am currently a microcontroller beginner, how can I learn it faster? Where should I start?” Regarding this question, I would like to share my thoughts on how I learned microcontrollers, how to get started, and how to become proficient. First, let’s talk about microcontrollers. The most commonly used ones are 8-bit microcontrollers with a 51 core (considering cost and pin resources, various models of the 51 microcontroller are used in actual development). There is a wealth of learning materials available, and the learning cost is very low. Some beginners might say that companies don’t use 51 microcontrollers, but rather use models from manufacturers like STMicroelectronics or NXP. However, I want to point out that do you have the auxiliary development tools for those microcontrollers? The 51 microcontroller has significant advantages for entry-level learning in smart electronic technology due to its low cost and simple development. The ARM is too mysterious, and PLCs are too expensive. After much consideration, the 51 microcontroller still stands out. I have experience with AVR and PIC, but now the 51 is also quite good. So how can one learn microcontrollers faster and better? As a subject that integrates electronic technology and computer programming, microcontroller study places great emphasis on hands-on practice. If you are a microcontroller expert, it indicates that you are also an expert in computer programming and electronic technology.2. Reading is Essential for Learning Microcontrollers You can’t just read books, but to learn, you must start with reading. Isn’t that contradictory? Because from books, you need to understand the various functional registers of microcontrollers (such as pin control registers, timers, interrupts, serial communication registers). The core of controlling a microcontroller lies in programming to manipulate its functional registers, assigning binary values of 0 or 1 to the registers. For internal resource registers like interrupts, timers, serial communication, and AD conversion, the microcontroller can also be set and used through binary data 0 and 1. For example, for the microcontroller pin register P1, the statement P1=0xfe; (MOV P1, #0FEH) controls the first pin of the microcontroller’s P1 port to output a low level, while other pins output a high level, allowing the peripheral circuit to operate based on high and low levels. For instance, for the interrupt enable register IE, the statement IE=0x81; (MOV IE, #81H) indicates that the overall switch for interrupts and the sub-switch for external interrupt 0 are turned on. Of course, the microcontroller’s registers can also accept bit control, making programming more convenient. As for reading books, is it enough to just understand what each pin and functional register of the microcontroller does? This is very important, and it may be one of the main purposes of referring to microcontroller reference books. The first time, the second time you may not understand, but that’s okay, as you still lack practical experience. Through the subsequent experiments, you will gain a very intuitive understanding. During this process, you must spend time; learning programs cannot be memorized blindly, but you must put effort into understanding the functions of the registers and memorize terms appropriately. I recommend one book, and this one is sufficient: the title is “Introduction to 8051,” which has versions in both assembly language and C language, and it is now in its third edition. This book is incredibly powerful, without advertisements, limitations, and unlike training manuals or textbooks, it is a very good reference book. I finished this book during a five-day holiday, and after reading it, I felt like I had become a microcontroller expert, as many previously abstract concepts became clear. The book is rich in illustrations and well-organized content, not like many technical documents on the market that preach, such as learning concepts, learning instructions, and learning interfaces sequentially, which can leave you feeling overwhelmed. So how to read the book? First, follow the book’s arrangement and gradually read through the first two chapters. When your mind begins to heat up and you feel like you are already an engineer, the next step must be practice, it is crucial. Of course, practice does not necessarily mean using a soldering iron with one hand and a universal board with the other; it can also be using simulation software like Proteus or a simple microcontroller experimental board (definitely avoid those with many surface-mounted devices that make it hard to see the circuit connections). During the Three Kingdoms period, Zhuge Liang’s execution of Ma Su reminds us that discussing tactics without practice is harmful. The same applies to learning microcontrollers; many graduate students and even Ph.D. students remain unaware of the distribution of microcontroller I/O ports until graduation, making development impossible without understanding distribution. As long as you pass the first hurdle, the subsequent path will be easier; starting is always the hardest. Second, if you have a beginner in microcontrollers nearby who has strong hands-on skills, ask them to help you set up a simple microcontroller minimal circuit, even if it’s just controlling an LED to blink. As long as you witness the circuit design, program writing, and program downloading process, you will be grateful to them for life because you have already stepped into the world of microcontrollers. For them, creating a minimal system board is easy, but for beginners, it can be much more challenging. Once the barrier is broken, everything becomes simple. In this process, you will learn how to download programs to the microcontroller, how to identify the microcontroller, and how to design the minimal microcontroller circuit. Why do many students in electronics and computer majors struggle to find jobs? Because many of them design their resumes impressively but have never seen a microcontroller in person. Only by understanding the hardware can one use it proficiently. Only by knowing how programs are downloaded can one understand why microcontroller control programs are written and where the motivation comes from. Microcontroller programming is like conversing with the microcontroller; if you don’t know who the other party is or if they are listening, will you still feel the urge to speak? Of course, if there is no such person, the same advice applies: search online for several minimal circuit schematics and solder them onto a breadboard. If you don’t know how to do that either, I suggest you definitely buy a simple experimental board that you can use for future microcontroller learning and project testing.4. How to Enter the World of Microcontroller Development Once you have a microcontroller experimental board, you should practice more. It’s best if you have a computer; download fewer movies, play fewer online games, connect your experimental board to the computer, install essential software (Keil, Proteus, STCisp), download reference programs, and modify them. Starting with the simplest traffic light experiment, once you discover that you can control the traffic lights and understand the soft and hardware design of traffic systems, you will realize that you have already entered the field. You will find how fascinating microcontrollers are; it’s not just about learning knowledge, but also about enhancing your own value. With such a wide range of applications in traffic design, you won’t feel troubled by a lack of skills anymore; you will realize you know something after all. You will be applying knowledge of computer programming and electronic technology. When the program you wrote works as you intended, it brings more joy than anything else; that sense of achievement and fulfillment from learning is very rare. Then, when you make the digital tube light up to display the required number, at this point, you will find it hard to turn back; you will start considering which career path to take. To get started, what does it mean to truly start? You must be true to yourself. My requirements are simple; whether you have started learning microcontrollers can be determined by three points: 1. Independently master the usage of Keil and Proteus software and design a simulated traffic light. 2. Independently assemble the minimal microcontroller circuit on a breadboard and download a HEX file to control an LED to blink. 3. Clearly understand your motivation for learning microcontrollers and make a study plan for yourself. However, while writing programs, you will certainly encounter many issues. At this point, you can refer back to books you’ve studied, including programming books and digital/analog electronics books. You will find that the knowledge you learned previously is still useful. When you encounter something you don’t understand, refer back to the books you’ve studied; this embodies the principle of “reviewing the old and learning the new, which can be a teacher.” Knowledge must be applied in real life to solve practical problems, like designing a simple household timer or an infrared remote control using microcontrollers; this is how its value is realized. Think carefully, after so many years of university, exploring for so long, hesitating and wandering, attending classes daily, what have you learned? Is it just for the sake of scoring 60 in the final exam, being lucky enough to score 90, and feeling proud of how well you learned your major? Unbeknownst to you, university exams are not like high school exams. What does it matter if you receive a scholarship? When you return to school next semester, you will find that you have forgotten everything you learned. What have you learned? Why do I recommend studying microcontrollers? Because microcontrollers are a subject for engineering students that integrates computer programming, electronic technology, and various control languages. Rather than saying you are learning microcontrollers, it is more accurate to say you are studying a comprehensive discipline.5. Should You Learn Assembly Language or C Language for Microcontroller Programming? Regarding the question of whether to use assembly or C language for programming. This issue troubles many people, but I believe that learning assembly language and C language is like a person entering society needing to learn both dialects and standard language. Both must be mastered, and it’s up to you to determine which is more important. It may primarily be due to the school curriculum and some textbooks guiding students; in the first year, C language programming is introduced without students understanding its practical applications before other languages are introduced. Even if a dedicated microcontroller course is offered, the content is often similar to technical documents, with many programs but few complete ones, leaving students unsure of why they need to learn programming. Many students take C language classes in their first year, and I did too, but at that time, it was all about simple arithmetic problems, factorials, etc., using C to solve elementary math problems, and practicing typing speed in class. After class, they have no idea what they have grasped or its applications. What’s the use of what they learned? If during an interview, the boss asks, “Have you studied programming?” what immediately comes to your mind? “C language, VC, VB, etc. Many things, C language is fundamental and engineering-oriented, while VC is advanced and object-oriented.” But if the boss asks, “Can you apply what you learned in C language to actual development, like designing a timed alarm in C?” you would be stumped because the teacher never taught that. Microcontroller programming can use either C language or assembly language, but I recommend using C language as it allows for modular management, is easier to write, and has strong portability, making it suitable for large programs. If you already have a foundation in C language, learning will be easier; if not, you can learn C while studying microcontrollers. Although many people start with assembly language, writing small programs in assembly is still simple, but if you want to implement certain algorithms, assembly can become complex. Although C language code tends to be longer than assembly after compilation and has lower execution efficiency, in earlier microcontroller development, chip technology limitations and microcontroller clock frequency constraints meant that many microcontrollers had very limited internal storage and clock frequency. However, that is not the case anymore; internal storage and clock frequencies have significantly increased. So, should assembly language be ignored? No, it must be learned for two reasons: first, when starting with microcontrollers, assembly language is simple in syntax. Second, if you aspire to be a senior designer of microcontroller programs, mastering assembly language is essential, as many advanced microcontrollers like ARM use assembly language as their boot code, and many newly released microcontrollers initially have assembly language compilers before C language compilers are available. Therefore, I believe that for learning microcontrollers, one should start with assembly language, become proficient in C language, and then master assembly language. There is a saying that goes, “A master in microcontroller C language is definitely a master in assembly language, but a master in assembly language is not necessarily a master in C language.” Finally, regarding learning microcontrollers, start with the basics, and then pay attention to the market and enterprises. Understand what kind of talents companies need; once you have a foundation, learning about the specific types of microcontrollers required before interviews will allow you to adapt quickly, as learning is fundamentally the same.

Mastering Microcontrollers: A Comprehensive Guide

Mastering Microcontrollers: A Comprehensive Guide

Leave a Comment