You are on page 1of 7

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 manual 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.

Figure 1: Editing Source Code .

Perhaps a better approach would be to create a new target. where you must make several changes to configure Keil's compiler to produce code that will work properly. Enter 22. This will bring up the Options for Target dialog box. . which is the fastest and easiest approach. First. the target named "Simulator" was modified to produce output compatible with this board. Step 3: Configure Build Target Click on the "Project" menu. 4. Define "Off-chip Xdata memory" from 0x4000 to 0x7FFF. Define "Off-chip Code memory" from 0x2000 to 0x3FFF. 3. Such memory allocation planning is beyond the scope of this simple example. with a name such as "PJRC 8051 Development Board. For larger projects. 2. you may need to change these settings to allocate the memory usage according to your project's requirements.1184 in the "Xtal (Mhz)" field. and select "Options for Target 'Simulator'". Rev 5" and apply these changes to that target rather than the "Simulator" target. Uncheck "Use On-chip ROM". select the "Target" tab: 1.(Optional): Define a New Target Name For This Board In this example.

. Target Tab Next.Figure 2: Options for Target Dialog. select the "Output" tab. you must check the "Create Hex File" option. Here. so that an intel hex output files is created. That is the file you can use to download to the board.

Check "Interrupt vectors at address:" and set the corresponding value to 0x2000.Figure 3: Options for Target Dialog. select the "C51" tab. . Output Tab Finally.

You may need to press the ENTER key to allow PAULMON2 to re-detect your baud rate. click "OK" to commit your changes to the build target. .Figure 4: Options for Target Dialog. hex". click on the "Project" menu and select "Build target". and enter 2000 (which should be the default). if your program overwrites the 4 bytes that are used to store the previously detected baud rate. C51 Tab Once all these changes have been made in all three tabs. If there are no errors. using the "J" (Jump) command. which in this example is "hello. To run your program. Download the intel-hex file as described in the Using the 8051 Development Board For the First Time page. the compiler will finish and produce an intel-hex output file. To quit. press the board's RESET button to return to the monitor. Step 4: Compile and Download Intel-Hex Output To compile the code.

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