Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Please help me with this code....

Status
Not open for further replies.

asmpic

New Member
Hey guys, can someone please help me out with the following code. As of now it doesn't really do anything, I'm having problems with the code towards the end. For some reason, it doesn't want to subtract 'entered_pass_code' from 'something_clever' correctly. For example when entered passcode is 0x05 and something_clever is 0x01, it should execute the 'return' statement since the result of the subtraction is not zero, but instead it executes the 'match_found' line.

Any ideas??

Code:
	list P=16F84
	include	P16F84.INC

; Define the direction bit types

f	equ	1
w	equ	0

; Define the data storage locations
			org	0x20
counter			    res 1
counter_2		     res 1
entered_pass_code   res 1
num_pass_codes	   res 1
something_clever    res 1

			org	0x30
passcodes			res	8	;location of the program

; start defining the program
; no interrupts, so start at 0x0

	org	0x00

compare_to_list
	call	  indirect
	incf	  counter_2,f
	incf	  counter,w
	subwf	 num_pass_codes,f
	btfss	 STATUS,Z
	goto	  no_match
	goto	  compare_to_list
	

indirect
	movlw	  passcodes	
   addwf     counter_2,w		
   movwf     FSR			  
   movf      INDF,w	
   movwf     something_clever

	movf	   entered_pass_code,w
	subwf	  something_clever,f

	btfss	  STATUS,Z
	goto	   match_found
return	

match_found
nop

no_match
nop
end
 
Your program is behaving correctly, it is you who have the problem.
the instruction:
BTFSS STATUS,Z
translates to SKIP IF ZERO, since the Z flag is SET for a zero result.
If you want it to work the other way round you will have to use:
BTFSC STATUS,Z
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top