CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

structure assignment syntax

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

structure assignment syntax
PostPosted: Fri May 31, 2013 11:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 31, 2013 3:28 pm     Reply with quote

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
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri May 31, 2013 4:16 pm     Reply with quote

THANK YOU very much

i was testing on a 2x2 struct array also - and looking at the
.LST file with confusion galore-
but
what i was missing was the nested {} DUH !!

SO much appreciated... Very Happy Very Happy Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group