asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
structure assignment syntax |
Posted: Fri May 31, 2013 11:20 am |
|
|
i am struggling with a simple - but frustrating problem.
am sure is ME not the compiler.
16 sets of 8 elements 'wellx'
the low 4 values of each of 16 payloads are set as 'virtual' constants
the upper 4 are meant to accept data from user in runtime
no problem with the runtime, assignment and readback -
but struggling to get the syntax right to declare and load
welldat[][] at startup/reset
Code: |
typedef struct {
int8 rexcite;
byte rgains;
} wellx;
// [1of16 kinds][8 different 'payloads']
wellx welldat[16][8];
// there are 16 groups of 8 wellx's
// typical data for one of the payloads:
// {100,0xA7} typical of first 4 of 8 [0-3]
// {0,0xFF} for unused 'soft' user upload values [4-7]
//
|
how to assign and get the load order right for all of welldat[][] ?? |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 31, 2013 3:28 pm |
|
|
This shows how to initialize a 2-dimensional array where each array element is a structure:
Code: |
#include <18F4520.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
typedef struct {
int8 a;
int8 b;
}ab_t;
#define NUM_ROWS 4
#define NUM_COLUMNS 3
ab_t array[NUM_ROWS][NUM_COLUMNS] = {
{{1,2}, {3,4}, {5,6}},
{{7,8}, {9,10}, {11,12}},
{{13,14}, {15,16}, {17,18}},
{{19,20}, {21,22}, {23,24}}
};
//======================================
void main(void)
{
int8 row, col;
for(row = 0; row < NUM_ROWS; row++)
{
for(col=0; col < NUM_COLUMNS; col++)
{
printf("%u,%u ", array[row][col].a, array[row][col].b);
}
printf("\r");
}
while(1);
}
|
Here is the output in MPLAB simulator:
Quote: |
1,2 3,4 5,6
7,8 9,10 11,12
13,14 15,16 17,18
19,20 21,22 23,24 |
|
|