Trying to Compare W to a variable

J

Jason

Guest
I am kinda new to this and was wondering if someone could help me out. I
have the following lines of code:



CheckNumber btfss PIR1,RCIF ;Check to see a transmission has been made!!
goto CheckNumber
movf RCREG,w

call EE_Read ;Sets w in 0x00 of EEPROM
SUBLW RCREG
btfsc STATUS,Z ;If true then run next line
goto oknum1

goto receive

oknum1 bcf STATUS, RP0 ; Bank 0
movlw 'o'
call send
movlw 'k'
call send
movlw '1'
call send

Whats not working is my SUBLW RCREG. call EE_Read is returning a number
that is store on the chip and pushing that into w. I need to compare w to
what is in my RCREG which should be a single byte of data from the serial
port. I can do something like SUBLW '3' to see if w is equal to 3 which
works fine but the other way doesn't. Is there a way to convert REREG to a
literal to compare it to w and see if they are equal? I have tried serveral
things including declaring a variable and trying - movf RCREG,TempVar and
then comparing TempVar to w but it still doesn't work. Any ideas??

Thanks!!

Jason
 
On Tue, 16 Mar 2004 02:32:56 GMT, the renowned "Jason"
<jason@mindspring.com> wrote:

I am kinda new to this and was wondering if someone could help me out. I
have the following lines of code:
I'll assume you've got the midrange Microchip PIC family here..
remember there are MANY microcontrollers, tnePIC line is probably not
even the most popular.

CheckNumber btfss PIR1,RCIF ;Check to see a transmission has been made!!
goto CheckNumber
movf RCREG,w

call EE_Read ;Sets w in 0x00 of EEPROM
SUBLW RCREG
btfsc STATUS,Z ;If true then run next line
goto oknum1

goto receive

oknum1 bcf STATUS, RP0 ; Bank 0
movlw 'o'
call send
movlw 'k'
call send
movlw '1'
call send

Whats not working is my SUBLW RCREG.
RCREG is the address of the register, not the number contained in that
register. The "L" stands for "Literal", which is a constant fixed at
assembly time.

You want subwf, which subtracts W from f, shoving the results into
either W or f. There is no compare instruction in the midrange
instruction set. The 18F series has several compare/conditional skip
instructions that don't trash one of the operands.

Thanks!!
Jason
BTW, some might say this stuff has little to do with electronic
design. There are also the comp.arch.embedded and
alt.microcontrollers.8bit newsgroups, which may be more appropriate.

Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
 
Thanks Maxfoo that worked like a champ!!


"maxfoo" <maxfooHeadFromButt@punkass.com> wrote in message
news:eoud50pb9v69b3cijck7icm9p0ii5p8t6m@4ax.com...
On Tue, 16 Mar 2004 02:32:56 GMT, "Jason" <jason@mindspring.com> wrote:

call EE_Read ;Sets w in 0x00 of EEPROM
SUBLW RCREG
btfsc STATUS,Z ;If true then run next line
goto oknum1

Try this;
movlw 0x01
subwf rcreg,W
btfsc STATUS,Z
goto oknum1
goto somewhereelse
The above is the VB equivalent of this;

If (RCREG = 1) Then
goto oknum1
ELSE
goto somewhereelse
ENDIF









Remove "HeadFromButt", before replying by email.
 

Welcome to EDABoard.com

Sponsor

Back
Top