NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » PSTR error?
May 16, 2011 by Snoogie2563 |
Hi all, I was trying to step out boldly and modify the led_blink code to make it write a message to line one of the LCD when the LED was on and a different one to line two of the LCD when it was off. Simple right? Not so much unfortunately! Below is my modified main loop. It looks to me like the compiler doesn't recognize the PSTR() macro but I don't know. Is there something else I should be including (.h file, etc) If somone could get me back on track it would be greatly appreciated Thanks, Chuck Reel int main() { // LED as output DDRC |= (1<<PC4);//DDRC is Data Direction Register C // loop keeps looking forever while(1) { // turn on LED PORTC |= (1<<PC4);
} return 0; } |
---|---|
May 16, 2011 by Snoogie2563 |
OK, I added include <avr/pgmspace.h>and at least it compiled, but I'm still not getting my intended messages on the LCD. For starters, how do you determine what libraries need to be included or not to make things happen? |
May 16, 2011 by hevans (NerdKits Staff) |
Hi Snoogie2563, You are very close. I think what you are missing now is a call to lcd_init() somewhere towards the top of your main method (not in the your while(1) loop). Knowing which includes you need just sort of takes practice. Pretty much every method has to be defined somewhere, so any method you use, you should ask yourself if you are including the library that defines it. Also, remember you can indent any code block with 4 spaces so that it will be pre-formatted. It will make any code you paste in much easier to read. (you can highlight a section of text and click the indent selection button) Humberto |
May 16, 2011 by Snoogie2563 |
Thanks Humberto, I'm not where the NERDKit is right now but I will give that a shot first thing in the morning. Now that I look at the initialload and tempsensor routines I see where you have lcd_(init) but of course that leads to another question. In the tempsensor program I see that you initialize the LCD with this code: // start up the LCD lcd_init(); FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home(); Can you give me some brief guidance as to what the whole part after the lcd_init() line is for, or can you at least point me to where I might want to look it up? It doesn't look like this was applicable on either the initialload or dip_arithmetic projects. Thanks again for all the help, Respectfully, Chuck Reel |
May 17, 2011 by hevans (NerdKits Staff) |
Hi Snoogie, Those lines are a bit of magic that set up a stream called lcd_stream. With this stream you can use fprintf_P() to print characters to the LCD. Check out our printf and scanf tutorial to see how useful being able to format a string can be. Humberto |
Please log in to post a reply.
Did you know that NerdKits has been featured on Slashdot, Hack A Day, Hacked Gadgets, the MAKE blog, and other DIY-oriented websites? Learn more...
|