You are on page 1of 138

8051/251 Evaluation Kit

Getting Started with the 8051 and MCS® 251
Microcontroller Development Tools

User’s Guide 11.97

ii

Keil Software

Information in this document is subject to change without notice and does not
represent a commitment on the part of the manufacturer. The software described
in this document is furnished under license agreement or nondisclosure
agreement and may be used or copied only in accordance with the terms of the
agreement. It is against the law to copy the software on any medium except as
specifically allowed in the license or nondisclosure agreement. The purchaser
may make one copy of the software for backup purposes. No part of this manual
may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or information storage and
retrieval systems, for any purpose other than for the purchaser’s personal use,
without written permission.
© Copyright 1990-1998 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.

Keil C51™ and dScope™ are trademarks of Keil Elektronik GmbH.
Microsoft®, MS-DOS®, and Windows™ are trademarks or registered trademarks
of Microsoft Corporation.
IBM®, PC®, and PS/2® are registered trademarks of International Business
Machines Corporation.
Intel®, MCS® 51, MCS® 251, ASM-51®, and PL/M-51® are registered
trademarks of Intel Corporation.

Every effort was made to ensure accuracy in this manual and to give appropriate
credit to persons, companies, and trademarks referenced herein.

8051/251 Evaluation Kit

Preface
This manual is an introduction to the Keil Software 8051 and MCS® 251
microcontroller software development tools. It introduces new users and
interested readers to our product line. With nothing more than this book, you
should be able to successfully run and use our tools. This user’s guide contains
the following chapters.
“Chapter 1. Introduction” gives an overview of this user’s guide.
“Chapter 2. Installation” describes how to install our software and how to setup
an operating environment for the tools.
“Chapter 3. 8051/251 Product Line” discusses the different products that we
offer for the 8051 and 251 microcontrollers. Read this chapter to determine
which product provides the tools you need.
“Chapter 4. 8051 Development Tools” describes the major features of our 8051
development tools including the C compiler, assembler, debugger, and integrated
development environment.
“Chapter 5. 251 Development Tools” describes the major features of our 251
development tools including the C compiler, assembler, debugger, and integrated
development environment.
“Chapter 6. Using the 8051/251 tools” describes the provided sample programs
along with a step-by-step guide that shows how to build them using our tools.
“Chapter 7. Hardware Products” introduces our hardware-based tools that you
can use to aid in development and debugging. Our evaluation boards for the
80C517A and 80C251SB and our EPROM emulator are discussed.
“Chapter 8. Real-Time Kernels” discusses the RTX-51 Tiny and RTX-51 Full
real-time operating systems. This chapter provides an overview of multitasking
systems, why they are desirable, and how they are used.
“Chapter 9. Command Reference” briefly describes the commands and controls
for our 8051 and 251 development tools.
NOTE
This manual assumes that you are familiar with Microsoft Windows and the
hardware and instruction set of the 8051 and MCS® 251 microcontrollers.

iii

Double-Click Click the mouse button twice in rapid succession. . release the button. For example: !Optional Items" Optional arguments in command-line and option fields are indicated by double brackets. Keys Text in this sans serif typeface represents actual keys on the keyboard. projectfile in a syntax string means that you must supply the actual project file name. . This text usually represents commands that you must type in literally. . The braces enclose all of the choices and the vertical bars separate the choices.TXT Bold capital text is used for the names of executable programs. For example. Elements that repeat… Ellipses (…) are used to indicate an item that may be repeated. . italics are also used to emphasize words in the text. . data files. Occasionally. while (1). Click Quickly press and release a mouse button while pointing at the item to be selected.” Point Move the mouse until the mouse pointer rests on the item desired. and commands you enter at the MS-DOS command prompt. When the item to be selected is at the desired position.iv Preface Document Conventions This document uses the following conventions: Examples Description README. One item in the list must be selected. For example: CLS DIR BL51. Variables Text in italics represents information that you must provide. “Press Enter to continue. separated by a vertical bar represents a group of items from which one must be chosen. Omitted code . For example. C51 TEST. hold the button down while moving the mouse. environment variables. source files.EXE Note that you are not required to enter these commands using all capital letters. Courier Text in this typeface is used to represent information that displays on screen or prints at the printer. Then. Vertical ellipses are used in source code listings to indicate that a fragment of the program is omitted. Drag Press the left mouse button while on a selected item. This typeface is also used within the text when discussing or describing command line items. For example: void main (void) { .C PRINT !(filename)" { opt1 | opt2 } Text contained within braces.

............ 59 OH251 Object-Hex Converter ........ Using the 8051/251 tools ......... 2 Types of Users ..........................................................................................................................................................................23 8051 Microcontroller Family........................ 24 A51 Macro Assembler ..... 8 Directory Structure ........................................................................................ 51 C251 Optimizing C Cross Compiler ......................................... 8051 Development Tools....8051/251 Evaluation Kit Contents Chapter 1.....................................63 Starting µVision and dScope ....................................... 52 A251 Macro Assembler ........... 64 dScope Simulator/Debugger Overview........................7 System Requirements..... 11 Chapter 3..... 70 v ................................... 41 BL51 Code Banking Linker/Locator ........................................... 60 µVision/251 for Windows ............................................................................................................................................................................................................................................................................................................................................................ 2 Changes to the Documentation ................................................................... Introduction... 47 µVision/51 for Windows ................... 64 µVision IDE Overview ........ 20 Tool Kit Comparison Chart ............................................................................................................................................. 10 Improving System Performance............................................................................................................................... 60 LIB251 Library Manager..................................................................13 8051 Development Tool Kits................................................................................... 43 OC51 Banked Object File Converter ........................................................................... 7 Backing Up Your Disks ............ 251 Development Tools......... 61 Chapter 6....... 48 Chapter 5...................................................... 1 Evaluation and Demo Kits ......... 47 OH51 Object-Hex Converter ...................................................................................... 8051/251 Product Line........................... 3 Requesting Assistance...... 60 dScope-251 for Windows ............................................................................................................................................................................................. 47 dScope-51 for Windows ..................................... 47 LIB51 Library Manager............................................... 3 Chapter 2...................................................................................... 23 C51 Optimizing C Cross Compiler ............................................................................................................................................ 17 Subscription Kits .......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... 22 Chapter 4..........................................1 Manual Topics ............................................................ 8 Installing the Software .............................................. 58 L251 Code Banking Linker/Locator .............................................................................................................................................................................................51 MCS® 251 Microcontroller Family............................................................................................................................................................................................................................................................................................................................................... 9 Environment Settings..................................................................................... 13 251 Development Tool Kits................................ Installation..

............121 C51/C251 Compiler ..........................................................................................................................................128 Index .....................................................................................81 MEASURE: A Remote Measurement System ...... Real-Time Kernels ............................................................79 HELLO: Your First 8051/251 C Program..............................127 OH251 Object-Hex Converter .. Hardware Products ...vi Contents Sample Programs ........................127 OH51 Object-Hex Converter ...........88 BADCODE: An Example with Syntax Errors............................................................107 ProROM EPROM Emulator .................................121 A51/A251 Macro Assemblers...................................................................................................................................107 MCB517A Evaluation Board............................................126 OC51 Banked Object File Converter .....111 Chapter 9.....................................................................................................................111 RTX-51 Real-Time Operating System.........................................................................105 Chapter 7......................................................................................................................124 L251 Linker/Locator ...............................................................................128 LIB51/LIB251 Library Manager................................................................................122 L51/BL51 Linker/Locator ....................................................................................109 Chapter 8..................................................................................................................................................................................108 MCB251SB Evaluation Board......................................................................................................... Command Reference ...........................................................................................................................129 ................

8051/251 Evaluation Kit 1 Chapter 1. but any level of programmer can use them to get the most out of the 8051 and 251 hardware. we also provide real-time kernels. object file converter. 8051 Development Tools” on page 23. and debugging hardware. ! µVision for Windows™ Integrated Development Environment. Introduction Thank you for allowing Keil Software to provide you with software development tools for the 8051 and 251 family of microprocessors. ! A51/A251 Macro Assembler. Manual Topics This manual discusses a number of topics including how to: ! Install the software on your system (see “Chapter 2. ! dScope for Windows™ Source-Level Debugger/Simulator. These tools are combined into the kits described in “Chapter 3. ! Use the 8051 development tools (see “Chapter 4. you can generate embedded applications for the multitude of 8051 and 251 derivatives. Refer to “Chapter 8. The individual tools are described in detail in “Chapter 4. Our 8051 and 251 development tools are listed below: ! C51/C251 Optimizing C Cross Compiler. 8051/251 Product Line” on page 13). In addition to the above development tools. 1 . Hardware Products” on page 107 for more information about these products. 8051/251 Product Line” on page 13. Our tools are designed for the professional software developer. library manager). evaluation boards. ! Select the best tool kit for your application (see “Chapter 3. 8051 Development Tools” on page 23). With our tools. ! 8051/251 Utilities (linker. Real-Time Kernels” on page 111 and “Chapter 7. Installation” on page 7) and fine tune it for maximum performance (see “Improving System Performance” on page 11).

