Help with something I SHOULD already know

Discussion in 'Embedded Systems and Microcontrollers' started by wannaBinventor, Jan 28, 2011.

  1. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    As the title implies, I've been programming PICs long enough that I should know this, but I really don't.

    Let's suppose that I have both the SPI peripheral pins and the LCD data lines (using four wire) on one port.

    Say the connections are like this:
    PORTB.0 = LCD D4
    PORTB.1 = LCD D5
    PORTB.2 = LCD D6
    PORTB.3 = LCD D7
    PORTB.4 = SPI MOSI
    PORTB.5 = SPI MISO
    PORTB.6 = SPI CLOCK
    PORTB.7 = No Connection
    LCD control pins are on a different port.

    Let's say I'm doing this

    Code ( (Unknown Language)):
    1.  
    2. MOVLW 0xAA
    3. MOVWF SSPBUF   ;notice I'm not checking to see if the SSPBUF is finished below
    4. MOVLW  0x04  ;clock in high nibble of character "A"
    5. MOVWF  PORTB  ;put on portb, this is where I'm curious
    6. <<<SUBROUTINE TO CLOCK INTO LCD GOES HERE>>
    7. MOVLW  0x01  ;clock in low nibble of character "A"
    8. MOVWF  PORTB   ;put on portb, this is where I'm curious
    9. <<SUBROUTINE TO CLOCK INTO LCD GOES HERE>>
    10.  
    If I did that, am I going to mess up what I'm trying to do with the SPI whenever I move 0x04 onto PORTB. I know the MISO (PORTB.5 in my example) is an input, so writes to the the port won't effect that pin, but what about the MOSI (PORTB.4) and SCK (PORTB.6) pins? 0x04 on PORTB technically clears those, but are the SPI pins even altered if I've enabled the SPI and it's writing? I want to make sure the above code wouldn't start the SPI clock and MOSI lines to working and then cut them off with the 0x04 write to PORTB.

    Also, I'm still not clear if I should be using PORTB or LATB on the PIC18F (which I'm still trying to learn) for writes. Is it truly as basic as "PORT" is for reading the port pins and "LAT" is for writing the port pins?

    Thanks!
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Writing to portb shouldn't have any effect on the SPI.
    I think you should write to LAT although if you are using movwf to write to the port I think that should also work fine. If you wanted to do BSF (or any other bit operation like RRF) on the port then using LAT is definitely safer. It's all to do with the "read, modify, write" problem.
     
Loading...