Error relative branch out of reach

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi I've got a main program and from that main program I do a breq to hiccup

As long as I only use timeoutL in the hiccup file everything goes well but if I include timeoutH also I get a 'Error relative branch out of reach'

timeoutL and timeoutH fill a counter in the interuptfile that occurs every 1msec to make a timer.
The mode bit is set if the timer is zero.

I can not figure out what I'm doing wrong or did I something that is not possible?

I include a piece of the code.

Main:
			ldi 	temp0,$00			;tijdelijk voor alleen hiccup!!!! Load $00 into register temp0
			mov		pwm,temp0			;tijdelijk voor alleen hiccup!!!! move the content of temp0 into register pwm

;*** selection of the setting *** 
			in		temp0,PINA			;read all the pins of port A into temp0
;			ANDI	temp0,$88			;only look at bit #3 and #7
			ANDI	temp0,$08			;only look at bit #3
			cpi		temp0,$08			;is bit #3 set (and bit #7 not set)?
			breq	hiccup				;yes jump to Hiccup
			cpi		temp0,$00			;are bit #3 (and #7 not set)?
			breq	latch				;yes jump to Latch

[/code]

;*** start hiccup mode and max alarm ***
Hiccup:		mov 	temp0, ana1			;Load the content of ana1 into temp0 this is the ADvalue from PA0
			cpi		temp0, maxI			;Compare temp0 with the constant maxI.C-flag is 1 if MaxI is higher otherwise C-flag is 0
			brcs	main3				;Branch if C-flag is set (1) to main3
			ldi 	temp0,$FF			;Load $FF into register temp0
			mov		pwm,temp0			;move the content of temp0 into register pwm
			ldi 	temp0,250			;load 250 into register temp0
			ldi		temp1,0
			mov 	timeoutL,temp0		;move the content of temp0 into register timeoutL
			mov		timeoutH,temp1
			cbi		portB,0				;set bit 0 on port B low (green led)
			sbi		portB,1				;set bit on output PB1 high (red Led)
			sbi		portA,6				;set bit 6 on port A high (relay) 
main1:		sbrs 	mode,7				;jump over the next instruction if bit 7 in register mode is set (1)
			rjmp 	main1				;Jump to main1 (250 x 1ms wachten)
			cbr		mode,$80			;Clear bit 7 in register mode (set to 0)
			ldi 	temp0,50			;load 50 into register temp0
			mov 	timeoutL,temp0		;move the content of temp0 into register timeoutL
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Either use a macro that uses a 'breq dest' or 'brne PC+1; rjmp dest' or 'brne PC+2; jmp dest' as appropriate.

Or you code it by hand in the first place.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks David
You are right if I do a breq to a rjmp and than to the other file everything works well.

But why was it working with timeoutL and not with timeoutL and timeoutH?
The breq and rjmp are ussing the same operation only breq looks at the Z-flag.
I can not figure it out why one works and the otherone not?

Patrick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have no idea what you are trying to say about 'TimeoutL'.

Remember that most AVR instructions do not set the SREG flags. You have to look up the correct instructions that will set or clear the Z flag. (normally only arithmetic and comparison)

David.