PIC microcontroller<\/a> will run.<\/p>\nWriting code in C or Basic is much easier but it hides the structure of the microcontroller from you, and leads to another common question we get – can you give me the C instruction set for AVR or PIC? There is no “C instruction set” for a particular microcontroller, just a series of standard C (or Basic) commands that the compiler converts into assembly language for the target microcontroller. So, the first thing you need to understand is basic C programming, For loops, While loops, if..else and switch instructions plus all the standard arithmetic and logic commands. These are the same for any target, including x86 PC programs or any microcontroller<\/p>\n
In theory, a C program can be recompiled to run on different microcontrollers, but in practice hardware differences get in the way. A lot of microcontroller code needs to change hardware settings to access I\/O ports, set up timers or use communication interfaces such as serial ports, and this means manipulating the hardware control registers that are microcontroller specific.<\/p>\n
It is much easier to understand these registers and how they interface with the rest of the microcontroller if you start with learning assembly language because this forces you to understand more about your device and how it works. Once you have written a few programs in assembler you will understand more about the microcontroller and moving on to C is much easier.<\/p>\n
The only benefit of assembly language is smaller, faster code but memory is cheap now, a microcontroller with a 16 KB program memory is not much more than an 8KB one, and C compilers have got better at producing smaller code, although free ones aren’t so good. The downside of assembler is you have to do everything, including memory management, and C constructions like loops are much easier and faster to write.<\/p>\n
So, it makes sense to produce programs in C or Basic, but you will never understand the way the microcontroller fits together and the different resources available or its limitations if you don’t learn assembly language first. Start with assembler, understand the device, then move on to C is our advice.<\/p>\n","protected":false},"excerpt":{"rendered":"
A common question we get is should I program my microcontroller in C or assembler? This usually means do I bother with assembler or just use C. Sometimes it just means that I do not know the difference. So what is the difference?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[19],"_links":{"self":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/171"}],"collection":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":6,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}