Searching \ for '[PIC] macros to get around read-modify-write' 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: 'macros to get around read-modify-write'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] macros to get around read-modify-write'
2008\01\25@143554 by Martin

face
flavicon
face
Do you use macros in your assembly program to get around the fact that
you shouldn't be using read-modify-write commands on a port?
I wrote two macros that should accomplish this:

setb    macro    port, pin
   movff    port,portbuf
   bsf        portbuf, pin
   movff    portbuf, port
   endm


clrb    macro    port, pin
   movff    port,portbuf
   bcf        portbuf, pin
   movff    portbuf, port
   endm

Simple, right? They don't work right. If I do this:

setb PORTB,0
setb PORTB,1
nop
clrb PORTB,0
clrb PORTB,1

Pin 0 is set then goes low while pin 1 goes high, then pin 1 goes low -
so it looks like the second "setb" doesn't occur until pin 0 is cleared.
The pulses don't overlap at all.
Do you know what the problem is?
-
Martin

2008\01\25@150632 by James Newton

face picon face
Don't read the port. Just set the "pin" in portbuf, then copy it out to the
port.

As long as you ALWAYS set the pin in portbuf FIRST, you will never loose
anything by not reading the port.

--
James.

{Original Message removed}

2008\01\25@151527 by Martin

face
flavicon
face
James Newton wrote:
> Don't read the port. Just set the "pin" in portbuf, then copy it out to the
> port.
>
> As long as you ALWAYS set the pin in portbuf FIRST, you will never loose
> anything by not reading the port.
>
> --
> James.
>  

I just realized that. I'm creating my own r-m-w problem, not bypassing it.
Thanks.

-Martin

2008\01\25@155728 by Tamas Rudnai

face picon face
So how would you handle this code with your macros if you modify that with
James' suggestion:

setb PORTB,0
setb PORTA,1
nop
clrb PORTC,0
clrb PORTD,1

?

Tamas


On Jan 25, 2008 8:15 PM, Martin <spam_OUTmartinTakeThisOuTspamnnytech.net> wrote:

{Quote hidden}

> -

2008\01\25@160545 by wouter van ooijen

face picon face
> Do you use macros in your assembly program to get around the
> fact that
> you shouldn't be using read-modify-write commands on a port?

yes, but not on 18F chips, where you can safely R-M-W the LATx
registers!

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu



2008\01\25@162423 by Jinx

face picon face
> setb PORTB,0
> setb PORTB,1
> nop
> clrb PORTB,0
> clrb PORTB,1
>
> Pin 0 is set then goes low while pin 1 goes high, then pin 1 goes
> low - so it looks like the second "setb" doesn't occur until pin 0
> is cleared. The pulses don't overlap at all. Do you know what
> the problem is?

As you've realised, r-m-w can produce some peculiar effects.
Sometimes the pins output the complete opposite of what was
intended

http://www.piclist.com/techref/scenix/sxrmw.htm

2008\01\26@031959 by Robin Abbott

flavicon
face
Why would you be doing this instead of using the LAT registers - which give
you a much clearer view of what is happening when an input changes to an
output.

Robin Abbott
Forest Electronics - Home of WIZ-C ANSI C Compiler for PIC's with RAD Front
end
.....robin.abbottKILLspamspam@spam@fored.co.uk
http://www.fored.co.uk


{Original Message removed}

2008\01\28@082633 by Martin

face
flavicon
face
Tamas Rudnai wrote:
> So how would you handle this code with your macros if you modify that with
> James' suggestion:
>
> setb PORTB,0
> setb PORTA,1
> nop
> clrb PORTC,0
> clrb PORTD,1
>
> ?
>
> Tamas
>
>
>  
Tamas, my macros are defined like this now:

setb    macro    pin
   bsf        portbbuf, pin
   movff    portbbuf, PORTB
   endm

clrb    macro    pin
   bcf        portbbuf, pin
   movff    portbbuf, PORTB
   endm



But like Wouter and Robin reminded me, this PIC has the LAT registers
that can be safely used with read-modify-write operations. Much nicer.

-
Martin

2008\01\28@082703 by Martin

face
flavicon
face
Just so you would ask why, of course.
It's been a while since I've done any major PIC programming, and the
last chip I used was the 12F675, so I didn't remember the LAT registers.
Thanks for reminding me.
-
Martin

Robin Abbott wrote:
{Quote hidden}

> {Original Message removed}

2008\01\28@091223 by Tamas Rudnai

face picon face
Mi Martin,

Please not that that fraction of code intended to use other ports than just
portb - just realized that the 'b' from the name setb is for portb only?
Then that's ok, I was just thinking of a generic way of port handling, sorry
for the confusion :-)

Anyway, yes, if you use 18F and later series, you have LAT which is way
better than any other shadow register solutions.

Tamas


On Jan 28, 2008 1:26 PM, Martin <.....martinKILLspamspam.....nnytech.net> wrote:

{Quote hidden}

> -

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