You may use the included sample programs to get real-world experience with our 8051 and 251 development tools. The included software provides you with the latest development . Even if you are only a evaluation user. They generate listing files where you can see the code generated by the compiler and other tools. This is all you need to do to begin using this kit. Introduction ! 1 Run the included sample programs (see “Chapter 6. Types of Users This manual addresses three types of users: evaluation users. and experienced users. The tools in the Demo Kit do not generate actual object code. The 8051/251 Demo Kit includes demonstration versions of our tools. Evaluation Users are those users who have not yet purchased the software but have requested the evaluation package to get a better feel for what the tools do and how they perform. and introduces the sample programs. This user’s guide is also included in each of our tool kits. If you want to get started immediately. Installation” on page 7) and running the sample programs (refer to “Chapter 6. The 8051/251 Evaluation Kit includes evaluation versions of our tools. Using the 8051/251 tools” on page 63). Using the 8051/251 tools” on page 63). The tools in the Evaluation Kit let you generate applications up to 2 Kbytes in size. you may do so by installing the software (refer to “Chapter 2. provides you with an overview of the development tools. Both kits include this user’s guide and software. You may use this kit to evaluate the effectiveness of our tools and to generate small target applications. The evaluation package includes evaluation copies of the development tools.2 Chapter 1. It explains how to install the software. New Users are those users who are purchasing our 8051 development tools for the first time. take the time to read this manual. new users. Evaluation and Demo Kits Keil Software provides two kits that let you evaluate our tools.

the sample programs. compiler. 3 1 . take the time to review the sample programs described in this manual. Make sure you are using the most current version of the software and utilities. library manager. 4. If. do the following before calling technical support. If you think you have discovered a problem with the software. and a full set of manuals. This manual provides a quick tutorial and helps new or inexperienced users quickly get started with the tools. Isolate the problem to determine if it is a problem with the assembler. If you have suggestions or comments regarding any of the printed manuals accompanying this product. or another development tool. 2. Requesting Assistance We are dedicated to providing you with the best embedded development tools and documentation available. If you are new to the 8051 or 251 or the tools. report them to our technical support group. after following these steps. If you contact us by fax. Changes to the Documentation Last minute changes and corrections to the software and manuals are listed in the README. and telephone numbers (voice and fax) where we can reach you. 1. 3. The software included with a product upgrade contains the latest development tools. your product serial number and version number.TXT file which is included in the root directory of your installation. please contact us.8051/251 Evaluation Kit tool versions as well as sample programs. you are still experiencing problems. linker. Isolate software problems by reducing your code to a few lines. Experienced Users are those users who have previously used our 8051 development tools and are now upgrading to the latest 8051 or 251 tools. Read the sections in this manual that pertain to the job or task you are trying to accomplish. Take the time to read this file to determine if there are any changes that may impact your installation. be sure to include your name.

The more descriptive your example.4 1 Chapter 1. If you have a one-page code example demonstrating the problem. Introduction Try to be as detailed as possible when describing the problem you are having. please fax it to us. . the faster we can find a solution. However. please try not send long listings as this slows down our response.

8051/251 Evaluation Kit 5 1 .

.

1 or higher. Before starting the installation program. are used to initialize environment variables used by the compiler and utilities. System Requirements There are minimum hardware and software requirements that must be satisfied to ensure that the compiler and utilities function properly.1 or higher. ! Hard disk with 6 MB free disk space. ! Hard disk with 6 MB free disk space. NOTE This chapter refers to various MS-DOS commands which may be used to customize your operating environment. For our DOS-based tools. ! Make a copy of the installation diskette for backup purposes. please refer to your DOS user’s guide.8051/251 Evaluation Kit 7 Chapter 2. you must have the following: ! 100% IBM compatible 386 or higher PC with 640 KB RAM. For our Windows-based tools. for example. ! Windows 3. 2 . ! MS-DOS Version 3. ! 4 MB RAM minimum. you must have the following: ! 100% IBM compatible 386 or higher PC. If you are not familiar with these commands and other MS-DOS operations mentioned in this chapter. Installation This chapter explains how to setup an operating environment and how to install the software on your hard disk. The SET and PATH commands. you must do the following: ! Verify that your computer system meets the minimum requirements.

SYS file should look similar to the following: BUFFERS=20 FILES=20 SHELL=C:\COMMAND. Then. insert the first product diskette into Drive A and enter the following command line at the DOS prompt: A:INSTALL Then. Installing the Software All of our products come with an installation program which allows easy installation of our software. Refer to your DOS user’s guide for more information. you can increase the amount of environment space by increasing the number 1024 in the above example.SYS file. Installation The C compiler and utilities require that you have at least 20 files and 20 buffers defined in your CONFIG. Be sure to store the original disks in a safe place in case your backups are lost or damaged. . Installing DOS-Based Products To install DOS-based products. use the backup disks to install the software. Backing Up Your Disks We strongly suggest that you make a backup copy of the installation diskettes using the DOS COPY or DISKCOPY commands.COM /e:1024 /p If you receive the message Out of environment space from DOS. Your 2 CONFIG.8 Chapter 2. follow the instructions displayed by the installation program. you need enough environment space for the environment variables used by the compiler and utilities (see “Environment Settings” on page 10). Additionally.

…\TS51 tScope-51 for DOS IOT drivers. 2 . …\RTX51 RTX-51 Full files. …\MON51 Target monitor files. …\EXAMPLES Sample applications. ! Enter A:SETUP at the Command Line prompt. The directory used depends on the kit being installed. …\INC C compiler include files. the installation program copies the development tools into the subdirectories listed in the following table. follow the instructions displayed by the installation program. Subdirectory Description …\ASM Assembler include files. …\BIN Executable files. \C251 251 development tools. \C51EVAL 8051 evaluation tools.8051/251 Evaluation Kit 9 Installing Windows-Based Products To install Windows-based products… ! Insert the first product diskette into Drive A. ! Select the Run… command from the File menu in the Program Manager. Then. …\LIB C compiler library files and startup code. Directory Structure The installation program copies the development tools into subdirectories of the following base directories. …\DS51 dScope-51 for DOS IOF drivers. ! Select the OK button. …\RTX_TINY RTX-51 Tiny files. \C251EVAL 251 evaluation tools. After creating the appropriate directory. Directory Description \C51 8051 development tools.

If the path does not exist. For best performance. you must include the …\BIN\ directory in your PATH. \C251\…. . TMP C51INC \C51\INC Specifies the path where the standard C51 compiler include files are located. In addition. C251LIB \C251\LIB Specifies the path where the standard C251 compiler library files are located. their default paths.10 Chapter 2. C251INC \C251\INC Specifies the path where the standard C251 compiler include files are located. the tools abort reporting a fatal error. The following table lists the environment variables. the path must exist. the path specified should be a RAM disk. and a brief description. PATH \C251EVAL\BIN Specifies the path of the 251 evaluation tools. If this environment variable is specified. C51LIB \C51\LIB Specifies the path where the standard C51 compiler library files are located. NOTE This manual makes references to programs and files in the \C51\… directory. Installation This table lists a complete installation that includes the entire line of 8051 development tools. Your installation may vary depending on the products you purchased. and \C251EVAL\… directories. PATH \C51EVAL\BIN Specifies the path of the 8051 evaluation tools. PATH \C251\BIN Specifies the path of the 251 development tools. Environment Settings 2 The compiler and utilities require entries in the DOS environment table that specify the path to include files and libraries. Specifies the path for temporary files generated. Variable Path Description PATH \C51\BIN Specifies the path of the 8051 development tools. This directory is equivalent to the \C51EVAL\….

This speeds up the execution of the many of the tools and utilities because they can use the RAM disk for temporary files.. A RAM disk is a memory-based disk emulator. RAMDRIVE. you should consider using a RAM disk.8051/251 Evaluation Kit 11 Typically.SYS and are the names of the RAM disk programs that are most commonly shipped with DOS. Refer to your DOS manual to learn how to install these programs. If you wish to put these settings in a separate batch file. If you are using a RAM disk. Because the contents of a RAM disk are stored in RAM. PATH=C:\C251EVAL\BIN.. You may: ! Provide a RAM disk for the compiler and utilities to use for temporary files... SET C51INC=C:\C51\INC SET C51INC=C:\C51EVAL\INC SET C51LIB=C:\C51\LIB SET C51LIB=C:\C51EVAL\LIB 251 Development Tools 251 Evaluation Tools PATH=C:\C251\BIN. Using a RAM Disk If your computer has sufficient extended or expanded memory available. you can set the value of the TMP environment variables to the drive name of the RAM disk... A number of RAM disk software packages are available.. the environment settings must be entered as follows: 8051 Development Tools 8051 Evaluation Tools PATH=C:\C51\BIN..SYS 2 . SET C251INC=C:\C251\INC SET C251INC=C:\C251EVAL\INC SET C251LIB=C:\C251\LIB SET C251LIB=C:\C251EVAL\LIB Improving System Performance There are two methods you can employ to improve performance of the C51 compiler and utilities. These techniques are generic and should help boost performance of most applications.. access is very fast. environment settings are automatically installed in your AUTOEXEC. VDISK. ! Use a disk cache to store the most recently accessed disk files.BAT file by the installation program.. PATH=C:\C51EVAL\BIN...

and linker. In these situations. source file. This is significantly faster than waiting for the disk drive to read the information. the compiler. Installation Using a Disk Cache 2 A disk cache utilizes a large memory pool to temporarily store information read from disk. and object file can all be held in the cache. Refer to your DOS manual to learn how to install and use this program. the information is read from the cache memory instead of from the disk.0 of MS-DOS both come with a disk-caching utility called SMARTDRV.12 Chapter 2. assembler. The editor. it first checks the cache to see if the desired information is already in the cache. Version 5. When the computer accesses the disk. Typically. compiler.0 and Version 6. a disk cache improves the performance of your editor.SYS. and disk accesses are kept to a minimum. If it is. software development involves an edit-compile-edit-compile… cycle. .

8051/251 Evaluation Kit 13 Chapter 3. You may use an assembler to assemble your 8051 assembly program. Our 8051 kits are described below in the “8051 Development Tool Kits” section. 8051/251 Product Line Keil Software provides the premier 8051 and 251 development tools in the industry. To help you become familiar with how we distribute our tools. Compile or assemble source files. and you may use a linker to create an absolute object module suitable for your in-circuit emulator. Tool Kit Overview The development cycle described above may be best illustrated by a block diagram (shown on the following page) of the complete 8051 tool set. Therefore. Correct errors in source files. 4. Test linked application. Create source files in C or assembly. 8051 Development Tool Kits When you use the Keil Software tools. While it makes little sense to have a compiler without a linker. 3. 5. it also makes little sense to have a linker without a compiler or assembler. 3 . the 8051 project development cycle is roughly the same as for any software development project. A tool kit is comprised of several application programs that you use to create your 8051 application. our tools are packaged into various kits. you may use a compiler to compile your C source code into an object file. Link object files from compiler and assembler. we would like to introduce the concept of a tool kit. Our 251 kits are described in the “251 Development Tool Kits” section on page 17. 1. 2.

By loading specific I/O drivers. When the linker processes a library. Object files created by the compiler and assembler and library files Monitor-51 created by the library manager are Target Debugging processed by the linker to create an absolute object module. programming. 8051/251 Product Line µVision/51 C51 Compiler C Library 3 A51 Macro Assembler LIB51 Library Manager RTX51 Real-Time Operating System BL51 Linker for Code-Banking dScope-51 Source Leve -Debugger Emulator & PROM Programmer As shown in this figure. only the object modules in the library that are necessary for program creation are used. files are created by the µVision/51 IDE and then passed to the C51 compiler or A51 assembler. A library is a specially formatted. ordered program collection of object modules that the linker can process. All the code in an absolute object file resides at fixed locations. CPU & Peripheral Simulator The absolute object file created by the linker may be used to program EPROM or other memory devices.14 Chapter 3. and debugging of complex applications where fast reaction to time critical events is essential. An absolute object file or module is an object file with no relocatable code. the debugger is even able to do source-level debugging on your target hardware. The RTX-51 real-time kernel simplifies the system design. The RTX-51 real-time operating system is a multitasking kernel for the 8051 family. The compiler and assembler process source files and create relocatable object files. reliable high-level-language program debugging. The kernel is fully integrated into the C51 compiler and is easy to use. you can simulate the attributes and peripherals of a variety of 8051 derivatives. Task description tables and operating system . Object files created by the compiler and assembler may be used by the LIB51 library manager to create a library. The debugger contains a high-speed simulator and a target debugger that let you simulate an entire 8051 system including on-chip peripherals. In conjunction with Monitor-51. The absolute object module may also be used with the dScope-51 debugger/simulator or with an in-circuit emulator. The dScope-51 source level debugger/simulator is ideally suited for fast.

Tool Kit Introduction The preceding diagram shows the full extent of the Keil Software 8051 development tools. PK51—C51 Professional Developer’s Kit The PK51 C51 professional developer’s kit includes everything the professional 8051 developer needs to create sophisticated embedded applications. the professional developer’s kit is described first. To best illustrate what is included in each tool kit. 3 .8051/251 Evaluation Kit 15 consistency are automatically controlled by the BL51 code banking linker/locator. ! BL51 Code Banking Linker/Locator. ! tScope-51 Target Debugger. Keil Software provides a number of other tool kits for the 8051 developer. ! Monitor-51 ROM Monitor and Terminal Program. ! LIB51 Library Manager. The tools listed in this diagram comprise the professional developer’s kit described on the following pages. we describe the kits in decreasing order of capability. This tool kit includes the following components: ! C51 Optimizing C Compiler. ! RTX-51 Tiny Real-Time Operating System. ! OH51 Object-Hex Converter. In addition to the professional kit. ! dScope-51 Simulator/Debugger. The most capable kit. ! Integrated Development Environment. the professional developer’s kit includes the following tools for Windows users: ! dScope-51 Simulator/Debugger for Windows. In addition. ! OC51 Banked Object File Converter. ! A51 Macro Assembler.

! A51 Macro Assembler. CA51—C51 Compiler Kit The CA51 C51 compiler kit is the best choice for developers who need a C compiler but not a debugging system. ! dScope-51 Simulator/Debugger. The professional developer’s kit can be configured for all 8051 derivatives. The tools included in this kit run under DOS on any 100% IBM PC 386 or higher compatible computer. ! OH51 Object-Hex Converter. . This tool kit includes the following components: ! C51 Optimizing C Compiler. The compiler kit can be configured for all 8051 derivatives. ! LIB51 Library Manager. The developer’s kit can be configured for all 8051 derivatives.16 Chapter 3. ! tScope-51 Target Debugger. ! BL51 Code Banking Linker/Locator. This kit lets you create 8051 C applications for your target hardware. This kit lets you create sophisticated embedded applications using a DOS-based development platform. ! Monitor-51 ROM Monitor and Terminal Program. ! OC51 Banked Object File Converter. 8051/251 Product Line ! µVision/51 Integrated Development Environment for Windows. ! Integrated Development Environment. DK51—C51 Developer’s Kit 3 The DK51 C51 developer’s kit is designed for users who need a complete DOS-based development system for the 8051. The tools included in this kit run under DOS on any 100% compatible IBM PC 386 or higher computer. The tools included in this kit run under DOS on any 100% compatible IBM PC 386 or higher computer.

This tool kit includes the following components: ! dScope-51 Simulator/Debugger. RTX-51 Full provides a superset of the features found in RTX-51 Tiny and also includes BITBUS and CAN communication protocol interface libraries. The differences are the names of the tools used to generate 251 3 . and memory locations. The assembler kit is easily configured for all 8051 derivatives. we have kept the names of the kits the same. The development process for a 251 application is much the same as it is for an 8051 application. ! Monitor-51 ROM Monitor and Terminal Program. The tools included in this kit run under DOS on any 100% compatible IBM PC 386 or higher computer. With this kit. The tools included in this kit run under DOS on any 100% compatible IBM PC 386 or higher computer. ! tScope-51 Target Debugger. you can quickly locate problems in your 8051 application because the simulator lets you step through your code one instruction at a time. The simulator kit comes with drivers for most popular 8051 derivatives. Where applicable. SFRs. DS51—dScope-51 Simulator Kit The DS51 simulator kit provides a debugger/simulator for use with the A51 assembler kit and the CA51 compiler kit. Refer to “Chapter 8.8051/251 Evaluation Kit 17 A51—A51 Macro Assembler Kit The A51 assembler kit includes our 8051 assembler and all the utilities you need to begin creating 8051 application. You can easily view program variables. Real-Time Kernels” on page 111 for more information about RTX-51 Tiny. FR51—RTX-51 Full Real-Time Kernel The RTX-51 Full kernel is a real-time operating system for the 8051 microcontroller. 251 Development Tool Kits Our 251 development tool set is very similar in function to our 8051 tools set.

! L251 Linker/Locator. This kit lets you create sophisticated embedded applications using a Windows-based development platform. 8051/251 Product Line code.18 Chapter 3. ! L251 Linker/Locator. ! A251 Macro Assembler. ! dScope-251 Simulator/Debugger for Windows. ! LIB251 Library Manager. Following are descriptions of the 251 development tool kits that we provide. . ! A251 Macro Assembler. ! µVision/251 Integrated Development Environment for Windows. The tools included in this kit run under Windows on any 100% IBM PC 386 or higher compatible computer. ! LIB251 Library Manager. This tool kit includes the following components: ! C251 Optimizing C Compiler. ! OH251 Object-Hex Converter. The developer’s kit can be configured for all modes of the 251. ! Monitor-251 ROM Monitor. CA251—C251 Compiler Kit for Windows The CA251 compiler kit is the best choice for developers who need a C compiler but not a debugging system. This kit lets you create 251 C and assembly applications for your target hardware. This tool kit includes the following components: 3 ! C251 Optimizing C Compiler. ! OH251 Object-Hex Converter. DK251—C251 Developer’s Kit for Windows The DK251 C251 developer’s kit is designed for users who need a complete development system for the 251.

The simulator kit comes with drivers for most popular 8051 and 251 derivatives.8051/251 Evaluation Kit ! 19 µVision/251 Integrated Development Environment for Windows. With this kit. The tools included in this kit run under Windows on any 100% IBM PC 386 or higher compatible computer. A251—A251 Macro Assembler Kit for Windows The A251 assembler kit includes our 251 assembler and all the utilities you need to begin creating 251 application. The tools included in this kit run under Windows on any 100% IBM PC 386 or higher compatible computer. The tools included in this kit run under Windows on any 100% IBM PC 386 or higher compatible computer. you can quickly locate problems in your 251 application because the simulator lets you step through your code one instruction at a time. You can easily view program variables. ! Monitor-251 ROM Monitor. ! LIB251 Library Manager. 3 . This tool kit includes the following components: ! A251 Macro Assembler. DS251—dScope-251 Simulator Kit for Windows The DS251 simulator kit is provides a Windows-based debugger/simulator for the A251 assembler kit and the CA251 compiler kit. SFRs. The compiler kit can be configured for every mode of the 251. ! µVision/251 Integrated Development Environment for Windows. This tool kit includes the following components: ! dScope-251 Simulator/Debugger for Windows. and memory locations. ! L251 Linker/Locator. ! OH251 Object-Hex Converter.

! C51 Optimizing C Compiler. ! A51 Macro Assembler. The following components are included in this kit. ! L251 Linker/Locator. . ! OH251 Object-Hex Converter. ! OH51 Object-Hex Converter. The subscription kits provide the 8051 and 251 development tools as well as one year of free software upgrades. ! A251 Macro Assembler. SDK251—8051/251 Developer’s Kit Subscription The SDK251 subscription includes all the components of the DK51 developer’s kit and the DK251 developer’s kit. ! tScope-51 Target Debugger for DOS. we have added the 8051/251 subscription kits to our product line. ! Monitor-51 ROM Monitor and Terminal Program. 8051/251 Product Line FR251—RTX-251 Full Real-Time Kernel The RTX-251 Full kernel is a real-time operating system for the 251 microcontroller. RTX-251 Full provides a superset of the features found in RTX-251 Tiny and is comparable to the RTX-51 kernel for the 8051. This kit provides a complete solution for 8051 developers who plan to use the 251. ! OC51 Banked Object File Converter. ! LIB251 Library Manager. ! BL51 Code Banking Linker/Locator.20 Chapter 3. ! LIB51 Library Manager. ! dScope-51 Simulator/Debugger for DOS. Subscription Kits 3 To best support users who develop 8051 and 251 applications. ! C251 Optimizing C Compiler.

! µVision/251 Integrated Development Environment for Windows. ! OH251 Object-Hex Converter. ! C51 Optimizing C Compiler. The following components are included in this kit. ! OH51 Object-Hex Converter. ! BL51 Code Banking Linker/Locator. ! L251 Linker/Locator. ! µVision/251 Integrated Development Environment for Windows. ! C251 Optimizing C Compiler.8051/251 Evaluation Kit ! dScope-251 Simulator/Debugger for Windows. 3 . This kit is the best choice for 8051 developers who plan to use the 251 but who don’t need a debugging solution. ! Monitor-251 ROM Monitor. ! A51 Macro Assembler. ! A251 Macro Assembler. ! LIB51 Library Manager. ! LIB251 Library Manager. 21 SCA251—8051/251 Compiler Kit Subscription The SCA251 subscription includes all the components of the CA51 compiler kit and the CA251 compiler kit. ! OC51 Banked Object File Converter.

22 Chapter 3. 8051/251 Product Line Tool Kit Comparison Chart The following table provides a check list of the features found in each of our development kits. Use this cross reference to select the kit that best suits your needs. Part numbers are listed across the top and features are listed down the side. 3 Support PK51 DK51 A51 8051 ! ! ! 251 ! DK251 CA251 A251 SDK251 SCA251 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! Assembler ! ! Compiler ! ! ! Simulator ! ! ! IDE ! ! ! RTX ! Windows ! DOS ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! .

More than 200 different 8051 derivatives are available today from a variety of chip vendors. As an embedded processor. 8051 Microcontroller Family The 8051 has been available since the early 1980’s. 8051 Development Tools This chapter discusses the features and advantages of the 8051 microprocessor family and the development tools available from Keil Software. 4 . ! LIB51 Library Manager (see page 47) ! dScope-51 for Windows (see page 47). ! µVision/51 for Windows (see page 48). ! OC51 Banked Object File Converter (see page 47).8051/251 Evaluation Kit 23 Chapter 4. code memory. ! BL51 Code Banking Linker/Locator (see page 43). A flexible memory interface lets you expand the capabilities of the 8051 using standard peripherals and memory devices. our tools are easy to use and are guaranteed to help you achieve your design goals. ! A51 Macro Assembler (see page 41). A typical 8051 family member contains the 8051 CPU core. data memory. For this reason. and some versatile peripheral functions. ! OH51 Object-Hex Converter (see page 47). the 8051 has no equal. the 8051 CPU core is destined to see service well into the next century. We have designed our development tools to help you quickly and successfully complete your job. With a wide variety of outstanding features and peripherals. 8051 Development Tools Keil Software provides the following development tools for the 8051: ! C51 Optimizing C Compiler (see page 24). More than half of all embedded projects with a CPU use members of the 8051 microcontroller family.

The development environment can be expanded with all Intel compatible tools such as Intel PL/M-51 or iDCX-51 and with emulators from a wide range of manufactures. Many applications can be solved more easily and efficiently with C than with other more specialized languages. For most 8051 applications. A rudimentary knowledge of the 8051’s memory architecture is desirable but not necessary. elements of structured programming. Using a high-level language like C has many advantages over assembly language programming. . The C51 compiler generates code for the 8051 microprocessor but is not a universal C compiler adapted for the 8051 target. For example: ! Knowledge of the processor instruction set is not required. the C51 compiler gives software developers the flexibility of programming in C while matching the code efficiency and speed of assembly language. NOTE All of our 8051 tools utilize the Intel OMF51 object module format. It is a ground-up implementation dedicated to generating extremely fast and compact code for the 8051 microprocessor.24 Chapter 4. 8051/251 Product Line” on page 13. Its generality. C is not a big language and is not designed for any one particular area of application. ! The ability to combine variable selection with specific operations improves program readability. C51 Optimizing C Cross Compiler 4 The C programming language is a general-purpose programming language that provides code efficiency. combined with its absence of restrictions. refer to “Chapter 3. make C a convenient and effective programming solution for a wide variety of software tasks. ! Keywords and operational functions that more nearly resemble the human thought process can be used. and a rich set of operators. 8051 Development Tools For information on the products which include these tools. ! Register allocation and addressing mode details are managed by the compiler. The Keil Software C51 optimizing cross compiler for the MS-DOS operating system is a complete implementation of the ANSI (American National Standards Institute) standard for the C language.

! The library files that are supplied provide many standard routines (such as formatted output. Existing software investments can be quickly and easily converted from or adapted to other processors or environments. ! Memory Models. The C51 compiler includes extensions for: ! Data Types. ! Existing routine can be reused in new programs by utilizing the modular programming techniques available with C. 25 C51 Language Extensions The C51 compiler is an ANSI compliant C compiler and includes all aspects of the C programming language that are specified by the ANSI standard. A number of extensions to the C programming language are provided to support the facilities of the 8051 microprocessor. The following sections briefly describe these extensions. ! Pointers. ! The C language is very portable and very popular. ! Real-Time Operating Systems. and floating-point arithmetic) that may be incorporated into your application. ! Reentrant Functions. C compilers are available for almost all target systems. ! Interfacing to PL/M and A51 source files.8051/251 Evaluation Kit ! Program development and debugging times are dramatically reduced when compared to assembly language programming. ! Interrupt Functions. data conversions. 4 . ! Memory Types.

and sfr16 data types are specific to the 8051 hardware and the C51 and C251 compilers. of course. sfr. sbit. sign extensions are automatically carried out for signed variables. In addition to data type conversions. Each variable may be explicitly assigned to a specific memory space. a bit variable used in an integer assignment is converted to an integer. Memory Types The C51 compiler supports the architecture of the 8051 and its derivatives and provides access to all memory areas of the 8051.175494E-38 to ±3. 8051 Development Tools Data Types The C51 compiler supports the data types listed in the following table. . and sfr16 data types are included to allow access to the special function registers that are available on the 8051. In addition to these scalar types. unions. coerce a conversion by using a type cast. For example. Except as noted. For example. This is the address of PORT 0 on the 8051. and arrays.402823E+38 sbit † 1 sfr † 8 1 0 to 255 sfr16 † 16 2 0 to 65535 0 to 1 † The bit.26 Chapter 4. you may use pointers to access these data types. The C51 compiler automatically converts between data types when the result implies a different data type. You can. variables can be combined into structures. The are not a part of ANSI C and cannot be accessed through pointers. Data Type 4 Bits Bytes Value Range bit † 1 signed char 8 1 0 to 1 -128 to +127 unsigned char 8 1 0 to 255 enum 16 2 -32768 to +32767 signed short 16 2 -32768 to +32767 unsigned short 16 2 0 to 65535 signed int 16 2 -32768 to +32767 unsigned int 16 2 0 to 65535 signed long 32 4 -2147483648 to 2147483647 unsigned long 32 4 0 to 4294967295 float 32 4 ±1. The sbit. declares the variable P0 and assigns it the special function register address of 0x80. the declaration: sfr P0 = 0x80. sfr.

For example: char data var1.y.z. The default memory type is determined by the SMALL. COMPACT and LARGE compiler control directives. float idata x.8051/251 Evaluation Kit Memory Type 27 Description code Program memory (64 Kbytes). If the memory type specifier is omitted in a variable declaration. char code text[] = "ENTER PARAMETER:". By including a memory type specifier in the variable declaration. you can specify where variables are stored. 4 . data Directly addressable internal data memory. accessed by opcode MOVX @Rn. xdata External data memory (64 Kbytes). unsigned int pdata dimension. For this reason. char bdata flags. the default or implicit memory type is automatically selected. bdata Bit-addressable internal data memory. accessed across the full internal address space (256 bytes). fastest access to variables (128 bytes). Function arguments and automatic variables which cannot be located in registers are also stored in the default memory area. you may include memory type specifiers in the variable declaration. you should place frequently used variables in internal data memory and less frequently used variables in external data memory. pdata Paged (256 bytes) external data memory. unsigned long xdata array[100]. idata Indirectly addressable internal data memory. These directives specify the memory model to use for the compilation. Accessing the internal data memory is considerably faster than accessing the external data memory. unsigned char xdata vector[10][4][4]. accessed by opcode MOVX @DPTR. As with the signed and unsigned attributes. accessed by opcode MOVC @A+DPTR. allows mixed bit and byte access (16 bytes).

You specify the memory model on the command line using the SMALL. This is the same as if they were explicitly declared using the pdata memory type specifier. the compact model is faster than the large model. SMALL In this model. the small model is the best model to use. variable access is not as fast. Memory access through this data pointer is inefficient. This is the same as if they were declared explicitly using the data memory type specifier.28 Chapter 4. The high byte of the address is usually set up via port 2. Stack size is critical because the stack space used depends upon the nesting depth of the various functions. all variables default to the internal data memory of the 8051. and variables declared with no explicit memory type. In this memory model. and most efficient code. which is indirect through registers R0 and R1. The limitation is due to the addressing scheme used. This memory model is not as efficient as the small model. COMPACT. However. all data objects. . all variables default to external data memory. you may override the default memory type. 8051 Development Tools Memory Models The memory model determines the default memory type used for function arguments. and LARGE control directives. This memory model can accommodate a maximum of 256 bytes of variables. if the BL51 code banking linker/locator is configured to overlay variables in the internal data memory. as well as the stack must fit into the internal RAM. This type of data access generates more code than the small or compact models. The data pointer (DPTR) is used for addressing. Typically. 4 NOTE You should always use the SMALL memory model. LARGE In large model. However. variable access is very efficient. By explicitly declaring a variable with a memory type specifier. tightest. It generates the fastest. COMPACT Using compact model. therefore. You can always explicitly specify the memory area for variables. The compiler does not set this port for you. especially for variables with a length of two or more bytes. automatic variables. all variables default to one page of external data memory. This is the same as if they were explicitly declared using the xdata memory type specifier. Move up in model size only if you are unable to make your application fit or operate using SMALL model.

/* ptr to string in data */ /* ptr to int(s) in xdata */ /* ptr to long(s) in code */ Because the memory type is specified at compile-time. However. the memory type byte required by untyped pointers is not needed by typed pointers. 4 . int *numptr. long *state. You may use pointers to perform all operations available in standard C. Generic pointers may be used to access any variable regardless of its location in 8051 memory space. a function can access data regardless of the memory in which it is stored. int xdata *numtab. bdata. and pdata pointers) or two bytes (code and xdata pointers). Memory Specific Pointers Memory specific pointers always include a memory type specification in the pointer declaration and always refer to a specific memory area. /* string ptr */ /* int ptr */ /* long ptr */ Generic pointers are always stored using three bytes. because of the unique architecture of the 8051 and its derivatives. For example: char *s. data. Typed pointers can be stored using only one byte (idata.8051/251 Evaluation Kit 29 Pointers The C51 compiler supports pointer declarations using the asterisk character (‘*’). the C51 compiler supports two different types of pointers: memory specific pointers and generic pointers. By using these generic untyped pointers. For example: char data *str. The first byte is for the memory type. Generic Pointers Generic pointers are declared in the same way as standard C pointers. and the third is for the low-order byte of the offset. Many of the library routines use these pointer types for this reason. the second is for the high-order byte of the offset. long code *powtab.

The reentrant function attribute allows you to declare functions that may be reentrant and.@R0 DPL.xp A. 4 Description Idata Pointer Xdata Pointer Generic Pointer Sample Program char idata *ip. } Reentrant functions can be called recursively and can be called simultaneously by two or more processes. 8051 Development Tools Comparison: Memory Specific & Generic Pointers You can significantly accelerate an 8051 C program by using ‘memory specific’ pointers.p CLDPTR Reentrant Functions A reentrant function can be shared by several processes at the same time.30 Chapter 4.p + 2 R2. char val. When a reentrant function is executing. may be called recursively.xp +1 DPH. Execution Time 4 cycles 7 cycles 13 cycles R0. For each reentrant function. return (x * b). char *p. C51 functions cannot be called recursively or in a fashion which causes reentrancy.A R1. char val. . For example: int calc (char i.p + 1 R3. The following sample program shows the differences in code & data size and execution time for various pointer declarations. val = *xp. val = *ip. Reentrant functions are often required in real-time applications or in situations where interrupt code and non-interrupt code must share a function. char xdata *xp.ip val. int b) reentrant { int x. The reason for this limitation is that function arguments and local variables are stored in fixed memory locations. a reentrant stack area is simulated in internal or external memory depending on the memory model. therefore. val = *p.@DPTR val. 8051 Program Code Generated MOV MOV MOV MOV MOV MOV MOV MOV MOV CALL Pointer Size 1 byte data 2 bytes data 3 bytes data Code Size 4 bytes code 9 bytes code 11 bytes code + Lib. Normally. char val. another process can interrupt the execution and then begin to execute that same reentrant function. x = table [i].

unsigned int interruptcnt. 1-byte pointer int. The compiler automatically generates the interrupt vector and entry and exit code for the interrupt routine.8051/251 Evaluation Kit 31 NOTE By selecting the reentrant attribute on a function by function basis. Interrupt Functions The C51 compiler provides you with a method of calling a C function when an interrupt occurs. 2-byte pointer long. This significantly improves system performance since arguments do not have to be written to and read from memory. } } /* count to 4000 */ /* second counter */ /* clear int counter */ Parameter Passing The C51 compiler passes up to three function arguments in CPU registers. Argument Number char. specifies that the associated function is an interrupt function. you can specify the register bank used for that interrupt with the using function attribute. Argument passing can be controlled with the REGPARMS and NOREGPARMS control directives. unsigned char second. You need only be concerned with the interrupt number and register bank selection. interruptcnt = 0. This support allows you to create interrupt service routines in C. Making an entire program reentrant may cause it to be larger and consume more memory. when included in a declaration. The interrupt function attribute. you can select the use of this attribute where it’s needed without making the entire program reentrant. float generic pointer 1 R7 R6 & R7 R4 — R7 R1 — R3 2 R5 R4 & R5 3 R3 R2 & R3 4 . Additionally. The following table lists the registers used for different arguments and data types. void timer0 (void) interrupt 1 using 2 { if (++interruptcnt == 4000) { second++.

32

Chapter 4. 8051 Development Tools

If no registers are available for argument passing or too many arguments are
involved, fixed memory locations are used for those extra arguments.

Function Return Values
CPU registers are always used for function return values. The following table
lists the return types and the registers used for each.

4

Return Type

Register

Description

bit

Carry Flag

char, unsigned char, 1-byte pointer

R7

int, unsigned int, 2-byte pointer

R6 & R7

MSB in R6, LSB in R7

long, unsigned long

R4 — R7

MSB in R4, LSB in R7

float

R4 — R7

32-Bit IEEE format

generic pointer

R1 — R3

Memory type in R3, MSB R2, LSB
R1

Register Optimizing
Depending on program context, the C51 compiler allocates up to 7 CPU registers
for register variables. Any registers modified during function execution are
noted by the C51 compiler within each module. The linker/locator generates a
global, project-wide register file which contains information of all registers
altered by external functions. Consequently, the C51 compiler knows the
register used by each function in an application and can optimize the CPU
register allocation of each C function.

Real-Time Operating System Support
The C51 compiler integrates well with both the RTX-51 Full and RTX-51 Tiny
multitasking real-time operating systems. The task description tables are
generated and controlled during the link process. For more information about
the RTX real-time operating systems, refer to “Chapter 8. Real-Time Kernels”
on page 111.

8051/251 Evaluation Kit

33

Interfacing to Assembly
You can easily access assembly routines from C and vice versa. Function
parameters are passed via CPU registers or, if the NOREGPARMS control is
used, via fixed memory locations. Values returned from functions are always
passed in CPU registers.
You can use the SRC directive to direct the C51 compiler to generate a file
ready to assemble with the A51 assembler instead of an object file. For example,
the following C source file:
unsigned int asmfunc1 (unsigned int arg){
return (1 + arg);
}

generates the following assembly output file when compiled using the SRC
directive.
?PR?_asmfunc1?ASM1
SEGMENT CODE
PUBLIC
_asmfunc1
RSEG ?PR?_asmfunc1?ASM1
USING 0
_asmfunc1:
;---- Variable 'arg?00' assigned to Register 'R6/R7'
MOV
A,R7
; load LSB of
ADD
A,#01H
; add 1
MOV
R7,A
; put it back
CLR
A
ADDC A,R6
; add carry &
MOV
R6,A

---the int
into R7
R6

?C0001:
RET

; return result in R6/R7

You may use the #pragma asm and #pragma endasm preprocessor directives
to insert assembly instructions into your C source code.

Interfacing to PL/M-51
Intel’s PL/M-51 is a popular programming language that is similar to C in many
ways. You can easily interface routines written in C to routines written in
PL/M-51. You can access PL/M-51 functions from C by declaring them with the
alien function type specifier. All public variables declared in the PL/M-51
module are available to your C programs. For example:
extern alien char plm_func (int, char);

4

34

Chapter 4. 8051 Development Tools

Since the PL/M-51 compiler and the Keil Software tools all generate object files
in the OMF51 format, external symbols are resolved by the linker.

4

The compiler analyzes the generated code to produce the most efficient instruction sequences. Each increasing level includes the optimizations of levels below it. The following is a list of all optimizations currently performed by the C51 compiler. The C51 compiler provides six different levels of optimizing. ! Register Variables: Automatic variables and function arguments are located in registers whenever possible. No data memory space is reserved for these variables. ! Dead Code Elimination: Code which cannot be reached (dead code) is removed from the program. This means that the compiler takes certain steps to ensure that the code generated and output to the object file is the most efficient (smaller and/or faster) code possible. ! Jump Optimizing: Jumps are inverted or extended to the final target address when the program efficiency is thereby increased. ! Parameter Passing Via Registers: A maximum of three function arguments can be passed in registers. This ensures that your C program runs as quickly and effectively as possible in the least amount of code space.8051/251 Evaluation Kit 35 Code Optimizations The C51 compiler is an aggressive optimizing compiler. General Optimizations ! Constant Folding: Several constant values occurring in an expression or address calculation are combined as a single constant. 4 . ! Global Common Subexpression Elimination: Identical subexpressions or address calculations that occur multiple times in a function are recognized and calculated only once whenever possible.

4 without application register coloring. ! Case/Switch Optimizing: Depending upon their number. Program code size is reduced at the expense of program speed.36 Chapter 4. Registers which are not altered in external functions can be used to hold register variables. ! NOAREGS: The C51 compiler no longer uses absolute register access. the PL/M-51 compiler. With the application wide register optimization. Program code created with this #pragma is compatible to earlier versions of the C51 compiler. Options for Code Generation ! OPTIMIZE(SIZE): Common C operations are replaced by subprograms. switch and case statements can be further optimized by using a jump table or string of jumps. the C compiler knows the registers used by external functions. The following sample program compares the code generated by C51 version 5. The code generated by the C compiler needs less data and code space and executes faster. Global Register Optimization The C51 compiler provides support for application wide register optimization which is also known as application register coloring. and location. In the following . sequence.0 using application register coloring to the code generated by C51 version 3. ! NOREGPARMS: Parameter passing is always performed in local data segments rather then dedicated registers. Program code is independent of the register bank. ! Access Optimizing: Constants and variables are computed and included directly in operations. ! Data Overlaying: Data and bit segments of functions are identified as OVERLAYABLE and are overlaid with other data and bit segments by the BL51 code banking linker/locator. 8051 Development Tools 8051-Specific Optimizations 4 ! Peephole Optimization: Complex operations are replaced by simplified operations when memory space or execution time can be saved as a result. and the ASM-51 assembler. ! OPTIMIZE(SPEED): Common C operations are expanded in-line. Program speed is increased at the expense of code size.

@DPTR A @DPTR. Without Global Register Optimization /* get number of values */ ?C0001: LCALL MOV MOV MOV input DPTR. ?C0001: LCALL input . variable names.8051/251 Evaluation Kit 37 example input and output are external functions. In addition. and so on to allow detailed and thorough debugging and analysis with dScope-51 or Intel compatible emulators.AR7 do { a = input (). the compiler can include all the necessary information such as. ?C0005: LCALL input . LCALL _output DJNZ R6. With Global Register Optimization main () { unsigned char i. line numbers.A /* output value */ LCALL _output /* decrement values */ MOV MOVX DEC MOVX JNZ DPTR. function names.R7 @DPTR. the OBJECTEXTEND control directive embeds additional variable type information in the object file which allows type-specific display of variables and structures when using certain emulators..A /* get input value */ ?C0005: LCALL MOV MOV MOVX input DPTR.#a A.'a' assigned to 'R7' MOV R5. while (1) { i = input ().'i' assigned to 'R6' MOV R6.#i A. Additionally. unsigned char a.AR7 output (a).A ?C0005 SJMP ?C0001 } } RET Code Size: 18 Bytes RET Code Size: 30 Bytes Debugging The C51 compiler uses the Intel Object Format (OMF51) for object files and generates complete symbol information..#i A. All Intel compatible emulators may be used for program debugging. which require only a few registers. You should check with your emulator vendor to determine if it is 4 .R7 @DPTR.?C0005 SJMP ?C0001 } while (--i).

Intrinsic Function Description _crol_ Rotate character left. _lrol_ Rotate long integer left. 4 Library File Description C51S. Source code is provided for library modules that perform hardware-related I/O and is found in the \C51\LIB directory. _irol_ Rotate integer left. Intrinsic Library Routines The libraries included with the compiler include a number of routines that are implemented as intrinsic functions. _cror_ Rotate character right. _lror_ Rotate long integer right.LIB Large model floating-point arithmetic library 80C751. 8051 Development Tools compatible with the Intel OMF51 object module format and if it can accept Keil object modules.LIB Small model floating-point arithmetic library C51C. Intrinsic functions generate in-line code (which is faster and more efficient) to perform the library routine.LIB Library for use with the Philips 8xC751 and derivatives. _nop_ No operation (8051 NOP instruction). _iror_ Rotate integer right.LIB Compact model library without floating-point arithmetic C51FPC.LIB Compact model floating-point arithmetic library C51L. You may use these source files to help you quickly adapt the library to perform I/O using any I/O device in your target.LIB Small model library without floating-point arithmetic C51FPS. _testbit_ Test and clear bit (8051 JBC instruction). .38 Chapter 4. Library Routines The C51 compiler includes seven different ANSI compile-time libraries which are optimized for various functional requirements.LIB Large model library without floating-point arithmetic C51FPL. Non-intrinsic functions generate ACALL or LCALL instructions to perform the library routine.

8051/251 Evaluation Kit 39 Listing File Example The C51 compiler produces a listing file that contains source code. an assembly listing. 4 . and a symbol table. directive information.

/* TMOD */ 13 1 TCON = 0x69. Error messages and warning messages are included in the listing file. SOURCE LINE # 20 0020 22 RET . SOURCE LINE # 11 0000 759852 MOV SCON. SOURCE LINE # 13 The CODE compiler option includes an assembly code listing in the listing file. 9 1 10 1 /* setup serial port hdw (2400 Baud @12 MHz) */ 11 1 SCON = 0x52.h> /* standard i/o definitions */ 3 #include <ctype. SOURCE LINE # 12 . SOURCE LINE # 17 . SOURCE LINE # 19 001D E4 001E F580 CLR MOV A P0. SOURCE LINE # 7 .R7 A.02. /* SCON */ 12 1 TMOD = 0x20. SAMPLE 07/01/95 08:00:00 PAGE 1 DOS C51 COMPILER V5.#020H 0006 758869 MOV TCON.EXE SAMPLE. /* TH1 */ 15 1 16 1 while ((c = getchar ()) != EOF) { 17 2 putchar (toupper (c)). Source line numbers are embedded within the generated code. ASSEMBLY LISTING OF GENERATED OBJECT CODE . 8051 Development Tools C51 COMPILER V5.#0F3H 000C 000F 0011 0012 0013 120000 8F00 EF F4 6008 E R LCALL MOV MOV CPL JZ getchar c.40 Chapter 4. FUNCTION main (END) MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 33 ---CONSTANT SIZE = ------XDATA SIZE = ------PDATA SIZE = ------DATA SIZE = ---1 IDATA SIZE = ------BIT SIZE = ------END OF MODULE INFORMATION. C51 COMPILATION COMPLETE.C CODE stmt level source 1 #include <reg51.#052H 0003 758920 MOV TMOD. FUNCTION main (BEGIN) .02. SOURCE LINE # 16 . /* clear Output Port to signal ready */ 20 1 } 4 The C51 compiler produces a listing file with page numbers as well as time and date of the compilation. 18 2 } 19 1 P0 = 0.OBJ COMPILER INVOKED BY: C:\C51\BIN\C51.h> /* SFR definitions for 8051 */ 2 #include <stdio. . COMPILATION OF MODULE SAMPLE OBJECT MODULE PLACED IN SAMPLE. 0 WARNING(S).A . /* TCON */ 14 1 TH1 = 0xF3.R7 A ?C0002 0015 120000 0018 120000 E E LCALL LCALL _toupper _putchar 001B 80EF 001D SJMP ?C0002: . 0 ERROR(S) The total number of errors and warnings is stated at the end of the listing file. The listing includes a line number for each statement and a nesting level for each block enclosed within curly braces (‘{‘ and ‘}’). SOURCE LINE # 18 ?C0001 . . SOURCE LINE # 14 .#069H 0009 758DF3 000C MOV ?C0001: TH1. A memory overview provides information about the 8051 memory areas that are used.h> /* defs for char conversion */ 4 5 #define EOT 0x1A /* Control+Z signals EOT */ 6 7 void main (void) { 8 1 unsigned char c. Remarks about the compiler invocation and object file output are displayed in this listing.

The listing file contains source code. It translates symbolic assembly language mnemonics into relocatable object code where the utmost speed. 8052. The macro facility speeds development and conserves maintenance time since common sequences need only be developed once. and hardware control are critical. In addition to the object file. the object file contains full symbolic information for debugging with dScope or an in-circuit emulator. 80152. 8051Fx. The A51 assembler supports symbolic access to all features of the 8051 architecture and is configurable for the numerous 8051 derivatives. 80C515A. 80515. the NOMOD51 control lets you override these definitions with processor-specific include files. The special function register (SFR) set of the 8051 is predefined. machine code generated. 8xC592. 8xCL781. 80451. You can easily create include files for other 8051 family members. small code size. 4 . directive information. Listing File Example The following example shows a listing file generated by the A51 assembler during assembly. Functional Overview The A51 assembler translates an assembler source file into a relocatable object module. 8x552. If the DEBUG control is used. 80C517. The A51 assembler is fully compatible with Intel ASM-51 source modules. and a symbol table. 8xCL410 and 80C320 microcontrollers. However. 80C517A. 8051GB. The A51 assembler is shipped with include files for the 8051.8051/251 Evaluation Kit 41 A51 Macro Assembler The A51 assembler is a macro assembler for the 8051 microcontroller family. the A51 assembler generates a list file which may optionally include symbol table and cross reference information. 80452. Configuration The A51 assembler supports all members of the 8051 family.

TXTBIT=1 read from XDATA END XREF SYMBOL TABLE LISTING ---. loop which displays a text on the console. . The listing file includes a line number for each source line. RSEG CONST TXT: DB 'TEST PROGRAM'. . . . The register banks used. . .0 REL=UNIT 9# 32 REL=UNIT 8# 27 EXT 4# 17 REL=UNIT 7# 15 EXT 4# 23 EXT 4# 24 SEG=PROG 22# 25 13# 2 SEG=PROG 13 17# SEG=CONST 22 28# SEG=BITVAR 5 5 21 33# SEG SEG ADDR SEG ADDR ADDR ADDR ADDR NUMB ADDR ADDR ADDR R A R R R REGISTER BANK(S) USED: 0 ASSEMBLY COMPLETE. . . . . .----. . . . . and the total number of warnings and errors is stated at the end of the listing file. INITSERIAL PROG .02 OBJECT MODULE PLACED IN SAMPLE. . START. . The position of each error is clearly marked. . . PUT_CRLF . . Error messages and warning messages are included in the listing file.Init Serial Interface . .00H RSEG TXTBIT: DBIT The A51 assembler produces a listing file with page numbers as well as the time and date of the assembly. TXTBIT=0 read from CODE . . . PUTSTRING. PROG InitSerial . Remarks about the assembler invocation and the object file output are displayed in this listing. The line number where the symbol is defined is marked with a pound symbol (‘#’). . PUTSTRING. The cross reference report shows all symbols and the line numbers in which they are used. . . . . . . .-----. CONST. TXTBIT .------N A M E BITVAR . . . . . SAMPLE . . ***** Start: CALL 0 Typical programs start with EXTERN. This is the main program. and SEGMENT directives. RESET. . . . It is an endless . 0 ERROR(S) The XREF assembler option produces a cross reference list. . .#TXT CALL PUTSTRING CALL PUT_CRLF SJMP Repeat . read from CODE Repeat: MOV DPTR. CLR TXTBIT .EXE SAMPLE. T Y P E V A L U E ATTRIBUTES / REFERENCES B C C C C C C C N C C B 0001H 000DH ----0010H --------0005H 0000H ----0000H 0000H 0000H.A51 XREF LOC ---0000 ---0000 4 0003 0005 0008 000B 000E ---0000 0004 0008 000C ---0000 OBJ LINE 1 2 3 4 5 6 7 8 9 10 11 12 020000 F 13 14 15 16 120000 F 17 18 19 20 C200 F 21 900000 F 22 120000 F 23 120000 F 24 80F5 25 26 27 54455354 28 2050524F 4752414D 00 29 30 31 32 33 34 35 SOURCE $TITLE ('Test Program') NAME SAMPLE EXTRN CODE (PUT_CRLF. the HEX values are displayed at the beginning of the line. PUBLIC. . .42 Chapter 4. . REPEAT . . . . . . 0 WARNING(S). . . . TXT.OBJ ASSEMBLER INVOKED BY: C:\C51\BIN\A51. BITVAR 1 If a source line generates code. . InitSerial) PUBLIC TXTBIT PROG CONST BITVAR Reset: SEGMENT SEGMENT SEGMENT CODE CODE BIT CSEG AT JMP Start RSEG . . . . . . . 8051 Development Tools A51 MACRO ASSEMBLER Test Program 07/01/95 08:00:00 PAGE 1 DOS MACRO ASSEMBLER A51 V5. . . . . . .

The default controls for the BL51 code banking linker/locator have been carefully chosen to accommodate most applications without the need to specify additional directives. However. You may use the OVERLAY directive to manually control functions references the linker uses to determine exclusive memory areas. The linker automatically selects the appropriate run-time library and links only the library modules that are required. This greatly reduces the overall memory requirement of most 8051 applications. This process is known as bank switching. The NOOVERLAY directive lets you completely disable memory overlaying. These directives are useful when using indirectly called functions or when disabling overlaying for debugging. Normally. and assigns absolute addresses to relocatable programs segments. there must be external hardware that swaps code banks. The BL51 code banking linker/locator processes object modules created by the Keil C51 compiler and A51 assembler and the Intel PL/M-51 compiler and ASM-51 assembler. The linker also resolves external and public references. The BL51 code banking linker/locator analyzes the references between functions to carry out memory overlaying. The hardware that does this must be controlled by software running on the 8051. Code Banking The BL51 code banking linker/locator supports the ability to create application programs that are larger than 64 Kbytes. it is easy for you to specify custom settings for your application. Data Address Management The BL51 code banking linker/locator manages the limited internal memory of the 8051 by overlaying variables for functions that are mutually exclusive.8051/251 Evaluation Kit 43 BL51 Code Banking Linker/Locator The BL51 code banking linker/locator combines one or more object modules into a single executable 8051 program. 4 . you invoke the BL51 code banking linker/locator from the command line specifying the names of the object modules to combine. Since the 8051 does not directly support more than 64 Kbytes of code address space.

By default. ! Code Constants. By carefully grouping functions in the different banks. ! C51 Interrupt Functions. and returns execution to the calling routine. The bank switching process requires approximately 50 CPU cycles and consumes an additional 2 bytes of stack space. The BL51 code banking linker/locator generates a jump table for functions in other code banks. It may also contain frequently used code. . When your C program calls a function located in a different bank.44 Chapter 4. jumps to the desired function. Common Area 4 The common area in a bank switching program is an area of memory that can be accessed at all times from all banks. The BL51 code banking linker/locator lets you specify the bank in which to locate a particular program module. Executing Functions in Other Banks Code banks are selected by additional software-controlled address lines that are simulated using 8051 port I/O lines or a memory-mapped latch. ! Bank Switch Jump Table. you can create very large. You can dramatically improve system performance by grouping interdependent functions in the same bank. it switches the bank. 8051 Development Tools The BL51 code banking linker/locator lets you manage 1 common area and 32 banks of up to 64 Kbytes each for a total of 2 Mbytes of bank-switched 8051 program space. The common area contains program sections and constants which must be available at all times. The common area cannot be physically swapped out or moved around. The code in the common area is either duplicated in each bank (if the entire program area is swapped) or can be located in a separate area or EPROM (if the common area is not swapped). restores the previous bank (when the function completes). Software support for the external bank switching hardware includes a short assembly file you can edit for your specific hardware platform. ! Some C51 Run-Time Library Functions. the following code sections are automatically located in the common area: ! Reset and Interrupt Vectors. efficient applications.

0 0000H.7 IDATA 0021H 0001H UNIT * * * * * * * "REG BANK 0" ?DT?GETCHAR _DATA_GROUP_ *** GAP *** ?BI?GETCHAR *** GAP *** ?STACK * * * * * * * CODE 0000H CODE 0003H CODE 0024H CODE 0030H CODE 0057H CODE 0068H CODE 0080H * * * * * * * C O D E 0003H 0021H 000CH 0027H 0011H 0018H 000AH OVERLAY MAP OF MODULE: M E M O R Y ABSOLUTE UNIT UNIT UNIT UNIT UNIT UNIT The link-map contains a table of the memory usage of the physical 8051 memory area. Listing File Example The following example shows a map file created by the BL51 code banking linker/locator: BL51 BANKED LINKER/LOCATER V3.52.OBJ (SAMPLE) C:\C51\LIB\C51S.1 UNIT 0020H.LIB (GETCHAR) C:\C51\LIB\C51S. 4 SAMPLE (SAMPLE) TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------* * * * * * * D A T A M E M O R Y REG 0000H 0008H ABSOLUTE DATA 0008H 0001H UNIT DATA 0009H 0001H UNIT 000AH 0016H BIT 0020H.LIB (_GETKEY) LINK MAP OF MODULE: The BL51 code banking linker/locator produces a map file with the time and date of the link/locate run. ?PR?MAIN?SAMPLE ?C_C51STARTUP ?PR?PUTCHAR?PUTCHAR ?PR?GETCHAR?GETCHAR ?PR?_TOUPPER?TOUPPER ?PR?_GETKEY?_GETKEY SAMPLE (SAMPLE) SEGMENT DATA_GROUP +--> CALLED SEGMENT START LENGTH ---------------------------------------------?C_C51STARTUP --------+--> ?PR?MAIN?SAMPLE ?PR?MAIN?SAMPLE +--> ?PR?GETCHAR?GETCHAR +--> ?PR?_TOUPPER?TOUPPER +--> ?PR?PUTCHAR?PUTCHAR 0009H 0001H ?PR?GETCHAR?GETCHAR +--> ?PR?_GETKEY?_GETKEY +--> ?PR?PUTCHAR?PUTCHAR ----- ----- LINK/LOCATE RUN COMPLETE.8051/251 Evaluation Kit 45 Functions which are frequently invoked from multiple banks should be located in the common area. Error messages and warnings are listed at the end of the map file. These messages .OBJ MEMORY MODEL: SMALL The invocation line and the selected memory module are listed. INVOKED BY: C:\C51\BIN\BL51.52 07/01/95 08:00:00 PAGE 1 MS-DOS BL51 BANKED LINKER/LOCATER V3.LIB (TOUPPER) C:\C51\LIB\C51S.LIB (?C_STARTUP) C:\C51\LIB\C51S.1 0000H.EXE SAMPLE. 0 WARNING(S). 0 ERROR(S) The overlay-map displays the structure of the program and the location of the bit and data segments of each function. INPUT MODULES INCLUDED: SAMPLE.LIB (PUTCHAR) C:\C51\LIB\C51S.

4 . 8051 Development Tools indicate possible problems during the link/locate run.46 Chapter 4.

A library file is a formatted collection of one or more object files. Banked object modules are created by the BL51 code banking linker/locator when you create a bank switching application. You may use the OC51 banked object file converter to create absolute object modules for the command area and for each code bank in your banked object module. dScope-51 is a software-only product that lets you simulate 4 . OH51 Object-Hex Converter The OH51 object-hex converter creates Intel HEX files from absolute object modules. The LIB51 library manager may be controlled interactively or from the command line. They can be easily loaded into a device programmer for writing EPROMS. The LIB51 library manager lets you create a library file. You may then generate Intel HEX files for each of the absolute object modules using the OH51 object-hex converter.8051/251 Evaluation Kit 47 OC51 Banked Object File Converter The OC51 banked object file converter creates absolute object modules for each code bank in a banked object module. and list the contents of a library file. Libraries can be effectively used by the BL51 code banking linker/locator. remove object modules from a library file. LIB51 Library Manager The LIB51 library manager lets you create and maintain library files. dScope-51 for Windows dScope-51 is a source level debugger and simulator for programs created with the Keil C51 compiler and A51 assembler and the Intel PL/M-51 compiler and ASM-51 assembler. Intel HEX files are ASCII files that contain a hexadecimal representation of your application. add object modules to a library file. Absolute object modules can be created by the BL51 code banking linker or by the OC51 banked object file converter. Library files provide a convenient method of combining and referencing a large number of object files. Symbolic debugging information is copied to the absolute object files and can be used by dScope or an in-circuit emulator.

4 µVision/51 for Windows µVision/51 is an integrated software development platform that includes a full-function editor.48 Chapter 4. The only differences are the support for either 8051 or 251 development tools. µVision is used throughout this book to refer to either IDE. dScope-51 simulates a wide variety of 8051 peripherals including the internal serial port. and environment control for the Keil 8051 tools. project manager. ! Project manager for creating and maintaining projects. external I/O. ! Full-function editor with user-definable key sequences. ! Multiple file editing capability. Refer to “µVision IDE Overview” on page 64 for examples that show how to use µVision/51. make facility. dScope is used throughout this book to refer to either debugger. 8051 Development Tools the features of an 8051 without actually having target hardware. The only differences are the support for either 8051 or 251 development tools. Refer to “dScope Simulator/Debugger Overview” on page 70 for examples that show how to use dScope-51. and timers. ! Dialog boxes for all environment and development tool settings. NOTE µVision/51 and µVision/251 are essentially the same product. ! Integrated make facility for building target programs from your projects. NOTE dScope-51 and dScope-251 are essentially the same product. ! On-line help system. You may use dScope-51 to test and debug your embedded application before actual 8051 hardware is ready. you no longer have to learn the command-line syntax of any of the tools. µVision/51 speeds your embedded application development by providing the following: ! Standard Windows user interface. When you use µVision/51. ! Application manager for adding external programs into the pull-down menu. .

8051/251 Evaluation Kit 49 4 .

50 4 Chapter 4. 8051 Development Tools .

8051/251 Evaluation Kit 51 Chapter 5. ! Direct addressing mode for 64KB. Intel has developed the new MCS® 251 microcontroller family. Intel’s first derivative. By design. We have designed our development tools to help you quickly and successfully complete your job. MCS® 251 Microcontroller Family In response to demands for more power and capability. the 251 offers configuration options for binary mode (8051 compatible instruction set) or source mode (251 instruction set). C applications that are recompiled with Keil C251 can execute up to 15 times faster. The 251 is completely backwards compatible with the 8051. ! 8-bit. For this reason. The following are a few highlights of the 251: ! 8-bit. 251 Development Tools This chapter discusses the features and advantages of the 8051 and MCS® 251 microprocessor family and the development tools available from Keil Software. All of your existing 8051 software can run on the new 251 CPU. page or non-page mode. and wait state generation. our tools are easy to use and are guaranteed to help you achieve your design goals. In addition to these features. ! Direct support for 16-bit and 32-bit pointers. the 80C251SB. At an equivalent clock speed. existing 8051 code executes up to 5 times faster on the 251. is a direct pin-for-pin replacement for the 80C51FX. Your existing 8051 software can achieve dramatic performance increases by using the features found in the 251 instruction set. and 32-bit instructions. 5 . 16-bit. 16-bit. and 32-bit registers. ! 16 Mbyte linear address space. the 251 is a powerful 8-bit/16-bit CPU. ! 16-bit stack & stack addressing.

C251 Optimizing C Cross Compiler The Keil C251 Compiler is a dedicated ANSI C compiler designed explicitly for the MCS® 251 microcontroller family.52 Chapter 5. refer to “Chapter 3. ! L251 Linker/Locator (see page 59). 5 NOTE All of our 251 tools utilize the Intel OMF251 object module format. 8051/251 Product Line” on page 13. . Additionally. 251 Development Tools 251 Development Tools Keil Software provides the following development tools for the 251: ! C251 Optimizing C Compiler (see below). ! dScope-251 for Windows (see page 60). The C251 compiler is an extended ANSI C compiler which allows full access to all resources in a 251 microcontroller system. ! A251 Macro Assembler (see page 55). You may re-compile your existing C51 code with the C251 compiler. ! µVision/251 for Windows (see page 61). For information on the products which include these tools. ! LIB251 Library Manager (see page 60). ! OH251 Object HEX Converter (see page 60). the L251 linker/locator can combine OMF251 and OMF51 object modules.

pdata Paged XDATA memory (256 bytes). ebit Extended bit-addressable RAM. access with MOVX @Ri. idata Indirect memory addressing for on-chip RAM (256 bytes). mixed bit and byte accesses (16 bytes). xdata XDATA memory (64 Kbytes). Each variable can be explicitly located anywhere in the 251 address space. In addition. access with MOVC. code CODE memory (64 Kbytes). mixed bit and byte accesses. all addressing modes of the 8051 are fully supported by the 251. object size < 64 Kbytes. Data Type Bits bit 1 signed char 8 1 -128 to +127 unsigned char 8 1 0 to 255 signed int 16 2 -32768 to +32767 unsigned int 16 2 0 to 65535 signed long 32 4 -2147483648 to +2147483647 unsigned long 32 4 0 to 4294967295 float 32 4 ±1. or 4 Object address pointer Bytes Value Range 0 or 1 sbit 1 0 or 1 sfr 8 1 0 to 255 sfr16 16 2 0 to 65535 Memory Selector The C251 compiler provides full support for the 251 architecture and can access all system components. fast 8-bit accesses.175494E-38 to ±3.7E-308 to ±1. huge 16 Mbyte indirect memory addressing.402823E+38 double 64 8 ±1. access with MOV @Ri. 2. ebdata. Selector 251 Address Space near 64 Kbyte direct and indirect memory addressing. far 16 Mbyte indirect memory addressing. access with MOVX @DPTR. any object size.8051/251 Evaluation Kit 53 Data Types The C251 compiler supports the following data types. data Direct memory addressing for on-chip RAM (128 bytes).7E+308 1. 5 . 3. bdata Bit-addressable RAM. The linear 16 Mbyte address space can be accessed with many addressing modes.

ROM Directive JMP Instruction CALL Instruction SMALL AJMP ACALL COMPACT AJMP LCALL LARGE LJMP LCALL HUGE LJMP ECALL . 8) directs the C251 compiler to locate global variables 2 bytes in size or smaller in data memory.C HOLD (2. 5 Memory Model Parameters & Automatic Variables Global Variables Constant Variables Pointer Definition Pointer Size TINY data data near near * 2 bytes SMALL data data near far * 3 / 4 bytes COMPACT pdata pdata near far * 3 / 4bytes MEDIUM near near far far * 3 / 4 bytes LARGE xdata xdata near far * 3 / 4 bytes Program Size The MCS® 251 microcontroller family allows program sizes up to 16 Mbytes. the following command line: C251 PROG. 251 Development Tools Memory Models The memory model determines the default memory selector used for automatic variables and parameter passing areas. With the HOLD directive you can specify additional memory selectors for small objects. for example. The following table lists the memory areas used for each memory model.54 Chapter 5. The generated 251 code can be optimized by using specific JMP and CALL instructions. The ROM directive lets you choose the combination of JMP and CALL instructions that is used. 4. variables 3 or 4 bytes in size in near memory. and variables 5 to 8 bytes in size in xdata memory.

5 . the C251 compiler knows the registers used by each function in an application. Any registers modified during function execution are noted within each module. Source code for I/O and memory allocation functions is also included. Additional parameters are passed via fixed memory locations or the 251’s hardware stack. and a symbol table.8051/251 Evaluation Kit 55 Register Optimization Depending on the program context. This permits the C251 compiler to support fast reentrant functions. C Run-Time Library The run-time libraries provided with the C251 compiler contain over 100 routines. the C251 compiler allocates up to 24 CPU registers for register variables. the C251 compiler can optimize the overall CPU register allocation of those functions. The #pragma reentrant and #pragma noreentrant preprocessor directives control code generation. Reentrant Code The 251 supports stack-based variable addressing. Data overlaying considerably reduces the memory requirements in C applications of this type. With this information. Non-reentrant code stores variables in directly addressable memory locations and yields the fastest program execution. an assembly listing. directive information. Registers R0-R7 are used for parameter passing. This technique yields very efficient code that compares favorably to assembly programming. Consequently. project-wide register file which contains information about the registers altered by external functions. all of which are reentrant. The linker/locator generates a global. Listing File Example The C251 compiler produces a listing file that contains source code.

.result DR0. C251 COMPILATION COMPLETE. power--) result *= num. } The listing includes a line number for each statement and a nesting level for each block enclosed within curly braces (‘{‘ and ‘}’).C CODE stmt level source 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <reg251sb. for (result = 1.56 Chapter 5.num ?C?LMUL result. Source line numbers are embedded within the generated code.power ?C0002 001A 001E 0022 0025 A57E1D00 A57E0D00 120000 A57A1D00 R R E R MOV MOV LCALL MOV DR4. COMPILATION OF MODULE SAMPLE OBJECT MODULE PLACED IN SAMPLE. A memory overview provides information about the 251 memory areas that are used.power+01H A. ASSEMBLY LISTING OF GENERATED OBJECT CODE .00.00. SAMPLE 07/01/95 08:00:00 PAGE 1 DOS C251 COMPILER V1. unsigned long result. SOURCE LINE # 13 0033 A57E1D00 R . 251 Development Tools C251 COMPILER V1. power != 0.WR10 MOV ORL JZ A. SOURCE LINE # 10 .h> /* SFRs for the 251SB CPU */ unsigned long outsqr ( unsigned long num.result The CODE compiler option includes an assembly code listing in the listing file. SOURCE LINE # 14 0037 0037 22 ?C0004: RET . SOURCE LINE # 11 R ?C0005: 80E1 ?C0002: . } { return (result). Remarks about the compiler invocation and object file output are displayed in this listing.DR4 .WR10 result.EXE SAMPLE.#01H result+02H. SOURCE LINE # 3 .power+01H power+01H ?C0005 power SJMP ?C0001 MOV DR4.DR4 0029 002B 002D 002F 0031 0031 0033 E500 1500 7002 1500 R R MOV DEC JNZ DEC A. SOURCE LINE # 5 .WR10 WR10. SOURCE LINE # 9 5 0004 0007 000B 0010 0014 0014 0016 0018 A56D55 A57A5500 R A57E540001 A57A5500 R ?C0001: E500 R 4500 R 6019 XRL MOV MOV MOV WR10. FUNCTION OUTSQR (BEGIN) 0000 A57A1D00 R MOV num. 0 ERROR(S) The total number of errors . Error messages and warning messages are included in the listing file. unsigned power) { 1 1 1 1 2 2 1 1 1 The C251 compiler produces a listing file with page numbers as well as time and date of the compilation. 0 WARNING(S). FUNCTION OUTSQR (END) MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 56 ---CONSTANT SIZE = ------XDATA SIZE = ------PDATA SIZE = ------DATA SIZE = ---10 IDATA SIZE = ------BIT SIZE = ------EDATA SIZE = ------FDATA SIZE = ------END OF MODULE INFORMATION.OBJ COMPILER INVOKED BY: C:\C251\BIN\C251.

5 .8051/251 Evaluation Kit and warnings is stated at 57 the end of the listing file.

251 Development Tools A251 Macro Assembler The A251 assembler is a macro assembler for the 251 family which supports both the Intel Macro Programming Language (MPL) and Microsoft style macros. and a symbol table. machine code generated. The listing file includes a line number for each source line. Typical programs start with EXTERN. object files contain full symbolic information for debugging with dScope or an in-circuit emulator. If the DEBUG control is used.58 Chapter 5. ***** Start: CALL CODE CODE BIT 0 PROG InitSerial .EXE SAMPLE.OBJ ASSEMBLER INVOKED BY: C:\C251BIN\A251. A251 MACRO ASSEMBLER Test Program 07/01/95 08:00:00 PAGE 1 DOS MACRO ASSEMBLER A251 V1. and SEGMENT directives. Functional Overview The A251 assembler translates 251 assembly source file into relocatable object modules. The listing file contains source code.A51 LOC OBJ ---------------000000 000000 020000 -----000000 120000 LINE SOURCE 1 2 3 4 5 6 7 8 9 10 11 12 13 F 14 15 16 17 E 18 19 $TITLE ('Test Program') $MODSRC NAME SAMPLE EXTRN PUBLIC CODE (PUT_CRLF. directive information.00 OBJECT MODULE PLACED IN SAMPLE. 5 Listing File Example The following example shows a listing file generated by the A251 assembler during assembly. The A251 assembler translates symbolic assembly mnemonics into executable machine code. PUBLIC. you can easily re-assemble source code written for the Keil A51 assembler or the Intel ASM-51 assembler. The A251 assembler also generates a list file which may include symbol table and cross reference listings.Init Serial Interface The A251 assembler produces a listing file with page numbers as well as the time and date of the assembly. InitSerial) TXTBIT PROG SEGMENT STRINGS SEGMENT BITVAR SEGMENT Reset: CSEG AT JMP Start RSEG . . Remarks about the assembler invocation and the object file output are displayed in this listing. With the A251 assembler. PUTSTRING.

. . . address. PUT_CRLF . the object type. The symbol table listing includes names of data objects. . TXT. loop which displays a text on the console. REPEAT . and assigns absolute addresses to relocatable programs segments. START. . RSEG STRINGS TXT: DB 'TEST PROGRAM'. . CLR TXTBIT . read from CODE Repeat: MOV DPTR. . . . . . SAMPLE . . It is an endless . The L251 linker/locator combines one or more object modules into a single executable 251 program. . . . . . . RESET. .0 REL=UNIT. . The L251 linker lets you combine object modules created by our 251 tools with object modules created with our 8051 tools. . . . and the total number of warnings and errors is stated at the end of the listing file. INITSERIAL PROG . . .----. .0 59 . . . . . ALN=BYTE EXT EXT SEG=PROG SEG=?CO?SAMPLE?4 SEG ADDR SEG ADDR ADDR ADDR ADDR ---ADDR SEG ADDR ADDR R R R R R SEG=PROG REL=UNIT. . . .00H RSEG TXTBIT: DBIT BITVAR . . TXTBIT . and A251 assembler and also processes object modules created by the Intel PL/M-51 compiler and ASM-51 assembler. . The linker also resolves external and public references. . The position of each error is clearly marked. ALN=BYTE SEG=STRINGS SEG=BITVAR REGISTER BANK(S) USED: 0 ASSEMBLY COMPLETE. . the HEX values are displayed at the beginning of the line. . . . TXTBIT=0 read from CODE 1 . ALN=BIT EXT REL=UNIT. . . Error messages and warning messages are included in the listing file. . STRINGS. . L251 Code Banking Linker/Locator The L251 linker/locator is a code banking linker for our 251-based tools. .------N A M E BITVAR . T Y P E V A L U E ATTRIBUTES B C C C C C C -C C C B 000001H ------000010H ------------0005H 0000H ------0000H 00000DH 0000H 0000H. . A51 assembler. . . . . . The L251 linker/locator processes object modules created by the Keil C51 compiler.#TXT CALL PUTSTRING CALL PUT_CRLF SJMP Repeat . END SYMBOL TABLE LISTING -----. The linker automatically selects the appropriate run-time library and links only the library modules that are required. . . . . This is the main program. . . . . TXTBIT=1 read from XDATA If a source line generates code. . . . C251 compiler. PUTSTRING.8051/251 Evaluation Kit 000003 000005 000008 00000B 00000E C200 900000 120000 120000 8000 F F E E F -----000000 000004 000008 00000C 54455354 2050524F 4752414D 00 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 -----0000. 0 ERROR(S) 5 The register banks used. . and other attributes. 0 WARNING(S).

Intel HEX files are ASCII files that contain a hexadecimal representation of your application. However. Absolute object modules are typically created by the L251 linker/locator. Libraries can be effectively used by the L251 linker/locator. OH251 Object-Hex Converter The OH251 object-hex converter creates Intel HEX files from OMF251 absolute object modules. 251 Development Tools Normally. dScope-251 simulates all peripherals of the 251 including the 16 Mbyte address space.60 Chapter 5. . A library file is a formatted collection of one or more object files. remove object modules from a library file. Library files provide a convenient method of combining and referencing a large number of object files. The LIB251 library manager may be controlled interactively or from the command line. The LIB251 library manager lets you create a library file. They can be easily loaded into a device programmer for writing EPROMS. You may use dScope-251 to test and debug your embedded application before actual 251 hardware is ready. The default command-line directives for the linker have been chosen to accommodate most applications without the need to specify additional directives. and list the contents of a library file. you invoke the linker from the command line specifying the names of the object modules to combine. dScope-251 is a software-only product that lets you simulate the features of the 251 without actually having target hardware. it is easy for you to specify custom settings for your application. add object modules to a library file. dScope-251 for Windows dScope-251 is a source level debugger and simulator for programs created with the Keil C251 compiler and A251 assembler. LIB251 Library Manager 5 The LIB251 library manager lets you create and maintain library files.

make facility. Refer to “dScope Simulator/Debugger Overview” on page 70 for examples that show how to use dScope-251. ! Full-function editor with user-definable key sequences. Refer to “µVision IDE Overview” on page 64 for examples that show how to use µVision/251. ! Integrated make facility for building target programs from your projects. 5 . µVision/251 for Windows µVision/251 is an integrated software development platform that includes a full-function editor. The only differences are the support for either 8051 or 251 development tools. µVision is used throughout this book to refer to either IDE. ! Application manager for adding external programs into the pull-down menu. µVision/251 speeds your embedded application development by providing the following: ! Standard Windows user interface. The only differences are the support for either 8051 or 251 development tools. NOTE µVision/51 and µVision/251 are essentially the same product. project manager. ! On-line help system. and environment control for the Keil 251 tools. ! Dialog boxes for all environment and development tool settings. dScope is used throughout this book to refer to either debugger. ! Multiple file editing capability.8051/251 Evaluation Kit 61 NOTE dScope-51 and dScope-251 are essentially the same product. ! Project manager for creating and maintaining projects.

.

Refer to the “Eval Kit Notes” for more information on the limitations of the evaluation tools.8051/251 Evaluation Kit 63 Chapter 6. 8051/251 Product Line” on page 13 for a description of the kits that are available. These are the same tools distributed with our 8051/251 Evaluation Kit. ! dScope simulator/debugger overview. ! µVision integrated development environment overview. The following sections are included in this chapter: ! Starting µVision and dScope. NOTE The 8051/251 Evaluation Kit includes evaluation versions of our 8051/251 tools. This chapter introduces the primary user-interface products. ! Sample programs. 6 . we provide an evaluation diskette with sample programs and limited versions of our tools. and shows you how to use them to compile. you need to purchase one of our development kits. ! Building the BADCODE sample program. Using the 8051/251 tools To make it easy for you to evaluate and become familiar with our 8051 and 251 product line. Contact sales/support if you would like a copy of our DOS-based evaluation kit. and run the provided sample programs. link. Refer to “Chapter 3. The examples and descriptions in this chapter are illustrated using our Windows-based tools. The sample programs are also included with our standard product kits. The evaluation tools are limited in functionality and the code size of the application you can create. µVision and dScope. For larger applications. ! Building and running the MEASURE sample program. ! Building and running the HELLO sample program.

! Application manager for linking external program files into the pull-down menu. project manager. You launch them by double-clicking on the appropriate icon in the program group created by the installation program.64 Chapter 6. Using the 8051/251 tools Starting µVision and dScope Both µVision for Windows and dScope for Windows are standard Windows applications. 251. ! Dialog boxes for all environment and development tool settings. and linking your embedded applications. 6 µVision IDE Overview µVision is an integrated software development platform that combines a robust editor. and make facility. ! Integrated make facility for assembling. µVision helps expedite the development process of your embedded applications by providing the following: ! Full-function editor with user-definable key sequences. µVision supports all of the Keil tools for the 8051. and 166. . compiling. ! Project manager for creating and maintaining your projects.

8051/251 Evaluation Kit 65 About the Environment In µVision. You may also use the keyboard to enter program text. you may use the keyboard or the mouse to select menu commands. settings. Menu bar Tool bar Source window Vertical scroll bar 6 Status bar Horizontal scroll bar . and one or more windows for source files. dialog boxes. and information displays. The µVision screen provides you with a menu bar for command entry. and options for the development tools. a tool bar where you can rapidly select command buttons.

you can refer to header file information in another window.66 Chapter 6. You can move and resize source windows using the mouse or keyboard. Using the 8051/251 tools You can quickly access many of the features of µVision using the buttons on the tool bar. 6 . While writing part of your C program in one window. Print Tile horizontally Save Tile vertically Open Color syntax highlighting New file Find Repeat find Compile Update Show occurrences Help Paste text Copy selected text Cut selected text Build all µVision lets you simultaneously open and view multiple source files.

You can change key assignments for almost all editor functions. you control the µVision operations. You may use either the mouse or the keyboard to access commands from the menu bar. The following table lists a few of the editor functions that are available: Beginning of File Beginning of Line Beginning of Page Cascade Windows Close File Copy to Clipboard Cursor Down Cursor Left Cursor Right Cursor Up Cut to Clipboard Delete Delete Line Delete to End of Line Destructive Backspace End of File End of Line End of Page Exclusive Mark Forward Quick Search Forward Replace Full Search Insert Template Mark Block Mark Columns Mark Lines Move/Resize Window New File Next Error Open File Page Down Page Up Paste from Clipboard Previous Error Previous Window Print File Repeat Last Search Reverse Quick Search Undo Word Left Word Right Menu Commands Through pull-down menus on the menu bar and editor commands.8051/251 Evaluation Kit 67 Editor µVision’s built-in editor can be customized to emulate many popular text editors. 6 .

Using the 8051/251 tools The menu bar provides you with access to menus for file operations. This means that a project includes a large collection of individual files. as well as the exact sequence of operations required to build the target.68 Chapter 6. Development Tool Options µVision lets you set options for software development tools such as the C51 compiler and A51 assembler. use the make commands from the Project menu to compile source files . including file nesting. and on-line help. The project manager can easily handle file-to-file dependencies. The project manager gives you a method of creating and maintaining a project so that the target program is always up-to-date. project maintenance. development tool option settings. Use the project manager dialog box to define the source files that make up the project. µVision includes a project manager facility. 6 Project Manager Most embedded programs are composed of several source files. and some files may require custom translation in order to create a target program. Some files may require compilation with the C51 compiler. To accommodate the intricacies of project maintenance. external program execution (such as running the dScope debugger/simulator or another program). Simply select the appropriate item from the Options menu and use the mouse or the keyboard to change the options. editor operations. window selection and manipulation. some files may require assembly.

6 . the debugger and simulator options. and the make facility options. and debug your application. then. The project file includes: the source files that make up the target program. test. assembler. and linker command line options. use the simulator and emulator commands from the Run menu to execute. All aspects of a project are saved in a project file. the compiler.8051/251 Evaluation Kit 69 and to generate the target.

and timers.70 Chapter 6. Support for the various microcontroller derivatives is provided through the use of dynamic link libraries (DLLs). In addition. external I/O. dScope is a software-only product that simulates most of the features of 8051 and 251 microcontrollers without actually having target hardware. You can use dScope to test and debug your embedded application before the hardware is ready. Using the 8051/251 tools dScope Simulator/Debugger Overview dScope is a source level debugger/simulator for the entire Keil Software product line. dScope interfaces directly to the 8051 and 251 monitor programs and to several popular emulators. In addition to simulating the CPU. Menu bar Tool bar 6 Register window Debug window Command window Serial window . You can use dScope to debug the applications you develop using the C51 and C251 compilers and A51 and A251 assemblers. dScope lets you debug application written using the Intel PL/M-51 compiler and the ASM-51 assembler. dScope simulates a wide variety of 8051 and 251 peripherals including the serial port.

and select debugging options.DLL Keil Software 8051 Target Monitor MON251. 80C520. provides you with a menu bar for command entry. and 80C530 8051. 8051. and commands. CPU Driver DLLs Supported Derivatives 80251S.DLL Intel 82930 USB MON51.DLL Dallas Semiconductor 80C320. a tool bar where you can rapidly select command buttons. you must select the appropriate CPU driver from the CPU driver drop-down box on the tool bar.and 80C51 6 . Call stack window Code coverage window Toolbox window CPU driver Open object file Reset Help Command window Symbol browser window Debug window Memory window Register window Performance analyzer window Serial window Watch window CPU Simulation dScope simulates virtually every derivative of the 8051 and 251 microcontrollers. serial I/O. You can quickly display and hide the windows shown above with the buttons on the tool bar.DLL Intel Reduced Instruction Set Monitor (RISM) for the 251 80320. The following CPU drivers are included with dScope. Support for each CPU is provided through the use of DLLs. and several windows for displaying registers.DLL Intel 80C251SA.DLL Keil Software 251 Target Monitor RISM251. memory contents. The dScope screen.DLL 8031.8051/251 Evaluation Kit 71 About the Debugger In dScope. You may also select the Load CPU driver command from the File menu. 80C251SB. 80C31. you may use the keyboard or the mouse to select menu commands. 80C251SQ. Before you load your target application. and 80C251SP 82930. step through your application. pictured above.

and 80C52 80552.DLL 80C517 and 80C537 80517A. or code execution access. 8xC751. dScope also provides support for the integrated peripherals of the various 8051 and 251 derivatives. 8051FB.DLL 8xC552 80751.DLL 8032.DLL 8xCL410 80781. and 8051FC 8052.DLL 8xC750. and 8xC752 80410.DLL 80C515A and 80C535A 80517. The CPU’s on-chip peripherals are supported by the CPU driver in the DLL. You can also change the aspects of each peripheral using the controls in the dialog boxes.DLL 80C515 and 80C535 80515A.DLL 8051FA. . dScope traps and reports illegal memory accesses. 6 You can select and display the on-chip peripheral components using the Peripherals menu.DLL 8xCL781 dScope simulates up to 16 Mbytes of memory from which areas can be mapped for read. 8052.72 Chapter 6. write. Using the 8051/251 tools CPU Driver DLLs Supported Derivatives 80515.DLL 80C517A and 80C537A 8051FX. 80C32. In addition to memory mapping.

In addition to target program. or you can use the Load object file command from the File menu. ! View Assembly. This display format shows your original source text mixed with the assembly code generated by the compiler or assembler. assembly. You can use the button on the tool bar to open your object file. or PL/M-51 source text. To enable the trace history. This display format shows only the assembly code generated for your source. They are: ! View High Level. Three display formats are available from the Command menu in the debug window. 6 . select the Record Trace command from the Command menu in the debug window.8051/251 Evaluation Kit 73 The Debug Window After you have loaded the appropriate CPU driver. ! View Mixed. the debug window can display a trace history of up to 512 previously executed instructions. This display format shows your original source text exactly as it appears in your source files. the dScope debug window displays your C. Once your application is loaded. you are ready to load your target program.

You are not limited to using the command window to control dScope. . Using the 8051/251 tools Command Window You interact with dScope by entering commands from the keyboard and selecting options with the mouse. R7 = 12 Assign the value 12 to register R7.hour Displays the hour member of the time structure. You can also use the mouse to select pull-down menus from the menu bar and invoke commands from the tool bar. and memory locations from the command window. You can interactively display and change variables. you can type the following text commands at the command prompt: 6 Text Effect DPTR Display the DPTR register.74 Chapter 6. time.hour++ Increments the hour member of the time structure. time. dScope responds to the commands you enter at the command prompt (‘>’). You can also enter assembly code to patch or test parts of your program. index = 0 Assigns the value 0 to index. registers. For example. You can enter nearly all dScope commands in the command window.

Not only can you watch the variables in your program. This lets you simulate the CPU’s UART without the need for external hardware. Watch Window You can use the watch window to interactively display variables and complex structures. you can also change them using standard C expressions you enter at the command prompt in the command window.8051/251 Evaluation Kit 75 Serial Window dScope provides a serial window for serial input and output. Serial data output from the simulated CPU is displayed in this window. This is useful when you want to see the effects or your program on a buffer or data structure. 6 . Characters you type in this window are input to the simulated CPU.

The following statistics are maintained for each function or program block: ! min time Minimum time spent in the function or block. You may select a function to view statistics in the bottom portion of the performance analyzer window. . ! total time Total time spent in the function or block. ! avg time Average amount time spent in the function or block.76 Chapter 6. Performance analysis results are displayed in the performance analyzer window. Using the 8051/251 tools Performance Analyzer Window dScope has a built-in performance analyzer that lets you record timing statistics for functions and program blocks. ! max time Maximum time spent in the function or block. 6 The performance analyzer window shows the name of each function or memory range of each block along with a bar graph showing the percentage of time spent in that function or block. ! count Number of times the function or block was entered.

You can even set a breakpoint based on the type of memory access type or repetition factor. and conditional expressions. Simply move the mouse pointer to the line or instruction and double-click. When dScope reaches a breakpoint. extend the command set of dScope. ! Signal Functions generate input to the 8051 peripherals. it can perform a wide range of operations—from simple probing to running macro functions. Breakpoints It is easy to set breakpoints on high-level statements. assembler instructions. dScope offers numerous other functions that provide a robust debugging environment. 6 . ! Built-in Functions provide convenient utility routines (like printf and memset) that you can use in user or signal functions. Refer to “Signal Functions” on page 99 for an example of how to use functions in dScope. For example. and generate digital and analog input to hardware ports. There are three types of functions available to dScope: ! User Functions extend the command scope of the debugger. Functions A powerful feature of dScope is its ability to let you define and use C-like functions for a wide variety of applications. you can create dScope functions to manipulate the on-chip peripherals.8051/251 Evaluation Kit 77 Other Features In addition to the features described above.

78 Chapter 6. You can use this feature when you test your embedded application to determine the sections of code that have not yet been exercised. The Code Coverage dialog box also provides useful information and code coverage statistics. In the debug window. Using the 8051/251 tools Code Coverage dScope provides a code coverage function which marks the lines of code that have been executed. lines of code which have been executed are market with a plus sign (‘+’) in the left column. 6 .

PRJ project file and compile. The Intel PL/M-51 compiler is required. Refer to “BADCODE: An Example with Syntax Errors” on page 105 for more information about this sample program. Use the HELLO.8051/251 Evaluation Kit 79 Sample Programs This section describes the sample programs that are included in our evaluation kits and product kits.PRJ project file. The following table lists the sample programs and their directories. Build this sample program using the FIB.PRJ project file. Refer to “HELLO: Your First 8051/251 C Program” on page 81 for more information about this sample program. Build this program using the BL51_EX2. Each sample program is stored in a separate subdirectory along with project files and batch files that help you quickly build and evaluate each sample program. \BL51_EX1\ BL51_EX1 demonstrates a bank switching application written in C.PRJ project file. \BL51_EX2\ BL51_EX2 demonstrates a C program that has constant messages stored in different code banks. \BL51_EX3\ BL51_EX3 demonstrates a bank switching program that has only one module with functions located in different banks.PRJ project file. This sample program is a multiple module project that you can build using the CSAMPLE. Directory Description \A51\ A51 is a sample program for the A51 assembler. \HELLO\ The HELLO sample program is the embedded 8051 C Hello World program. Build this program using the BL51_EX1. \LSIEVE\ LSIEVE demonstrates the large model version of the sieve of Eratosthenes prime number generator. Build this program using the BL51_EX4.PRJ project file.PRJ project file. \CSAMPLE\ The CSAMPLE sample program demonstrates a simple addition and subtraction calculator. Use µVision to open the BADCODE. The sample programs are found in the \C51\EXAMPLES\ directory. \BL51_EX4\ BL51_EX4 demonstrates a bank switching. µVision takes you to each error in BADCODE.PRJ project file to build this program.PRJ project file. You can use the sample programs to learn how to use our tools. This example is mainly provided for benchmark enthusiasts. This sample program invokes functions in different code banks. \BADCODE\ BADCODE is a sample program with a number of syntax errors. Intel PL/M-51 program that calls functions in different code banks. Build this program using the DHRY.C. Additionally. Build this program using the BL51_EX3.PRJ project file. This example is mainly provided for benchmark enthusiasts. \FIB\ The FIB sample program generates fibonacci numbers and shows you how to use the reentrant function attribute to declare recursive functions. you can copy the code from our samples for your own use. \DHRY\ The DHRY example is a DHRYSTONE benchmark program that calculates and displays the dhrystones per second for the host CPU. This program is the PL/M-51 equivalent to BL51_EX1. The sample programs are ready for you to run. Build this program using the LSIEVE. 6 .

\TRAFFIC\ The TRAFFIC sample program shows how to control a traffic light using the RTX-51 Tiny real-time executive. The following sections in this chapter describe how to use the tools to build the following sample programs: ! HELLO: Your First C51 Program ! MEASURE: A Remote Measurement System ! BADCODE: An Example with Syntax Errors . you must switch to the directory in which the sample resides. Build this program using the SSIEVE. Build this program using the MEASURE. you may use either the provided DOS batch files or the µVision for Windows project file to build and test the sample program. Build this program using the WHETS.PRJ project file. \RTX_EX2\ The RTX_EX2 sample program demonstrates an RTX-51 Tiny application that uses signals. This example is mainly provided for benchmark enthusiasts. Build this program using the SAMPL517. This example is mainly provided for benchmark enthusiasts.PRJ project file.PRJ project file.PRJ project file.PRJ project file.PRJ project file. Build this program using the TRAFFIC. Build this program using the RTX_EX2.PRJ project file. Refer to “MEASURE: A Remote Measurement System” on page 88 for more information about this sample program. It simulates a data acquisition system that might be found in a weather station or in a process control application. Using the 8051/251 tools Directory Description \MEASURE\ The MEASURE sample C program collects analog and digital data.PRJ project file. \RTX_EX1\ The RTX_EX1 sample program demonstrates round-robin multitasking using RTX-51 Tiny. \TDP\ The TDP sample program demonstrates how to use interrupt-driven serial I/O to interface to an alarm clock driven by an interrupt-driven timer.80 6 Chapter 6. Build this program using the RTX_EX1. To begin using one of the sample files. \SSIEVE\ The SSIEVE sample program demonstrates the small model version of the sieve of Eratosthenes prime number generator. \SAMPL517\ The SAMPL517 sample program provides an RPN-style calculator that takes advantage of the 80C517 arithmetic processor. \WHETS\ The WHETS example is a WHETSTONE benchmark program that calculates and displays the number whetstones per second for the host CPU. Then. Build this program using the TDP.

The project file contains names of all source files associated with the project and also tells the 6 ..8051/251 Evaluation Kit 81 HELLO: Your First 8051/251 C Program The HELLO sample program is located in the \C51\EXAMPLES\HELLO\ directory. TI = 1. TH1 = 0xf3.h> /* prototype declarations for I/O functions */ /****************/ /* main program */ /****************/ void main (void) { SCON = 0x50. link. */ } /* /* /* /* */ */ */ */ An embedded program does not stop and never returns.. or from µVision for Windows using the provided project file. The entire program is contained in a single source file. ------------------------------------------------------------------------------*/ #pragma DEBUG OBJECTEXTEND CODE /* pragma lines can contain /* command line directives */ */ #include <reg51. enable rcvr TMOD: timer 1. Inc. HELLO Project File In µVision. You do not actually need a target CPU because dScope lets you simulate the hardware required for this program.). applications are maintained in a project file. mode 2. TR1 = 1. 8-bit reload TH1: reload value for 2400 baud TR1: timer 1 run TI: set TI to send first char of UART */ */ */ */ */ */ printf ("Hello World\n"). /*-----------------------------------------------------------------------------HELLO. using batch files.. You can perform these operations from the DOS command line.C Copyright 1995 KEIL Software. /* /* /* /* /* /* } execution starts here after stack init SCON: mode 1. 8-bit UART. and debug an application. The only on-chip peripheral used is the serial port. TMOD |= 0x20.C.. This small application helps you confirm that you can compile. which is listed below. We've used an endless loop. /* the 'printf' function call */ while (1) { .h> /* special function register declarations /* for the intended 8051 derivative */ */ #include <stdio. You may wish to put in your own code were we've printed the dots (. HELLO does nothing more than print the text “Hello World” to the serial port. HELLO. /* . Hardware Requirements The hardware for HELLO is based on the standard 8051CPU.

select the Open command from the Project menu and open the HELLO.C from the files list and select the OK button. called HELLO. has been created for HELLO.PRJ project file from the \C51\EXAMPLES\HELLO directory. A project file. Editing HELLO. Select HELLO. Select the Open command from the File menu. Using the 8051/251 tools tools how to compile.82 Chapter 6. assemble. µVision prompts you with the Open File dialog box. To load this project file.PRJ.C 6 You can now edit HELLO. and link to generate an executable target program.C. .

6 . click on the Build All button on the tool bar or select the Make: Build Project command from the Project menu. Compiling and Linking HELLO When you are ready to compile and link your project.C in a window.8051/251 Evaluation Kit µVision loads and displays the contents of 83 HELLO. During the build. µVision displays the status in a window. µVision begins to compile and link the source files in your project and create an absolute object module that you can load into dScope for testing.

6 . µVision displays a message indicating the build is finished.84 Chapter 6. You can add the path specifications in µVision when you select the Environment Pathspecs command from the Options menu. Using the 8051/251 tools When the build is complete. If it is not there. If µVision says it cannot find or run the compiler or linker. you must add it so that µVision can find the compiler and the other tools. check your PATH for the \C51\BIN directory. You may press Esc at any time to halt the build. NOTE You should encounter no errors when you use µVision with the provided sample projects.

Select the Colors and Fonts command from the Setup menu to configure the different windows in dScope. select the DS51 Simulator command from the Run menu and press Enter when the dScope Command Arguments dialog box displays.8051/251 Evaluation Kit 85 Testing HELLO With dScope Once the HELLO program is compiled and linked.INI) to dScope. In µVision. you can test it with the dScope debugger/simulator. 6 NOTE The first time you invoke dScope. you may need to change the fonts and colors used for the different windows. µVision passes an initialization file (HELLO. This file contains commands for dScope that load the CPU driver DLL and the HELLO sample program. . the following screen displays. When dScope loads.

make sure to reset the CPU driver. click on the Stop button in the debug window or type Ctrl+C. you may type exit to leave the dScope debugger. After HELLO outputs “Hello World. After you have halted program execution. Using the 8051/251 tools Running HELLO To run the HELLO program.” it begins executing an endless loop. click on the Go button in the debug window or enter g at the command prompt. First.86 Chapter 6. To do this. then type the following lines at the command prompt: . make sure program simulation is halted. The HELLO program executes and displays the text “Hello World” in the serial window. To halt execution. Single-Stepping Through HELLO 6 You can single-step through the HELLO program using the Step buttons in the debug window.

The g. The current instruction is always highlighted. You may exit dScope at any time. but the highlight moves each time you step.8051/251 Evaluation Kit 87 reset g. To step through the HELLO program.main command begins executing the program and stops when it reaches the main C function. To do so. You may continue stepping through your program by clicking on the StepOver button. click on the StepOver button in the debug window. halt execution of HELLO and enter at the command prompt. exit 6 .main The reset command resets the simulated 8051 CPU. the simulator executes one statement. Each time you click on this button.

MCOMMAND. MEASURE runs a remote measurement system that collects analog and digital data like a data acquisition systems found in a weather stations and process control applications. Port 4 and port 5 are used for the digital inputs and AN0 through AN3 are used for the analog inputs. Hardware Requirements The hardware for MEASURE is based on the 80517 CPU. MEASURE is composed of three source files: GETLINE.88 Chapter 6.C. You do not actually need a target CPU because dScope lets you simulate all the hardware required for this program. and MEASURE. Using the 8051/251 tools MEASURE: A Remote Measurement System The MEASURE sample program is located in the \C51\EXAMPLES\MEASURE\ directory. 6 . This microcontroller provides analog and digital input capability. MEASURE records data from two 8-bit digital ports and four 8-bit analog-to-digital inputs. A timer controls the sample rate. The sample interval can be configured from 1 millisecond to 60 minutes. Each measurement saves the current time and all of the input channels to an 8 Kbyte RAM buffer.C.C.

The Project Manager dialog box shows the source files that compose the MEASURE project. There are three source files in this project. The timer interrupt routine.PRJ from the \C51\EXAMPLES\MEASURE directory.00V and 5. Timer 0 was used to maintain compatibility with the 8051 which can be used if fewer input channels are required. To open a source file from the Project Manager dialog box. MCOMMAND. GETLINE. MEASURE. To load this project file. To close the Project Manager dialog box.C This source file contains the main C function for the measurement system and the interrupt routine for timer 0. timer0. These functions are called from main.PRJ.00V. 6 . and interval commands. The display command lists the analog values in floating-point format to give a voltage between 0. press Esc or click on the Cancel button.C This source file contains the command-line editor for characters received from the serial port.C This source file processes the display.8051/251 Evaluation Kit 89 MEASURE Project File The project file for the MEASURE sample program is called MEASURE. manages the real-time clock and the measurement sampling of the system. double-click on the filename. Select the Edit Project command from the Project menu to display the Project Manager dialog box. The main function initializes all peripherals of the 80517 and performs command processing for the system. select the Open command from the Project menu and open MEASURE. time.

90 Chapter 6. you can use dScope to simulate the hardware. µVision begins to compile and link the source files in MEASURE and displays a message when the build is finished. select the DS51 Simulator command from the Run menu and press Enter when the dScope Command Arguments dialog box displays. In µVision. If you have actual target hardware. click on the Build All button on the tool bar or select the Make: Build Project command from the Project menu. Once the MEASURE program is compiled and linked. Once compiling and linking are complete. You can also use the serial window in dScope to provide serial input. If you do not have target hardware. Using the 8051/251 tools Compiling and Linking MEASURE When you are ready to compile and link MEASURE. you can use a host computer or dumb terminal to communicate with the 80517 CPU. you are ready to begin testing the MEASURE sample program. 6 . Testing MEASURE With dScope The MEASURE sample program is designed to accept commands from the on-chip serial port. you can test it with dScope.

000 (for 60 minutes). All commands must be terminated with a carriage return. After receiving the start command. Interval I mm:ss. Command Serial Text Description Clear C Clears the measurement record buffer. Once these are loaded. Time T hh:mm:ss Sets the current time in 24-hour format.001 (for 1ms) and 60:00. These commands are composed of ASCII text characters. Display D Displays the current time and input values.8051/251 Evaluation Kit 91 The initialization file that µVision passes to dScope automatically loads the CPU driver and MEASURE program. Start S Starts the measurement recording. MEASURE samples all data inputs at the specified interval. The interval time must be between 0:00. 6 . Remote Measurement System Commands The serial commands that MEASURE supports are listed in the following table.ttt Sets the interval time for the measurement samples. dScope displays the following screen.

To view this information. The qualifiers are separated by the backslash character (‘\’). Quit Q Quits the measurement recording. line numbers. Use the mouse to drag and drop the idx symbol from the symbol browser window to the command window. all symbols in the data memory area are removed from the display.92 Chapter 6. Otherwise. the recording must be stopped. Viewing Debug Symbols The MEASURE sample program is configured for full debug information and includes public and local symbols. the read command transmits all recorded measurements. The fully qualified symbol name with module name and function name are inserted as shown. You can read measurements on the fly if the interval time is more than 1 second. You may filter the symbols displayed by selecting the memory space filter. If you clear the data check box. select the Locals radio button and the Options check box as shown below. You may specify the number of most recent samples to display with the read command. dScope displays the value of idx. If no count is specified. Then. and high-level type information. Select the command window and press Enter. click on the Symbol Browser button on the tool bar to open the symbol browser window. 6 dScope supports the drag and drop feature of Windows and lets you access the symbols this way. . Using the 8051/251 tools Command Serial Text Description Read R [count] Displays the recorded measurements.

you may use the scroll bars to scroll through the memory area. I:0xFF dScope can dynamically update the memory window while your application is running. 6 To display the on-chip data memory. enter the address range you want to view. Viewing Memory Contents dScope displays memory in HEX and ASCII in the memory window. To toggle dynamic updating. select the Update Memory window command from the Setup menu. enter “I*” and click the Apply button. The bounds for scrolling are defined by the address range specified. To limit the symbol list to those beginning with the letter I.8051/251 Evaluation Kit 93 You can specify a search mask to limit the symbols displayed. When Update Memory window is checked. In the command window. for example: D X:0x0000. X:0xFFFF Since the memory window cannot show the entire memory range at once. D I:0x0000. 0x0000 to 0xFFFF for this example. Open the memory window by clicking on the Memory button on the tool bar. . dynamic updating is enabled. enter the following in the command window.

. The debug window shows intermixed source and assembly lines. Then. to change the view mode. select the reset button to reset dScope.94 Chapter 6. register. View Mixed. and serial windows. and Serial buttons on the tool bar to display the debug. Then. From the toolbar. View Mixed changes to the mixed source and assembly display. For example. click on the StepInto button once. In the debug window. Display the debug window using the debug button on the tool bar. Register. or View Assembly. select the View Mixed command from the Commands menu. open the Commands menu in the debug window and select View High level. Using the 8051/251 tools Changing the View Mode dScope lets you change the view mode in the debug window. 6 Program Execution Before you begin simulating the MEASURE program. You may disable other windows if your screen is not large enough. use the Debug.

Click on the StepInto button a few more times to get to the loop which clears the on-chip data space of the CPU. dScope lets you use the current cursor line as a temporary breakpoint. dScope executes the startup code and halts on the first statement in the main function.8051/251 Evaluation Kit 95 The StepInto button lets you single-step through your application and into function calls. you can skip over the . 6 To skip the initialization code and go directly to the main function. Use this feature to skip over code in your application.main”. select the command window and enter “G. Go Until Current Cursor Line The current cursor line is the line which marks the current assembly or high-level statement. For example. You can move the line using the keyboard or the mouse.

. You can do this in one of two ways: ! Variant 1: Move the cursor line to the LJMP main instruction.96 Chapter 6. starts execution from the current PC. Using the 8051/251 tools initialization code and stop one instruction before the main function is called. with the right mouse button. This makes the selected line the current cursor line. on the LJMP main instruction. Click on the GoTilCurs button in the debug window. You can use the cursor keys or you can click the mouse on that line. Select the View High level command from the debug window Commands menu. dScope starts execution at the current program counter and stops at the current cursor line. the current cursor line and the current program counter (PC) line are the same. 6 NOTE After performing this command. ! Variant 2: Double-click. Stepping Through High-Level Statements Click on the StepInto button in the debug window and dScope jumps to the main function of the MEASURE sample program. The background color used for the line is the PC highlight color. and stops when the current line is reached. The program counter is now at the LJMP main instruction.

Click on the StepInto button and watch as the current program counter line moves down the screen.8051/251 Evaluation Kit 97 When viewing your application in high level mode. If we set a breakpoint on the TR0 = 1 statement. The selected line is highlighted and a [BR n] label is displayed at the end of the line. NOTE You cannot StepOut from the main function because it is invoked by a long jmp (LJMP) rather than a call instruction. the debug window appears as follows: 6 . you may accidentally step into a function unnecessarily. You can use the StepOut button to complete execution of that function and return to the statement immediately following the function call. NOTE The StepOver button operates much like the StepInto button with the exception that a function call is considered a single statement. Stepping Out of a Function On occasion. the meaning of a step changes to mean one high-level statement instead of one assembly instruction. Setting and Removing Breakpoints You can set an execution breakpoint in the debug window by double-clicking on the desired source line.

98 Chapter 6. the numeric address of the invoked function. . You can display the caller of a function by selecting the function from the list. You can view the function nesting at any time by opening the Call Stack window. Use the Call Stack button on the tool bar to display Call Stack window. Then. you can use the Show invocation button to display the function call in the debug window. To remove a breakpoint. Using the 8051/251 tools Click on the Go button and dScope starts execution from the current program counter and stops when the breakpoint is reached. 6 This dialog box lists all currently nested functions. Call Stack dScope internally tracks function nesting as the program executes. Each line contains a nesting level number. and the symbolic name of the function if debug information is available. double-click on the line containing the breakpoint.

0) G 6 . } /* forever */ /* analog input-0 */ /* 30000 Cycles Time-Break */ /* increase voltage */ { /* 30000 Cycles Time-Break */ /* decrease voltage */ } } After loading the analog include file. ANALOG0 (5.5. } volts = limit-0. while (1) { volts = 0.5) ain0 = volts. twatch (30000).5.inc This loads the analog function from the file ANALOG. volts += 0. printf ("ANALOG0 (%f) ENTERED\n". Signal Functions dScope lets you create signal functions to provide an input signal for digital or analog inputs. INCLUDE analog.3 volts. while (volts >= 0. SIGNAL void analog0 (float limit) { float volts. halt program execution by clicking on the Stop button in the debug window and enter the following command in the command window. volts -= 0.8051/251 Evaluation Kit 99 Port Inputs dScope provides two different ways to set digital and analog port inputs. limit).5. enter the following commands in the command window. You can use the Peripheral menu in the main window to view and change the status of input lines or you can enter I/O values in the command window. This file defines a signal function that adjusts the analog value that appears on analog channel 0. To load a signal function.INC. while (volts <= limit) { ain0 = volts. PORT4=0x23 AIN1=3. twatch (30000). This function appears as follows. The following commands change port values in the command window. set analog input AIN1 to 3.3 set digital input PORT3 to 0x23.

MEASURE displays a menu and waits for input after displaying Command. two port values. Click on the View Trace button to view the trace buffer. Trace Recording It is common during debugging to reach a breakpoint where you require information like register values and other circumstances which led to the breakpoint. . dScope provides trace recording for this purpose. In the serial window. To enable trace recording. and finally the analog input values. Using the 8051/251 tools These commands set the limit for analog channel 0 to 5. Click on the Stop button in the debug window. Start running the MEASURE program (click on the Go button in the debug window) and select the serial window. When trace recording is enabled.100 Chapter 6. dScope records up to 512 assembly instructions and register contents. select the Record trace command from the Commands menu to toggle instruction trace recording. This halts program execution immediately. Select the serial window and type D Enter. You can use trace recording with the MEASURE example. You should see the analog channel 0 signal begin swinging from 0 to 5 volts.0 volts and start program execution. MEASURE begins to display measurement values. 6 The serial window displays what you would see on a dumb terminal connected to the 80517’s serial port. the record time. When you enter this command. enter d.

The trace history lines begin with negative numbers. The program counter line is the delimiter between the trace history and instructions not yet executed. To display this dialog box. and arrays. Watchpoints Watchpoints are used to view the contents of simple variables. NOTE Program execution must be stopped before you can view the trace buffer. the oldest entries are removed to make space for new entries.8051/251 Evaluation Kit 101 The upper portion of the debug window shows the trace history. The lower portion of the debug window shows instructions from the program counter. The newest trace buffer entry is –1. The register window shows the register contents for the selected instruction in the trace buffer. 6 . The oldest entry is –511. You may setup watchpoints using the Watchpoints dialog box. You may scroll into the trace buffer using the keyboard or the mouse. select the Watchpoints command from the Setup menu. structures. When the buffer overflows.

a function address or line number specifies where to stop execution. . The watch window updates at the end of each execution command (StepInto.102 Chapter 6. Using the 8051/251 tools The following steps show you how to define two watchpoints: one for the variable sindex which is an unsigned int and one for the structure current which contains a nested time struct. You may configure dScope to periodically update the watch window during execution by selecting the Update Watch Window command from the Setup menu. Execution breakpoints are the simplest form. select the Multiple radio button to display structure members on separate lines. The watch window now contains the two watch expressions just defined. Structure members display on separate lines and are indented to reflect the nesting level. The last few lines display the data stored in the analog array. Breakpoints You use breakpoints to stop program execution on a given address or a specified condition. or Go). StepOut. To add a watchpoint for sindex: Type sindex in the Expr input line and click on the Define watch button. and click on the Define watch button. 6 The second watch expression for current generates much more output. To add a watchpoint for current: Type current in the Expr input line. The first watch expression shows the value of sindex on a single line.

The following example shows you how to stop program execution when the current. In the Expression input line. Reset dScope.time. enter current. To test the breakpoint condition perform the following steps: 1. click on the Define button to set the breakpoint.8051/251 Evaluation Kit 103 You may want to halt program execution when a variable contains a certain value. enter the following commands in the command window. Using the Performance Analyzer dScope lets you perform timing analysis of your applications using the integrated performance analyzer. When you are finished. The program counter line in the debug window marks the line in which the breakpoint occurred. Begin executing the MEASURE sample program (click on the Go button in the debug window).sec==3. 2. After a few seconds. Select the Breakpoints command from the Setup menu to display the Breakpoints dialog box. In the Count input line. To prepare for timing analysis. Press Enter in the serial window at the MEASURE command prompt. You can specify an address range or a function for dScope to use. enter 1. 3. dScope halts execution.sec structure member is set to 3. PA main PA timer0 PA clear_records PA measure_display PA save_current_measurements PA read_index RESET PA /* Initialize PA */ 6 .time. Select the Write check box (this option specifies that the break condition is tested only when the expression is written to).

Open the performance analyzer window using the button on the tool bar. The <unspecified> line accumulates all execution time outside the defined ranges. Perform the following steps to watch the performance analyzer in action: 1.104 Chapter 6. The display shows the ranges defined above. 3. The performance analyzer window shows a bar graph for each range. Select the serial window and type S Enter D Enter. Reset dScope. Click on the range to see timing statistics for each individual range. 2. Start program execution by clicking on the Go button in the debug window. . Using the 8051/251 tools These commands create the performance analyzer address ranges for timing statistics. 6 The bar graph is dynamically updated and shows the percent of the time spent executing code in each range. You may create or view the ranges with the Setup Performance Analyzer command in the Setup menu. 4.

6 When the error window displays. Select the Compile File command from the Project menu to compile the file. it may cover a portion of the source window. This file is used to demonstrate how µVision interacts with the compiler to help you locate errors and warnings in your source program. You may use the cursor keys in the error window to scroll through the errors generated by the compiler. µVision determines that there are errors and displays an error window for you to peruse. the source window is updated to reflect the line on which the error was encountered. After compilation.C.8051/251 Evaluation Kit 105 BADCODE: An Example with Syntax Errors The \C51\EXAMPLES\BADCODE\ directory contains a file called BADCODE. Use the tile vertical or tile horizontal button to display the windows side-by-side. .C file using the Open command in the File menu. As you move from line to line. Open the BADCODE.

.

Additionally. Hardware Products Keil Software offers a number of hardware products that you can use to assist in 8051/251 software development. ! MCB517A Evaluation Board. ! PC parallel-port cable. ! ProROM EPROM Emulator.8051/251 Evaluation Kit 107 Chapter 7. our hardware products include: ! ProROM EPROM Emulator. The ProROM EPROM emulator comes complete with: ! User’s Manual. It only takes a few seconds to download 64 Kbytes of program code to ProROM. 7 . ProROM provides a quick. you can rapidly develop and test your embedded target program. ProROM comes with an easy to use loader program that downloads your binary or Intel HEX files. ! Software and file conversion utilities. Currently. With ProROM. ProROM EPROM Emulator ProROM is an EPROM emulator that connects between the parallel printer port of your PC and the ROM socket of your target hardware. Each of these products is described in the following sections. You no longer have to rely on or wait for EPROM programmers and erasers that may take several minutes between software iterations. ! 28-pin DIP interface cable. ! MCB251SB Evaluation Board. convenient solution for rapid software development. you can use ProROM with the µVision development environment to automate your build and load development cycle.

. ! dScope-51 simulator for Windows. The MCB517A is a complete starter package for anyone interested in the Siemens 517. The MCB517A lets you write and test code for the 80C517(A) using the Keil Software 8051 development tools and the 8051 monitor. You can build applications using µVision and the C51 compiler and A51 assembler. and you can test and debug applications using dScope and the monitor. The tools provided include: ! The C51 compiler. 7 The MCB517A is a complete starter package for anyone interested in the Siemens 517. 80C515(A) and 80C517(A). this frees up the standard 8051 serial interface for the user application. The MCB517A uses for communication with the Monitor the 2nd serial interface of the 517 CPU. The MCB517A includes a user’s manual that clearly describes the board and an evaluation kit that includes a 2 Kbyte size-limited tool set. ! and several example programs. ! 8051 Monitor program and dScope interface DLLs. Hardware Products MCB517A Evaluation Board The MCB517A evaluation board is a single board computer that supports the Siemens 80C517(A) microcontroller.108 Chapter 7. Since the Siemens 517 CPU is a superset of the 8051 and 80515 the MCB517A board can be used also for projects using the 8051. ! all the necessary utilities. ! µVision/51 IDE for Windows. ! A51 assembler. The 8051 monitor lets you download and execute 8051 applications you develop using the tools included with the package.

! µVision/251 IDE for Windows. The tools provided include: ! The C251 compiler. 7 . Board configuration is accomplished using clearly labeled DIP switches.8051/251 Evaluation Kit 109 MCB251SB Evaluation Board The MCB251SB evaluation board is a single board computer that supports the Intel 80C251SB microcontroller. and you can test and debug applications using dScope and the monitor. A 2 Kbyte size limited tool set is also included with the MCB251SB. source mode. non-page mode. ! A251 assembler. ! 251 Monitor program and dScope interface DLLs. You can build applications using µVision and the C251 compiler and A251 assembler. The MCB251SB includes a user’s manual that describes the board and data books that describe the 251 architecture. ! all the necessary utilities and example programs to help you get started. The MCB251SB lets you evaluate all operating modes of the 251 including page mode. The monitor lets you download and execute 251 applications you develop using the tools included with the package. ! dScope-251 simulator for Windows. and binary mode. The 251 monitor program comes installed on the board.

110 Chapter 7. 7 . Hardware Products The MCB251SB is a complete starter package for anyone interested in the Intel 251.

Task switching is accomplished by round-robin multitasking and signals.8051/251 Evaluation Kit 111 Chapter 8. a real-time operating system (RTOS) allows 8 . RTX-51 Tiny which is a subset of RTX-51 Full. You can force a task to wait for an interrupt. RTX-51 Tiny easily runs on single-chip 8051 systems without any external data memory. The rest of this section uses RTX-51 to refer to RTX-51 Full and RTX-51 Tiny. Differences between the two are stated where applicable. Signals and messages may be passed between tasks using a mailbox system. You can allocate and free memory from a memory pool. 3. RTX-51 Tiny supports many of the features found in RTX-51 Full with the following exceptions: 1. time-critical applications. RTX-51 Full works in parallel with interrupt functions. Preemptive task switching is not supported. No message routines are included. RTX-51 Real-Time Operating System The RTX-51 real-time operating system is a multitasking kernel for the 8051 family of processors that simplifies the software design of complex. Introduction Many microcontroller applications require simultaneous execution of multiple jobs or tasks. For such applications. No memory pool allocation routines are available. Real-Time Kernels This chapter discusses the different real-time operating systems that are available for the 8051 and 251 microcontrollers. 2. There are two distinct versions of RTX-51: RTX-51 Full which performs both round-robin and preemptive task switching using up to four task priorities. time-out. 4. or signal or message from another task or interrupt.

/* repeat forever */ /* process serial input */ /* process keyboard input */ /* adjust the controller */ /* increment counter */ . void main (void) { counter = 0. counter++. 8 void main (void) { counter = 0. memory. In this scheme. RTX-51 implements a powerful RTOS which is easy to use.112 Chapter 8. RTX-51 programs also require that you include the real-time executive header file and link using the BL51 code banking linker/locator and the appropriate RTX-51 library file. Single Task Program A standard C program starts execution with the main function. For example: int counter. You write and compile RTX-51 programs using standard C constructs and compiling them with C51. In an embedded application. Only a few deviations from standard C are required in order to specify the task ID and priority. For example: int counter. main is usually coded as an endless loop and can be thought of as a single task which is executed continuously. } /* repeat forever */ /* increment counter */ } Round-Robin Program A more sophisticated C program may implement what is called a round-robin pseudo-multitasking scheme without using a RTOS. tasks or functions are called iteratively from within an endless loop. process_kbd_cmds (). while (1) { check_serial_io ().) to several tasks. process_serial_cmds (). while (1) { counter++. Real-Time Kernels flexible scheduling of system resources (CPU. check_kbd_io (). RTX-51 works with all 8051 derivatives. adjust_ctrlr_parms (). etc.

The periodic interrupt that is generated is used to drive the RTX-51 clock. The two tasks in this program are simple counter loops. After job0 executes for a while. It automatically begins executing task 0. The available CPU time is divided into time slices and RTX-51 assigns a time slice to every task. If you do have a main function. RTX-51 switches to another task that is ready to run and allows that task to execute for a while. you must manually start RTX-51 using the os_create_task function in RTX-51 Tiny and the os_start_system function in RTX-51. Each task is allowed to execute for a predetermined amount of time. The following example shows a simple RTX-51 application that uses only round-robin task scheduling. usually only a few milliseconds. Tasks are not executed concurrently but are time-sliced. After job1 executes for a while. RTX-51 does not require you to have a main function in your program. void job0 (void) _task_ 0 { os_create_task (1). #include <rtx51tny.h> int counter0. int counter1. RTX-51 switches back to job0. RTX-51 uses a timing routine which is interrupt driven by one of the 8051 hardware timers. } } 8 /* mark task 1 as ready */ /* loop forever */ /* update the counter */ /* loop forever */ /* update the counter */ . while (1) { counter0++. } } void job1 (void) _task_ 1 { while (1) { counter1++. RTX-51 starts executing task 0 which is the function names job0. For this reason. it appears as though the tasks are executing simultaneously. RTX-51 switches to job1.8051/251 Evaluation Kit 113 } } Round-Robin Scheduling With RTX-51 RTX-51 also performs round-robin multitasking which allows quasi-parallel execution of several endless loops or tasks. This process is repeated indefinitely. Then. This function adds another task called job1. The time slices are very short.

114

Chapter 8. Real-Time Kernels

RTX-51 Events
Rather than waiting for a task’s time slice to be up, you can use the os_wait
function to signal RTX-51 that it can let another task begin execution. This
function suspends execution of the current task and waits for a specified event to
occur. During this time, any number of other tasks may be executing.

Using Time-outs with RTX-51
The simplest event you can wait for with the os_wait function is a time-out
period in RTX-51 clock ticks. This type of event can be used in a task where a
delay is required. This could be used in code that polled a switch. In such a
situation, the switch need only be checked every 50ms or so.
The next example shows how you can use the os_wait function to delay
execution while allowing other tasks to execute.
#include <rtx51tny.h>
int counter0;
int counter1;
void job0 (void) _task_ 0 {
os_create_task (1);
while (1) {
counter0++;
os_wait (K_TMO, 3, 0);
}
}
void job1 (void) _task_ 1 {
while (1) {
counter1++;
os_wait (K_TMO, 5, 0);
}
}

8

/* mark task 1 as ready
/* loop forever
/* update the counter
/* pause for 3 clock ticks

*/
*/
*/
*/

/* loop forever */
/* update the counter */
/* pause for 5 clock ticks */

In the above example, job0 enables job1 as before. But now, after
incrementing counter0, job0 calls the os_wait function to pause for 3 clock
ticks. At this time, RTX-51 switches to the next task, which is job1. After
job1 increments counter1, it too calls os_wait to pause for 5 clock ticks.
Now, RTX-51 has no other tasks to execute, so it enters an idle loop waiting for
3 clock ticks to elapse before it can continue executing job0.
The result of this example is that counter0 gets incremented every 3 timer ticks
and counter1 gets incremented every 5 timer ticks.

8051/251 Evaluation Kit

115

Using Signals with RTX-51
You can use the os_wait function to pause a task while waiting for a signal (or
binary semaphore) from another task. This can be used for coordinating two or
more tasks. Waiting for a signal works as follows: If a task goes to wait for a
signal, and the signal flag is 0, the task is suspended until the signal is sent. If
the signal flag is already 1 when the task queries the signal, the flag is cleared,
and execution of the task continues. The following example illustrates this:
#include <rtx51tny.h>
int counter0;
int counter1;
void job0 (void) _task_ 0 {
os_create_task (1);
while (1) {
if (++counter0 == 0)
os_send_signal (1);
}
}
void job1 (void) _task_ 1 {
while (1) {
os_wait (K_SIG, 0, 0);
counter1++;
}
}

/* mark task 1 as ready
/* loop forever
/* update the counter
/* signal task 1

*/
*/
*/
*/

/* loop forever */
/* wait for a signal */
/* update the counter */

In the above example, job1 waits until it receives a signal from any other task.
When it does receive a signal, it increments counter1 and again waits for
another signal. job0 continuously increments counter0 until it overflows to 0.
When that happens, job0 sends a signal to job1 and RTX-51 marks job1 as
ready for execution. job1 does not start until RTX-51 gets its next timer tick.

Priorities and Preemption
One disadvantage of the above program example is that job1 is not started
immediately when it is signaled by job0. In some circumstances, this is
unacceptable for timing reasons. RTX-51 allows you to assign priority levels to
tasks. When a higher priority task becomes available, it interrupts or preempts a
lower priority task. This is called preemptive multitasking or just preemption.
NOTE
Preemption and priority levels are not supported by RTX-51 Tiny.

8

116

Chapter 8. Real-Time Kernels

You can modify the above function declaration for job1 to give it a higher
priority than job0. By default, all tasks are assigned a priority level of 0. This
is the lowest priority level. The priority level can be 0 through 3. The following
example shows how to define job1 with a priority level of 1.
void job1 (void) _task_ 1 _priority_ 1 {
while (1) {
os_wait (K_SIG, 0, 0);
counter1++;
}
}

/* loop forever */
/* wait for a signal */
/* update the counter */

Now, whenever job0 sends a signal to job1, job1 starts immediately.

Compiling and Linking with RTX-51
RTX-51 is fully integrated into the C51 programming language. This makes
generating RTX-51 applications very easy to master. You do not need to write
any 8051 assembly routines or functions. You only have to compile your
RTX-51 programs with C51 and link them with the BL51 code banking
linker/locator.
For example, you should use the following command lines with RTX-51 Tiny.
C51 EXAMPLE.C
BL51 EXAMPLE.OBJ RTX51TINY

Use the following command lines to compile and link with RTX-51.
C51 EXAMPLE.C
BL51 EXAMPLE.OBJ RTX51

Interrupts

8

RTX-51 works in parallel with interrupt functions. Interrupt functions can
communicate with RTX-51 and can send signals or messages to RTX-51 tasks.
RTX-51 Full lets you assign an interrupt to a task.

Message Passing
RTX-51 Full supports message exchange between tasks with the following
functions: isr_recv_message, isr_send_message, os_send_message, and
os_wait.

8051/251 Evaluation Kit

117

A message is a 16-bit value which can be interpreted as a number or as a pointer
to a memory block. RTX-51 Full supports variable sized messages using a
memory pool system.

CAN Communication
Controller Area Networks are easily implemented with RTX-51/CAN.
RTX-51/CAN is a CAN task integrated into RTX-51 Full. An RTX-51 CAN
task implements message passing via the CAN network. Other CAN stations can
be configured either with or without RTX-51.

BITBUS Communication
RTX-51 Full includes both master and slave BITBUS tasks supporting message
passing with the Intel 8044.

Events
RTX-51 supports the following events for the os_wait function:
!

A Timeout suspends the running task for a defined number of clock ticks.

!

An Interval is similar to a timeout, however, the interval is intended for use
with tasks that must execute synchronously.

!

Signals are used for inter-task coordination.

!

Messages are used for exchange of messages. †

!

An Interrupt lets a task wait for an 8051 hardware interrupt. †

!

Semaphores are used for management of shared system resources. †
† These events are available only in RTX-51 Full.

8

Additional debug and support functions in RTX-51 Full include the following: 8 Function Description oi_reset_int_mask Disables interrupt sources external to RTX-51. os_check_semaphores Returns information about the state of all semaphores in the system. . 81 os_enable_isr † Enable 8051 hardware interrupts. 172 os_detach_interrupt † Remove interrupt assignment. os_check_mailbox Returns information about the state of a specific mailbox. 71 (with message) isr_send_message † Send a message (call from interrupt). 67 os_wait Wait for an event. Real-Time Kernels RTX-51 Functions The following table lists some of the RTX-51 functions along with a brief description and execution timing (for RTX-51 Full). 57 os_create_task Move a task to execution queue. 443 with task switch os_send_signal Send a signal to a task (call from tasks).118 Chapter 8. 160 os_get_block † Get a block from a memory pool. os_check_tasks Returns information about all tasks in the system. 644 (size 20 * 10 bytes) os_delete_task Remove a task from execution queue. os_check_pool Returns information about the blocks in a memory pool. 408 with task switch 316 with fast task switch 71 without task switch os_send_token † Set a semaphore (call from task). Function Description CPU Cycles isr_recv_message † Receive a message (call from interrupt). oi_set_int_mask Enables interrupt sources external to RTX-51. 46 os_attach_interrupt † Assign task to interrupt source. 80 os_free_block † Return a block to a memory pool. 96 os_disable_isr † Disable 8051 hardware interrupts. os_check_mailboxes Returns information about the state of all mailboxes in the system. 68 for pending signal 160 for pending message † These functions are available only in RTX-51 Full. 119 os_clear_signal Delete a previously sent signal. 343 with fast task switch 94 without task switch os_set_slice † Set the RTX-51 system clock time slice. 53 isr_send_signal Send a signal to a task (call from interrupt). os_check_task Returns information about a specific task. 148 os_send_message † Send a message (call from task). 302 os_create_pool † Define a memory pool. os_check_semaphore Returns information about the state of a specific semaphore.

can_receive Receive all unbound objects. can_get_status Get CAN controller status. CAN Function Description can_bind_obj Bind an object to a task. can_def_obj Define communication objects. can_wait Wait for reception of a bound object. CAN controllers supported include the Philips 82C200 and 80C592 and the Intel 82526. 8 . can_task_create Create the CAN communication task. More CAN controllers are in preparation. can_stop Stop CAN communications. task is started when object is received. can_start Start CAN communications. can_read Directly read an object’s data. can_send Send an object over the CAN bus. can_write Write new data to an object without sending it. can_request Send a remote frame for the specified object.8051/251 Evaluation Kit 119 CAN Functions The CAN functions are available only with RTX-51 Full. can_unbind_obj Disconnect the binding between a task and an object. can_hw_init Initialize CAN controller hardware.

46 bytes DATA 20 ..120 Chapter 8. max.. 19 tasks active 16 RAM requirements 40 .. 200 bytes IDATA (user stack) min. 8KB 900 bytes Hardware requirements timer 0 or timer 1 timer 0 System clock 1000 . 700 cycles depends on stack load Mailbox system 8 mailboxes with 8 integer entries each not available Memory pool system up to 16 memory pools not available Semaphores 8 * 1 bit not available ... Real-Time Kernels Technical Data 8 Description RTX-51 Full RTX-51 Tiny Number of tasks 256.. 100 cycles (fast task) 180 . 65535 cycles Interrupt latency < 50 cycles < 20 cycles Context switch time 70 . 700 cycles (standard task) depends on stack load 100 ... 650 bytes XDATA 7 bytes DATA 3 * <task count> IDATA Code requirements 6KB . 40000 cycles 1000 .

MODBIN ‡ Selects 251 binary mode (default). Underlined characters represent abbreviations for the particular control or directive.8051/251 Evaluation Kit 121 Chapter 9. A51 / A251 Controls Meaning CASE ‡ Enables case sensitive symbol names. ERRORPRINT!(filename)" Outputs error messages to filename. MODSRC ‡ Selects 251 source mode. NOAMAKE Excludes AutoMAKE information from the object file. NOLINES Excludes line number information from the object file. NOCOND Excludes unassembled conditional assembly code from the listing file. DATE(date) Places date string in header (9 characters maximum). You may use a command file to make assembling a source file easier or when you have more directives than fit on the command line. MACRO Enables standard macro processing. DEBUG Includes debugging symbol information in the object file. Command Reference This chapter briefly describes the commands and controls for the Keil Software 8051 and 251 development tools. directives are control parameters which are described in the following table. INCLUDE(filename) Includes the contents of filename in the assembly. 9 . Commands and controls are listed in a tabular format along with a description. MPL Enables Intel-style macro processing. A51/A251 Macro Assemblers A51 sourcefile !directives" Invocation: A251 sourcefile !directives" A51 @commandfile A251 @commandfile where sourcefile is the name of an assembler source file. NOGEN Disables macro expansions in the listing file. commandfile is the name of a file which contains a complete command line for the assembler including a sourcefile and directives.

‡ These controls are available only in A251 macro assembler. You may use a command file to make compiling a source file easier or when you have more directives than fit on the command line. REGISTERBANK(num. NOSYMBOLS Excludes the symbol table from the listing file. SET (symbol. NOMOD51 † Disables predefined 8051-specific special function registers. NOMOD251 ‡ Disables enhanced 251 instruction set. XREF Includes a symbol cross reference listing in the listing file. † These controls are available only in the A51 macro assembler. TITLE(title) Includes title in the listing file header. OBJECT!(filename)". C51/C251 Compiler Invocation: C51 sourcefile !directives" C251 sourcefile !directives" C51 @commandfile C251 @commandfile where sourcefile is the name of a C source file. NOOBJECT Enables or disables object file output. PAGELENGTH(n) Sets maximum number of lines in each page of listing file. The object file is saved as filename if specified.122 Chapter 9. directives are control parameters which are described in the following table. …). NOPRINT Enables or disables listing file output. PRINT!(filename)". Command Reference A51 / A251 Controls Meaning NOLIST Excludes the assembler source code from the listing file. NOMACRO Disables standard macro processing. commandfile is the name of a file which contains a complete command line for the compiler including a sourcefile and directives. NOREGISTERBANK Indicates that one or more registerbanks are used or indicates that no register banks are used. RESET (symbol. …) Assigns a value of 0000h to the specified symbols. PAGEWIDTH(n) Sets maximum number of characters in each line of listing file. NOSYMLIST Excludes symbol definitions from the listing file. …) Assigns a value of 0FFFFh to the specified symbols. The listing file is saved as filename if specified. 9 .

MODBIN ‡ Generates 251 binary mode code. NOAMAKE Excludes AutoMAKE information from the object file.n. INTERVAL † Specifies the interval for interrupt vectors. PARM51 ‡ Uses parameter passing conventions of the C51 compiler. NOCOND Excludes skipped conditional code from the listing file. 9 . MOD517 † Enables support for the additional hardware of the Siemens 80C517 and its derivatives. OBJECT!(filename)". LISTINCLUDE Includes the contents of include files in the listing file. OPTIMIZE Specifies the level of optimization performed by the compiler. HOLD(d. NOINTPROMOTE † Disables ANSI integer promotion rules. INTVECTOR(n). LARGE Selects the LARGE memory model.8051/251 Evaluation Kit 123 C51 / C251 Controls Meaning CODE Includes an assembly listing in the listing file. FLOATFUZZY Specifies the number of bits rounded during floating-point comparisons. NOAREGS † Disables absolute register addressing using ARn instructions. and xdata (x) memory areas. COMPACT Selects the COMPACT memory model. near (n). The object file is saved as filename if specified. INTR2 ‡ Saves upper program counter byte and PSW1 in interrupt functions. or excludes interrupt vectors from the object file.x) ‡ Specifies size limits for variables placed in data (d). PAGELENGTH(n) Sets maximum number of lines in each page of listing file. DEBUG Includes debugging information in the object file. MODDP2 † Enables support for the additional hardware of Dallas Semiconductor 80C320/520/530 and the AMD 80C521. MODSRC ‡ Generates 251 source mode code. NOEXTEND Disables 8051/251 extensions and processes only ANSI C constructs. OBJECTEXTEND † Includes additional variable type information in the object file. using n. PAGEWIDTH(n) Sets maximum number of characters in each line of listing file. ORDER Locates variables in memory in the same order in which they are declared in the source file. NOINTVECTOR Specifies offset for interrupt table. NOOBJECT Enables or disables object file output. MAXARGS(n) Specifies the number of bytes reserved for variable length argument lists. DEFINE Defines preprocessor names on the command line. NOREGPARMS † Disables passing parameters in registers.

The preprocessor listing file is saved as filename if specified. outputfile is the name of the absolute object module the linker creates.124 Chapter 9. ROM({SMALL|COMPACT|LARGE}) Controls generation of AJMP and ACALL instructions. You may use a command file to make linking your application easier or when you have more input files or more directives than fit on the command line. that the linker includes in the final 8051 application. commandfile is the name of a file which contains a complete command line for the linker/locator including an inputlist and directives. L51/BL51 Linker/Locator Invocation: BL51 inputlist !TO outputfile" !directives" L51 inputlist !TO outputfile" !directives" BL51 @commandfile L51 @commandfile where 9 inputlist is a list of the object files and libraries. REGISTERBANK † Selects the register bank to use functions in the source file. WARNINGLEVEL(n) Controls the types and severity of warnings generated. SMALL Selects the SMALL memory model. SYMBOLS Includes a list of the symbols used in the listing file. NOPRINT Enables or disables listing file output. Command Reference C51 / C251 Controls Meaning PREPRINT!(filename)" Produces a preprocessor listing file with all macros expanded. directives are control parameters which are described in the following table. SRC Creates an assembly source file instead of an object file. ‡ These controls are available only in C251 compiler. separated by commas. REGFILE(filename) Specifies the name of the generated file to contain register usage information. † These controls are available only in the C51 compiler. BL51 Controls Meaning BANKAREA ‡ Specifies the address range where the code banks are located. The listing file is saved as filename if specified. . PRINT!(filename)".

IDATA Locates and orders IDATA segments. NODEFAULTLIBRARY Excludes modules from the run-time libraries. 9 . PRECEDE Locates and orders segments that should precede all others in the internal data memory. ‡ These controls are available only in the BL51 code banking linker/locator. BIT Locates and orders BIT segments. NOLINES Excludes line number information from the listing file. RAMSIZE Specifies the size of the on-chip data memory. CODE Locates and orders CODE segments. NOOVERLAY Prevents overlaying or overlapping local BIT and DATA segments. NOMAP Excludes memory map information from the listing file. This directive is essentially the same as the CODE directive. REGFILE(filename) Specifies the name of the generated file to contain register usage information. NODEBUGLINES Excludes line number information from the object file. NOPUBLICS Excludes public symbol information from the listing file. IXREF Includes a cross reference report in the listing file. PAGELENGTH(n) Sets maximum number of lines in each page of listing file. RTX51 ‡ Includes support for the RTX-51 full real-time kernel.8051/251 Evaluation Kit 125 BL51 Controls Meaning BANKx ‡ Specifies the starting address. and object modules to place in the common bank. NOSYMBOLS Excludes local symbol information from the listing file. and object modules for code banks 0 to 31. NOAMAKE Excludes AutoMAKE information from the object file. OVERLAY Directs the linker to overlay local data & bit segments and lets you change references between segments. RTX51TINY ‡ Includes support for the RTX-51 tiny real-time kernel. DATA Locates and orders DATA segments. PRINT Specifies the name of the listing file. NODEBUGSYMBOLS Excludes local symbol information from the object file. XDATA Locates and orders XDATA segments. segments. NODEBUGPUBLICS Excludes public symbol information from the object file. segments. STACK Locates and orders STACK segments. NAME Specifies a module name for the object file. PDATA Specifies the starting address for PDATA segments. COMMON ‡ Specifies the starting address. PAGEWIDTH(n) Sets maximum number of characters in each line of listing file.

See NOCOMMENTS. NOAMAKE Excludes AutoMAKE information from the object file. separated by commas. commandfile is the name of a file which contains a complete command line for the linker/locator including an inputlist and directives. NOPUBLICS. directives are control parameters which are described in the following table. . NOLINES Excludes line number information from the listing file and object file. NAME Specifies a module name for the object file. NOLINES. OBJECTCONTROLS Excludes specific debugging information from the object file. Subcontrols must be specified in parentheses. CLASSES Specifies a physical address range for segments in a memory class. and PURGE. NOMAP Excludes memory map information from the listing file. NODEFAULTLIBRARY Excludes modules from the run-time libraries. Command Reference L251 Linker/Locator L251 inputlist !TO outputfile" !directives" Invocation: L251 @commandfile where inputlist is a list of the object files and libraries.126 Chapter 9. L251 Controls 9 Meaning ASSIGN Defines public symbols on the command line. that the linker includes in the final 251 application. NOPUBLICS Excludes public symbol information from the listing file and the object file. NOOVERLAY Prevents overlaying or overlapping local BIT and DATA segments. outputfile is the name of the absolute object module the linker creates. NOSYMBOLS. NOSYMBOLS Excludes local symbol information from the listing file. You may use a command file to make linking your application easier or when you have more input files or more directives than fit on the command line. NOCOMMENTS Excludes comment information from the listing file and the object file. IXREF Includes a cross reference report in the listing file. NOTYPES Excludes type information from the listing file and the object file.

RTX251 Includes support for the RTX-251 full real-time kernel. RAMSIZE Specifies the size of the on-chip data memory. 9 . PRINTCONTROLS Excludes specific debugging information from the listing file. SEGSIZE Specifies memory space used by a segment. and PURGE. OH51 Object-Hex Converter Invocation: OH51 absfile !HEXFILE(hexfile)" where absfile is the name of an absolute object file.8051/251 Evaluation Kit L251 Controls 127 Meaning OVERLAY Directs the linker to overlay local data & bit segments and lets you change references between segments. NOPUBLICS. NOLINES. OC51 Banked Object File Converter Invocation: OC51 banked_file where banked_file is the name of a banked object file. PAGELENGTH(n) Sets maximum number of lines in each page of listing file. PRINT Specifies the name of the listing file. RESERVE Reserves memory ranges and prevents the linker from using these memory areas. See NOCOMMENTS. REGFILE(filename) Specifies the name of the generated file to contain register usage information. PAGEWIDTH(n) Sets maximum number of characters in each line of listing file. NOSYMBOLS. PURGE Excludes all debugging information from the listing file and the object file. WARNINGLEVEL(n) Controls the types and severity of warnings generated. SEGMENTS Defines physical memory addresses and orders for specified segments. RTX251TINY Includes support for the RTX-251 tiny real-time kernel. hexfile is the name of the Intel HEX file to create. Subcontrols must be specified in parentheses.

end specifies the ending address of the range. LIB51 / LIB251 Command Meaning ADD Adds an object module to the library file. DELETE Removes an object module from the library file. EXIT Exits the library manager interactive mode. CREATE Creates a new library file. hexfile is the name of the HEX file to create. for example: 0xFFFFFF. RANGE specifies the address range of data in the absfile to convert and store in the HEX file. H386 specifies that an Intel HEX-386 file is created. LIB51/LIB251 Library Manager Invocation: LIB51 !command" LIB251 !command" where command 9 is a control command described in the following table. for example: 0xFF0000.128 Chapter 9. LIST Displays module and public symbol information stored in the library file. start specifies the starting address of the range. HELP Displays help information for the library manager. HEX specifies that a standard Intel HEX file is created. Command Reference OH251 Object-Hex Converter Invocation: OH251 absfile !HEXFILE(hexfile)" !{HEX|H386}" !RANGE(start-end)" where absfile is the name of an absolute object file. . If no command is given LIB51 enters an interactive command mode. This address must be entered in C hexadecimal notation. The default range is 0xFF0000 to 0xFFFFFF. This address must be entered in C hexadecimal notation.

............ 24 Parameter Passing .....56 Project Manager............... 29 Pointers ..................21....................................60 Overview.. 16 C251 Developer’s Kit .......... 35 Listing File Example ......................9 B Backing Up Your Disks.............................. 16 C51 Compiler......................................................................31 AUTOEXEC....54 µVision/51 for Windows ......................... 30 Generic Pointers ..................46 8051 Development Tools ....................................37 Listing File Example.............................................................56 µVision/251 for Windows ........................8051/251 Evaluation Kit 129 Index µVision Editor ............ 40 Listing File Example .. use of.................45 8051/251 Product Line ...............iv alien ....................................................... 27 Real-Time Operating System Support ..15 Additional items... iv braces...............................................18 8051/251 Development Tools .......11 A A251 ........... 27 Interfacing to Assembly ...... 26 Memory Specific Pointers ..................................................................... 24 Debugging .....51 Functional Overview..... 30 ....................................................................................................................... 39 Common Area ..............................................................21 8051/251 Compiler Kit Subscription..................................37 A51 Macro Assembler Kit. 27 Memory Types .......................................... 35 Memory Models .......................... 26 Data Types ..... 47 Program Size ....19 8051/251 Developer’s Kit Subscription........ 48 Memory Selector ............37 Configuration ...................... 39 Code Banking.....................................17 A251 Assembler .... 30 Interfacing to PL/M-51........................... 29 Language Extensions..... document conventions.51 Listing File Example............17 A51 ...........................BAT ..... 49 C251 Compiler Kit.37 Functional Overview.... 39 Executing Functions in Other Banks........................... 49 Register Optimization....................... 34 Function Return Values.......................................... iv C C251 Compiler..................................31 asm ............................................... 31 Interrupt Functions ..................................15 A51 Assembler .............................................................. 22 Code Optimizations.............................................................. 23 Large model ...................................... 48 Reentrant Code.....................................6 BL51 code banking linker/locator .............................. 26 Library Routines...... 40 Data Address Management...... 32 Compact model ..... 49 Run-Time Library.........................59 Options...................................................................................21 8051 Microcontroller Family.........................................................................................51 A251 Macro Assembler Kit....................................................60 Starting...... 41 bold capital text...........................................43 251 Development Tools ...................... 47 Listing File Example .... 46 Data Types ......................................................... use of .....59 Menu Commands ............................................... 49 Memory Models .............

................................................................... 14 can_bind_obj .......66 CPU Simulation............... 109 Changes to the Documentation ........................................ 6 courier typeface........ use of .....................................15 G Global Register Optimization.....67 dScope-251 for Windows........................... 15 dScope Breakpoints ..... 109 can_receive .................................................................. 109 can_read....................8 Evaluation Kit .....................56 Watch Window........................... 2 Directory Structure .................... 14 C51 Developer’s Kit .... 109 can_write......... iv D DEBUG ...................... document conventions.................................... iv Documentation Changes ..................................................3 HOLD.....................................................................9 Installation.................63 Debug Window......................... 109 can_unbind_obj ....... document conventions ...... 109 can_stop ............ 14 Document conventions.....................130 Index Reentrant Functions ...............................SYS ...................18 FR51.. 16 DK51 ............................................................................106.......51 Demo Kit ....................................... iv COMPACT .............68 Serial Window........ 25........70 Command Window............................ 5 double brackets.........17 dScope-51 for Windows.......................................................... 13 CA251........2 Evaluation Users .... 26 C51 Compiler Kit ...............................................................26 CONFIG.............1 isr_recv_message ...................... document conventions .............................................. 28 Register Optimizing .......................................................................... 109 can_start....................................................................................29 Introduction........................... 6 DOS-based tool requirements ..................65 Functions ........................................................ iv DK251 .................................................................. 109 can_wait............... 30 Small model .................... 7 Disk Cache.................................................. use of..........................62 Performance Analyzer Window ..........31 Environment Settings ........................................ iv DS251 ....................15 E ellipses..42 dScope-51 Simulator Kit................................................. 109 can_def_obj .........3 F Filename..................... 69 Code Coverage ........................... 16 CA51................ use of .............................................................. 109 can_get_status........................................... 14 C51 Professional Developer’s Kit ............. 109 can_task_create..................................69 Overview ........... 37...............53 dScope-251 Simulator Kit........................................... vertical....................................6 interrupt..67 Starting ......... 109 can_send .2 Experienced Users.......................................33 H Help.................................................................... 17 DS51 ......iv ellipses..................... 109 can_hw_init.......................iv FR251................................................................................................... 109 can_request ... use of .............. 3 Choices..... 3 DOS-Based Product Installation ............................................108 ......................................... 10 Displayed text.................................5 Installing the Software..........................48 I Improving System Performance ...iv endasm ..................................................................................................

.iv K Key names.......................................................................................... 108 os_free_block.108 isr_send_signal ..........................................45 N New Users ............42 oi_reset_int_mask....................................................................................... document conventions.............................. 108 os_send_token................37 NOOVERLAY ......... 108 os_send_message ........................ 39 P PK51 .......... 108 os_get_block .22...........99 MCB517A Evaluation Board ......................26 LIB251 library manager ...53 LIB51 library manager ..... iv ProROM EPROM Emulator .... 48 RTX-251 Full Real-Time Kernel ..............................108 OMF251 ....................................... 108 os_check_tasks....107 Functions ...................... 108 os_disable_isr ......................................................................... use of.......... 101 Linking ......... 29 Reporting a problem .............................................................................................49 REGPARMS................................................................108 os_send_signal ..................... document conventions ........................................................................................................42 M Manual Topics............25.....46 OMF51 ......iv L L251 linker/locator ............................................ document conventions.....34 OC51 Banked Object File Converter .........106... 108 os_delete_task.................. 9 README......................30 O OBJECTEXTEND ...................................................108 italicized text...............................98 MCS® 251 Microcontroller Family..... 108 os_create_pool ..................................... 107 CAN Communication.............29............. 108 os_set_slice .........................108 os_check_mailbox ............... 106 Introduction.......... 28....................................................................................................................................................39 NOREGPARMS.................42 OH251 Object-Hex Converter..................52 LARGE...................... 18 RTX-51 ...............41 MCB251SB Evaluation Board ..................................... 101 BITBUS Communication .29..................... 108 os_clear_signal..............iv os_attach_interrupt ....................... 104... 13 Printed text..................... 106 Events...........................................8051/251 Evaluation Kit isr_send_message ................... 108 os_create_task.. 108 os_wait ................................. 106 ............................... 106.108 131 os_check_mailboxes ................................................. document conventions......iv Optional items.............. 108 os_check_task .. 3 reentrant ............................. 106............31............................TXT............... 97 R RAM Disk............ 3 ROM ..............................................1 Map files........................................ 108 Interrupts ..........................................................2 NOMOD51....................................................... 3 Requesting Assistance..................... 108 os_detach_interrupt....................................108 OVERLAY ...............34 Omitted text......................................................................108 oi_set_int_mask... 107 Compiling.........................................................53 OH51 Object-Hex Converter....... 108 os_check_semaphores....... 108 os_check_pool ...................... 108 os_enable_isr ....... 108 os_check_semaphore ..........

...........2 using ...........2 Windows-Based Product Installation.....iv W What’s Included ......... 15 Temporary Files .............. 104 RTX-51 Full Real-Time Kernel....5 ........................................ 31 System Requirements............................................................................................................................ 106 Preemption .......29 V S sans serif typeface....... 105 Priorities...................................................132 Index Message Passing .............................................9 Types of Users................................................ 25....... iv SCA251 .......................................................... 110 Using Signals ............2 U User ...............iv vertical bar.............26 SRC................................................. 18 SMALL.................. 105 Round-Robin Scheduling ... 5 T Technical Support. 19 SDK251 ................ 105 Using Time–outs .... 3 Variables.............................. use of ........................................7 Windows-based tool requirements ............. 103 Technical Data ....................................... document conventions................................ use of .................................................................