Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
14.04.2015
Размер:
1.37 Mб
Скачать

154

Chapter 6. Advanced Programming Techniques

 

 

XBANKING.A51

This file provides routines for far (HDATA) and const far (HCONST) memory type support. The extended LX51 linker/locater manages the extended address spaces HDATA and HCONST that are addressed with far and const far. The Cx51 Compiler uses a 3-byte generic pointer to access these memory areas. Variables defined with the far memory type are placed in the memory class HDATA. Variables defined with const far get the memory class HCONST. The LX51 linker/locater allows you to locate these memory classes in the physical 16MB code or 16MB xdata spaces. To use far memory with the C51 Compiler for classic 8051 devices you must use the “VARBANKING” directive described on page 84.

The memory types far and const far provide support for the large code/xdata spaces of new 8051 devices. If the CPU you are using provides an extended 24-bit DPTR register, you may adapt the default version of the file XBANKING.A51 and define the symbols listed in the following table.

Constant Name Description

?C?XPAGE1SFR SFR address of DPTR page register that contains DPTR bit 16-23.

?C?XPAGE1RST Reset value of the ?C?XPAGE1SFR to address the X:0 region. This setting used by the C51 compiler when you are using the VARBANKING(1) directive. With VARBANKING(1) the C51 compiler saves the ?C?XPAGE1SFR at the beginning of interrupt functions and sets this register to the ?C?XPAGE1RST value

The far memory type allows you to address special memory areas like EEPROM 6 space or strings in code banking ROM. Your application accesses these memory

areas as if they are a part of the standard 8051 memory space. Example programs in the folder C51\EXAMPLES\FARMEMORY show how to use the C51 far memory type on classic 8051 devices. If an example that fulfills your requirements is not provided, you may adapt the access routines listed in the table below.

Access Routine

Description

 

 

?C?CLDXPTR, ?C?CSTXPTR load/store a BYTE (char) in extended memory.

?C?ILDXPTR, ?C?ISTXPTR load/store a WORD (int) in extended memory.

?C?PLDXPTR, ?C?PSTXPTR load/store a 3-BYTE pointer in extended memory.

?C?LLDXPTR, ?C?LSTXPTR load/store a DWORD (long) in extended memory.

Keil Software — Cx51 Compiler User’s Guide

155

 

 

Each access routine gets as a parameter the memory address in a 3-byte pointer representation in the CPU registers R1/R2/R3. The register R3 holds the memory type value. For classic 8051 devices, the Cx51 compiler uses the following memory type values:

R3 Value

Memory Type

Memory Class

Address Range

0x00

data / idata

DATA / IDATA

I:0x00-I:0xFF

0x01

xdata

XDATA

X:0x0000-X:0xFFFF

0x02-0x7F

far

HDATA

X:0x010000-X:0x7E0000

0x80-0xFD

far const

HCONST

C:0x800000-C:0xFD0000 (far const is

 

 

 

mapped into the banked memory areas)

0xFE

pdata

XDATA

one 256-byte page in XDATA memory

0xFF

code

CODE / CONST

C:0x0000-C:0xFFFF

The R3 values 0x00, 0x01, 0xFE and 0xFF are already handled within the runtime library. Only the values 0x02 - 0xFE are passed to the XPTR access routines described above. The AX51 macro assembler provides the MBYTE operator that calculates the R3 value that needs to be passed to the XPTR access function. Below is an AX51 Assembler example for using XPTR access functions:

MOV

R1,#LOW

(variable)

; gives LSB address byte of variable

MOV

R1,#HIGH

(variable)

; gives MSB address byte of variable

MOV

R1,#MBYTE (variable)

; gives memory type byte of variable

CALL

?C?CLDXPTR

 

; load BYTE variable into A

6

156

Chapter 6. Advanced Programming Techniques

 

 

Basic I/O Functions

The following files contain the source code for the low-level stream I/O routines. When you use the µVision2 IDE, you can simply add the modified versions to the project.

C Source File

Description

PUTCHAR.C

Used by all stream routines that output characters. You may adapt this

 

routine to your individual hardware (for example, LCD or LED displays).

 

The default version outputs characters via the serial interface. An

 

XON/XOFF protocol is used for flow control. Linefeed characters (‘\n’) are

 

converted into carriage return/linefeed sequences (‘\r\n’).

GETKEY.C

Used by all stream routines that input characters. You may adapt this routine

 

to your individual hardware (for example, for matrix keyboards).

 

The default version reads a character via the serial interface. No data

 

conversions are performed.

Memory Allocation Functions

The following files contain the source code for the memory allocation routines.

 

 

C Source File

 

Description

 

 

 

CALLOC.C

 

Allocates memory for an array from the memory pool.

 

 

 

FREE.C

 

Returns a previously allocated memory block to the memory pool.

 

 

 

INIT_MEM.C

 

Specifies the location and size of a memory pool from which memory may be

 

6

 

 

 

allocated using the malloc, calloc, and realloc functions.

 

 

MALLOC.C

 

Allocates memory from the memory pool.

 

 

 

 

 

 

 

REALLOC.C

 

Resizes a previously allocated memory block.

 

 

 

 

 

 

 

Соседние файлы в папке HLP