STC — 8051单片机全球第一品牌,全球最大的8051单片机设计公司
官方网站:www.STCMCU.com
www.GXWMCU.com
STC12C5A60S2系列单片机器件手册
---
加������������
�������������
密�����������
性强,有全球唯一ID号
---ISP/IAP,在线编程,无需编程器/仿真器
---双串口,两个独立串口
---高速10位A/D转换器,8通道
---1个时钟/机器周期8051
---高速,高可靠
---低功耗,超低价
---强抗静电,强抗干扰
STC12C5A08S2,
STC12C5A16S2,
STC12C5A20S2,
STC12C5A32S2,
STC12C5A40S2,
STC12C5A48S2,
STC12C5A52S2,
STC12C5A56S2,
STC12C5A60S2,
STC12C5A62S2,
C
T
S
U
C
M
d
e
t
i
im
STC12C5A08AD
STC12C5A16AD
STC12C5A20AD
STC12C5A32AD
STC12C5A40AD
STC12C5A48AD
STC12C5A52AD
STC12C5A56AD
STC12C5A60AD
STC12C5A62AD
L
STC-ISP:最方便的在线升级软件,无需编程器,无需仿真器
STC——8051单片机全球第一品牌,全球最大的8051单片机设计公司
请同行不要再抄袭我们的设计、规格和管脚排列,再抄袭就很无耻了
全部中国本土独立自主知识产权,请全体中国人民支持,您的支持是中国本土
力量前进的������
有力保证.
封装后,全部175oC八小时高温烘烤,高品质制造保证
技术支持网站:www.STCMCU.com
www.GXWMCU.com
Update date: 2013/12/30
STC12C5A60S2系列单片机指南
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
研发顾问QQ:800003751
超强抗干扰,超级加密
TM
STC micro
8051单片机全球第一品牌,全球最大的8051单片机设计公司
全部中国大陆本土独立自主知识产权;品质保证:TSMC上海制造
宏 晶 科 技
www.STCMCU.com
官方网站:
www.GXWMCU.com
南通 Tel: 0513-5501 2928 5501 2929
深圳 Tel: 0755-8294 8411 8294 8412
P0
IAP
1T 8051
看门狗
STC
集成MAX810
专用复位电路
集成片内
R/C时钟
5组8位
微处理器
超低功耗,超低价
并行端口
P0/P1
高速(0-35M),高可靠
P2/P3/P4
超强抗干扰,超级加密
+
P5.0 - P5.3
1T 8051单片机,最快指令快24倍
增加了外部低压检测电路和第二功能复位脚/P4.6
掉电模式:
<
>=
equals
not equals
less than
less than or equal to
greater than
greater than or equal to
Note that for each operator, two forms are acceptable (e.g., "EQ" or "="). In the following examples, all relational
tests are "true":
MOV A, #5 = 5
MOV A,#5 NE 4
MOV A,# 'X' LT 'Z'
MOV A,# 'X' >= 'X'
MOV A,#$ > 0
MOV A,#100 GE 50
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
553
STC12C5A60S2系列单片机指南
技术支持网站:www.GXWMCU.com
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
So, the assembled instructions are equal to
MOV
A, #0FFH
Even though expressions evaluate to 16-bit results (i.e., 0FFFFH), in the examples above only the low-order eight
bits are used, since the instruction is a move byte operation. The result is not considered too big in this case, because as signed numbers the 16-bit value FFFFH and the 8-bit value FFH are the same (-1).
Expression Examples
The following are examples of expressions and the values that result:
Expression
Result
'B' - 'A'
0001H
8/3
0002H
155 MOD 2
0001H
4 * 4
0010H
8 AND 7
0000H
NOT 1
FFFEH
'A' SHL 8
4100H
LOW 65535
00FFH
(8 + 1) * 2
0012H
5 EQ 4
0000H
'A' LT 'B'
FFFFH
3 < >=
NOT
AND
OR XOR
When operators of the same precedence are used, they are evaluated left to right.
Examples:
Expression
Value
HIGH ( 'A' SHL 8)
0041H
HIGH 'A' SHL 8
0000H
NOT 'A' - 1
FFBFH
'A' OR 'A' SHL 8
4141H
554
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
ASSEMBLER DIRECTIVES
Assembler directives are instructions to the assembler program. They are not assembly language instructions executable by the target microprocessor. However, they are placed in the mnemonic field of the program. With the
exception of DB and DW, they have no direct effect on the contents of memory.
ASM51 provides several catagories of directives:
Assembler state control (ORG, END, USING)
Symbol definition (SEGMENT, EQU, SET, DATA, IDATA, XDATA, BIT, CODE)
Storage initialization/reservation (DS, DBIT, DB, DW)
Program linkage (PUBLIC, EXTRN,NAME)
Segment selection (RSEG, CSEG, DSEG, ISEG, ESEG, XSEG)
Each assembler directive is presented below, ordered by catagory.
Assembler State Control
ORG (Set Origin)
The format for the ORG (set origin) directive is
ORG
expression
The ORG directive alters the location counter to set a new program origin for statements that follow. A label is
not permitted. Two examples follow.
ORG
ORG
.
d
e
t
i
m
Li
100H
;SET LOCATION COUNTER TO 100H
($ + 1000H) AND 0F00H ;SET TO NEXT 4K BOUNDARY
U
C
M
The ORG directive can be used in any segment type. If the current segment is absolute, the value will be an absolute address in the current segment. If a relocatable segment is active, the value of the ORG expression is treated
as an offset from the base address of the current instance of the segment.
End
C
T
S
The format of the END directive is
END
END should be the last statement in the source file. No label is permitted and nothing beyond the END statement
is processed by the assembler.
Using
The format of the END directive is
USING expression
This directive informs ASM51 of the currently active register bank. Subsequent uses of the predefined symbolic
register addresses AR0 to AR7 will convert to the appropriate direct address for the active register bank. Consider
the following sequence:
USING
PUSH
USING
PUSH
3
AR7
1
AR7
The first push above assembles to PUSH 1FH (R7 in bank 3), whereas the second push assembles to PUSH 0FH
(R7 in bank 1).
Note that USING does not actually switch register banks; it only informs ASM51 of the active bank. Executing 8051 instructions is the only way to switch register banks. This is illustrated by modifying the example above
as follows:
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
555
STC12C5A60S2系列单片机指南
MOV
USING
PUSH
MOV
USING
PUSH
技术支持网站:www.GXWMCU.com
PSW, #00011000B
3
AR7
PSW, #00001000B
1
AR7
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
;SELECT REGISTER BANK 3
;ASSEMBLE TO PUSH 1FH
;SELECT REGISTER BANK 1
;ASSEMBLE TO PUSH 0FH
Symbol Definition
The symbol definition directives create symbols that represent segment, registers, numbers, and addresses. None
of these directives may be preceded by a label. Symbols defined by these directives may not have been previously
defined and may not be redefined by any means. The SET directive is the only exception. Symbol definiton directives are described below.
Segment
The format for the SEGMENT directive is shown below.
symbol
SEGMENT
segment_type
.
d
e
t
i
m
The symbol is the name of a relocatable segment. In the use of segments, ASM51 is more complex than conventional assemblers, which generally support only "code" and "data" segment types. However, ASM51 defines additional segment types to accommodate the diverse memory spaces in the 8051. The following are the defined 8051
segment types (memory spaces):
Li
CODE (the code segment)
XDATA (the external data space)
DATA (the internal data space accessible by direct addressing, 00H–07H)
IDATA (the entire internal data space accessible by indirect addressing, 00H–07H)
BIT (the bit space; overlapping byte locations 20H–2FH of the internal data space)
C
T
S
U
C
M
For example, the statement
EPROM
SEGMENT
CODE
declares the symbol EPROM to be a SEGMENT of type CODE. Note that this statement simply declares what
EPROM is. To actually begin using this segment, the RSEG directive is used (see below).
EQU (Equate)
Symbol
The format for the EQU directive is
EQU
expression
The EQU directive assigns a numeric value to a specified symbol name. The symbol must be a valid symbol
name, and the expression must conform to the rules described earlier.
The following are examples of the EQU directive:
N27
EQU
27
HERE
EQU
$
CR
EQU
0DH
MESSAGE:
DB 'This is a message'
LENGTH
EQU
$ - MESSAGE
;SET N27 TO THE VALUE 27
;SET "HERE" TO THE VALUE OF
;THE LOCATION COUNTER
;SET CR (CARRIAGE RETURN) TO 0DH
;"LENGTH" EQUALS LENGTH OF "MESSAGE"
Other Symbol Definition Directives
The SET directive is similar to the EQU directive except the
symbol may be redefined later, using another SET directive.
556
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
The DATA, IDATA, XDATA, BIT, and CODE directives assign addresses of the corresponding segment type
to a symbol. These directives are not essential. A similar effect can be achieved using the EQU directive; if used,
however, they evoke powerful type-checking by ASM51. Consider the following two directives and four instructions:
FLAG1
FLAG2
EQU
BIT
SETB
SETB
MOV
MOV
05H
05H
FLAG1
FLAG2
FLAG1, #0
FLAG2, #0
The use of FLAG2 in the last instruction in this sequence will generate a "data segment address expected" error
message from ASM51. Since FLAG2 is defined as a bit address (using the BIT directive), it can be used in a set
bit instruction, but it cannot be used in a move byte instruction. Hence, the error. Even though FLAG1 represents
the same value (05H), it was defined using EQU and does not have an associated address space. This is not an
advantage of EQU, but rather, a disadvantage. By properly defining address symbols for use in a specific memory
space (using the directives BIT, DATA, XDATA,ect.), the programmer takes advantage of ASM51's powerful
type-checking and avoids bugs from the misuse of symbols.
.
d
e
t
i
m
Storage Initialization/Reservation
U
C
M
Li
The storage initialization and reservation directives initialize and reserve space in either word, byte, or bit units.
The space reserved starts at the location indicated by the current value of the location counter in the currently active segment. These directives may be preceded by a label. The storage initialization/reservation directives are
described below.
C
T
S
DS (Define Storage)
[label:]
The format for the DS (define storage) directive is
DS
expression
The DS directive reserves space in byte units. It can be used in any segment type except BIT. The expression
must be a valid assemble-time expression with no forward references and no relocatable or external references.
When a DS statement is encountered in a program, the location counter of the current segment is incremented by
the value of the expression. The sum of the location counter and the specified expression should not exceed the
limitations of the current address space.
The following statement create a 40-byte buffer in the internal data segment:
LENGTH
BUFFER:
DSEG AT
30H
EQU
40
DS
LENGRH
;PUT IN DATA SEGMENT (ABSOLUTE, INTERNAL)
;40 BYTES RESERVED
The label BUFFER represents the address of the first location of reserved memory. For this example, the buffer
begins at address 30H because "AT 30H" is specified with DSEG. The buffer could be cleared using the following
instruction sequence:
LOOP:
MOV R7,
MOV R0,
MOV @R0,
DJNZ R7,
(continue)
南通国芯微电子有限公司
#LENGTH
#BUFFER
#0
LOOP
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
557
STC12C5A60S2系列单片机指南
技术支持网站:www.GXWMCU.com
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
To create a 1000-byte buffer in external RAM starting at 4000H, the following directives could be used:
XSTART
XLENGTH
XBUFFER:
EQU
4000H
EQU
1000
XSEG
AT
DS XLENGTH
XSTART
This buffer could be cleared with the following instruction sequence:
LOOP:
MOV
DPTR, #XBUFFER
CLR
A
MOVX @DPTR, A
INC
DPTR
MOV
A,
DPL
CJNE
A,
#LOW (XBUFFER + XLENGTH + 1), LOOP
MOV
A,
DPH
CJNE
A,
#HIGH (XBUFFER + XLENGTH + 1), LOOP
(continue)
.
d
e
t
i
m
This is an excellent example of a powerful use of ASM51's operators and assemble-time expressions. Since an
instruction does not exist to compare the data pointer with an immediate value, the operation must be fabricated
from available instructions. Two compares are required, one each for the high- and low-bytes of the DPTR. Furthermore, the compare-and-jump-if-not-equal instruction works only with the accumulator or a register, so the
data pointer bytes must be moved into the accumulator before the CJNE instruction. The loop terminates only
when the data pointer has reached XBUFFER + LENGTH + 1. (The "+1" is needed because the data pointer is
incremented after the last MOVX instruction.)
DBIT
U
C
M
Li
The format for the DBIT (define bit) directive is,
[label:]
C
T
S
DBIT
expression
The DBIT directive reserves space in bit units. It can be used only in a BIT segment. The expression must be a
valid assemble-time expression with no forward references. When the DBIT statement is encountered in a program, the location counter of the current (BIT) segment is incremented by the value of the expression. Note that
in a BIT segment, the basic unit of the location counter is bits rather than bytes. The following directives creat
three flags in a absolute bit segment:
KEFLAG:
PRFLAG:
DKFLAG:
BSEG
DBIT 1
DBIT 1
DBIT 1
;BIT SEGMENT (ABSOLUTE)
;KEYBOARD STATUS
;PRINTER STATUS
;DISK STATUS
Since an address is not specified with BSEG in the example above, the address of the flags defined by DBIT
could be determined (if one wishes to to so) by examining the symbol table in the .LST or .M51 files. If the definitions above were the first use of BSEG, then KBFLAG would be at bit address 00H (bit 0 of byte address 20H).
If other bits were defined previously using BSEG, then the definitions above would follow the last bit defined.
DB (Define Byte)
[label:]
The format for the DB (define byte) directive is,
DB
expression [, expression] […]
The DB directive initializes code memory with byte values. Since it is used to actually place data constants in
code memory, a CODE segment must be active. The expression list is a series of one or more byte values (each of
which may be an expression) separated by commas.
558
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
The DB directive permits character strings (enclosed in single quotes) longer than two characters as long as they
are not part of an expression. Each character in the string is converted to the corresponding ASCII code. If a label
is used, it is assigned the address of th first byte. For example, the following statements
SQUARES:
MESSAGE:
CSEG AT
0100H
DB
0, 1, 4, 9, 16, 25
DB
'Login:', 0
;SQUARES OF NUMBERS 0-5
;NULL-TERMINATED CHARACTER STRING
When assembled, result in the following hexadecimal memory assignments for external code memory:
Address
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
Contents
00
01
04
09
10
19
4C
6F
67
69
6E
3A
00
DW (Define Word)
[label:]
.
d
e
t
i
m
U
C
M
Li
The format for the DW (define word) directive is
DW
C
T
S
expression
[, expression] […]
The DW directive is the same as the DB directive except two memory locations (16 bits) are assigned for each
data item. For example, the statements
CSEG
DW
AT
200H
$, 'A', 1234H, 2, 'BC'
result in the following hexadecimal memory assignments:
Address
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
Contents
02
00
00
41
12
34
00
02
42
43
Program Linkage
Program linkage directives allow the separately assembled modules (files) to communicate by permitting intermodule references and the naming of modules. In the following discussion, a "module" can be considered a "file."
(In fact, a module may encompass more than one file.)
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
559
STC12C5A60S2系列单片机指南
Public
技术支持网站:www.GXWMCU.com
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
The format for the PUBLIC (public symbol) directive is
PUBLIC
symbol
[, symbol] […]
The PUBLIC directive allows the list of specified symbols to known and used outside the currently assembled
module. A symbol declared PUBLIC must be defined in the current module. Declaring it PUBLIC allows it to be
referenced in another module. For example,
PUBLIC
Extrn
INCHAR, OUTCHR, INLINE, OUTSTR
The format for the EXTRN (external symbol) directive is
EXTRN
segment_type (symbol [, symbol] […], …)
The EXTRN directive lists symbols to be referenced in the current module that are defined in other modules. The
list of external symbols must have a segment type associated with each symbol in the list. (The segment types are
CODE, XDATA, DATA, IDATA, BIT, and NUMBER. NUMBER is a type-less symbol defined by EQU.) The
segment type indicates the way a symbol may be used. The information is important at link-time to ensure symbols are used properly in different modules.
The PUBLIC and EXTRN directives work together. Consider the two files, MAIN.SRC and MESSAGES.
SRC. The subroutines HELLO and GOOD_BYE are defined in the module MESSAGES but are made available
to other modules using the PUBLIC directive. The subroutines are called in the module MAIN even though they
are not defined there. The EXTRN directive declares that these symbols are defined in another module.
.
d
e
t
i
m
MAIN.SRC:
EXTRN
…
CALL
…
CALL
…
END
C
T
S
U
C
M
Li
CODE (HELLO, GOOD_BYE)
HELLO
GOOD_BYE
MESSAGES.SRC:
HELLO:
GOOD_BYE:
PUBLIC
HELLO, GOOD_BYE
…
(begin subroutine)
…
RET
(begin subroutine)
…
RET
…
END
Neither MAIN.SRC nor MESSAGES.SRC is a complete program; they must be assembled separately and
linked together to form an executable program. During linking, the external references are resolved with correct
addresses inserted as the destination for the CALL instructions.
Name
560
The format for the NAME directive is
NAME module_name
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
All the usual rules for symbol names apply to module names. If a name is not provided, the module takes on
the file name (without a drive or subdirectory specifier and without an extension). In the absence of any use of
the NAME directive, a program will contain one module for each file. The concept of "modules," therefore, is
somewhat cumbersome, at least for relatively small programming problems. Even programs of moderate size (encompassing, for example, several files complete with relocatable segments) needn't use the NAME directive and
needn't pay any special attention to the concept of "modules." For this reason, it was mentioned in the definition
that a module may be considered a "file," to simplify learning ASM51. However, for very large programs (several
thousand lines of code, or more), it makes sense to partition the problem into modules, where, for example, each
module may encompass several files containing routines having a common purpose.
Segment Selection Directives
When the assembler encounters a segment selection directive, it diverts the following code or data into the selected segment until another segment is selected by a segment selection directive. The directive may select may select
a previously defined relocatable segment or optionally create and select absolute segments.
RSEG (Relocatable Segment)
RSEG
.
d
e
t
i
m
The format for the RSEG (relocatable segment) directive is
segment_name
Li
Where "segment_name" is the name of a relocatable segment previously defined with the SEGMENT directive.
RSEG is a "segment selection" directive that diverts subsequent code or data into the named segment until another
segment selection directive is encountered.
Selecting Absolute Segments
hand, is selected using one of the directives:
CSEG
DSEG
ISEG
BSEG
XSEG
(AT
(AT
(AT
(AT
(AT
address)
address)
address)
address)
address)
C
T
S
U
C
M
RSEG selects a relocatable segment. An "absolute" segment, on the other
These directives select an absolute segment within the code, internal data, indirect internal data, bit, or external
data address spaces, respectively. If an absolute address is provided (by indicating "AT address"), the assembler
terminates the last absolute address segment, if any, of the specified segment type and creates a new absolute segment starting at that address. If an absolute address is not specified, the last absolute segment of the specified type
is continuted. If no absolute segment of this type was previously selected and the absolute address is omitted, a
new segment is created starting at location 0. Forward references are not allowed and start addresses must be absolute.
Each segment has its own location counter, which is always set to 0 initially. The default segment is an absolute code segment; therefore, the initial state of the assembler is location 0000H in the absolute code segment.
When another segment is chosen for the first time, the location counter of the former segment retains the last
active value. When that former segment is reselected, the location counter picks up at the last active value. The
ORG directive may be used to change the location counter within the currently selected segment.
ASSEMBLER CONTROLS
Assembler controls establish the format of the listing and object files by regulating the actions of ASM51. For the
most part, assembler controls affect the look of the listing file, without having any affect on the program itself.
They can be entered on the invocation line when a program is assembled, or they can be placed in the source file.
Assembler controls appearing in the source file must be preceded with a dollor sign and must begin in column 1.
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
561
STC12C5A60S2系列单片机指南
技术支持网站:www.GXWMCU.com
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
There are two categories of assembler controls: primary and general. Primary controls can be placed in the
invocation line or at the beginnig of the source program. Only other primary controls may precede a primary control. General controls may be placed anywhere in the source program.
LINKER OPERATION
In developing large application programs, it is common to divide tasks into subprograms or modules containing
sections of code (usually subroutines) that can be written separately from the overall program. The term "modular programming" refers to this programming strategy. Generally, modules are relocatable, meaning they are not
intended for a specific address in the code or data space. A linking and locating program is needed to combine the
modules into one absolute object module that can be executed.
Intel's RL51 is a typical linker/locator. It processes a series of relocatable object modules as input and creates
an executable machine language program (PROGRAM, perhaps) and a listing file containing a memory map and
symbol table (PROGRAM.M51). This is illustrated in following figure.
.
d
e
t
i
m
PROGRAM.ABS
FILE3.OBJ
FILE2.OBJ
RL51
FILE1.OBJ
Legend
Utility program
User file
C
T
S
CU
Li
PROGRAM.MAP
M
Linker operation
As relocatable modules are combined, all values for external symbols are resolved with values inserted into
the output file. The linker is invoked from the system prompt by
RL51
input_list
[T0 output_file]
[location_controls]
The input_list is a list of relocatable object modules (files) separated by commas. The output_list is the name
of the output absolute object module. If none is supplied, it defaults to the name of the first input file without any
suffix. The location_controls set start addresses for the named segments.
For example, suppose three modules or files (MAIN.OBJ, MESSAGES.OBJ, and SUBROUTINES.OBJ) are
to be combined into an executable program (EXAMPLE), and that these modules each contain two relocatable
segments, one called EPROM of type CODE, and the other called ONCHIP of type DATA. Suppose further that
the code segment is to be executable at address 4000H and the data segment is to reside starting at address 30H (in
internal RAM). The following linker invocation could be used:
RS51
MAIN.OBJ, MESSAGES.OBJ, SUBROUTINES.OBJ TO EXAMPLE & CODE
(EPROM (4000H) DATA (ONCHIP (30H))
Note that the ampersand character "&" is used as the line continuaton character.
If the program begins at the label START, and this is the first instruction in the MAIN module, then execution begins at address 4000H. If the MAIN module was not linked first, or if the label START is not at the beginning of MAIN, then the program's entry point can be determined by examining the symbol table in the listing file
EXAMPLE.M51 created by RL51. By default, EXAMPLE.M51 will contain only the link map. If a symbol table
is desired, then each source program must have used the SDEBUG control. The following table shows the assembler controls supported by ASM51.
562
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
Assembler controls supported by ASM51
NAME
DATE (date)
DEBUG
EJECT
ERRORPRINT
(file)
NOERRORPRINT
PRIMARY/
GENERAL
PRINT(file)
NOPRINT
SAVE
RESTORE
REGISTERBANK
(rb,...)
NOREGISTERBANK
SYMBOLS
NOSYMBOLS
TITLE(string)
P
P
G
G
P
MEANING
Place string in header (9 char. max.)
Outputs debug symbol information to object file
Continue listing on next page
Designates a file to receive error messages in addition to the
listing file (defauts to console)
NOERRORPRINT
NOEP Designates that error messages will be printed in listing file
only
GENONLY
GO
List only the fully expanded source as if all lines generated
by a macro call were already in the source file
GENONLY
NOGE List only the original source text in the listing file
not applicable
IC
Designates a file to be included as part of the program
LIST
LI
Print subsequent lines of source code in listing file
LIST
NOLI Do not print subsequent lines of source code in lisitng file
MACRO(50)
MR
Evaluate and expand all macro calls. Allocate percentage of
free memory for macro processing
MACRO(50)
NOMR Do not evalutate macro calls
MOD51
MO
Recognize the 8051-specific predefined special function
registers
MOD51
NOMO Do not recognize the 8051-specific predefined special
function registers
OBJECT(source.OBJ)
OJ
Designates file to receive object code
OBJECT(source.OBJ) NOOJ Designates that no object file will be created
PAGING
PI
Designates that listing file be broken into pages and each
will have a header
PAGING
NOPI Designates that listing file will contain no page breaks
PAGELENGT(60)
PL
Sets maximun number of lines in each page of listing file
(range=10 to 65536)
PAGEWIDTH(120)
PW
Set maximum number of characters in each line of listing
file (range = 72 to 132)
PRINT(source.LST)
PR
Designates file to receive source listing
PRINT(source.LST)
NOPR Designates that no listing file will be created
not applicable
SA
Stores current control settings from SAVE stack
not applicable
RS
Restores control settings from SAVE stack
REGISTERBANK(0)
RB
Indicates one or more banks used in program module
P
REGISTERBANK(0)
NORB
Indicates that no register banks are used
P
P
G
SYMBOLS
SYMBOLS
TITLE( )
SB
NOSB
TT
WORKFILES
(path)
XREF
P
same as source
WF
Creates a formatted table of all symbols used in program
Designates that no symbol table is created
Places a string in all subsequent page headers (max.60
characters)
Designates alternate path for temporay workfiles
P
NOXREF
XR
NOXREF
P
NOXREF
NOXR
P
P
G
P
P
GEN
G
GENONLY
INCLUED(file)
LIST
NOLIST
MACRO
(men_precent)
NOMACRO
MOD51
G
G
G
G
P
NOMOD51
P
OBJECT(file)
NOOBJECT
PAGING
P
P
P
NOPAGING
PAGELENGTH
(N)
PAGE WIDTH (N)
P
P
P
P
P
南通国芯微电子有限公司
DEFAULT
DATE( )
NODEBUG
not applicable
NOERRORPRINT
ABBREV.
DA
DB
EJ
EP
.
d
e
t
i
m
C
T
S
U
C
M
Li
Creates a cross reference listing of all symbols used in
program
Designates that no cross reference list is created
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
563
STC12C5A60S2系列单片机指南
技术支持网站:www.GXWMCU.com
临时技术支持Tel:13922829991
研发顾问Tel:13922805190
MACROS
The macro processing facility (MPL) of ASM51 is a "string replacement" facility. Macros allow frequently used
sections of code be defined once using a simple mnemonic and used anywhere in the program by inserting the
mnemonic. Programming using macros is a powerful extension of the techniques described thus far. Macros can
be defined anywhere in a source program and subsequently used like any other instruction. The syntax for macro
definition is
%*DEFINE
(call_pattern)
(macro_body)
Once defined, the call pattern is like a mnemonic; it may be used like any assembly language instruction by
placing it in the mnemonic field of a program. Macros are made distinct from "real" instructions by preceding
them with a percent sign, "%". When the source program is assembled, everything within the macro-body, on
a character-by-character basis, is substituted for the call-pattern. The mystique of macros is largely unfounded.
They provide a simple means for replacing cumbersome instruction patterns with primitive, easy-to-remember
mnemonics. The substitution, we reiterate, is on a character-by-character basis—nothing more, nothing less.
For example, if the following macro definition appears at the beginning of a source file,
%*DEFINE
(PUSH_DPTR)
(PUSH DPH
PUSH DPL
)
then the statement
%PUSH_DPTR
will appear in the .LST file as
PUSH
PUSH
DPH
DPL
C
T
S
U
C
M
.
d
e
t
i
m
Li
The example above is a typical macro. Since the 8051 stack instructions operate only on direct addresses,
pushing the data pointer requires two PUSH instructions. A similar macro can be created to POP the data pointer.
There are several distinct advantages in using macros:
A source program using macros is more readable, since the macro mnemonic is generally more indicative
of the intended operation than the equivalent assembler instructions.
The source program is shorter and requires less typing.
Using macros reduces bugs
Using macros frees the programmer from dealing with low-level details.
The last two points above are related. Once a macro is written and debugged, it is used freely without the worry
of bugs. In the PUSH_DPTR example above, if PUSH and POP instructions are used rather than push and pop
macros, the programmer may inadvertently reverse the order of the pushes or pops. (Was it the high-byte or lowbyte that was pushed first?) This would create a bug. Using macros, however, the details are worked out once—
when the macro is written—and the macro is used freely thereafter, without the worry of bugs.
Since the replacement is on a character-by-character basis, the macro definition should be carefully constructed with carriage returns, tabs, ect., to ensure proper alignment of the macro statements with the rest of the
assembly language program. Some trial and error is required.
There are advanced features of ASM51's macro-processing facility that allow for parameter passing, local
labels, repeat operations, assembly flow control, and so on. These are discussed below.
564
南通国芯微电子有限公司
总机:0513-5501 2928 / 2929 / 2966
传真:0513-5501 2969 / 2956 / 2947
STC12C5A60S2系列单片机指南
官方网站:www.STCMCU.com
研发顾问QQ:800003751
STC — 全球最大的8051单片机设计公司
Parameter Passing
A macro with parameters passed from the main program has the following modified format:
%*DEFINE
(macro_name (parameter_list))
(macro_body)
For example, if the following macro is defined,
%*DEFINE
(CJNE
)
(CMPA# (VALUE))
A, #%VALUE, $ + 3
then the macro call
%CMPA# (20H)
will expand to the following instruction in the .LST file:
CJNE
A, #20H, $ + 3
Although the 8051 does not have a "compare accumulator" instruction, one is easily created using the CJNE
instruction with "$+3" (the next instruction) as the destination for the conditional jump. The CMPA# mnemonic
may be easier to remember for many programmers. Besides, use of the macro unburdens the programmer from
remembering notational details, such as "$+3."
Let's develop another example. It would be nice if the 8051 had instructions such as
JUMP
JUMP
JUMP
JUMP
IF
IF
IF
IF
ACCUMULATOR
ACCUMULATOR
ACCUMULATOR
ACCUMULATOR
.
d
e
t
i
m
Li
GREATER THAN X
GREATER THAN OR EQUAL TO X
LESS THAN X
LESS THAN OR EQUAL TO X
U
C
M
but it does not. These operations can be created using CJNE followed by JC or JNC, but the details are tricky.
Suppose, for example, it is desired to jump to the label GREATER_THAN if the accumulator contains an ASCII
code greater than "Z" (5AH). The following instruction sequence would work:
CJNE
JNC
C
T
S
A, #5BH, $÷3
GREATER_THAN
The CJNE instruction subtracts 5BH (i.e., "Z" + 1) from the content of A and sets or clears the carry flag accordingly. CJNE leaves C=1 for accumulator values 00H up to and including 5AH. (Note: 5AH-5BH