Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

campare two registers in pic16f84

Status
Not open for further replies.

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
hello!
i am in a big trouble. i want to compare two registers in pic1684
for example
i creat register J and put decimal 15 in it
now i put 15 in working register
now i want to compare it with J
both reigster have the same value so go to location 0
now i put in w register 14 or 16
now the w and j are not same so go to location 2
how i can do this? is this possible
the 16 is bigger than J but the 14 is smaller than J
thanking you in anticipation

---------- Post added at 09:27 ---------- Previous post was at 09:26 ----------

i want it in assembly
 

Use 'subwf' it sets the Z flag in the status register if the values are equal.
subwf J, f will leave the result in J
subwf J,w will leave the result in w
so if yu need to keep the value for use later, make sure you use the correct version that doesn't change it in J or w.

example:
subwf J,w
btfss STATUS,Z ;jump over the next instruction if J = w
goto not_equal
goto equal

Brian.
 

will XOR funtion ok for this problem
 

Yes, it will work exactly as 'subwf' in this case. The advantage of using subwf is it also set other flags in the STATUS register which you can use to tell if J is greater than or less than W. Using xor will only tell you if they are the same or not.

Brian.
 

i just want to know that they are same or not.
so is this code ok for this purpose or some suggestions.


#include "p16f84.inc" ; This includes PIC16F84 definitions for the MPASM assembler

; Please insert your code here.
J equ 21h
K equ 22h
main:
org 00h
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
clrf PORTB
movlw D'10'
movwf J
clrw
movlw D'10'
xorwf J , 0
movwf K
btfsc K , 0
goto a
btfsc K , 1
goto a
btfsc K , 2
goto a
btfsc K , 3
goto a
btfsc K , 4
goto a
btfsc K , 5
goto a
btfsc K , 6
goto a
btfsc K , 7
goto a
goto fin
a:
bsf PORTB , 0


fin:
goto fin

END

---------- Post added at 10:23 ---------- Previous post was at 10:11 ----------

modified programme of above code

#include "p16f84.inc" ; This includes PIC16F84 definitions for the MPASM assembler

; Please insert your code here.
J equ 21h
main:
org 00h
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
clrf PORTB
movlw D'10'
movwf J
clrw
movlw D'9'
xorwf J , 0
btfss STATUS , 2
a:
bsf PORTB , 0


fin:
goto fin

END


please which one is more secure above one or this one if i use it in a digital lock?
 

Hi,

Think you have missed the two points Betwixt was making.

When you XOR your two values the Pics STATUS register is affected by the result.
Certain bits of it are set on or off to reflect the result, such as the Z bit and C bit.

Its these bits that you test with BTFSS\C STATUS,Z etc.

Again its better to use the SUB than XOR as more of the STATUS register bits are affected.

Use MPLAB SIM and single step though your code using the WATCH window to see the Status and your registers changing.

At the end of the 84s datasheet there is the instruction set, look up the SUBLW instruction which details how it works.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top