中断声明方法如下:void serial_ISR () interrupt 4 [using 1]{/* ISR */}为提高代码的容错能力,在没用到的中断入口处生成iret语句,定义没用到的中断。/* define not used interrupt, so generate \"IRET\" in their entrance */void extern0_ISR() interrupt 0{} /* not used */void timer0_ISR () interrupt 1{} /* not used */void extern1_ISR() interrupt 2{} /* not used */void timer1_ISR () interrupt 3{} /* not used */void serial_ISR () interrupt 4{} /* not used */
2. 通用存储工作区
3. 选通用存储工作区由using x声明,见上例。
4. 指定存储模式
由small compact 及large说明,例如:void fun1(void) small { }提示:small说明的函数内部变量全部使用内部RAM。关键的经常性的耗时的地方可以这样声明,以提高运行速度。
直接在数据定义后加上_at_ const即可,但是注意:(1)绝对变量不能被初使化;(2)bit型函数及变量不能用_at_指定。例如:idata struct link list _at_ 0x40;指定list结构从40h开始。xdata char text[25b] _at_0xE000;指定text数组从0E000H开始提示:如果外部绝对变量是I/O端口等可自行变化数据,需要使用volatile关键字进行描述,请参考absacc.h。
启动文件STARTUP.A51中包含目标板启动代码,可在每个project中加入这个文件,只要复位,则该文件立即执行,其功能包括:l 定义内部RAM大小、外部RAM大小、可重入堆栈位置l 清除内部、外部或者以此页为单元的外部存储器l 按存储模式初使化重入堆栈及堆栈指针l 初始化8051硬件堆栈指针l 向main( )函数交权开发人员可修改以下数据从而对系统初始化 常数名 意义IDATALEN 待清内部RAM长度XDATA START 指定待清外部RAM起始地址XDATALEN 待清外部RAM长度IBPSTACK 是否小模式重入堆栈指针需初始化标志,1为需要。缺省为0IBPSTACKTOP 指定小模式重入堆栈顶部地址XBPSTACK 是否大模式重入堆栈指针需初始化标志,缺省为0XBPSTACKTOP 指定大模式重入堆栈顶部地址PBPSTACK 是否Compact重入堆栈指针,需初始化标志,缺省为0PBPSTACKTOP 指定Compact模式重入堆栈顶部地址PPAGEENABLE P2初始化允许开关PPAGE 指定P2值PDATASTART 待清外部RAM页首址PDATALEN 待清外部RAM页长度提示:如果要初始化P2作为紧凑模式高端地址,必须:PPAGEENAGLE=1,PPAGE为P2值,例如指定某页1000H-10FFH,则PPAGE=10H,而且连接时必须如下:L51 PDATA(1080H),其中1080H是1000H-10FFH中的任一个值。以下是STARTUP.A51代码片断,红色是经常可能需要修改的地方:;------------------------------------------------------------------------------; This file is part of the C51 Compiler package; Copyright KEIL ELEKTRONIK GmbH 1990;------------------------------------------------------------------------------; STARTUP.A51: This code is executed after processor reset.;; To translate this file use A51 with the following invocation:;; A51 STARTUP.A51;; To link the modified STARTUP.OBJ file to your application use the following; L51 invocation:;; L51 , STARTUP.OBJ ;;------------------------------------------------------------------------------;; User-defined Power-On Initialization of Memory;; With the following EQU statements the initialization of memory; at processor reset can be defined:;; ; the absolute start-address of IDATA memory is always 0IDATALEN EQU 80H ; the length of IDATA memory in bytes.;XDATASTART EQU 0H ; the absolute start-address of XDATA memoryXDATALEN EQU 0H ; the length of XDATA memory in bytes.;PDATASTART EQU 0H ; the absolute start-address of PDATA memoryPDATALEN EQU 0H ; the length of PDATA memory in bytes.;; Notes: The IDATA space overlaps physically the DATA and BIT areas of the; 8051 CPU. At minimum the memory space occupied from the C51 ; run-time routines must be set to zero.;------------------------------------------------------------------------------;; Reentrant Stack Initilization;; The following EQU statements define the stack pointer for reentrant; functions and initialized it:;; Stack Space for reentrant functions in the SMALL model.IBPSTACK EQU 0 ; set to 1 if small reentrant is used.IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1.;; Stack Space for reentrant functions in the LARGE model. XBPSTACK EQU 0 ; set to 1 if large reentrant is used.XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.;; Stack Space for reentrant functions in the COMPACT model. PBPSTACK EQU 0 ; set to 1 if compact reentrant is used.PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1.;;------------------------------------------------------------------------------;; Page Definition for Using the Compact Model with 64 KByte xdata RAM;; The following EQU statements define the xdata page used for pdata; variables. The EQU PPAGE must conform with the PPAGE control used; in the linker invocation.;PPAGEENABLE EQU 0 ; set to 1 if pdata object are used.PPAGE EQU 0 ; define PPAGE number.;;------------------------------------------------------------------------------