--- Makefile~ Thu Jul 3 14:12:34 2003 +++ Makefile Tue Jul 8 15:30:52 2003 @@ -18,8 +18,11 @@ # Override is only needed by avr-lib build system. -override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) +CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) +CFLAGS += -funsigned-char -Wno-char-subscripts \ + -mcall-prologues override LDFLAGS = -Wl,-Map,$(PRG).map + OBJCOPY = avr-objcopy OBJDUMP = avr-objdump --- adc.c~ Fri Jul 4 11:44:20 2003 +++ adc.c Tue Jul 8 13:43:26 2003 @@ -11,6 +11,7 @@ //*************************************************************************** #include +#include #include "demo.h" #include "adc.h" @@ -18,9 +19,13 @@ #include "lcd_functions.h" #include "timer0.h" -// le quite el __flash al inicio -// was __flash int TEMP_Celcius_pos[] = -int TEMP_Celcius_pos[] = // Positive Celcius temperatures (ADC-value) +#include "gcc.h" + +// Someone might teach those programmers spelling some day. ;-) +// Celcius was actually called Celsius, and Fahrenheit had another "h" +// in his name. :) + +int TEMP_Celcius_pos[] PROGMEM = // Positive Celcius temperatures (ADC-value) { // from 0 to 60 degrees 806,796,786,775,765,754,743,732,720,709,697,685,673,661,649, 636,624,611,599,586,574,562,549,537,524,512,500,488,476,464, @@ -28,14 +33,12 @@ 297,288,279,271,263,255,247,240,233,225,219,212,205,199,193, 187, }; -// le quite el __flash al inicio -int TEMP_Celcius_neg[] = // Negative Celcius temperatures (ADC-value) +int TEMP_Celcius_neg[] PROGMEM = // Negative Celcius temperatures (ADC-value) { // from -1 to -15 degrees 815,825,834,843,851,860,868,876,883,891,898,904,911,917,923, }; -// le quite el __flash al inicio -int TEMP_Farenheit_pos[] = // Positive Farenheit temperatures (ADC-value) +int TEMP_Farenheit_pos[] PROGMEM = // Positive Farenheit temperatures (ADC-value) { // from 0 to 140 degrees 938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902, 898, 894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851, 847, 842, @@ -51,15 +54,13 @@ }; -// le quite el __flash al inicio -int LIGHT_ADC[] = // Table used to find the Vref, when using the voltage-reading function +int LIGHT_ADC[] PROGMEM = // Table used to find the Vref, when using the voltage-reading function { 0x35,0x60,0x80,0x0B0,0x11D,0x13D,0x15A,0x17A,0x197,0x1B9,0x1DA, 0x1F9,0x216,0x240,0x26D,0x282,0x2A2,0x2EF,0x332,0x3B0,0x3F2 }; -// le quite el __flash al inicio -float LIGHT_VOLTAGE[] = // Vref table correspondent to the LIGHT_ADC[] table +float LIGHT_VOLTAGE[] PROGMEM = // Vref table correspondent to the LIGHT_ADC[] table { 2.818,2.820,2.824,2.827,2.832,2.835,2.839,2.841,2.843,2.847,2.850, 2.853,2.857,2.863,2.867,2.870,2.874,2.882,2.893,2.917,2.939 @@ -181,7 +182,7 @@ { for (i=0; i<=25; i++) // Find the temperature { - if (ADCresult <= TEMP_Celcius_neg[i]) + if (ADCresult <= pgm_read_int(TEMP_Celcius_neg, i)) { break; } @@ -193,7 +194,7 @@ { for (i=0; i<100; i++) { - if (ADCresult >= TEMP_Celcius_pos[i]) + if (ADCresult >= pgm_read_int(TEMP_Celcius_pos, i)) { break; } @@ -224,7 +225,7 @@ { for (i=0; i<=141; i++) // Find the temperature { - if (ADCresult > TEMP_Farenheit_pos[i]) + if (ADCresult > pgm_read_int(TEMP_Farenheit_pos, i)) { break; } @@ -274,7 +275,7 @@ // Find Vref for (i=0; i<=22; i++) { - if (ADCresult <= LIGHT_ADC[i]) + if (ADCresult <= pgm_read_int(LIGHT_ADC, i)) { break; } @@ -284,7 +285,7 @@ else if(i > 21) Vref = 2.942; // if it's totally dark else - Vref = LIGHT_VOLTAGE[i]; + Vref = pgm_read_float(LIGHT_VOLTAGE, i); ADMUX = VOLTAGE_SENSOR; ADCresult = ADCresult_temp; // Get the ADCresult from the voltage reading --- dataflash.c~ Fri Jul 4 11:44:56 2003 +++ dataflash.c Tue Jul 8 14:11:29 2003 @@ -22,17 +22,20 @@ // Includes #include #include +#include #include "dataflash.h" //#include "demo.h" +#include "gcc.h" + // Constants //Look-up table for these sizes -> 512k, 1M, 2M, 4M, 8M, 16M, 32M, 64M -// le quite el flash y vease que no __flash del inicio de la declaracion -unsigned char DF_pagebits[] ={ 9, 9, 9, 9, 9, 10, 10, 11}; //index of internal page address bits +unsigned char DF_pagebits[] PROGMEM = +{ 9, 9, 9, 9, 9, 10, 10, 11}; //index of internal page address bits //Look-up table for these sizes -> 512k, 1M, 2M, 4M, 8M, 16M, 32M, 64M -// le quite el flash y vease que no __flash del inicio de la declaracion -unsigned int DF_pagesize[] ={264,264, 264, 264, 264, 528, 528,1056}; //index of pagesizes +unsigned int DF_pagesize[] PROGMEM = +{264,264, 264, 264, 264, 528, 528,1056}; //index of pagesizes // Globals @@ -110,8 +113,10 @@ result = DF_SPI_RW(0x00); //dummy write to get result index_copy = ((result & 0x38) >> 3); //get the size info from status register - PageBits = DF_pagebits[index_copy]; //get number of internal page address bits from look-up table - PageSize = DF_pagesize[index_copy]; //get the size of the page (in bytes) + //get number of internal page address bits from look-up table + PageBits = PRG_RDB((unsigned short)(DF_pagebits + index_copy)); + //get the size of the page (in bytes) + PageSize = pgm_read_int(DF_pagesize, index_copy); return result; //return the read status register value } --- demo.c~ Fri Jul 4 13:39:50 2003 +++ demo.c Tue Jul 8 14:13:37 2003 @@ -22,7 +22,7 @@ #include "bcd.h" #include "usart.h" //#include "sound.h" -#include "ADC.h" +#include "adc.h" #include "dataflash.h" //#include "test.h" //#include "eeprom.h" @@ -33,8 +33,6 @@ #define pLCDREG_test (*(char *)(0xEC)) -// cambie esta variable y le quite el extern __flash al inicio -// de la declaracion de la variable. extern unsigned int extern unsigned int LCD_character_table[]; extern char gPowerSaveTimer; // external Counter from "RTC.c" @@ -76,7 +74,7 @@ LCD_putc(9,'M'); LCD_putc(10,'E'); LCD_putc(11,'X'); - LCD_putc(12,'I '); + LCD_putc(12,'I'); LCD_putc(13,'C'); LCD_putc(14,'O'); LCD_putc(15,' '); @@ -352,9 +350,6 @@ * Bootloader-section. (the BOOTRST-fuse must be programmed) * *****************************************************************************/ -// le quite el __flash al inicio de la subrutina... - -char TEXT_BOOT[] = "Jump to bootloader"; char BootFunc(char input) { @@ -363,7 +358,7 @@ if(enter) { enter = 0; - LCD_puts_f(TEXT_BOOT, 1); + LCD_puts_f(PSTR("Jump to bootloader"), 1); } else if(input == KEY_ENTER) { @@ -395,9 +390,6 @@ * Purpose : Enable power save * *****************************************************************************/ -// le quite el __flash antes de inicializar la subrutina... - -char TEXT_POWER[] = "Press enter to sleep"; char PowerSaveFunc(char input) { @@ -406,7 +398,7 @@ if(enter) { enter = 0; - LCD_puts_f(TEXT_POWER, 1); + LCD_puts_f(PSTR("Press enter to sleep"), 1); } else if(input == KEY_ENTER) { --- gcc.h~ Tue Jul 8 12:43:54 2003 +++ gcc.h Tue Jul 8 13:56:31 2003 @@ -0,0 +1,37 @@ +/* + * avr-gcc helper functions + * written by Joerg Wunsch, 2003-07-08 + * placed in the public domain + */ +static inline int +pgm_read_int(const int *addr, int index) +{ + unsigned short s; + int i; + + s = (unsigned short)(addr + index); + i = PRG_RDB(addr); + addr++; + i += (PRG_RDB(addr) << 8); + + return i; +} + +static inline int +pgm_read_float(const float *addr, int index) +{ + unsigned short s; + union + { + unsigned char c[4]; + float f; + } u; + + s = (unsigned short)(addr + index); + u.c[0] = PRG_RDB(addr); addr++; + u.c[1] = PRG_RDB(addr); addr++; + u.c[2] = PRG_RDB(addr); addr++; + u.c[3] = PRG_RDB(addr); + + return u.f; +} --- lcd_driver.c~ Fri Jul 4 11:45:24 2003 +++ lcd_driver.c Tue Jul 8 13:56:09 2003 @@ -14,11 +14,14 @@ // Include files. #include +#include #include #include "lcd_driver.h" #include "demo.h" +#include "gcc.h" + #define FALSE 0 #define TRUE (!FALSE) @@ -28,7 +31,7 @@ extern BOOL gAutoPressJoystick; // Used to indicate when the LCD interrupt handler should update the LCD -char gLCD_Update_Required = FALSE; +volatile char gLCD_Update_Required = FALSE; // LCD display buffer (for double buffering). char LCD_Data[LCD_REGISTER_COUNT]; @@ -40,8 +43,8 @@ // Only six letters can be shown on the LCD. // With the gScroll and gScrollMode variables, // one can select which part of the buffer to show -signed char gScroll; -char gScrollMode; +volatile signed char gScroll; +volatile char gScrollMode; ////Start-up delay before scrolling a string over the LCD char gLCD_Start_Scroll_Timer = 0; @@ -57,11 +60,7 @@ // Look-up table used when converting ASCII to // LCD display data (segment control) -// tuve que comentar la parte __flash ya que GCC no se lleva bien con ella. -//__flash unsigned int LCD_character_table[] = -// I had to change this because the __flash before of the function... - -unsigned int LCD_character_table[] = +unsigned int LCD_character_table[] PROGMEM = { 0x0A51, // '*' (?) 0x2A80, // '+' @@ -193,7 +192,7 @@ c -= '*'; - seg = LCD_character_table[c]; + seg = (unsigned int)pgm_read_int(LCD_character_table, c); } // Adjust mask according to LCD segment mapping --- lcd_driver.h~ Tue Jul 1 11:52:32 2003 +++ lcd_driver.h Tue Jul 8 13:53:51 2003 @@ -40,13 +40,13 @@ /************************************************************************/ // Global variables /************************************************************************/ -extern char gLCD_Update_Required; +extern volatile char gLCD_Update_Required; extern char LCD_Data[LCD_REGISTER_COUNT]; extern char gTextBuffer[TEXTBUFFER_SIZE]; -extern char gScrollMode; +extern volatile char gScrollMode; extern char gFlashTimer; extern char gColon; -extern signed char gScroll; +extern volatile signed char gScroll; /************************************************************************/ --- lcd_functions.h~ Tue Jul 8 14:22:02 2003 +++ lcd_functions.h Tue Jul 8 14:22:18 2003 @@ -14,7 +14,7 @@ //Functions //void LCD_puts_f(char __flash *pFlashStr, char scrollmode); -void LCD_puts_f(char *pFlashStr, char scrollmode); +void LCD_puts_f(const char *pFlashStr, char scrollmode); void LCD_puts(char *pStr, char scrollmode); void LCD_UpdateRequired(char update, char scrollmode); void LCD_putc(char digit, char character); --- rtc.c~ Fri Jul 4 11:45:50 2003 +++ rtc.c Tue Jul 8 14:21:34 2003 @@ -13,6 +13,7 @@ // Include files #include #include +#include #include #include "demo.h" @@ -38,21 +39,19 @@ char clockformat = CLOCK_24; // set initial clock format to 24H // different date formates (text only) -// le quito el flash antes de char... __flash char -char EUROPEAN_DATE_TEXT[] = "DDMMYY"; -char AMERICAN_DATE_TEXT[] = "MMDDYY"; -char CANADIAN_DATE_TEXT[] = "YYMMDD"; +char EUROPEAN_DATE_TEXT[] PROGMEM = "DDMMYY"; +char AMERICAN_DATE_TEXT[] PROGMEM = "MMDDYY"; +char CANADIAN_DATE_TEXT[] PROGMEM = "YYMMDD"; // different date formates, table for putting DD, MM and YY at the right place // on the LCD -// le quito el flash antes de char... __flash char -char EUROPEAN_DATE_NR[] = { 4, 5, 2, 3, 0, 1 }; -char AMERICAN_DATE_NR[] = { 4, 5, 0, 1, 2, 3 }; -char CANADIAN_DATE_NR[] = { 0, 1, 2, 3, 4, 5 }; +char EUROPEAN_DATE_NR[] PROGMEM = { 4, 5, 2, 3, 0, 1 }; +char AMERICAN_DATE_NR[] PROGMEM = { 4, 5, 0, 1, 2, 3 }; +char CANADIAN_DATE_NR[] PROGMEM = { 0, 1, 2, 3, 4, 5 }; -char *DATEFORMAT_TEXT[] = {EUROPEAN_DATE_TEXT, AMERICAN_DATE_TEXT, CANADIAN_DATE_TEXT}; -char *DATE_FORMAT_NR[] = {EUROPEAN_DATE_NR, AMERICAN_DATE_NR, CANADIAN_DATE_NR}; +const char *DATEFORMAT_TEXT[] = {EUROPEAN_DATE_TEXT, AMERICAN_DATE_TEXT, CANADIAN_DATE_TEXT}; +const char *DATE_FORMAT_NR[] = {EUROPEAN_DATE_NR, AMERICAN_DATE_NR, CANADIAN_DATE_NR}; @@ -359,14 +358,14 @@ DH = (DH >> 4) + '0'; - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 0), YH); - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 1), YL); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 0), YH); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 1), YL); - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 2), MH); - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 3), ML); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 2), MH); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 3), ML); - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 4), DH); - LCD_putc( *(DATE_FORMAT_NR[dateformat] + 5), DL); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 4), DH); + LCD_putc( PRG_RDB(DATE_FORMAT_NR[dateformat] + 5), DL); LCD_putc(6, '\0'); --- sound.c~ Wed Jul 2 15:33:22 2003 +++ sound.c Tue Jul 8 15:15:52 2003 @@ -11,14 +11,16 @@ //*************************************************************************** #include -#include #include +#include #include "demo.h" #include "sound.h" #include "timer0.h" #include "lcd_functions.h" +#include "gcc.h" + /****************************************************************************** * @@ -31,10 +33,8 @@ * very last byte makes the song loop if it's "1", and not loop if it's "0". * ******************************************************************************/ -// le quite el __flash al inicio de la declaracion -char TEXT_SONG1[] = "Fur Elise"; -// le quite el __flash al inicio de la declaracion -int FurElise[] = +char TEXT_SONG1[] PROGMEM = "Fur Elise"; +int FurElise[] PROGMEM = { 3, 8,e2, 8,xd2, 8,e2, 8,xd2, 8,e2, 8,b1, 8,d2, 8,c2, 4,a1, 8,p, @@ -44,10 +44,8 @@ 0, 1 }; -// le quite el __flash al inicio de la declaracion -char TEXT_SONG2[] = "Turkey march"; -// le quite el __flash al inicio de la declaracion -int Mozart[] = +char TEXT_SONG2[] PROGMEM = "Turkey march"; +int Mozart[] PROGMEM = { 3, 16,xf1, 16,e1, 16,xd1, 16,e1, 4,g1, 16,a1, 16,g1, 16,xf1, 16,g1, @@ -59,9 +57,9 @@ }; /* -__flash char TEXT_SONG3[] = "Minuet"; +char TEXT_SONG3[] PROGMEM = "Minuet"; -__flash int Minuet[] = +int Minuet[] PROGMEM = { 2, 4,d2, 8,g1, 8,a1, 8,b1, 8,c2, 4,d2, 4,g1, 4,g1, 4,e2, 8,c2, @@ -72,9 +70,9 @@ }; -__flash char TEXT_SONG4[] = "Auld Lang Syne"; +char TEXT_SONG4[] PROGMEM = "Auld Lang Syne"; -__flash int AuldLangSyne[] = +int AuldLangSyne[] PROGMEM = { 3, 4,g2, 2,c3, 8,c3, 4,c3, 4,e3, 2,d3, 8,c3, 4,d3, 8,e3, 8,d3, 2,c3, @@ -82,11 +80,8 @@ 8,c3, 4,d3, 8,e3, 8,d3, 2,c3, 8,a2, 4,a2, 4,g2, 2,c3, 4,p, 0, 1 }; -*/ -// le quite el __flash al inicio de la declaracion -char TEXT_SONG5[] = "Sirene1"; -// le quite el __flash al inicio de la declaracion -int Sirene1[] = +char TEXT_SONG5[] PROGMEM = "Sirene1"; +int Sirene1[] PROGMEM = { 0, 32,400, 32,397, 32,394, 32,391, 32,388, 32,385, 32,382, 32,379, @@ -100,20 +95,16 @@ 32,385, 32,388, 32,391, 32,394, 32,397, 32,400, 0, 1 }; -// le quite el __flash al inicio de la declaracion -char TEXT_SONG6[] = "Sirene2"; -// le quite el __flash al inicio de la declaracion -int Sirene2[] = +char TEXT_SONG6[] PROGMEM = "Sirene2"; +int Sirene2[] PROGMEM = { 3, 4,c2, 4,g2, 0, 1 }; -// le quite el __flash al inicio de la declaracion -char TEXT_SONG7[] = "Whistle"; -// le quite el __flash al inicio de la declaracion -int Whistle[] = +char TEXT_SONG7[] PROGMEM = "Whistle"; +int Whistle[] PROGMEM = { 0, 32,200, 32,195, 32,190, 32,185, 32,180, 32,175, 32,170, 32,165, @@ -125,21 +116,17 @@ 32,175, 32,180, 32,185, 32,190, 32,195, 32,200, 0, 0 }; +*/ -// le quite el __flash al inicio de la declaracion -// y despues del int tambien... -int *Songs[] = { FurElise, Mozart, /*Minuet, AuldLangSyne,*/ Sirene1, Sirene2, Whistle, 0}; -// le quite el __flash al inicio de la declaracion -// y despues del char tambien... -char *TEXT_SONG_TBL[] = { TEXT_SONG1, TEXT_SONG2, /*TEXT_SONG3, TEXT_SONG4,*/TEXT_SONG5, TEXT_SONG6, TEXT_SONG7, 0}; +const int *Songs[] = +{ FurElise, Mozart, /*Minuet, AuldLangSyne, Sirene1, Sirene2, Whistle,*/ 0}; +const char *TEXT_SONG_TBL[] = +{ TEXT_SONG1, TEXT_SONG2, /*TEXT_SONG3, TEXT_SONG4,TEXT_SONG5, TEXT_SONG6, TEXT_SONG7,*/ 0}; -// le quite el __flash al inicio de la declaracion char PLAYING[] = "PLAYING"; -// le quite el __flash despues del int -int *pSong; // pointer to the different songs in flash -// le quite el extern al inicio de la siguiente declaracion. +const int *pSong; // pointer to the different songs in flash char gPlaying; // global variable from "main.c" static char Volume = 80; static char Duration = 0; --- vcard.c~ Fri Jul 4 11:46:20 2003 +++ vcard.c Tue Jul 8 14:25:05 2003 @@ -13,6 +13,7 @@ #include #include #include +#include #include "demo.h" #include "button.h" @@ -27,10 +28,6 @@ char Name[STRLENGHT]; -// le quite __flash antes de la inicializacion de la variable... -char TEXT_WAIT[] = "waiting for input on RS232"; - - /***************************************************************************** * Function name : vCard * Returns : char ST_state (to the state-machine) @@ -229,7 +226,7 @@ // bajo WINAVR // __enable_interrupt(); - LCD_puts_f(TEXT_WAIT, 0); + LCD_puts_f(PSTR("waiting for input on RS232"), 0); enter = 0; temp_index = 0; c = UDR0; // Dummy read to clear receive buffer