This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Display TIME and DATE

Could some body in this forum advise me with
a simple code on how to diplay DATE and TIME
using printf() statement. I tried cut and paste the one posted here, and it did not
even compile ... whole bunch of syntax errors !!!!


Thanks in advance,



JIMMY

Parents
  • The code referenced in http://www.keil.com/support/docs/471.htm is a technique that allows the user (while debugging with the dScope debugger) to get the time and date a function was compiled.

    Is this what you are trying to do?

    Since you don't give us the compiler errors/warnings, you make it diffucult for us to figure out what you are doing. So difficult, in fact, that we would have to create a test case to see what happens. So, I did. The following code compiles with no errors or warnings:

    #include <string.h>
    
    typedef unsigned char   U8;
    #define KC_DATA         data
    
    
    void main (void)
    {
    U8 KC_DATA Datestring[sizeof(__DATE__)];
    U8 KC_DATA Timestring[sizeof(__TIME__)];
    
    
    memcpy(Datestring, &__DATE__, sizeof(__DATE__));
    memcpy(Timestring, &__TIME__, sizeof(__TIME__));
    
    while (1);
    }

    The debugger function was written for the dScope debugger. Is that what you are using? If you are using the uVision2 debugger, this function must be modified for uVision2.

    func void Time_Stamp (long DateAddr, long TimeAddr ){
    
    long addr;
    
    printf(" ===============================================================\n");
    printf(" This is the time and date the function under test was built\n");
    printf(" Date: ");
    
    
    for (addr = DateAddr; _rbyte(addr) != 0; addr++)
      printf ("%c", _rbyte(addr));
    
    printf("\n Time:");
    
    for (addr = TimeAddr; _rbyte(addr) != 0; addr++)
      printf ("%c", _rbyte(addr));
    
    
    printf("\n =================================================================\n");
    }

    I suspect you are trying to include the debugger function in your C program--and that certainly won't work. The debugger function is intended for the debugger.

    Jon

Reply
  • The code referenced in http://www.keil.com/support/docs/471.htm is a technique that allows the user (while debugging with the dScope debugger) to get the time and date a function was compiled.

    Is this what you are trying to do?

    Since you don't give us the compiler errors/warnings, you make it diffucult for us to figure out what you are doing. So difficult, in fact, that we would have to create a test case to see what happens. So, I did. The following code compiles with no errors or warnings:

    #include <string.h>
    
    typedef unsigned char   U8;
    #define KC_DATA         data
    
    
    void main (void)
    {
    U8 KC_DATA Datestring[sizeof(__DATE__)];
    U8 KC_DATA Timestring[sizeof(__TIME__)];
    
    
    memcpy(Datestring, &__DATE__, sizeof(__DATE__));
    memcpy(Timestring, &__TIME__, sizeof(__TIME__));
    
    while (1);
    }

    The debugger function was written for the dScope debugger. Is that what you are using? If you are using the uVision2 debugger, this function must be modified for uVision2.

    func void Time_Stamp (long DateAddr, long TimeAddr ){
    
    long addr;
    
    printf(" ===============================================================\n");
    printf(" This is the time and date the function under test was built\n");
    printf(" Date: ");
    
    
    for (addr = DateAddr; _rbyte(addr) != 0; addr++)
      printf ("%c", _rbyte(addr));
    
    printf("\n Time:");
    
    for (addr = TimeAddr; _rbyte(addr) != 0; addr++)
      printf ("%c", _rbyte(addr));
    
    
    printf("\n =================================================================\n");
    }

    I suspect you are trying to include the debugger function in your C program--and that certainly won't work. The debugger function is intended for the debugger.

    Jon

Children