| Author |
Message |
|
|
Posted: May 19, 2012 - 02:04 AM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
I moved my ram wasting strings to program memory, but now my LCD speaks Borg. I must be picking the chars out of progmem improperly. I have this in a .CPP file, not a .C. Perhaps I need to follow a different tutorial?
http://www.avrfreaks.net/index.php?name ... sh+strings
My Write procedure:
Code:
void LCDWrite( char d )
{
Wait();
PORTD = PORTD | RSpin;
lcdByte(d);
SetUS(37);
}
And my WritesP procedure:
Code:
void LCDWritesP(const char *FlashSTR)
{
while (pgm_read_byte(FlashSTR) != 0x00)
LCDWrite(pgm_read_byte(FlashSTR++));
}
And my Heavens to Mergatroid procedure:
Code:
void HeavensToMergatroid(void)
{
char Heavens[] PROGMEM = "Heavens to";
char Mergatroid[] PROGMEM = "Mergatroid!";
LCDHome();
LCDWritesP(Heavens);
LCDxy(0,1);
LCDWritesP(Mergatroid);
}
Let me try putting it back to ramwasting mode to see that I've not goofed something else up. Nope. It says its piece in plain English.
One thing I notice... When I first put it to ramwasting with:
Code:
LCDWrites("Heavens");
LCDXY(0,1(;
LCDWrites("Mergatroid");
The compiler reported 29 bytes of ram used. But when I take this out in favor of the progmem solution, the compiler still reports 29 bytes. This makes me wonder if I successfully got the data into flash, or is it still copying it to ram then looking for it the wrong place...
Exit stage left!
(I see I've been spelling Mergatroyd wrong. That must be the problem.) |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 02:11 AM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
|
|
|
|
Posted: May 19, 2012 - 02:37 AM |
|

Joined: Jun 21, 2005
Posts: 882
Location: Chicago area, USA
|
|
|
Code:
void HeavensToMergatroid(void)
{
char Heavens[] PROGMEM = "Heavens to";
Do you get any compiler warnings? Never ignore them! You need to define this "static". |
|
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 03:26 AM |
|

Joined: Nov 17, 2004
Posts: 13840
Location: Vancouver, BC
|
|
|
Quote:
You need to define this "static".
Or make them global. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 12:12 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
1. Yes, I was thinking of Snagglepuss. Hence the "Exit stage left."
2. Didn't get any compiler warnings. I consider those as bad as errors so I get rid of them whenever I see them.
3. Static or Global.. Now that makes sense.
Now my ram use is 3 bytes, my thing no longer speaks Borg and Murgatroyd is spelled correctly.
So which cartoon character was always saying, "That's what I always say sometimes"? |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 12:26 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
| Wally Gator. |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 12:45 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| Didn't get a warning? Surely there was one about progmem attribute being ignored? Which version of AVR-GCC is this? |
_________________
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 02:56 PM |
|


Joined: Jan 23, 2004
Posts: 9826
Location: Trondheim, Norway
|
|
You should actually also get a warning or error that PROGMEM variables need to be marked as "const" - at least, in the version of avr-gcc shipped with Atmel Studio 6.
- Dean  |
_________________ Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
|
| |
|
|
|
|
|
Posted: May 19, 2012 - 04:37 PM |
|


Joined: Dec 21, 2006
Posts: 1483
Location: Saar-Lor-Lux
|
|
| Maybe you hit PR34734, fixed in 4.6.2. If so, use a section attribute as work-around. |
|
|
| |
|
|
|
|
|
Posted: May 20, 2012 - 02:11 AM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
Sounds like the opposite of that bug. I do get lots of warnings being ADD, typing on a netbook keyboard, and generally not knowing C very well. So when I get them, I figure out what it's complaining about and correct until I get no warnings.
However! I just had an
Code:
if (J=0)
which, of course should have been (J==0) and didn't get a warning. I was just left to wonder why the simulator bounced around with no rhyme or reason till I saw it and corrected it.
Tonight's experiment successful. I now know how my hall sensor responds to the magnet in different orientations.
Odd.. one of my tiny neodymium magnets has split open and spilled brown magnetic dust all over the others. Didn't know they'd do that. Maybe I have poor ones. |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 20, 2012 - 11:34 AM |
|

Joined: Jun 21, 2005
Posts: 882
Location: Chicago area, USA
|
|
|
Torby wrote:
which, of course should have been (J==0) and didn't get a warning
Do you have -Wall on your command line? (I normally use -Wextra -Wstrict-prototypes -Wundef -Wall -Werror) |
|
|
| |
|
|
|
|
|
Posted: May 20, 2012 - 06:43 PM |
|


Joined: Dec 21, 2006
Posts: 1483
Location: Saar-Lor-Lux
|
|
|
Torby wrote:
Code:
if (J=0)
which, of course should have been (J==0) and didn't get a warning.
Just turn on warnings and you get:
Code:
warning: suggest parentheses around assignment used as truth value
Tested with avr-gcc 3.4, 4.2, 4.3, 4.5, 4.6 and 4.7.
If you don't want a warning for such an assignment, write
Code:
if ((J=0))
|
|
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 04:16 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
Well, I usually see that warning and change it to ==. Almost always type it wrong to start.
As far as what teh command line says, I haven't a clue. Studio 6 does that. |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 04:50 PM |
|

Joined: Dec 16, 2005
Posts: 3088
Location: Bratislava, Slovakia
|
|
|
SprinterSB wrote:
If you don't want a warning for such an assignment, write
Code:
if ((J=0))
If you don't want a warning for such an assignment, you should consult your psychiatrist...
JW |
|
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 05:07 PM |
|


Joined: Oct 26, 2002
Posts: 159
Location: Lancaster PA
|
|
That's why I typically write
Code:
if (0==j)
Then if I drop = I get an error, although admittedly, it is harder to read. |
_________________ Jeff Dombach, JLD Systems
"We do the stuff behind the buttons!"
Your source for embedded solutions with a 100% Guarantee.
http://www.jldsystems.com
Phone 717.892.1100
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 06:01 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
I just edited out the correct extra = sign, and it did give me a warning, just didn't switch the tab at the bottom so I didn't notice it.
What do I typically write? Errors! That's why I rely on the warning list |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 06:51 PM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| Use -Werror then all warnings become errors and simply cannot be ignored. |
_________________
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 10:43 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
| How do you tell Studio 6 to add -Werror? |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 21, 2012 - 10:51 PM |
|

Joined: Mar 09, 2012
Posts: 1452
Location: North Carolina, USA
|
|
|
Torby wrote:
How do you tell Studio 6 to add -Werror?
Rightclick on your project in the solution explorer.
Select [Properties].
Select [Toolchain].
Select [AVR/GNU C compiler]/[Warnings].
Check [Warnings as errors].
You may want to set [Configuration] to [All Configurations] before you change this compiler option. |
|
|
| |
|
|
|
|
|
Posted: May 22, 2012 - 12:32 AM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
| Done and tried. Thanks. |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 22, 2012 - 03:03 AM |
|

Joined: Sep 29, 2002
Posts: 31
Location: Chicago,Il USA
|
|
I'm using WinAVR with Programmer's Notepad how can I select Warning are errors mode. Would it be an option in the make file?
Thanks
Don |
|
|
| |
|
|
|
|
|
Posted: May 22, 2012 - 03:50 AM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
I'm not familiar with Programmers Notepad but if the makefile calls avr-gcc.exe then just add -Werror to the line that invokes the compiler.
It's probably better if you can post the makefile, or the lines that call avr-gcc.exe, just to check. |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 22, 2012 - 08:58 AM |
|


Joined: Mar 27, 2002
Posts: 18561
Location: Lund, Sweden
|
|
|
Quote:
I'm using WinAVR with Programmer's Notepad how can I select Warning are errors mode. Would it be an option in the make file?
Yes.
Details depends on the makefile you use. |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 04:58 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
Now I'm trying to put the array of pointers in progmem:
Code:
const char Scale0[] PROGMEM = "1:20.3";
const char Scale1[] PROGMEM = "1:22";
const char Scale2[] PROGMEM = "1:24";
const char Scale3[] PROGMEM = "1:29";
const char Scale4[] PROGMEM = "1:32";
char* ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};
But the compiler says ScaleText has to be constant. So I add const:
Code:
const char Scale0[] PROGMEM = "1:20.3";
const char Scale1[] PROGMEM = "1:22";
const char Scale2[] PROGMEM = "1:24";
const char Scale3[] PROGMEM = "1:29";
const char Scale4[] PROGMEM = "1:32";
const char* ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};
But winavr still complains that ScaleText has to be constant to put in program memory. I tried telling it, but it just doesn't understand me.
Off to Memorializing activities with me! I'm the first disqualified of a long line of army veterans. (After I get the code tags right.) |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 05:01 PM |
|

Joined: Dec 16, 2005
Posts: 3088
Location: Bratislava, Slovakia
|
|
|
Code:
const char* const ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};
The first const says, you are pointing to a variable which is not going to change. The second const says that the pointer is not going to change either.
JW |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 05:21 PM |
|


Joined: Mar 27, 2002
Posts: 18561
Location: Lund, Sweden
|
|
Put
explain const char* const ScaleText []
into a Cdecl online server.
Then play around a bit, remove and add "const" at different places. |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 05:32 PM |
|

Joined: Dec 16, 2005
Posts: 3088
Location: Bratislava, Slovakia
|
|
|
JohanEkdahl wrote:
I am not the only C-Hater, then?
JW |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 05:34 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
JohanEkdahl wrote:
Put
explain const char* const ScaleText []
into a Cdecl online server.
Then play around a bit, remove and add "const" at different places.
Wow, Johan, you've given me a tool I didn't know about. Thank you for this post.  |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 05:49 PM |
|


Joined: Mar 27, 2002
Posts: 18561
Location: Lund, Sweden
|
|
| Chances are you actually have a commald-line based cdecl on your hard drive.. |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 06:16 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
JohanEkdahl wrote:
Chances are you actually have a commald-line based cdecl on your hard drive..
Maybe in one of my linux VMs, not on any of my hard drives and there is a ton of historic, read "very old and useless", stuff there. Is there a version that will run from from the command line or powershell that is compatible with Win7, or do I need cygwin or something like that? |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 06:23 PM |
|


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany
|
|
|
larryvc wrote:
Wow, Johan, you've given me a tool I didn't know about. Thank you for this post.
But keep in mind that it is not always correct.
E.g.
int volatile i; -> syntax error |
_________________ Stefan Ernst
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 07:07 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
sternst wrote:
But keep in mind that it is not always correct.
E.g.
int volatile i; -> syntax error
But it does work as this:
volatile int i; -> declare i as volatile int |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 07:25 PM |
|


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany
|
|
|
larryvc wrote:
But it does work as this:
volatile int i; -> declare i as volatile int
So what? That does not change the fact that the response to "int volatile i;" is wrong. |
_________________ Stefan Ernst
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 07:51 PM |
|


Joined: Mar 27, 2002
Posts: 18561
Location: Lund, Sweden
|
|
|
Quote:
Maybe in one of my linux VMs
Darn, I had a clear memory of that it actually came with the WinAVR installation, but no..
Then it must have been that I downloaded the source and built it. In Visual Studio. (I.e. no CygWin, no MinGW). |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 08:04 PM |
|


Joined: Jan 08, 2009
Posts: 1153
Location: Lund, Sweden
|
|
| As clawson said recently,
Code:
sudo apt-get install cutils
if you're using something like debian or ubuntu. |
|
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 08:14 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
Yeah, I was looking for one in windows as mentioned above.
Thanks anyways.  |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 28, 2012 - 08:24 PM |
|


Joined: Jan 08, 2009
Posts: 1153
Location: Lund, Sweden
|
|
| Yes, I realize that now, I read too fast,
Quote:
Maybe in one of my linux VMs
I thought that meant that you looked there and didn't find it. I now see that you probably meant "It may be there, but I want a Windows version". |
|
|
| |
|
|
|
|
|
Posted: May 29, 2012 - 12:17 AM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
Wow, at the speed of light, from far away Slovakia, the answer comes while I'm out playing with trains in a beautiful garden. Now the compiler is happy. Wonder if the silly program works. Oh, still need to....
(I'm not really hot on C either, but the world abandoned Pascal and Modula years ago.) |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|
Posted: May 30, 2012 - 07:28 PM |
|


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA
|
|
|
sternst wrote:
larryvc wrote:
But it does work as this:
volatile int i; -> declare i as volatile int
So what? That does not change the fact that the response to "int volatile i;" is wrong.
Sorry Stefan, I missed this.
I really meant to say that it worked for one and not the other. I was not questioning your statement above as I agree with it. |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: May 31, 2012 - 02:47 PM |
|


Joined: Nov 11, 2003
Posts: 3886
Location: Chicago Illinois USA
|
|
| No! I don't want to read this! I'll be putting "volatile" in the wrong place for the rest of my life! |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|