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:
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
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.
> 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
>
> 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
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.
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:
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
> 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.abbottKILLspamfored.co.uk
> http://www.fored.co.uk
>
>
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 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