problems with PROGMEM [SOLVED]

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will need to move some text over to PROGMEM to save RAM

First the program works with normal strings:

//declare
char settingtext[8][15]  ={"BURNER TEMP ST",
                          "BURNER TEMP F1",
                          "BURNER TEMP F2",
                          "BURNER TEMP F3",
                          "BURNER TEMP F4",
                          "BURNER TEMP F5",
                          "BURNER TEMP F6",
                          "HIGH TEMP ST  "};

//print func
void printtextCRT(char *ptr){
  while (*ptr)
    putcharCRT(*ptr++);
}

//call
printtextCRT(settingtext[(int)RCchangepointer]);

now I changed it to :

const char settingtext[8][15] PROGMEM ={"BURNER TEMP ST",
                          "BURNER TEMP F1",
                          "BURNER TEMP F2",
                          "BURNER TEMP F3",
                          "BURNER TEMP F4",
                          "BURNER TEMP F5",
                          "BURNER TEMP F6",
                          "HIGH TEMP ST  "};

//func
void printtextCRT_PGM(const char *ptr){
  while ( pgm_read_byte(*ptr) )
    putcharCRT(pgm_read_byte(*ptr++) );
}

//call
printtextCRT_PGM(settingtext[(int)RCchangepointer]);

It compile but don't work
where is my error ?

Edit: a type error
Add I use winAVR 20100110 but I guess this is my error and not the compiler

Last Edited: Mon. Nov 11, 2013 - 03:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Too many stars!

//func
void printtextCRT_PGM(const char *ptr){
  while ( pgm_read_byte(ptr) )
    putcharCRT(pgm_read_byte(ptr++) );
}

pgm_read_byte() dereferences the pointer anyway (just like * for RAM) so you don't want "*ptr" in there but just "ptr".

PS if you upgrade to 4.7.2 you could use __flash instead of PROGMEM and you wonuldn't need the pgm_read*() stuff so the flash code would be almost identical to the RAm code except for the addition of "__flash".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks it works
It's a bad bad time to change the compiler at the moment :)

I wanted to change the headline to add solved how to do that ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can hit the [Edit] button on the first post in the thread, change the "Subject" and that changes the thread title.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks that is one of those things you need to know :)