使用单片机编程的朋友们都知道,常规的51系列单片机地址寻址空间只有64K,如果程序编写超过64K,那么只好通过增加外部程序存储器来实现目标,但是如果这样做无疑增加了硬件成本,单片机生产商为了解决这个问题,现在已经开发出可寻址128K、256K,甚至更大ROM的单片机。
但是熟知keil的人都知道,keil默认64K寻址,如果想要做超过64K的程序该如何设置呢?这就要利用keil开发出来的BL51功能,下面以芯唐单片机W77E532为例进行介绍,具体操作步骤如下:
首先打开keil并选择要使用的芯片,如W77E532,之后点击“USE EXTENDED LINKER(LX51) INSTEAD OF BL51”为选中状态;之后设置点击“TARGET”设置晶振频率和memory model为small、code rom size为large、operating为none,该窗口下面的“code banking”选中,同时设置bank分区,如W77E532为2,后面的START和END可以设置成0x0000和0xFFFF;接下来设置“OUTPUT”点击“Create HEX Fi:”从后面的下拉列表中选择“HEX-386”,这些全部设置完成后点击“确定”以完成设置。
接下来开始设置工程信息,点击菜单栏中的“project”并选择下面的“Components,Environment,Books…”项,在group中添加3个分区的文件目录,依次为root,bank和bank1,
之后在各个目录下面添加属于该目录的文件,
设置完成后点击“确定”保存。
当这些都设置完成后,在左侧“project workspace”区域对root,bank和bank1的code bank和stop on exit分别设置,依次为:
common和translator fatal errors (exit code >=3),
bank#0和translator fatal errors (exit code >=3),
bank#1和translator fatal errors (exit code >=3);
之后对各个目录右侧进行设置,只选择“include in target build”,其余为空状态,点击“确定”完成设置。
注意在root目录中必须有L51_BANK.A51和STARTUP.A51存在,而L51_BANK.A51文件根据用户使用进行实际配置,配置区域如下:
NOMOD51NOLINES NOCOND
;——————————————————————————
; This file is part of the BL51 / LX51 Banked Linker/Locater package
; Copyright (c) 1988 - 2005 Keil Elektronik GmbH and Keil Software, Inc.
; Version 2.21 (Code and Variable Banking for Classic 8051 Derivatives)
;——————————————————————————
; ************** Configuration Section *********************
?B_NBANKS EQU 2 ; Define maximum Number of Banks *
; ; following values are allowed: 2, 4, 8, 16, 32, 64 *
; ; for BL51 the maximum value for ?B_BANKS is 32 *
; ; for LX51 the maximum value for ?B_BANKS is 64 *
; *
?B_MODE EQU 0 ; 0 for Bank-Switching via 8051 Port *
; ; 1 for Bank-Switching via XDATA Port *
; ; 4 for user-provided bank switch code *
; *
?B_RTX EQU 0 ; 0 for applications without real-time OS *
; ; 1 for applications using the RTX-51 real-time OS *
; *
?B_VAR_BANKING EQU 1 ; Variable Banking via L51_BANK (far memory support)*
; ; 0 Variable Banking does not use L51_BANK.A51 *
; ; 1 Variable Banking uses this L51_BANK.A51 module *
; Notes: ?B_VAR_BANKING uses the ‘far’ and ‘far const’ C51 memory types to *
; extent the space for variables in RAM and/or ROM of classic 8051 *
; device. The same hardware as for code banking is used. Program *
; code banking and variable banking share the same hardware I/O pins. *
; The C51 Compiler must be used with the VARBANKING directive. *
; Variable Banking is only supported with the LX51 linker/locater. *
; *
?B_RST_BANK EQU 0 ; specifies the active code bank number after CPU *
; ; Reset. Used to reduce the entries in the *
; ; INTERBANK CALL TABLE. The value 0xFF disables *
; ; this LX51 linker/locater optimization. *
; Note: Interbank Call Table optimization is only possible with LX51. *
; *
;—————————————————————————–*
; *
IF ?B_MODE = 0; *
;—————————————————————————–*
; if ?BANK?MODE is 0 define the following values *
; For Bank-Switching via 8051 Port define Port Address / Bits *
; *
P1 DATA 90H ; I/O Port Address *
; *
?B_PORT EQU P1 ; default is P1 *
?B_FIRSTBIT EQU 7 ; default is Bit 2 *
;—————————————————————————–*
ENDIF;
以上部分需要用户根据分区数量和用途自行设置。
注意:root和bank可以看做在一个分区,初始化的时候将这两个目录分在一起,bank1要靠root选择,一般使用P1口的后面几个引脚做分区使用,不能外接设备。
但是熟知keil的人都知道,keil默认64K寻址,如果想要做超过64K的程序该如何设置呢?这就要利用keil开发出来的BL51功能,下面以芯唐单片机W77E532为例进行介绍,具体操作步骤如下:
首先打开keil并选择要使用的芯片,如W77E532,之后点击“USE EXTENDED LINKER(LX51) INSTEAD OF BL51”为选中状态;之后设置点击“TARGET”设置晶振频率和memory model为small、code rom size为large、operating为none,该窗口下面的“code banking”选中,同时设置bank分区,如W77E532为2,后面的START和END可以设置成0x0000和0xFFFF;接下来设置“OUTPUT”点击“Create HEX Fi:”从后面的下拉列表中选择“HEX-386”,这些全部设置完成后点击“确定”以完成设置。
接下来开始设置工程信息,点击菜单栏中的“project”并选择下面的“Components,Environment,Books…”项,在group中添加3个分区的文件目录,依次为root,bank和bank1,
之后在各个目录下面添加属于该目录的文件,
设置完成后点击“确定”保存。
当这些都设置完成后,在左侧“project workspace”区域对root,bank和bank1的code bank和stop on exit分别设置,依次为:
common和translator fatal errors (exit code >=3),
bank#0和translator fatal errors (exit code >=3),
bank#1和translator fatal errors (exit code >=3);
之后对各个目录右侧进行设置,只选择“include in target build”,其余为空状态,点击“确定”完成设置。
注意在root目录中必须有L51_BANK.A51和STARTUP.A51存在,而L51_BANK.A51文件根据用户使用进行实际配置,配置区域如下:
NOMOD51NOLINES NOCOND
;——————————————————————————
; This file is part of the BL51 / LX51 Banked Linker/Locater package
; Copyright (c) 1988 - 2005 Keil Elektronik GmbH and Keil Software, Inc.
; Version 2.21 (Code and Variable Banking for Classic 8051 Derivatives)
;——————————————————————————
; ************** Configuration Section *********************
?B_NBANKS EQU 2 ; Define maximum Number of Banks *
; ; following values are allowed: 2, 4, 8, 16, 32, 64 *
; ; for BL51 the maximum value for ?B_BANKS is 32 *
; ; for LX51 the maximum value for ?B_BANKS is 64 *
; *
?B_MODE EQU 0 ; 0 for Bank-Switching via 8051 Port *
; ; 1 for Bank-Switching via XDATA Port *
; ; 4 for user-provided bank switch code *
; *
?B_RTX EQU 0 ; 0 for applications without real-time OS *
; ; 1 for applications using the RTX-51 real-time OS *
; *
?B_VAR_BANKING EQU 1 ; Variable Banking via L51_BANK (far memory support)*
; ; 0 Variable Banking does not use L51_BANK.A51 *
; ; 1 Variable Banking uses this L51_BANK.A51 module *
; Notes: ?B_VAR_BANKING uses the ‘far’ and ‘far const’ C51 memory types to *
; extent the space for variables in RAM and/or ROM of classic 8051 *
; device. The same hardware as for code banking is used. Program *
; code banking and variable banking share the same hardware I/O pins. *
; The C51 Compiler must be used with the VARBANKING directive. *
; Variable Banking is only supported with the LX51 linker/locater. *
; *
?B_RST_BANK EQU 0 ; specifies the active code bank number after CPU *
; ; Reset. Used to reduce the entries in the *
; ; INTERBANK CALL TABLE. The value 0xFF disables *
; ; this LX51 linker/locater optimization. *
; Note: Interbank Call Table optimization is only possible with LX51. *
; *
;—————————————————————————–*
; *
IF ?B_MODE = 0; *
;—————————————————————————–*
; if ?BANK?MODE is 0 define the following values *
; For Bank-Switching via 8051 Port define Port Address / Bits *
; *
P1 DATA 90H ; I/O Port Address *
; *
?B_PORT EQU P1 ; default is P1 *
?B_FIRSTBIT EQU 7 ; default is Bit 2 *
;—————————————————————————–*
ENDIF;
以上部分需要用户根据分区数量和用途自行设置。
注意:root和bank可以看做在一个分区,初始化的时候将这两个目录分在一起,bank1要靠root选择,一般使用P1口的后面几个引脚做分区使用,不能外接设备。