Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

2D Array

Status
Not open for further replies.

TucsonDon

Member
C:
#define Timer0              0x100
#define Timer1              0x108
#define Timer2              0x110
#define Timer3              0x118
#define Timer4              0x120
#define Timer5              0x128
#define Timer6              0x130
#define Timer7              0x138

uint16_t TmrAdd[][1] =
{
    Timer0,
    Timer1,
    Timer2,
    Timer3,
    Timer4,
    Timer5,
    Timer6,
    Timer7
};


static uint8_t TmrCount(void)
{
    uint8_t TCount = 0;
    uint8_t Tmr = 0;
    
    do
    {
        uint16_t bAdd = TmrAdd[TCount];
        Tmr = DATAEE_ReadByte(bAdd);
        if (Tmr != NoData)                      //NoData = 0xFF
        {
            TCount++;
        }
    }while (Tmr != NoData || TCount > 8);
    return TCount;
}

I am using this code to access EEPROM, using a 2D array for the EEPROM address.

C:
uint16_t bAdd = TmrAdd[TCount];

when I run the code and the above line bAdd ends up with the address of the array element and not the contents of the element.
How do I correct this?
 
You are addressing the 2D array by only one parameter. The result is a pointer to the start of the second parameter data.

You only need a single dimension for the list of addresses; just remove the second dimension in the definition.

Or address the array as TmrAdd[TCount][0];
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top