Searching \ for '[PIC]: Character compare and XOR'ing' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Character compare and XOR'ing'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Character compare and XOR'ing'
2003\04\05@142812 by Chuck Rice

picon face
Heyas,

Still working on a serial interfaced traffic light. Using a recurring
XOR to test the chars I saw in an earlier post. The problem is that it
will only turn on the Red LED (PortB.0), regardless of the input
character. I am sending the w register through the serial port as a test
to see what characters are coming back, and I get the same set for any
order of inputs.

R- G8 Y&

So it is doing something to the bits in w, and it does the same thing
independent of order. Not sure what the - means if not null since hyphen
in ascii is not 0000000?

Worked through the binary math and I'm pretty sure that the way I have
it set up it should hit on the correct characters, but it seems like all
characters are being interpreted as "R", or something else is busted.

Thanks!

//===== Code Below =====

           LIST P=16F876, R=DEC
           INCLUDE "p16F876.inc"

           __CONFIG _CP_OFF & _HS_OSC & _PWRTE_ON & _WDT_OFF &
_BODEN_ON

; Mainline

org 0

bsf STATUS, RP0                     ; Enable the Serial Port, bank 1
movlw (1 << TXEN)                    ; Enable Serial Transmission
movwf TXSTA ^ 0x080
movlw 51                                              ; Serial Port
running at 1200baud
movwf SPBRG ^ 0x080

bcf TRISB ^ 0x080, 0     ; Set PortB 0.1.2 to output
bcf TRISB ^ 0x080, 1
bcf TRISB ^ 0x080, 2

bcf STATUS, RP0                     ; Return to bank 0
movlw (1 << SPEN) | (1 << CREN)
movwf RCSTA                           ; Enable Serial I/O

Loop
btfss PIR1, RCIF                       ; Wait for rx character set
 goto Loop                                ; Nothing there
movf RCREG, 0                        ; Get rx character
bcf PIR1, RCIF                          ; Clear the Character Present
Flag

XORWF 'R', w                           ; Is the character R?
BTFSS STATUS, Z
 call GORED
XORWF ('Y'^'R'), w                    ; No? Is the character Y?
BTFSS STATUS, Z
 call GOYEL
XORWF ('G'^'Y'), w                    ; No? Is the character G?
BTFSS STATUS, Z
 call GOGRN

                                               ; Else it is not R, Y,
or G
bsf PORTB, 0                           ; Invalid Character, light all
LEDs
bsf PORTB, 1
bsf PORTB, 2

goto Loop

; Subroutines
GORED:                       ; Turn on Red LED
bsf PORTB, 0
bcf PORTB, 1
bcf PORTB, 2
movwf TXREG
goto Loop
;return

GOYEL:                        ; Turn on Yellow LED
bcf PORTB, 0
bsf PORTB, 1
bcf PORTB, 2
movwf TXREG
goto Loop
;return

GOGRN:                       ; Turn on Green LED
bcf PORTB, 0
bcf PORTB, 1
bsf PORTB, 2
movwf TXREG
goto Loop
;return

end

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\04\05@145129 by Russell C. Hay

flavicon
face
For the XORWF, shouldn't you be using XORLW since you are XORing literals
with W rather than registers?

-R

{Original Message removed}

2003\04\05@150416 by Olin Lathrop

face picon face
>  XORWF 'R', w                           ; Is the character R?
>  BTFSS STATUS, Z
>   call GORED
>  XORWF ('Y'^'R'), w                    ; No? Is the character Y?
>  BTFSS STATUS, Z
>   call GOYEL
>  XORWF ('G'^'Y'), w                    ; No? Is the character G?
>  BTFSS STATUS, Z
>   call GOGRN

Unless you really really need the speed from a small number of choices, use
a table.  That will be much easier to maintain.  Note that you have each
command character code in two places with your method.

See my HOS_CMD.ASPIC module in my HOS project at
http://www.embedinc.com/pic/hos.htm for an example of a table driven command
dispatch routine.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2003\04\05@183940 by Bob Ammerman

picon face
----- Original Message -----
From: "Olin Lathrop" <olin_piclistspamKILLspamEMBEDINC.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Saturday, April 05, 2003 12:02 PM
Subject: Re: [PIC]: Character compare and XOR'ing


{Quote hidden}

Your BTFSS STATUS,Z instructions should be BTFSC STATUS,Z

Bob Ammerman
RAm Systems

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\04\05@183950 by Bob Ammerman
picon face
> For the XORWF, shouldn't you be using XORLW since you are XORing literals
> with W rather than registers?

That's for sure.

Use XORLW instead of XORWF

Use BTFSC instead of BTFSS

and you should be good to go.

But be sure you understand why this as how it should be, or the time we've
taken to help you out is mostly wasted.

Bob Ammerman
RAm Systems

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\04\05@194958 by Chuck Rice

picon face
Thanks, I think I understand now. SC skips if not equal and before I was
xoring with null memory or something which is why I was getting bad
results. Works like a charm.

Incidentally, anyone know a good way to attach LEDs inside a case? I've
been using twisted pair crimps cut in half. Couldn't locate double
crimps that were small enough and reasonably priced. A friend uses
wrapping wire and bonds it with glue but I'd rather use the tubes than
get glue all over the place.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

2003\04\06@095340 by Dennis J. Murray

flavicon
face
FWIW, I've used small rubber grommets with a great deal of success.  They're
relatively cheap and hold the LED fairly securely.

I don't use those for customer products, however, 'cause I think it cheapens
the look.  For customer prototypes, I'll frequently use a regular mount
(available from Digi-Key).


{Original Message removed}

2003\04\06@155754 by Bob Barr

flavicon
face
On Sat, 5 Apr 2003 19:49:13 -0500, Chuck Rice wrote:

>Thanks, I think I understand now. SC skips if not equal and before I was
>xoring with null memory or something which is why I was getting bad
>results. Works like a charm.
>

Mistakenly using SC vs SS (or vice versa) on the Z bit is something
that I used to do all too frequently. Once I switched over to using
the 'skpz' and 'skpnz' pseudo-ops, the problem was solved.

I'd highly recommend using them. They save me from tearing out what
little hair I have left. :=)


Regards, Bob

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu>

2003\04\06@224934 by Andrew Warren

flavicon
face
Bob Ammerman <RemoveMEPICLISTTakeThisOuTspammitvma.mit.edu> wrote:

> Use XORLW instead of XORWF
>
> Use BTFSC instead of BTFSS
>
> and you should be good to go.

   Except that you'll also want to change your CALLs to GOTOs.

   -Andy

   P.S.  And to avoid possible read-modify-write problems, you MIGHT
         want to put small delays between the BCF/BSF operations on
         port B in GORED, GOYEL, and GOGRN... Or delete them and
         just do a MOVLW xx/MOVWF PORTB after the MOVWF TXREG in
         each of those sections.

=== Andrew Warren -- spamBeGoneaiwspamBeGonespamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...