Question

I want to work with 8051 Procedure. What i want to do is to declare a procedure for delay and use it for led blinking. I'm using Keil uVision3 to write my code. I have googled a lot but did not find any help. Below is the the sample code of my program.

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

This code gives some syntax errors. What is the correct syntax to declare a procedure and how to use it. Please guide me, what is wrong with my code and please make me correct. I would be thankful to you.

Was it helpful?

Solution

For the plain 8051 chips, you don't even have to bother by declaring procedures - just give them a label and call them. Such as:

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

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

If you do want to declare your procedure, according to the keil manual you have to do something like this:

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

delay PROC
    ; ... procedure code here ...
    RET
delay ENDP

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top