Help with something I SHOULD already know

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
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

Rich (BB code):
MOVLW 0xAA
MOVWF SSPBUF   ;notice I'm not checking to see if the SSPBUF is finished below
MOVLW  0x04  ;clock in high nibble of character "A"
MOVWF  PORTB  ;put on portb, this is where I'm curious
<<<SUBROUTINE TO CLOCK INTO LCD GOES HERE>>
MOVLW  0x01  ;clock in low nibble of character "A"
MOVWF  PORTB   ;put on portb, this is where I'm curious
<<SUBROUTINE TO CLOCK INTO LCD GOES HERE>>
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!
 

Markd77

Joined Sep 7, 2009
2,806
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.
 
Top