0

我想使用 8051 程序。我想要做的是声明一个延迟程序并将其用于 LED 闪烁。我正在使用Keil uVision3来编写我的代码。我用谷歌搜索了很多,但没有找到任何帮助。下面是我的程序的示例代码。

ORG 00h

MOV P0, #00h
MOV P1, #00h
MOV P2, #00h
MOV P3, #00h

CALL DELAY PROC     ;calling delay procedure to produce some delay.


DELAY PROC           ;procedure implementation starts here for generating some delay

    MOV R0, #255

    NOW:
    DJNE R0, 0 , HERE

    MOV R1, #255

    HERE: 
    DJNE R1, 0, NOW

    RET
    ENDP


END

此代码给出了一些语法错误。声明过程的正确语法是什么以及如何使用它。请指导我,我的代码有什么问题,请纠正我。我会很感激你的。

4

2 回答 2

0

对于普通的 8051 芯片,您甚至不必费心声明程序 - 只需给它们一个标签并调用它们即可。如:

    ACALL delay
    ; ... main progam continues here
    ; make sure you don't fall through into your procedure!

delay:
    ; ... procedure code here ...
    RET

如果您确实想声明您的程序,根据keil 手册,您必须执行以下操作:

    CALL delay
    ; ... main progam continues here
    ; make sure you don't fall through into your procedure!

delay PROC
    ; ... procedure code here ...
    RET
delay ENDP
于 2013-01-21T22:45:00.423 回答
0
ORG 0000

;MAIN PROGRAM

ACALL DELAY

;MAIN END

DELAY:
MOV R0, #255 //COUNTS VALUE
NOW: MOV R1, #255 //COUNTS VALUE (255*255 = COUNTS )
AGAIN: DJNZ R1 AGAIN // R1 WILL DECREMENTED UNTILL ZERO ENCOUNTERS
DJNZ R0 NOW // R0 WILL ALSO BE DECREMENTED UNITLL ZERO ENCOUNTERS, BUT MAKE R1 RELOADED 255 TIMES
RET // RETURN THERE FROM WHERE IT IS CALLED, I MEAN TO MAIN
于 2019-11-03T03:05:44.367 回答