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


Joined: Nov 11, 2003
Posts: 4040
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: 894
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: 13956
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: 4040
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: 4040
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: 62939
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: 9878
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: 1547
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: 4040
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: 894
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: 1547
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: 4040
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: 3095
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: 4040
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: 62939
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: 4040
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: 4040
Location: Chicago Illinois USA
|
|
| Done and tried. Thanks. |
_________________ Discursive design,
Torby
Some days, it's just not worth chewing through the restraints.
|
| |
|
|
|
|
|