How to stop this assembly program from repeating?

Thread Starter

thar07

Joined Jan 3, 2015
71
I wrote this program to rotate a servo motor from 0 to 90 to 180 by using a MCU 8051. The servo motor has minimum control pulse of 0.5 ms and maximum control pulse of 2.5 ms. When this program was simulated using Proteus software it repeated the process '0 to 90 to 180' for three times and stopped at 180. Why did this happen and how to stop it ?

org 000h



mov r2,#50 ;repeating singnal 50 times
stt: clr P1.5 ; duty cycle
mov r3,#1
here1: call delay
djnz r3,here1
setb P1.5
mov r0,#39 ;
here2: call delay
djnz r0,here2
djnz r2,stt


mov r2,#50;repeating singnal 50 times
stt1: clr P1.5 ; duty cycle
mov r3,#3
here11: call delay
djnz r3,here11
setb P1.5
mov r0,#37 ;
here22: call delay
djnz r0,here22
djnz r2,stt1


mov r2,#50 ;repeating singnal 50 times
stt2: clr P1.5 ; duty cycle
mov r3,#5
here111: call delay
djnz r3,here111
setb P1.5
mov r0,#35 ;
here222: call delay
djnz r0,here222
djnz r2,stt2



delay: mov r1,#228 ;generating 500 micro second delay
djnz r1,$
ret

end​
 

Attachments

Last edited:

ScottWang

Joined Aug 23, 2012
7,409
Try to insert a 'ret' instruction before the subroutine -- delay.
The same meaning as insert the 'ret' instruction in the end of the subroutine -- here222.
 

atferrari

Joined Jan 6, 2004
4,771
I have not even looked at your code but, if you write it following a flow diagram (I always do) just by simple visual inspection (of the diagram) you could say where to instruct your micro to stop repeating (and start doing something else or nothing).

That "nothing" in its simplest from could be something like this

Code:
TRAP_LINE
   goto TRAP_LINE
what would repeat forever until reset or power is disconnected.

I learnt that the first time I wrote a program (in BASIC). Since then, flow diagrams come first.
 
Last edited:

absf

Joined Dec 29, 2010
1,968
Code:
    org 000h

start:
    call stt0
    call stt1
    call stt2
here:    ajmp here    ;stop here

stt0:    mov r2,#50     ;repeating singnal 50 times
stt:     clr P1.5     ; duty cycle
    mov r3,#1
here1:     call delay
    djnz r3,here1
    setb P1.5
    mov r0,#39 ;
here2:     call delay
    djnz r0,here2
    djnz r2,stt
    ret
   
stt1:    mov r2,#50    ;repeating singnal 50 times
stt1a:     clr P1.5     ;duty cycle
    mov r3,#3
here11: call delay
    djnz r3,here11
    setb P1.5
    mov r0,#37 ;
here22: call delay
    djnz r0,here22
    djnz r2,stt1a
    ret
   
stt2:    mov r2,#50     ;repeating singnal 50 times
stt2a:     clr P1.5     ; duty cycle
    mov r3,#5
here111: call delay
    djnz r3,here111
    setb P1.5
    mov r0,#35 ;
here222: call delay
    djnz r0,here222
    djnz r2,stt2a
    ret
   
delay:     mov r1,#228     ;generating 500 micro second delay
    djnz r1,$
    ret
    end
What about now?

Allen
 
Top