void RFID_setRegister(uint8_t data,uint8_t address) { SLAVE_SELECT; SPI_tradeByte( address << 1 ); //transmit command start 0x01 is address SPI_tradeByte(data); SLAVE_DESELECT; }
void RTC_SPI_writeByte(uint8_t address, uint8_t data) //Writes a byte to the desired address { SLAVE_SELECT_RTC; //Enable the RTC comms SPI_tradeByte(address); //Send the address to be written to SPI_tradeByte(data); //Send the data to be written to address SLAVE_DESELECT_RTC; //Disable the RTC comms }
uint8_t RFID_readRegister(uint8_t address) { SLAVE_SELECT; SPI_tradeByte( address << 1 | 0x80 ); //transmit command start 0x01 is address SPI_tradeByte(0); SLAVE_DESELECT; return (SPDR); /* return the result */ }
uint8_t RTC_SPI_readByte(uint8_t address) //Reads and returns a byte at the desired address { SLAVE_SELECT_RTC; //Enable the RTC comms SPI_tradeByte(address); //Send the address to be read from SPI_tradeByte(0); //Send dummy byte to load SPDR with byte at address SLAVE_DESELECT_RTC; //Disable the RTC comms return(SPDR); //Return the byte. SPDR=SPI Data Register }
void SEV_SEG_writeByte(uint8_t address, uint8_t data) //Writes a byte to an address in the MAX7219 { SEV_SEG_LOAD_LOW; //Drop the level of the LOAD pin SPI_tradeByte(0); SPI_tradeByte(0); SPI_tradeByte(address); //Send the register address where the data will be stored SPI_tradeByte(data); //Send the data to be stored SEV_SEG_LOAD_HIGH; //Raise the level of the LOAD pin - this triggers latching of the sent bytes (last 16 bits of data are latched). }
void SEV_SEG_allClear(void) //Clears all digits. Bypasses function "SEV_SEG_writeByte" and clears equivalent digits on both drivers simultaneously (~halves clear time). { uint8_t i; for (i=8; i>0; i--) //Counts down through the digits from digit 7 (8) to digit 0 (1). { SEV_SEG_LOAD_LOW; //Drop the level of the LOAD pin SPI_tradeByte(i); //Push in digit address i (will be in driver B at latch) SPI_tradeByte(SEV_SEG_CODEB_BLANK); //Push in data to clear digit at i (will be in driver B at latch) SPI_tradeByte(i); //Push in digit address i (will be in driver A at latch) SPI_tradeByte(SEV_SEG_CODEB_BLANK); //Push in data to clear digit at i (will be in driver A at latch) SEV_SEG_LOAD_HIGH; //Raise the level of the LOAD pin - this triggers latching of the sent bytes (last 16 bits of data in driver are latched). } }
void SEV_SEG_writeByte(uint8_t address, uint8_t data) //Writes a byte to an address in both of the MAX7219s although one driver will receive data, the other will receive no-op command. { if(address & 0x80) //Check driver flag. If set, address is for driver B (DIG_8 to DIG_15). { SEV_SEG_LOAD_LOW; //Drop the level of the LOAD pin SPI_tradeByte(address); //Send the register address where the data will be stored SPI_tradeByte(data); //Send the data to be stored SPI_tradeByte(0); //Roll no-op data through to push real data out of driver A and into driver B (address byte) SPI_tradeByte(0); //Roll no-op data through to push real data out of driver A and into driver B (data byte) SEV_SEG_LOAD_HIGH; //Raise the level of the LOAD pin - this triggers latching of the sent bytes (last 16 bits of data are latched). } else //Not set, therefore address is for driver A (DIG_0 to DIG_7). { SEV_SEG_LOAD_LOW; //Drop the level of the LOAD pin SPI_tradeByte(0); //Roll no-op data in first for driver B when real data for driver A pushes it through (address byte) SPI_tradeByte(0); //Roll no-op data in first for driver B when real data for driver A pushes it through (data byte) SPI_tradeByte(address); //Send the register address where the data will be stored SPI_tradeByte(data); //Send the data to be stored SEV_SEG_LOAD_HIGH; //Raise the level of the LOAD pin - this triggers latching of the sent bytes (last 16 bits of data are latched). } }