My first DO loop worked, which is a software bit bang for SPI write. MSB goes out first.
The device select pin has already been pulled low before calling this to send a byte.
I remembered no way to copy a bit directly, so I don’t like that with the use of BTSS/BTSC,
the data pin would be set faster than it is cleared, so a serial waveform would look odd, despite working.
That is why the input byte is rotated where it is (for an extra instruction delay after the data pin possibly being sent low).
I’m wondering if I should AND the portb latch pin with the data bit for even timing?
So it would take the same time to set or clear the data pin before the latch pin is set?
void WriteSPIFast(unsigned char data_out) {
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 7; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 6; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 5; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 4; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 3; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 2; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out >> 1; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = data_out; SPICLOCKLAT = 1;
SPICLOCKLAT = 0; SPIOUTLAT = 0;
}
void WriteSPIFaster(unsigned char data_out) {
srbyte = data_out;
asm volatile ("BITBANG: DO #7, ENDBANG");
asm volatile ("BCLR LATB,#8");
asm volatile ("BTSC.b _srbyte,#7");
asm volatile ("BSET LATB,#7");
asm volatile ("BTSS.b _srbyte,#7");
asm volatile ("BCLR LATB,#7");
asm volatile ("RLNC.b _srbyte");
asm volatile ("ENDBANG: BSET LATB,#8");
asm volatile ("BCLR LATB,#8");
asm volatile ("BCLR LATB,#7");
}