Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Torby
PostPosted: May 19, 2012 - 02:04 AM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: May 19, 2012 - 02:11 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

This one's for you Torby:

http://www.phrases.org.uk/meanings/heav ... troyd.html

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
ezharkov
PostPosted: May 19, 2012 - 02:37 AM
Resident


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".
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 19, 2012 - 03:26 AM
10k+ Postman


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.
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 19, 2012 - 12:12 PM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 19, 2012 - 12:26 PM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 19, 2012 - 12:45 PM
10k+ Postman


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?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: May 19, 2012 - 02:56 PM
Moderator


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 Twisted Evil

_________________
Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
SprinterSB
PostPosted: May 19, 2012 - 04:37 PM
Posting Freak


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 20, 2012 - 02:11 AM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
ezharkov
PostPosted: May 20, 2012 - 11:34 AM
Resident


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)
 
 View user's profile Send private message  
Reply with quote Back to top
SprinterSB
PostPosted: May 20, 2012 - 06:43 PM
Posting Freak


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))
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 04:16 PM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wek
PostPosted: May 21, 2012 - 04:50 PM
Raving lunatic


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... Wink

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
jldsystems
PostPosted: May 21, 2012 - 05:07 PM
Hangaround


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
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 06:01 PM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 21, 2012 - 06:51 PM
10k+ Postman


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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 10:43 PM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
ChaunceyGardiner
PostPosted: May 21, 2012 - 10:51 PM
Posting Freak


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.
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 22, 2012 - 12:32 AM
Raving lunatic


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.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits