Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/30/02 18:40
Read: times


 
#23666 - RE: compare values
jeroen,

If your coding is assembler the following might be helpful, it assumes that a "1" at p0.3/4 lights the LED and that both LED's light if r2 simultaneously equals the higher and lower boundry (per your description):


$mod51

	org	0
	jmp	start                         ;Always good practice to 
                                                  ; jump over int. vectors

	org	40H

start:
	clr	p0.4			;Turn off LED's
	clr	p0.3

;	***-------------------------------***
;	*** Window Compare of value in R2 ***
;	***-------------------------------***

compare_r0:
	mov	a,r2			;Fetch subject for compare
	cjne	a,ar0,test_r0_carry	         ; Test against hi value

;	*** the value in r2 equals the value in r0 ***

light_r2r0:
	setb	p0.3			;Illuminate Hi boundry LED
	jmp	compare_r1 		; Branch to lower boundry testing

;	*** The value in R2 does not  ***
;	*** equal r0, is it greater ? ***

test_r0_carry:
	jnc	light_r2r0		;If r0 is not greater than r2
					; then light the hi bound LED

;	*** R2 is less than R0 ***

	clr	p0.3			;turn off upper threshold LED

;	***------------------------------------------***
;	*** Compare R2 against lower threshold value ***
;	***------------------------------------------***

compare_r1:
	cjne	a,ar1,test_R1_carry	;Test against lo boundry value

;	*** R2 equals lower threshold value ***

light_r2r1:
	setb	p0.4			;Illuminate the lower boundry led
	jmp	compare_exit		; stay here forever.
			
test_r1_carry:
	jc	light_r2r1		;If r2 is less r1 light low bound LED

;	*** The value is greater than r1 ***

	clr	p0.4			;turn off lower threshold LED

;	*** If this is a subroutine a "RETURN" would be coded here ***

compare_exit:
	jmp	$

	end



Your could compose a shorter routine but the above is for clarity.

regards,
p


List of 5 messages in thread
TopicAuthorDate
compare values            01/01/70 00:00      
RE: compare values            01/01/70 00:00      
RE: compare values            01/01/70 00:00      
   RE: compare values            01/01/70 00:00      
RE: compare values            01/01/70 00:00      

Back to Subject List