我想使用8051程序。我想要做的是声明延迟程序并将其用于LED闪烁。我正在使用 Keil uVision3 来编写我的代码。我google了很多但没有找到任何帮助。以下是我的程序的示例代码。
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
此代码提供了一些语法错误。声明过程以及如何使用它的正确语法是什么。请指导我,我的代码有什么问题,请让我纠正。我会感激你的。
答案 0 :(得分:0)
对于普通的8051芯片,您甚至不需要通过声明程序来打扰 - 只需给它们一个标签并调用它们即可。如:
ACALL delay
; ... main progam continues here
; make sure you don't fall through into your procedure!
delay:
; ... procedure code here ...
RET
如果你想申报你的程序,根据keil manual,你必须做这样的事情:
CALL delay
; ... main progam continues here
; make sure you don't fall through into your procedure!
delay PROC
; ... procedure code here ...
RET
delay ENDP
答案 1 :(得分: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