Posts tagged ‘Keil and C programming’

Micrcontroller Programming Using C With Keil IDE

KEIL uVision is the name of a software dedicated to the development and testing of a family of microcontrollers based on 8051 technology,  which we are going to use along this tutorial. You can can download an evaluation version of KEIL at their website: Most versions share merely the same interface, this tutorial uses KEIL C51 uVision 4 with the C51 compiler .

To create project,write and test the source code and also create hex file,follow the following steps:

Open Keil and Start a new project:


You will prompted to chose a name for your new project,chose  a name and click save.The following window will appear,where you will be asked to select a device for Target ‘Target 1’:

From the list ,select ATMEL and chose your microcntroller .The AT89s52 will be called your ‘Target device’ ,which is the final destination of your source code.You will be asked whether to copy standard 8051 startup code click No.

Click File,New and similar to the following window should appear.The blank space where your code should be written.

Now,You have to click ‘File ‘,Save as and chose a file name for code ending with the extension ‘.c’ and click save.Then you have to add this file to your project work space as shown in the following screen:

After right-clicking on ‘source group 1‘, click on ‘Add files to group…‘, then you will be prompted to browse the file to add to ‘source group 1’, chose the file that you just saved  and add it to the source group. You will notice that the file is added to the project tree at the left.

In some versions of this software you have to turn ON manually the option to generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target ‘target 1’, then under the ‘output‘ tab, by checking the box ‘generate HEX file‘. This step is very important as the HEX file is the compiled output of your project that is going to be transferred to the microcontroller.

You can then start to write the source code in the window ‘ then before testing your source code, you have to compile your source code, and correct eventual syntax errors. In KEIL IDE, this step is called ‘rebuild all targets’ .

You can use the output window to track eventual syntax errors, but also to check the FLASH memory occupied by the program (code = 49) as well as the registers occupied in the RAM (data = 9). If after rebuilding the targets, the ‘output window’ shows that there is 0 error, then you are ready to test the performance of your code.

There are many other features to discover in the KEIL IDE. You will easily discover them in first couple hours of practice.