Total Pageviews

Thursday 17 November 2011

keil starter


Using the KEIL environment
http://www.ikalogic.com/img/line2.gif

KEIL uVision is the name of a software dedicated to the development and testing of a family of microcontrollers based on 8051 technology, like the 89S52 which we are going to use along this tutorial. You can can download an evaluation version of KEIL at their website:http://www.keil.com/c51/. Most versions share merely the same interface, this tutorial uses KEIL C51 uVision 3 with the C51 compiler v8.05a. 

To create a project, write and test the previous example source code, follow the following steps:

http://www.ikalogic.com/img/a3.gif
 Open Keil and start a new project:

http://www.ikalogic.com/art_pics/8051_tut/keil1.jpghttp://www.ikalogic.com/art_pics/8051_tut/keil1.jpg
Figure: 2.8.a

http://www.ikalogic.com/img/a3.gif
 You will prompted to chose a name for your new project, Create a separate folder where all the files of your project will be stored, chose a name and click save. The following window will appear, where you will be asked to select a device for Target 'Target 1':
http://www.ikalogic.com/art_pics/8051_tut/keil2.jpg
Figure: 2.8.b

http://www.ikalogic.com/img/a3.gif
 From the list at the left, seek for the brand name ATMEL, then under ATMEL, select AT89S52. You will notice that a brief description of the device appears on the right. Leave the two upper check boxes unchecked and click OK. 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 codeclick No.

http://www.ikalogic.com/img/a3.gif
 click FileNew, and something similar to the following window should appear. The box named 'Text1' is where your code should be written later.
http://www.ikalogic.com/art_pics/8051_tut/keil3.jpg
Figure: 2.8.c

http://www.ikalogic.com/img/a3.gif
 Now you have to click 'File, Save as' and chose a file name for your source code ending with the letter '.c'. You can name is 'code.c' for example, and click save. Then you have to add this file to your project work space at the left as shown in the following screen shot:
http://www.ikalogic.com/art_pics/8051_tut/keil4.jpg
Figure: 2.8.d

http://www.ikalogic.com/img/a3.gif
 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, eventually 'code.c' and add it to the source group. You will notice that the file is added to the project tree at the left. 

http://www.ikalogic.com/img/a3.gif
 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 1Options 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.

http://www.ikalogic.com/img/a3.gif
 You can then start to write the source code in the window titled 'code.c' 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' and has this icon: http://www.ikalogic.com/art_pics/8051_tut/rebuild_but.jpg
http://www.ikalogic.com/art_pics/8051_tut/keil5.jpg
Figure: 2.8.e

http://www.ikalogic.com/img/a3.gif 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. In keil, like in most development environment, this step is called Debugging, and has this icon:http://www.ikalogic.com/art_pics/8051_tut/debug_but.jpg. After clicking on the debug icon, you will notice that some part of the user interface will change, some new icons will appear, like the run icon circled in the following figure: 
http://www.ikalogic.com/art_pics/8051_tut/keil6.jpg
Figure: 2.8.f

http://www.ikalogic.com/img/a3.gif You can click on the 'Run' icon and the execution of the program will start. In our example, you can see the behavior of the pin 0 or port one, but clicking on 'peripherals, I/O ports, Port 1'. You can always stop the execution of the program by clicking on the stop button (http://www.ikalogic.com/art_pics/8051_tut/stop_but.jpg) and you can simulate a reset by clicking on the 'reset' button http://www.ikalogic.com/art_pics/8051_tut/rst_but.jpg

You can also control the execution of the program using the following icons:http://www.ikalogic.com/art_pics/8051_tut/step_but.jpg which allows you to follow the execution step by step. Then, when you're finished with the debugging, you can always return to the programming interface by clicking again on the debug button (http://www.ikalogic.com/art_pics/8051_tut/debug_but.jpg).

There are many other features to discover in the KEIL IDE. You will easily discover them in first couple hours of practice, and the more important of them will be presented along the rest of this tutorial.