TODOPIC

Microcontroladores PIC => dsPIC => Mensaje iniciado por: STAI en 20 de Septiembre de 2009, 15:10:05

Título: Problemas con manejos bit a bit de un puerto...
Publicado por: STAI en 20 de Septiembre de 2009, 15:10:05
Hola a todos estoy tratando de modificar un solo bit del PORTB de mi dsPIC33FJ... pero cuando hago la instrucción PORTbits.RB15 = 1 me modifica todo lo que tenía el PORTB..., alguien que me colabore con ese asuntico... estoy pensando que es mi compilador pero no estoy seguro... gracias...
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: Nocturno en 20 de Septiembre de 2009, 15:12:04
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: STAI en 20 de Septiembre de 2009, 15:44:07
Si nocturno el C30, y voy a intentar lo que me dices, muchas gracias... te estare comentando...
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: STAI en 20 de Septiembre de 2009, 16:08:53
OK nocturno muchas gracias si me funciono, pero me queda la duda por qué no puedo utilizar PORTXbits.RBXX = #?
¿Utilizas C30?
En cualquier caso, prueba a escribir en el registro LAT, en lugar de directo al puerto.
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: Nocturno en 20 de Septiembre de 2009, 16:12:17
No estoy seguro, creo recordar que venía explicado en la datasheet, pero ahora mismo no me acuerdo porqué ocurre eso.
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: RedPic en 20 de Septiembre de 2009, 17:05:38
Del documento dspic30f family reference manual (70046e.pdf) Página 254 y siguientes:

11.2.2 PORT Registers
Data on an I/O pin is accessed via a PORTx register. A read of the PORTx register reads the
value of the I/O pin, while a write to the PORTx register writes the value to the port data latch.
Many instructions, such as BSET and BCLR instructions, are read-modify-write operations.
Therefore, a write to a port implies that the port pins are read, this value is modified, and then
written to the port data latch. Care should be taken when read-modify-write commands are used
on the PORTx registers and when some I/O pins associated with the port are configured as
inputs. If an I/O pin configured as an input is changed to an output at some later time, an unexpected
value may be output on the I/O pin. This effect occurs because the read-modify-write
instruction reads the instantaneous value on the input pin and loads that value into the port data
latch.


11.2.3 LAT Registers
The LATx register associated with an I/O pin eliminates the problems that could occur with
read-modify-write instructions. A read of the LATx register returns the values held in the port
output latches, instead of the values on the I/O pins. A read-modify-write operation on the LAT
register, associated with an I/O port, avoids the possibility of writing the input pin values into the
port latches. A write to the LATx register has the same effect as a write to the PORTx register.
The differences between the PORT and LAT registers can be summarized as follows:
• A write to the PORTx register writes the data value to the port latch.
• A write to the LATx register writes the data value to the port latch.
• A read of the PORTx register reads the data value on the I/O pin.
• A read of the LATx register reads the data value held in the port latch.
Any bit and its associated data and control registers that are not valid for a particular device will
be disabled. That means the corresponding LATx and TRISx registers, and the port pin, will read
as zeros


La diferencia fundamental está en que hay instrucciones que implican escritura que al actuar directamente sobre el registro del PORT realizan una lectura del estado del PORT que es transferida al LATCH,  pudiendo darse entonces un estado contradictorio entre el estado del PORT y del LATCH, al cambiar posteriormente el TRIS del puerto puede producirse un estado indefinido del mismo. Por ello aconsejan solo "leer" el PORT, no escribir en él pero por el contrario "leer"  y "escribir" alegremente el LATCH ya que éste no presenta los problemas del PORT.

Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: STAI en 20 de Septiembre de 2009, 17:56:18
OK nocturno muchas gracias por tu completa explicación, exitos...

Del documento dspic30f family reference manual (70046e.pdf) Página 254 y siguientes:

11.2.2 PORT Registers
Data on an I/O pin is accessed via a PORTx register. A read of the PORTx register reads the
value of the I/O pin, while a write to the PORTx register writes the value to the port data latch.
Many instructions, such as BSET and BCLR instructions, are read-modify-write operations.
Therefore, a write to a port implies that the port pins are read, this value is modified, and then
written to the port data latch. Care should be taken when read-modify-write commands are used
on the PORTx registers and when some I/O pins associated with the port are configured as
inputs. If an I/O pin configured as an input is changed to an output at some later time, an unexpected
value may be output on the I/O pin. This effect occurs because the read-modify-write
instruction reads the instantaneous value on the input pin and loads that value into the port data
latch.


11.2.3 LAT Registers
The LATx register associated with an I/O pin eliminates the problems that could occur with
read-modify-write instructions. A read of the LATx register returns the values held in the port
output latches, instead of the values on the I/O pins. A read-modify-write operation on the LAT
register, associated with an I/O port, avoids the possibility of writing the input pin values into the
port latches. A write to the LATx register has the same effect as a write to the PORTx register.
The differences between the PORT and LAT registers can be summarized as follows:
• A write to the PORTx register writes the data value to the port latch.
• A write to the LATx register writes the data value to the port latch.
• A read of the PORTx register reads the data value on the I/O pin.
• A read of the LATx register reads the data value held in the port latch.
Any bit and its associated data and control registers that are not valid for a particular device will
be disabled. That means the corresponding LATx and TRISx registers, and the port pin, will read
as zeros


La diferencia fundamental está en que hay instrucciones que implican escritura que al actuar directamente sobre el registro del PORT realizan una lectura del estado del PORT que es transferida al LATCH,  pudiendo darse entonces un estado contradictorio entre el estado del PORT y del LATCH, al cambiar posteriormente el TRIS del puerto puede producirse un estado indefinido del mismo. Por ello aconsejan solo "leer" el PORT, no escribir en él pero por el contrario "leer"  y "escribir" alegremente el LATCH ya que éste no presenta los problemas del PORT.


Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: RedPic en 21 de Septiembre de 2009, 04:10:15

OK nocturno muchas gracias por tu completa explicación, exitos...


De nada ... pero no soy Nocturno.  :mrgreen:
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: BrunoF en 21 de Septiembre de 2009, 04:28:55
Ah! ya los confunden. :mrgreen: :mrgreen: :mrgreen:
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: STAI en 21 de Septiembre de 2009, 12:21:59
Un hermano qué pena, miré muy de afan y no me fije bien, muchas gracias... exitos...

[/quote]

De nada ... pero no soy Nocturno.  :mrgreen:
[/quote]
Título: Re: Problemas con manejos bit a bit de un puerto...
Publicado por: Nocturno en 21 de Septiembre de 2009, 14:50:29
Por mí no hay problema, es un honor que me confundas con él.