- •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
212 |
Chapter 8. Library Reference |
|
|
Absolute Memory Access Macros
The Cx51 standard library contains definitions for a number of macros that allow you to access explicit memory addresses. These macros are defined in ABSACC.H. Each of these macros is defined to be used like an array.
CBYTE
The CBYTE macro allows you to access individual bytes in the program memory of the 8051. You may use this macro in your programs as follows:
rval = CBYTE [0x0002];
to read the contents of the byte in program memory at address 0002h.
CWORD
The CWORD macro allows you to access individual words in the program memory of the 8051. You may use this macro in your programs as follows:
rval = CWORD [0x0002];
to read the contents of the word in program memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the size of an integer (2 bytes).
8
C51 Compiler |
213 |
|
|
DBYTE
The DBYTE macro allows you to access individual bytes in the internal data memory of the 8051. You may use this macro in your programs as follows:
rval = DBYTE [0x0002]; DBYTE [0x0002] = 5;
to read or write the contents of the byte in internal data memory at address 0002h.
DWORD
The DWORD macro allows you to access individual words in the internal data memory of the 8051. You may use this macro in your programs as follows:
rval = DWORD [0x0002]; DWORD [0x0002] = 57;
to read or write the contents of the word in internal data memory at address 0004h (2 × sizeof (unsigned int) = 4).
NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the size of an integer (2 bytes).
8
214 |
Chapter 8. Library Reference |
|
|
FARRAY, FCARRAY
The FARRAY and FCARRAY macros can be used to access an array of type object in the far and const far memory areas. FARRAY provides access to the far space (memory class HDATA). FCARRAY provides access to the const far space (memory class HCONST). You can use this macros in your programs as follows:
int i; long l;
l = FARRAY (long, 0x8000)[i];
FARRAY (long, 0x8000)[10] = 0x12345678;
#define DualPortRam FARRAY (int, 0x24000) DualPortRam [i] = 0x1234;
l = FCARRAY (long, 0x18000)[5];
The FARRAY and FCARRAY macros scales the index by the size of type object and adds the result to addr. The final address is then used to access the memory.
NOTE
The absolute addressed object cannot cross a 64KB segment boundary. For example, you cannot access a long array that has 10 elements and starts at address 0xFFF8.
8
C51 Compiler |
215 |
|
|
FVAR, FCVAR,
The FVAR and FCVAR macro definitions may be used to access absolute memory addresses in the far and const far memory areas. FVAR provides access to the far space (memory class HDATA). FCVAR provides access to the const far space (memory class HCONST). You can use these macros in your programs as follows:
#define IOVAL FVAR (long, 0x14FFE) |
// long at HDATA address 0x14FFE |
|
|
var = IOVAL; |
/* read |
*/ |
|
IOVAL = 0x10; |
/* write */ |
|
|
var = FCVAR (int, 0x24002) |
/* read int from HCONST address 0x24002 |
*/ |
The HVAR macro uses the huge modifier to access the memory by segment and offset, as opposed to MVAR’s page and offset.
NOTE
The absolute addressed object cannot cross a 64KB segment boundary. For example, you cannot access a long variable at address 0xFFFE.
8