Read Modify Write problem?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2005
    Posts
    53

    Question Read Modify Write problem?

    I am writing to a 7segment LED display with a 16F627A and believe I might be experiencing a Read Modify Write problem, some segments will not turn off.
    If I use a pullup resistor on the output the segments will turn off. It seems like the output pin is being read as an input.

    I turned off analog comparators and set TRISA = %00001100 and
    TRISB = %00000010.

    Any suggestions how should I modify controlling the outputs?
    X0 is my variable that has the segment pattern and I write
    each output pin. Hardware serial port uses portB.1 & portB.2
    and prevents writing a word to the entire portB.


    PORTB.0 = X0.0 ' Send segments to LED
    PORTA.4 = X0.1
    PORTA.6 = X0.2
    PORTB.3 = X0.3
    PORTB.4 = X0.4
    PORTB.5 = X0.5
    PORTB.6 = X0.6
    PORTB.7 = X0.7

    Thanks,

    Mark

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Mark,

    Instead of trying to set the PORT's either high or low, set the PORT to the active ON state, then set the TRIS bit to INPUT(1) or OUTPUT(0) to control the LED's. No R-M-W that way.
    <br>
    DT

  3. #3
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    Is this what you meant?
    Variable X0 is the segment pattern and is sent to the output ports.
    TRISB. I use OR to maintain portB.1 as input
    TRISA. I use OR to maintain PortA.2 and PortA.3 as inputs
    Is there an better approach?



    'initialize ports
    TRISA = %00001100 'configure port A outputs = 0
    TRISB = %00000010 'configure port B outputs = 0

    Thanks,

    Mark

    'write segments to ports A and B
    PORTB.0 = X0.0 ' Send segments to LED 0 = ON
    PORTA.4 = X0.1
    PORTA.6 = X0.2
    PORTB.3 = X0.3
    PORTB.4 = X0.4
    PORTB.5 = X0.5
    PORTB.6 = X0.6
    PORTB.7 = X0.7

    TRISB = X0 OR %00000010 ' OFF segments = 1 (set to inputs)
    X1=X0 AND %01010000 ' isolate X1= PortA.4 and PortA.6 bits
    TRISA = X1 OR %00001100 'maintain PortA.2 and PortA.3 inputs

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    uh, nope.

    I was thinking something more like this.

    PORTA = 0
    PORTB = 0

    'write segments to ports A and B
    TRISB.0 = X0.0 ' Send segments to LED 0 = ON
    TRISA.4 = X0.1
    TRISA.6 = X0.2
    TRISB.3 = X0.3
    TRISB.4 = X0.4
    TRISB.5 = X0.5
    TRISB.6 = X0.6
    TRISB.7 = X0.7
    <br>
    DT

  5. #5
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Wink

    Thanks Darrel,

    That is much cleaner! I will give it a try.

    Mark

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 13:06
  3. Read Write Problem
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th June 2009, 19:03
  4. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  5. problem to read write 24LC512
    By edysan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th February 2008, 21:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts