Using __DATE__ and __TIME__ macros with XS12

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Using __DATE__ and __TIME__ macros with XS12

1,514件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

984件の閲覧回数
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 件の賞賛
返信

984件の閲覧回数
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 件の賞賛
返信