uchar SPI_Transmit_sw(uchar send_byte) { uchar rec_byte = 0; uchar i; for (i = 0; i < 8; i++) { // Transmit MSB first if ((send_byte & 0x80) != 0) { SET_MOSI(); // Set MOSI high } else { CLR_MOSI(); // Set MOSI low } // Shift 2nd msb to msb send_byte = send_byte << 1; // Get data from MISO pin rec_byte = rec_byte << 1; if (GET_MISO()) { rec_byte++; } // Pulse clock SET_SCK(); ten_us_delay(sw_delay_time); CLR_SCK(); ten_us_delay(sw_delay_time); } return rec_byte; }
//egy bitet kiküld a ledmeghajtó SDI lábára //b=0: low //b!=0: high static void send_one_bit(int b){ if(b) SET_SDI(); else CLR_SDI(); SET_SCK(); CLR_SCK(); }