Jump to content

Array Program withe EEPROM


robinfawell
 Share

Recommended Posts

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 text

Microsoft Windows XP [Version 5.1.2600]

© Copyright 1985-2001 Microsoft Corp.

C:\C_Stops>make

Makefile generated.

Makefile.bat generated.

Assembling MIOS SDCC wrapper

==========================================================================

Compiling main.c

Processor: 18F452

main.c:628: warning 24: index 13 is outside of the array bounds (array size is 1

3)

main.c:604: warning 18: Initializer different levels of indirections

==========================================================================

Compiling pic18f452.c

Processor: 18F452

==========================================================================

Linking project

==========================================================================

Converting to project.syx

Block 003000-0033FF allocated - Checksum: 1A

Block 003400-0037FF allocated - Checksum: 30

Block 003800-003BFF allocated - Checksum: 07

Block 003C00-003FFF allocated - Checksum: 73

Block 004000-0043FF allocated - Checksum: 43

Block 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

Link to comment
Share on other sites

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 char

when you put the 13 between the brackets the value of the 13th element in the array is written

the code below makes sure that all array elements are written to the eeprom

starting 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 0

the last element in you array has  index 12

Link to comment
Share on other sites

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 Code

unsigned char stored_pin[] =

{pedal_group_stored_pin,// this is line 605 

tremelo_strength_button_state,// etc etc as before

void 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 text

Compiling main.c

Processor: 18F452

main.c:605: warning 18: Initializer different levels of indirections

What does this mean?  Does the code seem right?

Robin

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

I am still worried aout the compiler warning I referred to in this thread, namely

warning 18: Initializer different levels of indirections

Does 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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Thanks.  Yes all the variables are unsigned chars.

The compiler shows a syntax error on the 2nd line of your suggested code.

Robin

That's strange, maybe you could mail me your code

it's not easy to find errors with some small code snippets

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 declare

unsigned 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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Solution

I 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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...