Searching \ for ' [PIC}: Bit operation quiz...' 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: 'Bit operation quiz...'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] [PIC}: Bit operation quiz...'
2002\03\10@060830 by Jinx

face picon face
> Jinx, your solution had the top 4 bits swapped.  With some
> code adjustments I managed to get the result in 14 steps.

Ah well. I have to admit to a little confusion over which nybble
was to be reversed.

"I can re-route the 4 lowest lines to the LED's, but the last 4
bits get reversed.  What's the fastest way, in code, to reverse
just those 4 lowest bits, and leave the 4 highest bits untouched?

Assume input = ABCDEFGH, then output should be ABCDHGFE"

I guessed wrong, as I would normally put the bit order HGFEDCBA.
Maybe I'd have gone a different way

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\10@112409 by Pic Dude

flavicon
face
So you're saying you'll take the challenge to beat 10 steps?  :-)


----- Original Message -----
From: "Jinx" <spam_OUTjoecolquittTakeThisOuTspamCLEAR.NET.NZ>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Sunday, March 10, 2002 5:07 AM
Subject: Re: [PIC}: Bit operation quiz...


{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\10@125014 by Sergio Masci

picon face
----- Original Message -----
From: Pic Dude <picdudespamKILLspamAVN-TECH.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Sunday, March 10, 2002 4:29 PM
Subject: Re: [PIC}: Bit operation quiz...


> So you're saying you'll take the challenge to beat 10 steps?  :-)
>

challenge eh?

movwf tmp
andlw 15
addwf pcl
goto lab0
goto lab1
goto lab2
goto lab3
goto lab4
goto lab5
goto lab6
goto lab7
goto lab8
goto lab9
goto lab10
goto lab11
goto lab12
goto lab13
goto lab14
goto lab14

lab0 movf tmp,w
goto labend

lab1 movf tmp,w
xorlw 9  ;1
goto labend

lab2 movf tmp,w
xorlw 6  ;2
goto labend

lab3 movf tmp,w
xorlw 15  ;3
goto labend

lab4 movf tmp,w
xorlw 6  ;4
goto labend

lab5 movf tmp,w
xorlw 15  ;5
goto labend

lab6 movf tmp,w
goto labend

lab7 movf tmp,w
xorlw 9  ;7
goto labend

lab8 movf tmp,w
xorlw 9  ;8
goto labend

lab9 movf tmp,w
goto labend

lab10 movf tmp,w
xorlw 15  ;10
goto labend

lab11 movf tmp,w
xorlw 5  ;11
goto labend

lab12 movf tmp,w
xorlw 15  ;12
goto labend

lab13 movf tmp,w
xorlw 6  ;13
goto labend

lab14 movf tmp,w
xorlw 9  ;14
goto labend

lab15 movf tmp,w
goto labend


Regards
Sergio

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\10@180327 by Jinx

face picon face
> So you're saying you'll take the challenge to beat 10 steps?  :-)

movf   datain,w    ;if datain is already in W, cut this ( = 10 steps)

andlw 0xf0           ;send upper nybble to port
movwf portc        ;portc = abcd 0000, datain = abcd efgh

btfsc datain,3      ;set lower nybble bit pattern
bsf   portc,0
btfsc datain,2
bsf   portc,1
btfsc datain,1
bsf   portc,2
btfsc datain,0
bsf   portc,3         ;portc = abcd hgfe

Dmitriy's method is mathematically elegant, although (and
this will sound terribly ingracious but it's not meant to be), it
needs MOVWF PORTC to complete it = 10 steps

Unfortunately I'm not wired mathematically, try as I may

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\10@233625 by Dmitriy A. Kiryashov

picon face
Hi Jinx.

Jinx wrote:
> > So you're saying you'll take the challenge to beat 10 steps?  :-)
> movf   datain,w    ;if datain is already in W, cut this ( = 10 steps)
> andlw 0xf0           ;send upper nybble to port
> movwf portc        ;portc = abcd 0000, datain = abcd efgh

