Appendix G Using the Keil µ Vision 4 Tools for 8051 – The x86 Microprocessors: 8086 to Pentium, Multicores, Atom and the 8051 Microcontroller, 2nd Edition

Appendix G

Using the KEIL μ Vision4 Tools for 8051

The latest version of RVDK (RealView Development Kit) supplied by Keil is μvision4. The evaluation version of this is freely downloadable by looking up ‘Keil μ Vision 4’ or from the link for 8051

The evaluation version can be used for simulation, and the only limitation it has is that a memory limitation of 2K for program code for 8051.

The ‘RealView Development Kit (RVDK) of Keil’ is a tool chain consisting of assemblers, compilers, debuggers, simulators, etc. for many chips of many families – it caters to the 8051 family, ARM and many more families of chips. It can be used for C programming of embedded devices as well as assembly language programs.

In Chapters 19 and 20, a number of assembly programs have been discussed and the Keil tool has been mentioned.

In this appendix, the steps in using this tool are discussed.

The discussion covers the step-by-step approach for using this tool for:

  1. assembly language
  2. C language programming
  3. building and debugging

A particular device of a specific ­family has to be chosen, and for this explanation, we choose the 8951 chip of Atmel.

Assembly Language Programming of 8051

Creating a Project

First make a folder in which your programs will be saved.

Then, open μvision4 and click the ‘Project’ menu and then ‘New μ Vision Project’ in it, as illustrated in Fig. A-G.1.

Figure A-G.1

Browse and get to the folder in which you will save it. Name the project FIRST, and it will be saved as FIRST.uvproj. (You can use any other name, this is just an example.)

With this, the device selection page will be opened, and it will look like as shown in Fig. A-G.2.

Figure A-G.2

Scroll and choose Atmel, and a list of names of chips of the 8051 family will be seen.

Select the device you want – here, we click on 89C51 as pointed in Fig. A-G.3.

Figure A-G.3

The next screen will ask the question ‘Copy Standard 8051 startup code to Project Folder and Add File to Project?’ This can be answered as ‘No’, as we do not need it for assembly language programming (For C programs, we answer ‘Yes)’.

Next, click on the File Tab and choose New. The editor opens and you can type your program here. This is an example program chosen.

Type this program and save it as FIRST.src. Any filename can be chosen, but the extension should be .src.

The next step is to add the filename to the source. For that, look to the left in the project workspace. Click the + sign on the left of ‘Target1’ and get ‘Source Group 1’.

Right click on it to get the screen as shown in Fig. A-G.4.

Figure A-G.4

Click on ‘Add files to group source Group 1’, browse for ‘src files and choose the file FIRST.src.-. This is shown in Fig. A-G.5. Click Add and then Close. After this, if you click the ‘+’ on the left of Source Group 1, this filename will be seen there.

Figure A-G.5

Next, we need to assemble this file. Click on the Project tab and get the ‘Build file’ Option or ‘Build all files’. Click on it, and the output window will open as shown in Fig. A-G.6.

Figure A-G.6

Since there are no errors, the message is that of 0 errors and 0 warnings. In case of any error, it will be listed as shown in Fig. A-G.7.

Figure A-G.7


Once building is done, we can do debugging. This is the option by virtue of which it is possible to view the contents of memory, registers, observe output waveform, etc.

There are actually a lot of things we can do, but only a few will be considered here. The rest of the options can be tried out easily, referring to the ‘Help’ menu.

Go to the Debug tab and click on ‘Start/Stop Debug session’.

The following actions are the result:

  1. A small window opens with the message EVALUATION MODE:

    Running with code size limit : 2K

  2. Click Ok and the debug session starts with a number of windows getting open. See Fig. A-G.8.

Figure A-G.8

You can open/close these windows using the View menu. The registers, memory, output, disassembly window, etc. can be opened or closed using ‘View’.

Figure A-G.8 shows the debug screen with the disassembly window, register window and Memory 2 window. In the memory window, typing c: 0x0000 (and pressing ENTER) gives us the content of ROM and typing d: 0x00 displays the content of RAM.

For checking the content of RAM, type d:0x00 in the memory window.

Single Stepping

The easiest thing to do is to ‘single step’ and get one instruction executed and then check the contents of registers and memory. For that, go to the Debug tab and click ‘Step’ or press F11. This activity is very interesting, as you will be able to observe the result of the execution of each instruction. Just after pressing FI, examine the content of the register or memory that is involved in the instruction executed. You will see how the content has changed.

If peripherals are involved in the program, go to the Peripherals tab and click on timers or I/O or serial ports, and single step through the program. All these actions become quicker, easier and fun with practice. The easiest is the GPIO peripheral window which shows the ON-OFF condition of all the pins.

Using the Logic Analyzer

We conclude this appendix by giving some tips on using the logic analyzer that allows us to view waveforms. The following program is used to discuss this.

This is an interrupt driven timer program, and a symmetric square wave is to be observed at pin P1.3


Build the program and then start the debug session.

You can see a ‘red and yellow’ waveform symbol on the toolbar. It is called the ‘Analysis Window’. Click and open it.

Click on the ‘setup window ‘on the open window of the logic analyzer. Refer Fig. A-G.9.

Figure A-G.9

The set up box alone is shown in Fig. A-G.10. Click on the square symbol at the left of the X symbol. A bar gets highlighted. On this bar, write P1.3 (for the output pin) and then click Hexadecimal display and write ‘0’ in the Shift Right box. You can select the color in the color box, and the display type may be chosen to be ‘Bit’ as shown in Fig. A-G.11.

Figure A-G.10

Figure A-G.11

Click close and then go to the Debug menu and click on Run.

The waveform at P1.3 will be displayed on the window. This waveform can be zoomed out and in, as you wish. If you want a stationary waveform, after Run, you can click on Stop and then click the logic analyzer window again. Figure A-G.12 shows the displayed waveform for the program used.

Figure A-G.12

Figure A-G.12 shows the debug window with the logic analyzer. Incidentally, the peripherals window is also open, showing the state of Port 1. (The disassembly and registers window have been closed).

All the square waveform generation examples of Chapter 19 have been tested using this logic analyzer. By reading more about this in the RVDK manual, a greater understanding of the debugging support facilitated by the Keil tools can be gained.

Using the Keil RVDK for C Programming of 8051

The steps in using the IDE for C programming is similar to what has been discussed for assembly language programming. There is a difference in one step, however.

Refer back to Fig. A-G.3 and the discussion following it, which is quoted below.

“The next screen will ask the question ‘Copy Standard 8051 startup code to Project Folder and Add File to Project?’ This can be answered as ‘No’, as we don’ t need it for assembly language programming (For C programs, we answer ‘Yes)’.”

The point is that, for C programs, we need to include the startup file as well. After this step, the C program is written into the editor and saved as filename.c. Then, this filename is added to the project. You will find that there are two files in the source group. One is the startup file and the other is the C file.

After this, the building and debugging are exactly the same as discussed for assembly language programming.