![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ljb
Joined: 19 Nov 2003 Posts: 30
|
struct within a struct |
Posted: Wed Jul 28, 2004 9:31 am |
|
|
The first struct maintains the running date and time. The second struct is a record with a time stamp. How do I include the datetime format within the record structure?
struct datetime{
int8 Yrs;
int8 Mth;
int8 Day;
int8 Hrs;
int8 Min;
int8 Sec;
}dtm, *dp=&dtm;
struct rec{
long rc;
//datetime format here ****************
long ChData[MaxChans];
int8 St;
}drec, *rp=&drec;
Many thanks in advance
Les |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 28, 2004 1:20 pm |
|
|
Quote: | How do I include the datetime format within the record structure? |
See the code below for an example of how I did it in one program.
For more examples, search Google for this string:
"structures within structures" int char
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
typedef struct
{
char c_month; // 1-12 month
char c_date; // 1-31 date
char c_year; // 00-99 year (based on year 2000)
char c_hours; // 0-23 hours
char c_minutes; // 0-59 minutes
}T_DATE_TIME;
// In this structure, bit fields are used to store tenths (ie., .0 to .9) of
// a minute, for latitude and longitude. The compiler stores them in 1 byte.
typedef struct
{
char c_latitude_degrees; // 0 to 90 degrees
char c_latitude_minutes; // 0 to 59 minutes, N/S in bit 7, 1 = South.
char c_longitude_degrees; // 0 to 180 degrees
char c_longitude_minutes; // 0 to 59 minutes, E/W in bit 7, 1 = West.
char nib_longitude_tenths:4; // 0 to 9 tenths of a minute (Long. in low nibble)
char nib_latitude_tenths:4; // 0 to 0 tenths of a minute (Lat. in high nibble)
}T_LAT_LONG;
// Next, combine the above types into the trip record structure.
typedef struct
{ // Size in bytes must be = 16
char c_duration; // 1
T_DATE_TIME starting_date_time; // 5
T_LAT_LONG starting_position; // 5
T_LAT_LONG ending_position; // 5
}T_TRIP_RECORD;
// Create one instance of the trip record. We'll temporarily
// store data here before we read or write to FRAM.
T_TRIP_RECORD gt_trip_record;
//====================================
main()
{
gt_trip_record.starting_date_time.c_month = 6;
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
ljb
Joined: 19 Nov 2003 Posts: 30
|
structures eating rom space |
Posted: Thu Jul 29, 2004 3:06 am |
|
|
Using a 16f876, when I grouped associated vars into a structure as below.
typedef struct{
int8 Yrs;
int8 Mth;
int8 Day;
int8 Hrs;
int8 Min;
int8 Sec;
}datetime;
datetime *dp;
the available rom space reduced by 5%. After adding another struct the rom space reduced again by a similar amount.
The prog works fine, but I can't figure out why the rom space should be reduced so dramaticaly when its only memory locations that are being pointed to.
please help, as I'm going to end up with a prog full of structures and very little code. Am I doing something wrong?
Cheers
Les |
|
![](templates/subSilver/images/spacer.gif) |
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Thu Jul 29, 2004 3:12 am |
|
|
How mutch ram is availible in *.lst file
ram used / 0.percentage
ex. RAM used: 247 (67%) at main() level
total ram ~ 247 / 0.67 => 368 bytes
I'm not sure but did you use
#device *=16
Gerrit |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|