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

150

Chapter 6. Advanced Programming Techniques

 

 

Customization Files

The Cx51 compiler provides a number of source files you can modify to adapt your target program to a specific hardware platform. These files contain:

Code that is executed upon startup (STARTUP.A51)

Code that is used to initialize static variables (INIT.A51)

Code that is used to perform low-level stream I/O

Code for memory allocation

The code contained in these files is already compiled or assembled and included in the C library. When you link your program, the code from the library is automatically included.

You may customize these files to adjust them to your requirements. If you are working with the µVision2 IDE, we recommend that you copy the customization file in your project folder to make modifications. The modified version of the file can be added the same way as other source files to your project.

When you are working with command-line tools, you must include the object files of the modified customization files in the linker command line. The following example shows you how to include custom replacement files for

STARTUP.A51 and PUTCHAR.C:

Lx51 MYMODUL1.OBJ, MYMODUL2.OBJ, STARTUP.OBJ, PUTCHAR.OBJ

6

The file XBANKING.A51

allows you to change the configuration of the extended

 

far memory access rountines.

Keil Software — Cx51 Compiler User’s Guide

151

 

 

STARTUP.A51

The STARTUP.A51 file contains the startup code for a Cx51 target program. This source file is located in the LIB directory. Include a copy of this file in each 8051 project that needs custom startup code.

The startup code is executed immediately upon reset of the target system and optionally performs the following operations, in order:

Clears internal data memory

Clears external data memory

Clears paged external data memory

Initializes the small model reentrant stack and pointer

Initializes the large model reentrant stack and pointer

Initializes the compact model reentrant stack and pointer

Initializes the 8051 hardware stack pointer

Transfers control to the main C function

The STARTUP.A51 file provides you with assembly constants that you may change to control the actions taken at startup. These are defined in the following table.

Constant Name

Description

 

 

6

IDATALEN

Indicates the number of bytes of idata that are to be initialized to 0. The

 

 

default is 80h because most 8051 derivatives contain at least 128 bytes of

 

 

internal data memory. Use a value of 100h for the 8052 and other derivatives

 

 

 

that have 256 bytes of internal data memory.

 

 

 

 

 

 

 

XDATASTART

Specifies the xdata address to start initializing to 0.

 

 

 

XDATALEN

Indicates the number of bytes of xdata to be initialized to 0.

The default is 0.

 

 

PDATASTART

Specifies the pdata address to start initializing to 0.

 

 

 

PDATALEN

Indicates the number of bytes of pdata to be initialized to 0.

The default is 0.

 

 

IBPSTACK

Indicates whether or not the small model reentrant stack pointer (?C_IBP)

 

 

 

should be initialized. A value of 1 causes this pointer to be initialized. A

 

 

 

value of 0 prevents initialization of this pointer. The default is 0.

 

 

IBPSTACKTOP

Specifies the top start address of the small model reentrant stack area. The

 

 

 

default is 0xFF in idata memory.

 

 

 

 

The Cx51 compiler does not check to see if the stack area available satisfies

 

 

 

the requirements of the applications. It is your responsibility to perform such

 

 

 

a test.

 

 

 

 

 

152

 

Chapter 6. Advanced Programming Techniques

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Constant Name

Description

 

 

 

 

XBPSTACK

Indicates whether or not the large model reentrant stack pointer (?C_XBP)

 

 

 

 

 

should be initialized. A value of 1 causes this pointer to be initialized. A

 

 

 

 

 

value of 0 prevents initialization of this pointer. The default is 0.

 

 

 

 

XBPSTACKTOP

Specifies the top start address of the large model reentrant stack area. The

 

 

 

 

 

default is 0xFFFF in xdata memory.

 

 

 

 

 

The Cx51 compiler does not check to see if the available stack area satisfies

 

 

 

 

 

the requirements of the applications. It is your responsibility to perform such

 

 

 

 

 

a test.

 

 

 

 

PBPSTACK

Indicates whether the compact model reentrant stack pointer (?C_PBP)

 

 

 

 

 

should be initialized. A value of 1 causes this pointer to be initialized. A

 

 

 

 

 

value of 0 prevents initialization of this pointer. The default is 0.

 

 

 

 

PBPSTACKTOP

Specifies the top start address of the compact model reentrant stack area.

 

 

 

 

 

The default is 0xFF in pdata memory.

 

 

 

 

 

The Cx51 compiler does not check to see if the available stack area satisfies

 

 

 

 

 

the requirements of the applications. It is your responsibility to perform such

 

 

 

 

 

a test.

 

 

 

 

PPAGEENABLE

Enables (a value of 1) or disables (a value of 0) the initialization of port 2 of

 

 

 

 

 

the 8051 device. The default is 0. The addressing of port 2 allows the

 

 

 

 

 

mapping of 256 byte variable memory in any arbitrary xdata page.

 

 

 

 

PPAGE

Specifies the value to write to Port 2 of the 8051 for pdata memory access.

 

 

 

 

 

This value represents the xdata memory page to use for pdata. This is the

 

 

 

 

 

upper 8 bits of the absolute address range to use for pdata.

 

 

 

 

 

For example, if the pdata area begins at address 1000h (page 10h) in the

 

 

 

 

 

xdata memory, PPAGEENABLE should be set to 1, and PPAGE should be

 

 

 

 

 

set to 10h. The BL51 Linker/Locator must contain a value between 1000h

 

 

 

 

 

and 10FFh in the PDATA directive. For example:

 

 

 

 

 

BL51 <input modules> PDATA (1050H)

 

 

 

 

 

Neither BL51 nor Cx51 checks to see if the PDATA directive and the PPAGE

 

 

 

 

 

assembler constant are correctly specified. You must ensure that these

 

6

 

 

 

parameters contain suitable values.

 

 

 

There are numerous devices in the 8051 family that require special startup code.

 

 

 

 

 

 

The following list provides an overview of the various startup versions:

 

 

 

 

 

 

 

 

Startup File

Description

 

 

 

 

STARTUP.A51

Standard startup code for classic 8051 devices.

 

 

 

 

START_AD.A51

Startup code for Analog Devices MicroConverters B2 series variants.

 

 

 

 

STARTLPC.A51

Startup code for Philips LPC variants.

 

 

 

 

START390.A51

Startup code for Dallas 80C390, 80C400, 5240 contigious mode.

 

 

 

 

START_MX.A51

Startup code for Philips 80C51MX architecture.

 

 

 

 

START751.A51

Startup code for Philips 80C75x variants.

 

Keil Software — Cx51 Compiler User’s Guide

153

 

 

INIT.A51

The INIT.A51 file contains the initialization routine for variables that were explicitly initialized. If your system is equipped with a watchdog timer, you can integrate a watchdog refresh into the initialization code using the watchdog macro. This macro needs to be defined only if the initialization takes longer than the watchdog cycle time. For example, if you are using an Infineon C515, the macro could be defined as follows:

WATCHDOG MACRO

SETB WDT

SETB SWDT

ENDM

The INIT_TNY.A51 file is a reduced version of INIT.A51 that may be used for projects that do not contain XDATA memory. You should use this file when you write code for single-chip devices, like the Philips LPC series, that contain variable initializations in data space.

6

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