#include #include "spi.h" void spi_init(){ while(!osccon.IOFS){} //wait for osc stable sspstat = 0b00000000; //SMP(7)=0, CKE(6)=0 (clock edge idle to active) sspcon1 = 0b00010010; //CKP(4)=1 clock polarity (idle high) //SSPM3:SSPM0(3:0)=010 spi clock FOSC/64 (<400kHz) sspcon1.SSPEN=1; //SSPEN(5)=1 enable SPI } unsigned char spi_putc(unsigned char send){ sspbuf=send; while(!sspstat.BF){} return sspbuf; }