About the hardware SPI you have:
#include <spi.h>
SPI exchange routine
unsigned char xchg_spi (unsigned char dat){
SSPBUF = dat;
while (!SSPSTATbits.BF);
return (BYTE)SSPBUF;
}
to use that routine use this commands
#define xmit_spi(dat) xchg_spi(dat)
#define rcvr_spi() xchg_spi(0xFF)
And finally I use this routines to set the speed of the SPI
static
void FCLK_SLOW(void){// Set slow clock (100k-400k)
SSPSTATbits.SMP = 0;
SSPCON1 = 0b00100010;// SSPEN (bit5) = 1, CKP (bit4) = 0, <3:0>0010 //0010 0010
SSPCON1bits.CKP = 0;
SSPSTATbits.CKE = 1; //Mode 0
SSPCON1bits.SSPEN = 1;
}
static
void FCLK_FAST(void){// Set fast clock (depends on the CSD)
SSPSTATbits.SMP = 0;
SSPCON1 = 0b00100000;// SSPEN (bit5) = 1, CKP (bit4) = 0, <3:0>0010 //0010 0010
SSPSTATbits.CKE = 1; //Mode 0
SSPCON1bits.CKP = 0;
SSPCON1bits.SSPEN = 1;
}
The pin settings for the SPI are in the datasheet. also remember to pull up and down your CS. In this configuration I gave you I seted up my SPI as master, in the datasheet you can check on how to set it to work as slave to use multiple pics.
About the software SPI you have:
#include <sw_spi.h>
OpenSWSPI(); //Set SPI Mode 0,CS pin B2,
//DIN pin B3, DOUT pin B7, SCK pin B6
you can change the pins but it would mean to edit and recompile the sw_spi.h library.
about the use of it, you can check the C18_libraries.pdf document and it goes like this.
3.5.2 Example of Use
#include <p18C452.h>
#include <sw_spi.h>
#include <delays.h>
void main( void )
{
char address;
// configure software SPI
OpenSWSPI();
for( address=0; address<0x10; address++ )
{
ClearCSSWSPI(); //clear CS pin
WriteSWSPI( 0x02 ); //send write cmd
WriteSWSPI( address ); //send address hi
WriteSWSPI( address ); //send address low
SetCSSWSPI(); //set CS pin
Delay10KTCYx( 50 ); //wait 5000,000TCY
}
}
In that document doesn't say anything about the software SPI speed so if you have any clue about it let me know, otherwise I'll run some test and let you know as soon as posible.