We can clone PIC16LF870 protected chip source code, please view the PIC16LF870 protected chip features for your reference:
When the application software is expecting to receive valid data, the SSPBUF should be read before the next byte of data to transfer is written to the SSPBUF. Buffer Full bit, BF (SSPSTAT<0>), indicates when SSPBUF has been loaded with the received data (transmission is complete). When the SSPBUF is read, the BF bit is cleared. This data may be irrelevant if the SPI is only a transmitter.
Generally, the SSP interrupt is used to determine when the transmission/reception has completed. The SSPBUF must be read and/or written if Clone PIC16LF870 Protected Chip Source Code.
If the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur after Clone Microchip dsPIC30F3010 16-Bit Digital Signal Controllers. Example 14-1 shows the loading of the SSPBUF (SSPSR) for data transmission. The SSPSR is not directly readable or writable and can only be accessed by addressing the SSPBUF register.
Additionally, the SSP Status register (SSPSTAT) indicates the various status conditions. To enable the serial port, SSP Enable bit, SSPEN (SSPCON<5>), must be set to faciliate the procedures of IC Break. To reset or reconfigure SPI mode, clear the SSPEN bit, re-initialize the SSPCON registers and then set the SSPEN bit. This configures the SDI, SDO, SCK and SS pins as serial port pins.
For the pins to behave as the serial port function, some must have their data direction bits (in the TRIS register) appropriately programmed. That is:
SDI is automatically controlled by the SPI module
SDO must have TRISC<4> bit cleared
SCK (Master mode) must have TRISC<6> bit cleared
SCK (Slave mode) must have TRISC<6> bit set
SS must have TRISA<5> bit set
Any serial port function that is not desired may be overridden by programming the corresponding data direction (TRIS) register to the opposite value in the process of Unlock Microprocessor PIC16F873 Secured Heximal.