How to stop this assembly program from repeating?

Discussion in 'Embedded Systems and Microcontrollers' started by thar07, Mar 20, 2015.

  1. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0
    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 ?

     
    • serv.txt
      File size:
      800 bytes
      Views:
      14
    Last edited: Mar 20, 2015
  2. ScottWang

    Moderator

    Aug 23, 2012
    4,848
    767
    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.
     
  3. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    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 (Text):
    1.  
    2. TRAP_LINE
    3.    goto TRAP_LINE
    4.  
    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: Mar 20, 2015
    thar07 likes this.
  4. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0
    It didn't work.
     
  5. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    Code (Text):
    1.  
    2.     org 000h
    3.  
    4. start:
    5.     call stt0
    6.     call stt1
    7.     call stt2
    8. here:    ajmp here    ;stop here
    9.  
    10. stt0:    mov r2,#50     ;repeating singnal 50 times
    11. stt:     clr P1.5     ; duty cycle
    12.     mov r3,#1
    13. here1:     call delay
    14.     djnz r3,here1
    15.     setb P1.5
    16.     mov r0,#39 ;
    17. here2:     call delay
    18.     djnz r0,here2
    19.     djnz r2,stt
    20.     ret
    21.    
    22. stt1:    mov r2,#50    ;repeating singnal 50 times
    23. stt1a:     clr P1.5     ;duty cycle
    24.     mov r3,#3
    25. here11: call delay
    26.     djnz r3,here11
    27.     setb P1.5
    28.     mov r0,#37 ;
    29. here22: call delay
    30.     djnz r0,here22
    31.     djnz r2,stt1a
    32.     ret
    33.    
    34. stt2:    mov r2,#50     ;repeating singnal 50 times
    35. stt2a:     clr P1.5     ; duty cycle
    36.     mov r3,#5
    37. here111: call delay
    38.     djnz r3,here111
    39.     setb P1.5
    40.     mov r0,#35 ;
    41. here222: call delay
    42.     djnz r0,here222
    43.     djnz r2,stt2a
    44.     ret
    45.    
    46. delay:     mov r1,#228     ;generating 500 micro second delay
    47.     djnz r1,$
    48.     ret
    49.     end
    50.  
    51.  
    What about now?

    Allen
     
    thar07 likes this.
  6. thar07

    Thread Starter Member

    Jan 3, 2015
    71
    0
    It works :)

    Thank you
     
Loading...