- •Chapter 1. Introduction
- •Support for all 8051 Variants
- •Books About the C Language
- •Chapter 2. Compiling with the Cx51 Compiler
- •Environment Variables
- •Running Cx51 from the Command Prompt
- •ERRORLEVEL
- •Cx51 Output Files
- •Control Directives
- •Directive Categories
- •Reference
- •Chapter 3. Language Extensions
- •Keywords
- •Memory Areas
- •Program Memory
- •Internal Data Memory
- •External Data Memory
- •Far Memory
- •Special Function Register Memory
- •Memory Models
- •Small Model
- •Compact Model
- •Large Model
- •Memory Types
- •Explicitly Declared Memory Types
- •Implicit Memory Types
- •Data Types
- •Bit Types
- •Special Function Registers
- •sbit
- •Absolute Variable Location
- •Pointers
- •Generic Pointers
- •Pointer Conversions
- •Abstract Pointers
- •Function Declarations
- •Function Parameters and the Stack
- •Passing Parameters in Registers
- •Function Return Values
- •Specifying the Memory Model for a Function
- •Specifying the Register Bank for a Function
- •Register Bank Access
- •Interrupt Functions
- •Reentrant Functions
- •Chapter 4. Preprocessor
- •Directives
- •Stringize Operator
- •Predefined Macro Constants
- •Chapter 5. 8051 Derivatives
- •Analog Devices MicroConverter B2 Series
- •Atmel 89x8252 and Variants
- •Dallas 80C320, 420, 520, and 530
- •Arithmetic Accelerator
- •Data Pointers
- •Library Routines
- •Philips 8xC750, 8xC751, and 8xC752
- •Philips 80C51MX Architecture
- •Philips and Atmel WM Dual DPTR
- •Customization Files
- •STARTUP.A51
- •INIT.A51
- •XBANKING.A51
- •Basic I/O Functions
- •Memory Allocation Functions
- •Optimizer
- •General Optimizations
- •Options for Code Generation
- •Segment Naming Conventions
- •Data Objects
- •Program Objects
- •Interfacing C Programs to Assembler
- •Function Parameters
- •Parameter Passing in Registers
- •Parameter Passing in Fixed Memory Locations
- •Function Return Values
- •Using the SRC Directive
- •Register Usage
- •Overlaying Segments
- •Example Routines
- •Small Model Example
- •Compact Model Example
- •Large Model Example
- •Data Storage Formats
- •Bit Variables
- •Signed and Unsigned Long Integers
- •Generic and Far Pointers
- •Floating-point Numbers
- •Accessing Absolute Memory Locations
- •Absolute Memory Access Macros
- •Linker Location Controls
- •The _at_ Keyword
- •Debugging
- •Chapter 7. Error Messages
- •Fatal Errors
- •Actions
- •Errors
- •Syntax and Semantic Errors
- •Warnings
- •Chapter 8. Library Reference
- •Intrinsic Routines
- •Library Files
- •Standard Types
- •va_list
- •Absolute Memory Access Macros
- •CBYTE
- •CWORD
- •DBYTE
- •DWORD
- •FARRAY, FCARRAY
- •FVAR, FCVAR,
- •PBYTE
- •PWORD
- •XBYTE
- •XWORD
- •Routines by Category
- •Buffer Manipulation
- •Character Conversion and Classification
- •Data Conversion
- •Math Routines
- •Memory Allocation Routines
- •Stream Input and Output Routines
- •String Manipulation Routines
- •Miscellaneous Routines
- •Include Files
- •8051 Special Function Register Include Files
- •ABSACC.H
- •ASSERT.H
- •CTYPE.H
- •INTRINS.H
- •MATH.H
- •SETJMP.H
- •STDARG.H
- •STDDEF.H
- •STDIO.H
- •STDLIB.H
- •STRING.H
- •Reference
- •Compiler-related Differences
- •Library-related Differences
- •Appendix B. Version Differences
- •Version 6.0 Differences
- •Version 5 Differences
- •Version 4 Differences
- •Version 3.4 Differences
- •Version 3.2 Differences
- •Version 3.0 Differences
- •Version 2 Differences
- •Appendix C. Writing Optimum Code
- •Memory Model
- •Variable Location
- •Variable Size
- •Unsigned Types
- •Local Variables
- •Other Sources
- •Appendix D. Compiler Limits
- •Appendix E. Byte Ordering
- •Recursive Code Reference Error
- •Problems Using the printf Routines
- •Uncalled Functions
- •Using Monitor-51
- •Trouble with the bdata Memory Type
- •Function Pointers
- •Glossary
- •Index
Keil Software — Cx51 Compiler User’s Guide |
209 |
|
|
Chapter 8. Library Reference
The Cx51 run-time library provides you with more than 100 predefined functions and macros to use in your 8051 C programs. This library makes embedded software development easier by providing you with routines that perform common programming tasks such as string and buffer manipulation, data conversion, and floating-point math operations.
Typically, the routines in this library conform to the ANSI C Standard. However, some functions differ slightly in order to take advantage of the features found in the 8051 architecture. For example, the function isdigit returns a bit value as opposed to an int. Where possible, function return types and argument types are adjusted to use the smallest possible data type. In addition, unsigned data types are favored over signed types. These alterations to the standard library provide a maximum of performance while also reducing program size.
All routines in this library are implemented to be independent of and to function using any register bank.
Intrinsic Routines
The Cx51 compiler supports a number of intrinsic library functions. Non-intrinsic functions generate ACALL or LCALL instructions to perform the library routine. Intrinsic functions generate in-line code to perform the library routine. The generated in-line code is much faster and more efficient than a called routine would be. The following functions are available in intrinsic form:
_crol_ |
_iror_ |
_nop_ |
_cror_ |
_lrol_ |
_testbit_ |
_irol_ |
_lror_ |
|
These routines are described in detail in the following sections.
8
210 |
Chapter 8. Library Reference |
|
|
Library Files
The Cx51 library includes six different compile-time libraries which are optimized for various functional requirements. These libraries support most of the ANSI C function calls.
Library File |
Description |
C51S.LIB |
Small model library without floating-point arithmetic |
C51FPS.LIB |
Small model floating-point arithmetic library |
C51C.LIB |
Compact model library without floating-point arithmetic |
C51FPC.LIB |
Compact model floating-point arithmetic library |
C51L.LIB |
Large model library without floating-point arithmetic |
C51FPL.LIB |
Large model floating-point arithmetic library |
80C751.LIB |
Library for use with the Signetics 8xC751 and derivatives. |
The Philips 80C51MX, Dallas 390 contiguous mode and variable code banking requires a different set of Cx51 run-time libraries. The LX51 linker/locater automatically adds the correct library set to your project.
Several library modules are provided in source code form. These routines are used to perform low-level hardware-related I/O for the stream I/O functions. You can find the source for these routines in the LIB directory. You may modify these source files and substitute them for the library routines. By using these routines, you can quickly adapt the library to perform (using any hardware I/O device available in your target) stream I/O. Refer to “Stream Input and Output” on page 224 for more information.
8