"LOOP" routine in Assembly

=_NextPart_000_0047_01CA3C5F.D4A519F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi All

Google is NOT my friend here, or maybe I'm not searching correct - gets = gazillions of hits on examples which I don't understand

I have the below routine that work 100%, but I want to add a "LOOP" to = execute the FLASH routine i,e 5 times and then the FLASH_ODD routine 7 = times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code

#################################################

ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD

FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH

DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20

#################################################

Any suggestions will be greatly appreciated

Reply to
Lodewicus Maas
Loading thread data ...

=_NextPart_000_00B3_01CA3C5B.5FD956D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

begin: mov r3,#05 mov r4,#07

loop1: lcall flash djnz r3,loop1

Google is NOT my friend here, or maybe I'm not searching correct - = gets gazillions of hits on examples which I don't understand

I have the below routine that work 100%, but I want to add a "LOOP" to = execute the FLASH routine i,e 5 times and then the FLASH_ODD routine 7 = times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code

#################################################

ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD

FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH

DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20

#################################################

Any suggestions will be greatly appreciated

Reply to
TTman

=_NextPart_000_0014_01CA3C66.5061D500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

loop1: lcall flash djnz r3,loop1

Google is NOT my friend here, or maybe I'm not searching correct - = gets gazillions of hits on examples which I don't understand

I have the below routine that work 100%, but I want to add a "LOOP" = to execute the FLASH routine i,e 5 times and then the FLASH_ODD routine =

7 times before calling "AJMP FLASH" again to start from the beginning. = Below is just a scale down version of my code, but If I can get this = resolved, I will be able to implement it in my code

#################################################

ORG 00H ; Starts Here FLASH: CPL P1.0 ; Turn on/off the LED P1.0 ACALL DELAY ; call one second delay AJMP FLASH_ODD ; jump to FLASH_ODD

FLASH_ODD: CPL P1.3 ; Turn on/off the LED P1.3 ACALL DELAY ; call one second delay AJMP FLASH ; jump to FLASH

DELAY: MOV R1,#0FFH REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END=20

#################################################

Any suggestions will be greatly appreciated

Reply to
Lodewicus Maas

=_NextPart_000_000E_01CA437C.575E3D40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

HI All

At first I thought this is working , but when I added a huge delay to = closely monitor the ports I notice that it ignores the repeat intervals, = and after doing each of them sequentialy, it starts doing the routines = randomly. Any suggestion why this will happen: It seems to ignore the = results after the "MOV r?," commands , and do every LOOP? only once, and = then after completing them once, starts to do them in random order

ORG 00H ; Execution Starts Here

BEGIN: MOV r3,#2=20 MOV r4,#2 MOV r5,#2 MOV r6,#2 MOV r7,#3 =20 LOOP1: LCALL ENGINE_1 DJNZ r3,LOOP1 =20 LOOP2: LCALL EVENT_2 DJNZ r4,LOOP2 =20 LOOP3: LCALL EVENT_3 DJNZ r5,LOOP3 =20 LOOP4: LCALL CLEAR_CHECK_1 DJNZ r6,LOOP4 =20 LOOP5: LCALL RESULT_PULSE_1 DJNZ r7,LOOP5 LJMP BEGIN

....... CODE

loop1: lcall flash djnz r3,loop1

loop2: lcall flash_odd djnz r4,loop2 ljmp begin

Reply to
Lodewicus Maas

monitor the ports I

sequentialy, it starts

ignore the results

completing them once,

Are you sure you have posted all relevant code that is part to the problem you describe?

  1. There is no "huge delay" shown above.
  2. Each of the routines will be called twice in a row inside the outer loop and there is no evidence of "randomness", unless the routines modify registers they shouldn't touch.
--
Wil
Reply to
Wil Taphoorn

=_NextPart_000_0028_01CA439A.4EB108D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi Wil

Below between the ###### is the code I use. Within = ENGINE1_1,EVENT_2/_3,CLEAR_CHECK_1/2 - I don't call any registers, which = might reset the ones I declared in the START routine. I do suspect = something must can be wrong in my REPEAT routine. The REPEAT routine is = from a sample I googled, but I no where call this REPEAT routine , = except from within itself

Anu help will be greatly appreciated

Lodewicus Maas #########################################

; First Program, LCALL ENGINE_1=20 ; Hardware Notes: ; AT89C51 Running at 12 MHz

ORG 00H ; Execution Starts Here

START: MOV r3,#2 =20 MOV r4,#2 MOV r5,#20 MOV r6,#20 MOV r7,#3 =20 LOOP1: LCALL ENGINE_1 DJNZ r3,LOOP1 =20 LOOP2: LCALL EVENT_2 DJNZ r4,LOOP2 =20 LOOP3: LCALL EVENT_3 DJNZ r5,LOOP3 =20 LOOP4: LCALL CLEAR_CHECK_1 DJNZ r6,LOOP4 =20 LOOP5: LCALL CLEAR_CHECK_2 DJNZ r7,LOOP5 LJMP START

ENGINE_1: CPL P0.0 ; Turn on Port P0.0 . . =20 LCALL DELAY1 ; call one second delay =20 =20

EVENT_2: CPL P0.0 ; Turn on Port P0.0 . . LCALL DELAY1 ; call one second delay =20 EVENT_3: CPL P0.1 ; Turn on Port P0.1 . . LCALL DELAY1 ; call one second delay =20

CLEAR_CHECK_1: CPL P0.0 ; Turn on Port P0.0 . =20 . LCALL DELAY1 ; call one second delay

CLEAR_CHECK_2:=20 CPL P0.0 ; Turn on P0.0=20 .=20 . CPL P0.0 ; Turn off P0.0

DELAY1: MOV R1,#120 ; =20 =20 REPEAT: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,REPEAT RET END

##################################

closely monitor the ports I

them sequentialy, it starts

seems to ignore the results

after completing them once,

problem you describe?

loop and there is

they shouldn't touch.

Reply to
Lodewicus Maas

..

Main loop looks ok.

Make sure to put a RET instruction at the end of a subroutine. All your subroutines lack a RET.

This routine is ok.

--
Wil
Reply to
Wil Taphoorn

Thank you Wil

The missing RET in each routine caused the problem - added this and all is ok now

Lodewicus Maas

Reply to
Lodewicus Maas

There is one important thing missing though: you are not initializing the stack pointer. So at this moment it is sheer luck that a return from an LCALL ends up at the right place again.

Meindert

Reply to
Meindert Sprang

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.