Using __DATE__ and __TIME__ macros with XS12

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using __DATE__ and __TIME__ macros with XS12

937 Views
aceshigh99
Contributor I

I'm trying to read the current date and time of my MC9S12XS128 code compilation into an array to send out over Modbus, and the data I'm getting back appears to be garbage.

 

Here is the code that I'm using:

 

  const char date_check[14] = {__DATE__ "\0 "};

  const char time_check[10] = {__TIME__ "\0" };

 

And this is the data that I get back:

 

date_check array:

0    0   

1    0

2    15

3    -31

4    0

5    0

6    0

7    0

8    -113

9    16

10    0

11    0

12    -48

13    0

 

time_check array:

0    0   

1    0

2    15

3    -31

4    0

5    0

6    0

7    0

8    -113

9    16

 

Any idea on what the problem may be?  Thanks in advance.

Labels (1)
0 Kudos
2 Replies

407 Views
pgo
Senior Contributor V

Dear aceshigh99,

 

Tried this with Codewarrior ver 5 and the strings appear correctly in memory.  A minor point is that the "\0" and curly brackets are redundant.

 

Can I suggest running your sample code using the simulator and inspecting the memory?  You can also right-click and use pre-process to see the code produced after the pre-processor substitutions.

 

The actual code I tested is below.  I used the ch =.... to conveniently determine the string's address in memory.  Both strings appear correctly in memory.  Adding the brackets etc had no effect.  Added volatile to prevent the 1st assignment being optimised away (had no effect on the problem though).

 

Perhaps your check code has a problem?

 

 

#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */  volatile const char date_check[] = __DATE__;  volatile const char time_check[] = __TIME__; void main(void) {  char ch;    ch = date_check[0];  ch = time_check[0];  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */  /* please make sure that you never leave main */}

 

 

0 Kudos

407 Views
CompilerGuru
NXP Employee
NXP Employee

Does it work when you are not using __DATE__/__TIME__ but some simple string instead?

The "\0" seems to be unnecessary.

I shortly tried with MCU 10 (beta) and it did work fine for me, the date/time did end up in flash.

 

Daniel

0 Kudos