skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: 8051 Tools Development Board Example Code Keil C51

PJRC Store
8051 Board, $79
LCD 128x64 Pixel, $29
LCD 16x2 Char, $14
Serial Cable, $5
9 Volt Power, $6
More Components...
8051 Tools
Main Page
Software
PAULMON Monitor
Development Board
Code Library
89C2051 Programmer
Other Resources

Using Keil's "C51" C Compiler (µVision IDE)

These simple instuctions will walk you though the process of configuring Keil's µVision IDE and C51 C Compiler with settings that produce code that can be download and run on the 8051 development board.

PJRC does not provide technical support for use of Keil's software. We can not provide any assistance should these instructions not apply to your project's code or your µVision installation. However, these instructions were tested and confirmed to work using "Hello World" example provided with Keil's C51 evaluation software, version 7.06a.

For further assistance with Keil's software, please refer to the manaul Keil provides, or contact Keil for technical support.

Step 1: Copy Startup Code To Your Project

Copy the file "startup.a51" from "c:\keil\c51\lib" to "c:\keil\c51\examples\hello", or the equivilant pair of directories if you installed µVision in a different directory/drive location.

Add this new copy of "startup.a51" to your project.

  1. Right click "source group 1"
  2. Choose "Add Files to Group 'Source Group 1'
  3. Set "Files of type" to "All files (*.*)"
  4. and select "Startup.a51"

When "startup.a51" has been added to your project, the left side tree representing your project will be updated, similar to Figure 1.

Step 2: Edit Startup and Other Code

Edit "startup.a51" file. Locate the line "CSEG AT 0" and change it to "CSEG AT 0x2000". Remember that this will only change the "startup.a51" that you copied to this project. The global copy in "c:\keil\c51\lib" will remain unchanged.

Edit "hello.c", and change the line that sets TH1. For 115200 baud, you should set this to 255.

Figure 1 shows both of these files opened in µVision, edited with these changes.

Screenshot: Editing Code
Figure 1: Editing Source Code

(Optional): Define a New Target Name For This Board

In this example, the target named "Simulator" was modified to produce output compatible with this board, which is the fastest and easiest approach.

Perhaps a better approach would be to create a new target, with a name such as "PJRC 8051 Development Board, Rev 5" and apply these changes to that target rather than the "Simulator" target.

Step 3: Configure Build Target

Click on the "Project" menu, and select "Options for Target 'Simulator'". This will bring up the Options for Target dialog box, where you must make several changes to configure Keil's compiler to produce code that will work properly.

First, select the "Target" tab:

  1. Enter 22.1184 in the "Xtal (Mhz)" field.
  2. Uncheck "Use On-chip ROM".
  3. Define "Off-chip Code memory" from 0x2000 to 0x3FFF.
  4. Define "Off-chip Xdata memory" from 0x4000 to 0x7FFF.

For larger projects, you may need to change these settings to allocate the memory usage according to your project's requirements. Such memory allocation planning is beyond the scope of this simple example.

Screenshot: Target Tab
Figure 2: Options for Target Dialog, Target Tab

Next, select the "Output" tab. Here, you must check the "Create Hex File" option, so that an intel hex output files is created. That is the file you can use to download to the board.

Screenshot: Output Tab
Figure 3: Options for Target Dialog, Output Tab

Finally, select the "C51" tab. Check "Interrupt vectors at address:" and set the corresponding value to 0x2000.

Screenshot: C51 Tab
Figure 4: Options for Target Dialog, C51 Tab

Once all these changes have been made in all three tabs, click "OK" to commit your changes to the build target.

Step 4: Compile and Download Intel-Hex Output

To compile the code, click on the "Project" menu and select "Build target". If there are no errors, the compiler will finish and produce an intel-hex output file, which in this example is "hello.hex".

Download the intel-hex file as described in the Using the 8051 Development Board For the First Time page. To run your program, using the "J" (Jump) command, and enter 2000 (which should be the default).

To quit, press the board's RESET button to return to the monitor. You may need to press the ENTER key to allow PAULMON2 to re-detect your baud rate, if your program overwrites the 4 bytes that are used to store the previously detected baud rate.

(Optional) Reconfigure For Flash ROM

Alternately, you could define the off-chip code memory from 8000 to F7FF and off-chip Xdata memory from 2100 to 0x7FFF, set CSEG to 0x8000 in startup.a51, and set the interrupt vectors at address 0x8000. This would configure the compiled code to run from the Flash ROM, and you can use the autostart utility (on the LED blink example page) to make it run automatically when the board boots.


8051 Development System Circuit Board, Paul Stoffregen
http://www.pjrc.com/tech/8051/board5/keil.html
Last updated: February 24, 2005
Status: work in progress, more info to come
Suggestions, comments, criticisms: <paul@pjrc.com>