![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
time conversion..... |
Posted: Mon Apr 08, 2019 2:04 pm |
|
|
Hi All,
I'm trying to get a test program to work that will convert a GPS derived time (UTC) into timer ticks, so that I can perform a conversion to local time. At the moment, I'm just trying to convert a fixed time to timer ticks using the 'mktime' function in timer.h. I'm getting a strange error on the call to mktime:
Quote: | *** Error 112 "UTCtoLocalTimeConversion.c" Line 41(1,1): Function used but not defined: ... mktime 683 SCR=1580 |
Compiler is PCH 5.050
Here is my test program:
Code: |
//-----< Include Files, setup fuses >-----
#include <18F14K22.h>
#include <time.h>
//#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#fuses INTRC, NOWDT, NOBROWNOUT, PUT, NOPLLEN
// Tell compiler clock speed is 8.00 MHZ
#use delay(clock=8000000)
//-----< General Program Defines >-----
#define Rx_In PIN_B5 // serial data receive pin
#define Tx_Out PIN_B7 // serial data transmit pin
#define Serial_Diag PIN_B4
//-----< Firmware Version >-----
#define VER_MAJ 1 // Major version
#define VER_MIN 3 // Minor version
//-----< Serial Port Definition >-----
#use rs232(baud=19200, xmit=Serial_Diag, stream = LCD)
void main()
{
int32 UTC_Ticks = 0;
//Temorary Test Code
//Needed for the Time Structure in Timer.h....
Struct_tm MyTMInfo;
MyTMInfo.tm_sec = 0; // seconds after the minute (0-59)
MyTMInfo.tm_min = 29; // minutes after the hour (0-59)
MyTMInfo.tm_hour =14; // hours since midnight (0-23)
MyTMInfo.tm_mday = 8; // day of the month (1-31)
MyTMInfo.tm_mon = 4; // month of the year (0-11)
MyTMInfo.tm_year = 119; // years since 1900
MyTMInfo.tm_wday = 1; // day of the week (0-6) (Sunday=0)
MyTMInfo.tm_yday = 98; // day of the year (0-365)
UTC_Ticks = mktime(&MyTMInfo);
fprintf(LCD, "\r\nTimestamp:<%Lu>",UTC_Ticks);
while(1){}
} //Main
|
Appreciate any suggestions to get this working!
Thanks,
Jack |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Mon Apr 08, 2019 2:33 pm |
|
|
OK, humor the old guy whose been up waaay to long ...
this
Struct_tm MyTMInfo
I can't see where or how you tell the compiler the structure is composed of bits, bytes, words, ???? Since a 'structure' can be composed of several 'elements', they could be bits or bytes or words or a mix.....
If I'm totally wrong, tell me....
Jay |
|
![](templates/subSilver/images/spacer.gif) |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
|
Posted: Mon Apr 08, 2019 2:52 pm |
|
|
Hi Jay,
That is the declaration of the structure. The actual definition of the structure occurs in Timer.h
Thanks,
Jack |
|
![](templates/subSilver/images/spacer.gif) |
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Mon Apr 08, 2019 3:25 pm |
|
|
Directly after:
#include <time.h>
add:
#include <time.c> |
|
![](templates/subSilver/images/spacer.gif) |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
|
Posted: Tue Apr 09, 2019 3:31 pm |
|
|
Hi,
Doh! Yes, of course, I can't believe I missed that!
Here is some working test code for UTC to local time conversion:
Code: |
//-----< Include Files, setup fuses >-----
#include <18F14K22.h>
#include <time.h>
#include <time.c>
//#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#fuses INTRC, NOWDT, NOBROWNOUT, PUT, NOPLLEN
// Tell compiler clock speed is 8.00 MHZ
#use delay(clock=8000000)
//-----< General Program Defines >-----
#define Rx_In PIN_B5 // serial data receive pin
#define Tx_Out PIN_B7 // serial data transmit pin
#define Serial_Diag PIN_A2
#define Time_Valid PIN_C5
//-----< Firmware Version >-----
#define VER_MAJ 1 // Major version
#define VER_MIN 3 // Minor version
//-----< Serial Port Definition >-----
#use rs232(baud=19200, xmit=Serial_Diag, stream = LCD)
void main()
{
int32 UTC_Ticks = 0;
int32 LCL_Ticks = 0;
int8 iIndex = 0;
int8 tUTCString[80];
int8 tLCLString[80];
//Here we blink the Valid Time LED at power up
for ( iIndex=0 ; iIndex<3 ; iIndex++ )
{
output_high(Time_Valid);
delay_ms(250);
output_low(Time_Valid);
delay_ms(250);
}
//Here we clear the Hyperterminal display screen
fprintf(LCD, "\x1B[2J");
fprintf(LCD, "Time Conversion Test!\n\r");
//Temorary Test Code
//Needed for the Time Structure in Timer.h....
Struct_tm MyTMInfo;
MyTMInfo.tm_sec = 0; // seconds after the minute (0-59)
MyTMInfo.tm_min = 29; // minutes after the hour (0-59)
MyTMInfo.tm_hour =14; // hours since midnight (0-23)
MyTMInfo.tm_mday = 8; // day of the month (1-31)
MyTMInfo.tm_mon = 3; // month of the year (0-11) <- Note: April = 3 NOT 4!!
MyTMInfo.tm_year = 119; // years since 1900
MyTMInfo.tm_wday = 0; // day of the week (0-6) (Sunday=0)
MyTMInfo.tm_yday = 0; // day of the year (0-365) - was 98
UTC_Ticks = mktime(&MyTMInfo);
fprintf(LCD, "\r\nUTC Timestamp:<%Lu>\n\r",UTC_Ticks);
ctime(&UTC_Ticks, tUTCString);
fprintf(LCD, "Current UTC Time: %s\n\r", tUTCString);
//Here we apply a 'UTC offset' of 4 hours (4 hours * 3600 secs/hr = 14400 secs). This is for illustration only, and will be handled as
//a variable in the final code.
LCL_Ticks = UTC_Ticks - 14400;
ctime(&LCL_Ticks, tLCLString);
fprintf(LCD, "Current Local Time: %s\n\r", tLCLString);
while(1){}
} //Main
|
Quote: |
Time Conversion Test!
UTC Timestamp:<1554733740>
Current UTC Time: Mon Apr 8 14:29:00 2019
Current Local Time: Mon Apr 8 10:29:00 2019
|
Thanks,
Jack |
|
![](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
|