I previously wrote a brief tutorial on How to Use Keil and hope that you’re now capable of compiling your code. Moving on, if you haven’t noticed already, Keil uVision is also a debugger and can help you debug codes. I left out the debugging portion deliberately in my previous post as it was themed at getting familiar with Keil uVision. Debugging in Keil is simple to understand and also proves to be useful at crucial times.
It’s all over my mind and I can’t seem to ignore it so just let me write it down. While coding, we normally encounter two major types of errors.
They occur when you forget placing a semicolon (;) after a C/C++ statement, call a variable without declaring it first, use the wrong type of brackets, or use an invalid name for a variable etc – the list goes on. They are easily detected by the compiler and you can rectify them instantly, without thinking twice. So let’s not worry about them.
Suppose you’re expecting the number 124 at the output and something like 4 comes up and you don’t have a slightest clue as to how that happened. It’s confusing and annoying because there is no syntax error and no compilation error but still you’re getting the wrong answer. That’s a logical error – the logic you’re trying to implement for solving the problem has some problem in itself.
Debugging in Keil uVision
When you’re done writing your code, compile it. Keil will notify you of all the syntax errors (if any) in the program. Double click the error message and the cursor will automatically move to the exact statement containing the error. Read the error message and make changes accordingly.
When you’re done fixing all the syntax errors, you may proceed to debugging your code. You can do this by using the Debug Menu as shown.
These are the few basic terminologies and functionalities in almost all the debugging environments – not just Keil uVision. In addition to these useful features, you can also add a certain variable to watch window for keeping an eye on its value during the whole process. This specifically comes in handy if you’re programming in C language.
Using these simple options, you will be able to properly scan through your code and debug it. I hope you grasped the idea and will be able to do so yourself. Good luck!