Skip to content

Instantly share code, notes, and snippets.

@RozeDoyanawa
Created May 30, 2020 17:52
Show Gist options
  • Save RozeDoyanawa/0a2a05f777c2ce7bda16e5af544ea528 to your computer and use it in GitHub Desktop.
Save RozeDoyanawa/0a2a05f777c2ce7bda16e5af544ea528 to your computer and use it in GitHub Desktop.
#define SPI_HIGH 1
#define SPI_LOW 0
#define SPI_DELAY Delay1000us()
void pushByte(unsigned char byte){
LATBbits.LATB5 = SPI_HIGH;
LATBbits.LATB4 = SPI_HIGH;
SPI_DELAY;
for(int i = 0; i < 8; i++){
LATBbits.LATB5 = ((byte >> i) & 1);
LATBbits.LATB4 = SPI_LOW;
SPI_DELAY;
LATBbits.LATB4 = SPI_HIGH;
SPI_DELAY;
}
}
void doTransferSoftware(void){
unsigned char byte;
int i;
transferMode = 1;
pushByte(0);
pushByte(0);
pushByte(0);
pushByte(0);
transferMode = 2;
for(i = 0; i < pixelCount; i++){
signed int toTransfer = (transferOffset + transfered) % pixelCount;
pushByte(0b11100000 | transferBuffer[toTransfer].A);
pushByte(transferBuffer[toTransfer].B);
pushByte(transferBuffer[toTransfer].G);
pushByte(transferBuffer[toTransfer].R);
}
transferMode = 3;
for(i = 0; i < pixelCount; i++){
pushByte(0);
pushByte(0);
pushByte(0);
pushByte(0);
}
transferMode = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment