Programming Languages

From OpenCircuits
Revision as of 16:59, 30 March 2008 by Mzoran (talk | contribs) (→‎C)
Jump to navigation Jump to search


Very high level languages are less suitable for microcontrollers, so the choices are less then one would find on a PC. The main programming languages used in microcontrollers are Basic, C/C++, and assembly. Microcontrolers are generally harder to program then PCs because it isn't as easy to view debugging output, it takes more time to flash a new firmware, and the tools are generally less developed then PC tools. One suggestion is to learn basic programming on a PC first and then migrate to embedded systems after gaining some understanding. One hint on selecting a language is to always consider using the same language as the people you work ( play ) with do. This makes getting help much easier. Or pick a language with a strong support system on the internet. Of course the language cost and features matter too.


Some people consider this to be the easiest programming language to learn. The language is line oriented so compilers tend to produce more debugable error messages. Basic can either be interperated as in the Basic Stamp from Parallax or compiled as in PicBasic. Generally speaking the interperted basics run much slower than the compiled basics. In some cases the basic the basic firmware is part of the chip, this can boost the cost of the chip significantly. Still this type of solution can get a beginner up and running quickly. Traditionally basic has not required declaration of all variables and may not be strict about typing of variables, these can be a plus for beginners, by may be disliked by more experienced programmers. Not all Basics have these characteristics and some have optional settings.


C is a middle level language that is considered to be high enough for productivity but close enough to the hardware to have some of the power of assembly. C has free form formating rules so the look of C varies according to style and C compilers tend to produce harder to debug error messages. C is gaining in popularity over assembly with microcontrollers as embedded systems are becomming more and more complex. C is almost always compiled instead of interperated. Advanced C requires understanding of pointers which requires lower level understanding of the hardware then some people are interested in going. C compilers can be very expensive, however several free or demo versions of compilers are available.

  • Microchip C18 For 18fxxxx parts from Microchip. Integrates with MPLAB. Free student/Demo version is available that has some optimizations disabled.
  • Microchip C30 For Microchip's DsPIC and PIC24 microcontrollers. GCC based with extensions. Free student/Demo version available.
  • BoostC Compiler Overview Free for up to 2k of code, BoostC Full License US $69.95 The full license has unlimited RAM and ROM usage. Suitable for projects of all shapes and sizes. The definite choice of the serious programmer. Non-commercial use.


C++ is an extension of C. Many people consider C++ an object oriented language.

Some of the extension include:

  • Associations between data( classes ) and functions ( member functions ) that operate on that data
  • Modifications to existing classes through an extension method called inheritance without requiring modifications to the original code
  • Operator and function overloading

C++ is not as common as C for microcontrollers mostly because many microcontrollers are not powerfull enough to run software large enough where the extra features become imporant. C++ is not supported by as many compilers as C for microcontrollers.

TODO: Give an example of a C++ compiler for microcontrollers.


Assembly is a near exact mapping to the actual instructions executed by processors. It is very processor specific. Some architecture such as the older PIC processors are optimized for assembly programming where some RISC based architectors are optimized for higher level languages. Some C compilers do not produce the best possible code so writing in assembly can theoritically produce faster code, but poorly written hand assembly can be worse. Some people mix C and assembly in the same project and most compilers make it easy to integrate assembly in C programs.


We should expand this section, but for now will just mention some names, you can google them:

  • JAL Just another Language
  • Forth, a fourth generation language