我在8051汇编程序中遇到了一些MACRO问题(使用Keil uVision 5.11)。
我收到错误:
Build target 'Target 1'
assembling MAIN.a51...
MAIN.a51(62): error A45: UNDEFINED SYMBOL (PASS-2)
MAIN.a51(67): error A45: UNDEFINED SYMBOL (PASS-2)
MAIN.a51(72): error A45: UNDEFINED SYMBOL (PASS-2)
MAIN.a51(76): error A45: UNDEFINED SYMBOL (PASS-2)
MAIN.a51(89): error A45: UNDEFINED SYMBOL (PASS-2)
MAIN.a51(107): error A45: UNDEFINED SYMBOL (PASS-2)
Target not created.
这是我的代码(完整地,就像我试图缩短示例一样,错误没有发生)。
; UART
; 0.000001085 s ... NOP
; 1ms ... 922 NOPs
; 1 bit ... 96 NOPs
; Half bit ... 48 NOPs
UART_OUT equ P2.0
UART_CLK equ P2.1
DSEG at 30h
; Pomocne promenne
I: DS 1
J: DS 1
K: DS 1
; 1 ms delay
M_WAIT_1MS MACRO
MOV A,#229
NOP
NOP
NOP
CALL wait_a4_cycles
ENDM
; 1 bit time delay
M_WAIT_BIT MACRO
MOV A,#24
NOP
CALL wait_a4_cycles
ENDM
; half bit time delay
M_WAIT_HALF_BIT MACRO
MOV A,#12
NOP
CALL fn_wait_a4_cycles
ENDM
CSEG at 00000h
MOV SP,#70H
SETB UART_OUT
SETB UART_CLK
; Hlavni smycka
main:
M_WAIT_1MS ; *ERROR HERE*
MOV A,#'A'
CALL fn_uart_send_byte
M_WAIT_1MS ; *ERROR HERE*
MOV A,#'H'
CALL fn_uart_send_byte
M_WAIT_1MS ; *ERROR HERE*
MOV A,#'O'
CALL fn_uart_send_byte
M_WAIT_1MS ; *ERROR HERE*
MOV A,#'J'
CALL fn_uart_send_byte
JMP main
; Send byte in A over "UART"
fn_uart_send_byte:
MOV K,A ; store in tmp var
MOV J,#8 ; bit counter
CLR UART_OUT ; start bit
M_WAIT_BIT
fusb_1: ; loop over the bits
XCH A,K ; K -> A
RRC A ; Rotate A through carry
MOV UART_OUT,C ; Carry to output
XCH A,K ; A -> K
M_WAIT_HALF_BIT ; halfbit delay *NO ERROR HERE!?*
CLR UART_CLK ; Clock pulse
SETB UART_CLK
M_WAIT_HALF_BIT ; halfbit delay *ALSO NO ERROR*
DJNZ J,fusb_1 ; Repeat if there's more bits
CLR UART_OUT ; stop bit
M_WAIT_BIT ; *ERROR HERE*
SETB UART_OUT
RET ; Return from routine
; DELAY A*4 "NOP"s (excluding CALL)
fn_wait_a4_cycles:
NOP ; 1
NOP ; 1
NOP ; 1
PUSH I ; 2 Preserve original I
CLR C ; 1 Clear Carry
SUBB A,#3 ; 1 overhead = 3*4 = 12 Subtract fn overhead from requested count
MOV I,A ; 1 Store result in I
fwa4c_1: ; Waiting loop of length 4 NOPs
NOP
NOP
DJNZ I,fwa4c_1 ; 2
POP I ; 2 Restore original I
RET ; 2 Return
END
答案 0 :(得分:1)
问题是我在宏中使用了未定义的标签来调用 - 而Keil,这些工具通常都是愚蠢的,没有标记错误的正确位置。