/* * discussion6.c * * Created: 10/2/2013 11:51:05 AM * Author: Becca * Additional Code from : Dr. Robucci and websites listed below */ /* * Instructions: * 1. Read through the following code and take note of the difference between lcd_puts_P and lcd_puts * 2. Build (don't run or debug) the code using the function lcd_puts * 3. Note the Program Memory Usage and Data Memory Usage in the build output * 4. Change the code to call lcd_puts_P instead of lcd_puts using the same string (simply uncomment lcd_puts_P in main and comment lcd_puts) * 5. Note the Program Memory Usage and Data Memory Usage in the build output * 6. What changes happened and why? * 7. Play around with creating strings stored in program memories * */ #define F_CPU 8000000 #include #include "U0_LCD_Driver.h" void lcd_puts_P(const char c[]) { //same const char *c uint8_t ch = pgm_read_byte(c); int location = 0; while(ch != 0) { LCD_WriteDigit(ch, location); ch = pgm_read_byte(++c); location ++; } } void lcd_puts(const char c[]) { //same const char *c uint8_t ch = *c; int location = 0; while(ch != 0) { LCD_WriteDigit(ch, location); ch = *(++c); location ++; } } int main(void) { LCD_Init(); //lcd_puts_P(PSTR("Hey")); lcd_puts("Hey"); // Or: //const char SOME_STRING[] PROGMEM = "Hey"; //lcd_puts_P(SOME_STRING); } /* * Ideas to reduce your memory usage: * 1. shorten your prompts (or reuse parts of strings) * 2. don't have multiple temp string variables in memory at once * * Also, you can have gcc optimize for space, rather than for performance. * --> Project properties -> toolchain -> optimization -> optimize for space. * * http://pastebin.com/ZFutipXs * http://www.nongnu.org/avr-libc/user-manual/mem_sections.html * */