robinfawell Posted October 5, 2006 Report Share Posted October 5, 2006 Sorry for the long post.I want to store 13 variables (later on 21) in EEPROM. These will be stored in different blocks of the 256 locations, dependent on the start address (There are 6 start addresses and there will be 6 different stored blocks.Each of the 13 variables are in reality pin numbers(DIN). The pin numbers will vary. The function Memory_IO has been prototyped [code] unsigned char stored_pin[13] = { pedal_group_stored_pin,// tremelo_strength_button_state,// swell_princ_group_stored_pin,// swell_mixt_group_stored_pin,// swell_reed_group_stored_pin,// great_princ_group_stored_pin,// great_mixt_group_stored_pin,// great_reed_group_stored_pin,// pedal_couplers_group_stored_pin,// sub_oct_coupler_button_state,// swell_tremelo_select_button_state,// great_swell_coupler_button_state,// great_tremelo_select_button_state }; void Memory_IO(unsigned int start_addr, unsigned int finish_addr) // __wparam { //unsigned char value; //value = stored_pin[13] ; for(addr = start_addr; addr <= finish_addr; addr++) MIOS_EEPROM_Write(addr, stored_pin[13]); } Compiler textMicrosoft Windows XP [Version 5.1.2600]© Copyright 1985-2001 Microsoft Corp.C:\C_Stops>makeMakefile generated.Makefile.bat generated.Assembling MIOS SDCC wrapper==========================================================================Compiling main.cProcessor: 18F452main.c:628: warning 24: index 13 is outside of the array bounds (array size is 13)main.c:604: warning 18: Initializer different levels of indirections==========================================================================Compiling pic18f452.cProcessor: 18F452==========================================================================Linking project==========================================================================Converting to project.syxBlock 003000-0033FF allocated - Checksum: 1ABlock 003400-0037FF allocated - Checksum: 30Block 003800-003BFF allocated - Checksum: 07Block 003C00-003FFF allocated - Checksum: 73Block 004000-0043FF allocated - Checksum: 43Block 004400-0047FF allocated - Checksum: 2B==========================================================================SUCCESS!C:\C_Stops>This only works if I put 13 in the [] for the array. Even so I get the compiler warnings.Can anyone see whether I am on the right track and make any comments. Thanks in advance.Robin Quote Link to comment Share on other sites More sharing options...
mess Posted October 5, 2006 Report Share Posted October 5, 2006 This only works if I put 13 in the [] for the array. Even so I get the compiler warnings.You're trying to pass a array pointer to a function who expects a unsigned charwhen you put the 13 between the brackets the value of the 13th element in the array is writtenthe code below makes sure that all array elements are written to the eepromstarting from start_addr (I've removed finish_addr since this addres is determined by the array size)void Memory_IO(unsigned int start_addr) { unsigned char i; //unsigned char value; //value = stored_pin[13] ; for(start_addr,i = 0; sizeof(stored_pin);i++) MIOS_EEPROM_Write(addr + i, stored_pin); }about the outside of array bound warning:you've declared an array with 13 elements and because in C you allways count from 0the last element in you array has index 12 Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 6, 2006 Author Report Share Posted October 6, 2006 Mess Thank you for your input. The sizeof operator is very handy!I have changed my code to the following. My code is slightly different to your suggested code.However I still get the compiler warning shown below. Altered Codeunsigned char stored_pin[] = {pedal_group_stored_pin,// this is line 605 tremelo_strength_button_state,// etc etc as beforevoid Memory_IO(unsigned int start_addr ) // __wparam { unsigned char m; for( m =0; m = sizeof(stored_pin); m++) MIOS_EEPROM_Write(start_addr + m, stored_pin[m]); }Compiler textCompiling main.cProcessor: 18F452main.c:605: warning 18: Initializer different levels of indirectionsWhat does this mean? Does the code seem right?Robin Quote Link to comment Share on other sites More sharing options...
mess Posted October 6, 2006 Report Share Posted October 6, 2006 I'm sure that I are all those variables unsigned chars?maybe you could you try this:unsigned char stored_pin[13]; stored_pin[0] = pedal_group_stored_pin; stored_pin[1] = tremelo_strength_button_state; stored_pin[2] = swell_princ_group_stored_pin; stored_pin[3] = swell_mixt_group_stored_pin; stored_pin[4] = swell_reed_group_stored_pin; stored_pin[5] = great_princ_group_stored_pin; stored_pin[6] = great_mixt_group_stored_pin; stored_pin[7] = great_reed_group_stored_pin; stored_pin[8] = pedal_couplers_group_stored_pin; stored_pin[9] = sub_oct_coupler_button_state; stored_pin[10] = swell_tremelo_select_button_state; stored_pin[11] = great_swell_coupler_button_state; stored_pin[12] = great_tremelo_select_button_state; Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 6, 2006 Author Report Share Posted October 6, 2006 Thanks. Yes all the variables are unsigned chars.The compiler shows a syntax error on the 2nd line of your suggested code.Robin Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 7, 2006 Author Report Share Posted October 7, 2006 I am still worried aout the compiler warning I referred to in this thread, namelywarning 18: Initializer different levels of indirectionsDoes this matter? What does it mean? I have tried using the web to get an explanation but have had not obtained anything useful.Is there a reference where compiler errors and warnings can be explained?I would be grateful for any comments.Robin Quote Link to comment Share on other sites More sharing options...
stryd_one Posted October 7, 2006 Report Share Posted October 7, 2006 Is there a reference where compiler errors and warnings can be explained?There's a PDF doc called sdccman.pdf that has a bit of info in it that might be worth checking out....Edit: Oh and the Sf.net forums for SDCC can be really helpful sometimes too! Quote Link to comment Share on other sites More sharing options...
mess Posted October 7, 2006 Report Share Posted October 7, 2006 Thanks. Yes all the variables are unsigned chars.The compiler shows a syntax error on the 2nd line of your suggested code.RobinThat's strange, maybe you could mail me your codeit's not easy to find errors with some small code snippets Quote Link to comment Share on other sites More sharing options...
fluke Posted October 8, 2006 Report Share Posted October 8, 2006 I'm just guessing, but both errors involve references to pedal_group_stored_pin. So i'd suggest looking for its definition and seeing if it really is an unsigned char. Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 9, 2006 Author Report Share Posted October 9, 2006 Thanks to Stryd One, Mess and Fluke.I have tried the references from Stryd One but no luck so far. Perhaps the forum will prove successful.I have checked again. My variables used with the code snippets are definitely unsigned char. Perhaps I should emphasise that with the change in code I do not get a Compiler error now, I get a Warning.It might help if I could find out what "Initializer different levels of indirections" means". I have some idea what initialise means, but not "indirections".Robin Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 10, 2006 Author Report Share Posted October 10, 2006 I have spent several hours digging around the compiler warning with no result.With Stryd One's prompting I came across this http://sdcc.sourceforge.net/doc/sdccman.html/node112.htmlIs this relevant to my problem? I'm not sure.Robin Quote Link to comment Share on other sites More sharing options...
stryd_one Posted October 11, 2006 Report Share Posted October 11, 2006 Doesn't look like it....I've had a quick read... this error seems to occur when the types don't match... You mentioned this:unsigned char stored_pin[13];stored_pin[0] = pedal_group_stored_pin;stored_pin[1] = tremelo_strength_button_state;Caused an error... I think that's right. Now, I'm new to C, so bear with me if I'm wrong but... When you declareunsigned char stored_pin[13]; That means that the array should return an unsigned char...I'm willing to bet that the 'tremelo_strength_button_state' is a boolean value not a 8 bit char? Maybe this will cast into the right type, I'm not sure?I think fluke is on the right path. I'd recommend checking that your types all match up the way they should.... Maybe try declaring a bunch of dummy variables and put those in the array and see if it compiles? Quote Link to comment Share on other sites More sharing options...
fluke Posted October 17, 2006 Report Share Posted October 17, 2006 I had replied to this before, but that was on Friday the 13th. So here it is again from memory:Indirection basically means pointers, eg: int a; // direct int *b; // indirect int **c; // 2 levels of indirection Both errors were with pedal_group_stored_pin, it's definition should be: unsigned char pedal_group_stored_pin = ... But if it's: unsigned char *pedal_group_stored_pin = ... Then that's the source of your error. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted October 17, 2006 Report Share Posted October 17, 2006 IIRC my post after that said something about the fact that arrays of pointers don't work in SDCC (DAMN!!!)I think I also suggested again that you try it with dummy variables which are not used elsewhere. Quote Link to comment Share on other sites More sharing options...
robinfawell Posted October 29, 2006 Author Report Share Posted October 29, 2006 Thanks again to Fluke and Stryd_one.I'm back from my travels. By the way I wasn't using pointers ie no *. Maybe you can't define an array using variables without using pointers. I'm too new to this to be sure.Perhaps Thorsten could comment.I have solved the problem without using an array. It took a while to figure out.SolutionI defined a global variable q as an unsigned char.I have 5 Memory Buttons Din 1 to Din 5. I want to store the variables in different sections of the (Internal) EEprom depending on the Pin Number.I have reserved the first 10 memory locations for another purpose. The formula below divides the Memory into 25 address blocks. (I will use the unused space for other stored values.) Each variable is stored in the next location. I think that the solution lacks the elegance of an array but it works! q =25*(pin-1) + 10;// or even better, but I need to check the results q =(pin-1<< 5) + 10;//as per Wiki C tips, bit shifting, multiplies by 32 instead of 25 but I have the space. MIOS_EEPROM_Write(q , pedal_group_stored_pin); MIOS_EEPROM_Write(q + 1, tremelo_strength_button_state); MIOS_EEPROM_Write(q + 2, swell_princ_group_stored_pin); MIOS_EEPROM_Write(q + 3, swell_mixt_group_stored_pin); MIOS_EEPROM_Write(q + 4, swell_reed_group_stored_pin); MIOS_EEPROM_Write(q + 5, great_princ_group_stored_pin); MIOS_EEPROM_Write(q + 6, great_mixt_group_stored_pin); MIOS_EEPROM_Write(q + 7, great_reed_group_stored_pin); MIOS_EEPROM_Write(q + 8, pedal_couplers_group_stored_pin); MIOS_EEPROM_Write(q + 9, sub_oct_coupler_button_state); MIOS_EEPROM_Write(q + 10, swell_tremelo_select_button_state); MIOS_EEPROM_Write(q + 11, great_swell_coupler_button_state); MIOS_EEPROM_Write(q + 12, great_tremelo_select_button_state);I would welcome any comments.Robin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.