Search code examples
cavratmega16codevisionavr

How to declare a matrix that is stored in PROGMEM


I am trying to write a header file that will drive a LED Matrix but I'm stuck with a syntax error which I cannot resolve

I've already added " ; " everywhere I thought it was necessary and checked https://www.nongnu.org/avr-libc/user-manual/pgmspace.html

#ifndef max7219_H_
#define max7219_H_

#include <io.h>
#include <pgmspace.h>
#include <delay.h>
#include <stdint.h>

#define SLAVE_SELECT PORTB &= ~( 1<<PB4 );     
#define SLAVE_DESELECT PORTB |= ~( 1<<PB4 ); 

char characters[96][5] PROGMEM = 
{ 
   {
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000 
    }  
};

ERROR IS : Error: max7219.h(15), #included from: p2.c: ';' expected

line 15 is char characters[96][5] PROGMEM = ...


Solution

  • const PROGMEM uint8_t characters[96][5] = {
        {
          0b00000000,
          0b00000000,
          0b00000000,
          0b00000000,
          0b00000000 
       },
        ... // 95 more symbols
     };
    

    Note, if an array declared with dimension, it should contain all the data in the initializer, i.e. all 96 symbols.

    UPD: The error could be caused by the code in pc2.c just before #include "max7219.h" If you have several "includes", then check the previous one. I.e:

    #include "a.h"
    #include "b.h"
    #include "max7219.h"
    

    the error may be at the end of b.h