Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.

Choosing a Programming language for your microcontroller.

So you want to start programming and using microcontrollers in your projects but where do you start assembler, BASIC, C or Pascal. Each of the languages has different strengths and weaknesses which you need to consider before starting out.


Assembler is the most obvious language that you'll consider using
as you probably won't need to buy any other tools to use it. More
than likely the manufacturer will provide an assembler for the
chip and you won't need any books as all the instructions are in
the datasheet and you just start coding.

This route to programming is very easy but you may be setting
yourself up for problems later on as:
  1. It is trivial to write short programs.
  2. It becomes progressively more difficult to write large programs.
  3. It seems to be the best option as it gives the fastest code.
  4. It seems to be the best option as it gives the smallest code.

Assembler: Fast & small code

There is no doubt that assembler gives the fastest and most optimized code (your brain is better at optimization than any compiler!) but assembler is difficult – typically you'll spend ten times as long writing assembler as you would writing in a high level language.

Assembler / Compiler Trade off

This is the trade off; to write the fastest most optimized code or to get the task solved more quickly.

Another problem with assembler is that to do even the most trivial task you have to think about every aspect of the code and all implications on registers and register flags.

Even making a microcontroller perform the most trivial task is difficult e.g. for making a loop in assembler you need to think about which register to use and which instructions all the while thinking about how those registers should not interact with the loop register/other registers etc.

Assembler: Problem - changing the target

Another difficulty is when you change from one microcontroller to another (even in the same device family) the assembler instructions may be changed e.g. more instructions to improve microcontroller performance. So you will have to learn an entirely different instruction set when moving either to a new target microcontroller or moving to a different device within the same family i.e. code re-use is not possible unless you stay with one microcontroller (or devices with a similar internal architecture).

High level languages

HLL: Retarget

Retargeting code to another microcontroller is easier since the HLL will know the details of the new target i.e. instruction set, fuses etc.  All you need to worry about is the specific differences between the different microcontrollers (in the same family this will be setting up the internal peripherals).

The important point is that the HLL takes care of the assembler code needed to do the job.

HLL: Easy to understand.

The most useful aspect of a high level language (HLL) is that the language is written in a form you can easily understand – there are no cryptic assembler commands that you have to remember and most commands are made up of several machine code instructions – saving you coding effort (often there are built in libraries of code e.g. LCD driver, Serial port driver, I2C driver etc.

So the HLL makes it easy to write code as it generates the correct assembler for the target microcontroller.

HLL : Whitespace

You can also make use of white space (areas of no code) to separate out the various operations within the program – typically assembler code is just one great big list that is really very difficult to read – I know there are comments but you need to comment almost every line so that someone else can
understand the code.

HLL: Task splitting

One of the best features of a HLL is that you can split tasks into separate functions that you can concentrate on them individually (as the HLL takes care of local variables etc.). For assembler even when using a call instruction you have to take care of preserving the register state – in the HLL it's all done
for you.

HLL: Code re-use

Once you learn the HLL you will find it easy to read code written by other people and you will be able to re-use code that you have already written whereas with assembler you will constantly need to analyze the code to see if it fits in with your new functions.

The only decision then is which high level language? There are really three contenders BASIC, C and Pascal – these are the most popular languages and for popular microcontrollers there will be an HLL compiler for each one. I'll just list the advantages and disadvantages of each

BASIC Advantages

  1. Very easy to learn and use.
  2. A BASIC compiler will produce code that runs fast as a C compiler.
  3. Many in built functions (depending on compiler).
  4. Very popular – large user base with many example programs.

BASIC Disadvantages

  1. Non standard language.
  2. If using an interpreted HLL will run very slowly.

Note: Because the language is not standardized it will be difficult to move code to a new processor target type.

Pascal Advantages

  1. Easy to learn and use.
  2. A Pascal compiler will produce code that runs fast as a C compiler.
  3. Many in built functions (depending on compiler).

Pascal Disadvantages

  1. Not as popular as C – so not as many compilers.
  2. A bit wordy – it was originally intended as a teaching language.
  3. Not as flexible as C.

C Advantages

  1. Compiled language - always runs fast.
  2. Standardized language (ANSI)- easier to port to different compilers / target devices.
  3. Many compilers available.
  4. Many in built functions (depending on compiler).
  5. Very popular – large user base with many example programs.
  6. Used in many different industries.
  7. Usable at the hardware level as well as higher abstraction levels (although C++ is better for very abstracted programming models).

C Disadvantages

  1. Hard to learn at first.
  2. Strong type checking means you spend time pleasing the compiler (although this protects you from making errors).

New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Privacy Policy | Contact | About Me

Site Map | Terms of Use

Visit our Facebook Page:

   Click Here

Recent Articles

  1. Arduino Battery Charger: How to save the planet one battery at a time; Recycle and re-use Alkaline battries

    Arduino Battery Charger: A very useful project that lets you charge 'un-rechargeable' alkaline batteries!

    Read more

  2. [Arduino Tutorial] : How to use the 74HC595 shift register.

    The Essential Guide to the 74HC595; What it is and how you can easily use one in any of your projects.

    Read more

  3. How to use the MCP23017 I/O Expander on the Arduino

    How to use the MCP23017 to increase your I/O by 16 pins (or more) and use its interrupt system.

    Read more

Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:


Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates

Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's


- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan


"Awesome site,
very, very easy and nice
to navigate!"

- Matt

Learn Microcontrollers

"Interested in

Sign up for The
Free 7 day guide:


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."

- Dave


"Your site is a great
and perfect work.

- Suresh


"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.

- Anon

Back to Top