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 CCS Technical Support

Problem with array of struct

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



Joined: 10 Feb 2011
Posts: 3

View user's profile Send private message

Problem with array of struct
PostPosted: Fri Feb 11, 2011 7:47 am     Reply with quote

Hi all,

I am using PIC 18F4525, with this array of struct:

Code:

typedef unsigned char  BYTE;

typedef struct{
   BYTE bDay;
   BYTE bMon;
   BYTE bYear;
   BYTE bDow;
   BYTE bH;
   BYTE bM;
   BYTE bS;
} TIMER_ST;

TIMER_ST gstTimerStart[3];
TIMER_ST gstTimerEnd[3];


It works fine when I was using an array with 3 elements, but when I start using 5 elements, it stop working, like I can't acess the array elements...

I did a test changing the struct size and it works:
Code:

typedef unsigned char  BYTE;

typedef struct{
   BYTE bH;
   BYTE bM;
} TIMER_ST;

TIMER_ST gstTimerStart[5];
TIMER_ST gstTimerEnd[5];


But I need to use the first struct.

How I can do to solve this problem ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 10:19 am     Reply with quote

Compiler version?.
When asking _any_ question about a compiler problem (as opposed to stuff about interfacing), you need to tell us your compiler version. It'd cut the 'dross' here by a huge margin, if it was a 'capital' offence to not include this!... Smile

Best Wishes
bbruce



Joined: 10 Feb 2011
Posts: 3

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 3:35 pm     Reply with quote

Ttelmah,

The version is 4.049
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 4:04 pm     Reply with quote

Ouch.

Unfortunately, the early V4 compilers, had major problems. Up to about 4.068, things like your problem were common. Unfortunately, I suspect you will either have to do a evil 'bodge round', and hope it works, or upgrade...
I keep all compilers I actually use for production code. The first 'V4' compiler I kept, was 4.070. Up to this point, 3.249, was far superior.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 4:19 pm     Reply with quote

You didn't provide a test program, so I made one, and it works just fine
with 5 elements with vs. 4.049. Running the following program in MPLAB
simulator, I get this result:
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 25 26 27 28
29 30 31 32 33 34 35

Code:

#include <18F4525.h>
#fuses  INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, errors)

typedef struct{
   BYTE bDay;
   BYTE bMon;
   BYTE bYear;
   BYTE bDow;
   BYTE bH;
   BYTE bM;
   BYTE bS;
} TIMER_ST;

// Initialize the structure with incrementing data.
TIMER_ST gstTimerStart[5] = {
{1,2,3,4,5,6,7},
{8,9,10,11,12,13,14},
{15,16,17,18,19,20,21},
{22,23,24,25,26,27,28},
{29,30,31,32,33,34,35}
};

//============================
void main()
{
int8 i;

for(i = 0; i < 5; i++)
   {
    printf("%u ", gstTimerStart[i].bDay);
    printf("%u ", gstTimerStart[i].bMon);
    printf("%u ", gstTimerStart[i].bYear);
    printf("%u ", gstTimerStart[i].bDow);
    printf("%u ", gstTimerStart[i].bH);
    printf("%u ", gstTimerStart[i].bM);
    printf("%u ", gstTimerStart[i].bS);
    printf("\r");
   }

while(1);
}
bbruce



Joined: 10 Feb 2011
Posts: 3

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 8:41 pm     Reply with quote

Hi all....problem solved.

It wasn't the struct, I was using 3 arrays of int1. I Just changed it from int1 to int and works.

Thanks for the help!
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