Quantcast
Channel: Interview Mantra - India
Viewing all articles
Browse latest Browse all 10

Basic concepts of Micro controller programming

$
0
0

www.youtube.com/watch?v=dOm1bWEQHtU

Before you watch this video, be sure to view the video#1 on Introduction to Embedded systems.

I would like to share my experience with embedded systems. In 2005, I was a student of Electronics Engineering. Back then when I had started to learn Micro controller programming on my own, I had faced a lot of issues, lot of hurdles and lot of questions. But I was madly interested to learn it, whatever it may take, how much ever work it needed, I wanted to program a micro controller and build a fancy application.

I had many unanswered questions in mind:

  • What micro controller should I use? How should I use it?
  • How to program a micro controller? What is the process?
  • What does it take to make a micro controller get to work?
  • Is micro controller programming same as computer programming?

Learning Embedded Systems is all about learning to program a micro controller chip. The process of creating an embedded systems applicaiton is as follows:

  1. Set out with requirements i.e., set of tasks your embedded system should be designed to perform.
  2. Decide the hardware that is necessary for building your system. Assemble your hardware and keep it ready.
  3. Write the logic or algorithm on a paper, convert it into code in computer.
  4. Compile this code in a computer and obtain a byte code.
  5. Burn this byte code into the micro controller.
  6. Power on your embedded system and your program in the micro controller chip starts to work.

Let’s discuss these steps with a practical example. Let us say that we wish to build a clock using a micro controller chip. Step#1 is to note down the set of features that we need this clock to possess. Say we need the ability to set the time (hours/minutes/seconds), set 12/24 clock, set/clear alarm etc,. The clock should refresh time every second and show the updated time. The clock circuit should be able to activate an alarm at the preset tme.

Step#2 is to decide the hardware features of this clock. Say we wish to use a 16 x 2 LCD display; first column for displaying the time (hr:min:ss) and second column for displaying the alarm time. We need a 4 button keypad to manipulate various settings in the clock. We want a battery back up system such that if the electric power fails, the battery takes over and keeps the clock ticking.

Step#3 is to write an alogrithm for the clock to display time, to be able to manipulate the time and alarm time using the keypad clicks, to be able to show updated time on the LCD. Code for embedded systems is usually written either in Assembly Language or Embedded C.

Step#4 is to compile this assembly/C code into a byte code. This process is similar to compilation of a computer program to an executable file. In the case of computers, the output file is .exe or .o file. In case of micro controller programs, the output of compilation is a hexa decimal byte code. This code is understood only by the micro controller for which the code has been written. Whereas the code written in C or Assembly language is human understandable.

Step#5 is to transfer this code into the micro controller. This process is a somewhat similar to transferring a picture or a song from a computer to a mobile phone using a data cable. This process of moving the compiled hex code from computer to a micro controller is called burning. Burning is done using a hardware, software and a cable connecting the computer with this hardware. This hardware is also called as Micro controller programmer.

Step#6 is to power your circuit and check the output. If you had written the program correctly and had assembled hardware correctly, your clock should have been working as expected by now.

So for programming a micro controller(burning code), you need Micro Controller Programmer Hardware & Software and a data cable. You need a cross compiler that can compile the code written in computer into hex code that your chip can understand.

This process is called cross-compiling. Guess why?

Because the executable file that gets created by compiling a program that was written in a computer is not executed on the same computer. That is, the hex code is not run on your computer. But that hex code is run on another external micro controller chip. Whereas in the case of a traditional computer program, the executable is run on the computer where it was compiled. Hence micro controller compilers are called cross-compilers.

Feel free to shoot any questions related to these basics steps in micro controller programming. I will get back to you with answers as soon as possible.


Viewing all articles
Browse latest Browse all 10

Trending Articles