int main() { DDRB=0x01; // Set PB0 pin as output for display select spi_masterInit(); // Initialize spi module displayDriverInit(); // Initialize display chip // clear display (all zero's) for (char i =1; i<=2; i++) { spi_slaveSelect(0); // Select display chip spi_write(i); // digit adress: (digit place) spi_write(0); // digit value: 0 spi_slaveDeSelect(0); // Deselect display chip } wait(1000); // write 4-digit data for (char i =1; i<=2; i++) { spi_slaveSelect(0); // Select display chip spi_write(i); // digit adress: (digit place) spi_write(i); // digit value: i (= digit place) spi_slaveDeSelect(0); // Deselect display chip wait(1000); } wait(1000); return (1); }
// Set display off ('shut down') void displayOff() { spi_slaveSelect(0); // Select display chip spi_write(0x0C); // Register 0B: Shutdown register spi_write(0x00); // -> 1 = Normal operation spi_slaveDeSelect(0); // Deselect display chip }
void spi_writeWord( unsigned char adress, unsigned char data ) { spi_slaveSelect(0); // Select display chip spi_write(adress); // write to adress spi_write(data); // write data spi_slaveDeSelect(0); // Deselect display chip }
//Microcontrollers – TI2.3 - Opdrachten track 5 - versie 14-03-2016 Pagina 10 van 11 // Initialize the driver chip (type MAX 7219) void displayDriverInit() { spi_slaveSelect(0); // Select display chip (MAX7219) spi_write(0x09); // Register 09: Decode Mode spi_write(0xFF); // -> 1's = BCD mode for all digits spi_slaveDeSelect(0); // Deselect display chip spi_slaveSelect(0); // Select dispaly chip spi_write(0x0A); // Register 0A: Intensity spi_write(0x04); // -> Level 4 (in range [1..F]) spi_slaveDeSelect(0); // Deselect display chip spi_slaveSelect(0); // Select display chip spi_write(0x0B); // Register 0B: Scan-limit spi_write(0x01); // -> 1 = Display digits 0..1 spi_slaveDeSelect(0); // Deselect display chip spi_slaveSelect(0); // Select display chip spi_write(0x0C); // Register 0B: Shutdown register spi_write(0x01); // -> 1 = Normal operation spi_slaveDeSelect(0); // Deselect display chip }
void spi_writeWord(unsigned char adress, unsigned char data) { spi_slaveSelect(0); // Select display chip spi_write(adress); // digit adress: (digit place) spi_write(data); // digit value: i (= digit place) spi_slaveDeSelect(0); // Deselect display chip }