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.

Equivalent of CJNE instruction (8051) for PIC

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
In 8051 family, there is an aintruction CJNE. With this instruction we can check the two values, smaller, equal, or greater.
In PIC how we can do the same function?
Can we check if W reg. is zero or not (Like JZ or JNZ in 8051).
If yes then i think we can check the 2 values of W and L or F by using XOR instruction.
But how can we check the greater or smaller values?

Thanks in advance
 

Re: pic problem

Hi !

In the 16 bits core PIC family (18Fxxxx), they have three compare instructions:
CPFSEG compare f with W, skip if equal
CPFSGT compare f with W, skip if greater
CPFSLT compare f with W, skip if lesser

In the 14bits core family (16Fxxx) you can subtract one register from another and checking the Status bits Zero and Carry, using bit test instructions (BTFSC and BTFSS).

XOR instruction will check if the correpondent bits in each register are equal or not, but you can´t realize which register is greater.
 

Re: pic problem

Noman Yousaf,
If you check a variable is zero or not, you should to do...

movf VARIABLE,f
btfss STATUS,z
goto ISNOTEQUALZERO
;ISEQUALZERO


this opcode (copy in same place) changes flag 'z' (or not) of STATUS registrer

if you requiere to know smaller, equal, or greater, you should to do....

movf VARIABLE,W ;copmpares VARIABLE is != 12
sublw 0x0C
btfsc STATUS.2
goto _ES12

;VARIABLE IS =12 --> VARIABLE = 01
movlw 0x01
movwf VARIABLE
GOTO _FINAL

;VARIABLE is not 12 ---> VARIABLE = 02
_ES12:
movlw 0x01
movwf VARIABLE


;Final
_FINAL
 

Re: pic problem

If you need to check the value of a file register, do this:

movf File_reg, F ; does nothing but set Z flag, if File_reg=0
btfsc STATUS, Z ;
goto F_eq_zero ;


If you want to compare the File_reg with a certain value, do this:

movf File_reg,W ;get value in W
sublw VALUE ;subtract W from value to compare with
btfsc STATUS, Z ; jump if result zero, i.e. File_reg=VALUE
goto File_eq_zero ;
btfss STATUS, C ;check carry bit, if set, result was POSITIVE, so File_reg<VALUE
goto File_higher ;if C clear, result was negative, so File_reg>VALUE
goto File_lower ;C was set, so File_reg<VALUE

Note that sublw does two's complement operations, that is why C is set for positive results. But it subtracts W from VALUE.

If the quantity you need to compare is in W already, then you do not need the movf File_reg instruction, but after you do the jumps you must restore W by adding VALUE. That has to be done at each of those addresses: File_eq_zero, File_lower, File_higher.

Like this

File_lower: addlw VALUE ; restore W
...

File_higher: addlw VALUE ; restore W
...

File_eq_zero: addlw VALUE ; restore W
...

A little more complicated than the CJNE.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top