Neven Boyanov
Published © CC BY-SA

How to Interface a MAX7219 Driven LED Matrix with ATtiny85

The MAX7219 modules are very convenient to use with microcontrollers such as ATtiny85, or, in our case the Tinusaur board.

IntermediateProtip1 hour704
How to Interface a MAX7219 Driven LED Matrix with ATtiny85

Things used in this project

Hardware components

Tinusaur Shield GAMEx3
×1
Tinusaur Bundle Kit Gametinu
×1
Tinusaur Board 3 LITE
Tinusaur Board 3 LITE
×1

Software apps and online services

Tinusaur MAX7219LED8x8

Story

Read more

Schematics

Tinusaur Shield GAMEx3 v3.0.1

Tinusaur Shield GAMEx3 v3.0.1

Tinusaur Shield GAMEx3 v3.0.1

Code

Code snippet #1

Plain text
void max7219_byte(uint8_t data) {
    for(uint8_t i = 8; i >= 1; i--) {
        PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
        if (data & 0x80)                // Mask the MSB of the data
            PORTB |= (1 << MAX7219_DIN);    // Set DIN to HIGH
        else
            PORTB &= ~(1 << MAX7219_DIN);   // Set DIN to LOW
        PORTB |= (1 << MAX7219_CLK);        // Set CLK to HIGH
        data <<= 1;                     // Shift to the left
    }
}

Code snippet #2

Plain text
void max7219_byte(uint8_t data) {
    for(uint8_t i = 8; i >= 1; i--) {
        PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
        if (data & 0x80)                // Mask the MSB of the data
            PORTB |= (1 << MAX7219_DIN);    // Set DIN to HIGH
        else
            PORTB &= ~(1 << MAX7219_DIN);   // Set DIN to LOW
        PORTB |= (1 << MAX7219_CLK);        // Set CLK to HIGH
        data <<= 1;                     // Shift to the left
    }
}

Code snippet #3

Plain text
void max7219_word(uint8_t address, uint8_t data) {
    PORTB &= ~(1 << MAX7219_CS);    // Set CS to LOW
    max7219_byte(address);          // Sending the address
    max7219_byte(data);             // Sending the data
    PORTB |= (1 << MAX7219_CS);     // Set CS to HIGH
    PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
}

Code snippet #4

Plain text
void max7219_word(uint8_t address, uint8_t data) {
    PORTB &= ~(1 << MAX7219_CS);    // Set CS to LOW
    max7219_byte(address);          // Sending the address
    max7219_byte(data);             // Sending the data
    PORTB |= (1 << MAX7219_CS);     // Set CS to HIGH
    PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
}

Code snippet #5

Plain text
uint8_t initseq[] = {
    0x09, 0x00, // Decode-Mode Register, 00 = No decode
    0x0a, 0x01, // Intensity Register, 0x00 .. 0x0f
    0x0b, 0x07, // Scan-Limit Register, 0x07 to show all lines
    0x0c, 0x01, // Shutdown Register, 0x01 = Normal Operation
    0x0f, 0x00, // Display-Test Register, 0x00 = Normal Operation
};

Code snippet #6

Plain text
uint8_t initseq[] = {
    0x09, 0x00, // Decode-Mode Register, 00 = No decode
    0x0a, 0x01, // Intensity Register, 0x00 .. 0x0f
    0x0b, 0x07, // Scan-Limit Register, 0x07 to show all lines
    0x0c, 0x01, // Shutdown Register, 0x01 = Normal Operation
    0x0f, 0x00, // Display-Test Register, 0x00 = Normal Operation
};

Code snippet #9

Plain text
max7219_init();
for (;;) {
    for (uint8_t r = 1; r <= 8; r++) {
        uint8_t d = 1;
        for (uint8_t i = 9; i > 0; i--) {
            max7219_row(r, d);
            d = d << 1;
            _delay_ms(50);
        }
    }
}

Code snippet #10

Plain text
max7219_init();
for (;;) {
    for (uint8_t r = 1; r <= 8; r++) {
        uint8_t d = 1;
        for (uint8_t i = 9; i > 0; i--) {
            max7219_row(r, d);
            d = d << 1;
            _delay_ms(50);
        }
    }
}

Bitbucket

https://bitbucket.org/tinusaur/max7219led8x8

Credits

Neven Boyanov

Neven Boyanov

7 projects • 9 followers
Computer programmer, entrepreneur and maker. Interested in science, technology and how things work. Lecturer in schools and universities.

Comments