What about this particular movwf portc ? ;)

{Quote hidden}

That was Payson's idea initially ;)

Actually you should be very carefull using bsf operation under port
which is direct driving bunch of LED's. Read-modify-write is a hint.
As well as shadow port register.

WBR Dmitry.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\11@025306 by Jinx

face picon face
> Actually you should be very carefull using bsf operation
> under port which is direct driving bunch of LED's. Read-
> modify-write is a hint. As well as shadow port register

Yes, I know what you mean, but there's no modification
is there ? The bits being read are in DATAIN, not the
port (which is only being written to), so it should be OK

As they're only LEDs it shouldn't matter, but I wouldn't
use this method with port pins that are clock lines for
example, might be unpredictable

I think you still have me beat by a cycle

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


2002\03\11@075345 by Dmitriy A. Kiryashov

picon face
Good morning/day Jinx.

After you put byte into port you are making bsf manipulation.
In reality PIC _is_ reading port value than modify the bit than
writes it back to port. In your example modified data is stored
exactly in port itself.

What I was saying that depending from load situation or delays
because of capacitance if you write "0"/"1" you probably won't
get it back two cycles later for say on 20MHz clocking.

I stepped onto this trouble couple times in the past. After that
if I doubt a little bit I better use shadow register technique.
All manipulations are performed under some memory cells than that
value is copied to requied port.


WBR Dmitry.

PS. Nobody beat anybody, especially by the cycle ;)



Jinx wrote:
{Quote hidden}

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


'[PICLIST] Re [PIC}: Bit operation quiz...'
2002\03\11@155934 by Jinx

face picon face
> Good morning/day Jinx.
>
And good day to you

> After you put byte into port you are making bsf manipulation.
> In reality PIC _is_ reading port value than modify the bit than
> writes it back to port. In your example modified data is stored
> exactly in port itself.

I mistakenly "thought" that mov instructions are r-m-w but bsf/bcf
aren't. It says in the manual that "All write operations are r-m-w.
So a write to a port implies that that the port pins are first read,
then this value is modified and written to the port latch". I'm
aware of the bsf-nop-bcf of course and use that in my own s/w
and so shouldn't have made such an erroneous statement

The btfsc instructions between the bsf instructions should be
enough to avoid a bad r-m-w situation with LEDs

> What I was saying that depending from load situation or delays
> because of capacitance if you write "0"/"1" you probably won't
> get it back two cycles later for say on 20MHz clocking.

That's certainly something to watch out for, perhaps more so
in analogue circuits. Digital interfaces should be alright shouldn't
they ? Are you thinking of an instance where you'd drive a
logic chip with one pin and expect to see a result on another ?
>
> I stepped onto this trouble couple times in the past. After that
> if I doubt a little bit I better use shadow register technique.
> All manipulations are performed under some memory cells
> than that value is copied to requied port

That's a sensible thing to do. Is r-m-w a peculiarity of the PIC ?
The AVR, for example, is quite different. There's no mention
of r-m-w with regard to any port operation. In fact you can
perform two distinct reads of a port - you can either read the
latches or use the PIN instruction to read the logical values
present on the pins

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


2002\03\12@035041 by Michael Rigby-Jones

flavicon
face
> That's a sensible thing to do. Is r-m-w a peculiarity of the PIC ?
> The AVR, for example, is quite different. There's no mention
> of r-m-w with regard to any port operation. In fact you can
> perform two distinct reads of a port - you can either read the
> latches or use the PIN instruction to read the logical values
> present on the pins
>
Most micro's use RMW, the peculiarity with the PIC is that when such an
operation is performed on a PORT, the value read is not that in the data
latch, but rather the values on the pins.  The 18C/18F series fixed this
problem as you can read either the pins or the data latch.

Mike

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


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