April 14, 2009

C for embedded systems

This is for those who are completely new to programming micro controllers. using C language Here i try to give a head start to such people.
  1. First choose a platform to work on. I suggest going for the AVR. AVR microcontrollers are relatively cheap and a fairly powerful. The best part however, is that you can test a multitude of the microcontrollers'' features using just the simulator provided in the IDE. You can download it from here free of cost after a small registration.
  2. Now you have to download a compiler. Please note that IDE is different from compiler. I have seen this misconception very strong among freshers who have used Turbo C compiler for a long time. A compiler is more often than not a command line utility. IDE ( Integrated Development Environment) help us by managing the files and abstracting from us complex commandline arguments that are needed to compile your code. Download WINAVR.
  3. Please install WINAVR first and then AVRStudio. This will ensure that AVRStudio automatically picks up the WINAVR path.
  4. Use the GUI to guide you and create a simple project. There are many samples available. However, the wizard is very helpful. You can choose any microcontroller to start with. 
  5. create a simple file with just the following code
int main(void)
{
     int i =0;
     int j = 5;
     i = i + j + 100;
     return 0;
}
 
[ compile the code (F7) after saving the file as anyname.c]

There you are done with your first C program for an embedded microcontroller. You will have to set the target as AVR simulator for debugging and stepping through your code.

I will not put more stuff here since that will take away the fun part from you.

What can you do?
  • Try to write a program to add two number and store the output in a global variable.
  • Other simple C programs without any printf or scanf statments.
Just one note, It is not really true to say the printf is a part of "C". Technically speaking pure "C" is the one in which there is no # include statement. When we say #include what we are doing is adding in libraries. Note that Libraries are not a part of "C", these are what users write. I dont know if i make full sense here :-S

In later posts i will try to explain the significance of #include in embedded code.

Please leave your comment. You can subscribe to this blog by using the links under "Subscribe" section.
 


No comments:

Post a Comment