CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

GPS Clock
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

GPS Clock
PostPosted: Wed Oct 10, 2012 12:29 pm     Reply with quote

Can someone here help me in create GPS Clock?plz... Question
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 12:51 pm     Reply with quote

Hi,

This is a "help you" forum, not a "do for you" forum, so tell us what you've done so far, and we'll be glad to help. If you haven't started, at least give us your ideas on how you plan to proceed!

I did this project recently with a Sparkfun EM-406 GPS module, and a PIC 16F648A. I just decoded the $GPRMC message from the GPS module to extract time, and then I display it on a GLCD.

John
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 6:57 pm     Reply with quote

i'm using PIC16f876A.i want to extract the time and date then display it on lcd 16x2.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 6:59 pm     Reply with quote

You're going to have to put a bit more research into it than that - what are you planning on using for the front end (GPS signal). What kind of information do you want to display. Have you looked into what the gps strings are and how to extract the data from them from your selected front end device ??

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 7:03 pm     Reply with quote

ezflyr wrote:
Hi,

This is a "help you" forum, not a "do for you" forum, so tell us what you've done so far, and we'll be glad to help. If you haven't started, at least give us your ideas on how you plan to proceed!


(two thumbs up)


BTW, I EZ, I think I sent you a PM on that GPS project for the plane I mentioned so long ago. (it's up and running on my panel slaved off my GPS296...)

Let me know -- an ttyl!
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 7:17 pm     Reply with quote

Code:
if (GPSDataReady)
      {
         GPRMC_decode(GPSData, &MyGPRMCInfo);
         if (MyGPRMCInfo.Valid == 'A')
         {
               #ifdef DEBUG_MODE
                     printf("\n\rTime: %d:%d:%d\n\r", MyGPRMCInfo.DT.Hour, MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
                     printf("Date: %d/%d/%d\n\r", MyGPRMCInfo.DT.Day, MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
                     printf("Data saved!\n\r");
               #endif
         }
         GPSDataReady = FALSE;
      }


this is some coding that i got and edited. i dont know how to define MyGPRMCInfo..i define like this. it's correct??


Code:
typedef struct _GPRMCInfo
{
   char Valid;
   DateTimeInfo DT;
} GPRMCInfo;
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 7:19 pm     Reply with quote

Ian, please use the "code" formatting function when you post.

it makes reading code a lot easier for everyone... (and thus more eager to help)

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 8:29 pm     Reply with quote

lan ahmad wrote:


this is some coding that i got and edited. i dont know how to define MyGPRMCInfo..i define like this. it's correct??


Code:
typedef struct _GPRMCInfo
{
   char Valid;
   DateTimeInfo DT;
} GPRMCInfo;



Well, I'm not sure what you're asking. Could you elaborate more?

Are you keeping strings or structures of integers?

I would convert the time/date into the structure commonly used to keep a systems time. (see the part of the CCS manual that covers PIC's that have built-in RTC's. )

Then you can printf all you like however you like.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Oct 11, 2012 3:52 am     Reply with quote

Assuming the GPS squawks NMEA sentences then the PIC must receive those sentences. Often the GPS uses r232 so an electrical interface is needed to connect to the PIC ( ex max232). Next the PIC must accept a sentence at anytime. Usually this is done via an ISR and the #RDA interrupt in which characters are received and placed in a buffer. Since the GPS squawks several types of sentences a filter to ignore unwanted sentences is frequently employed in the ISR. A NMEA sentence ex $GPRMC has a fixed comma separated format and a check digit. The sentence needs parsing by a subroutine and often the parsed sentence is passed back as a structure. The universal time (UT) stamp now is represented by variables within the structure usually integers for hour min sec etc. UT will need adjusting to local time. GPS satellites have accurate atomic clocks so the raw signal has nanosecond precision the GPS receiver processes this raw info and a knowledge of the position of the satellites into a series of NMEA sentences and squawks them to the PIC. Maybe you have downloaded some code and are wondering how it works. Start with the NMEA sentence definitions and follow the PIC code as it receives and parses the sentences
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

PostPosted: Thu Oct 11, 2012 6:18 am     Reply with quote

I got the coding http://www.ccsinfo.com/forum/viewtopic.php?t=45827. I just edit the coding to get the time and date.

This is my whole coding.

Code:

///////////////////////////////////////////////////////////////////////////////
#include <16F876A.h>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <string.h>
#include <stdlib.h>
///////////////////////////////////////////////////////////////////////////////

char GPSData[128];
unsigned int8 GPSDataPtr=0;
char c;
int8 GPSDataReady = FALSE;
int8 GPSmsgCount = 0;

typedef struct _DateTimeInfo
{
   int8 Day;
   int8 Month;
   int8 Year;
   int8 Hour;
   int8 Minute;
   int8 Second;
} DateTimeInfo;
////////////////////////////////////////
typedef struct _GPRMCInfo
{
   char Valid;
   DateTimeInfo DT;
} GPRMCInfo;
///////////////////////////////////////////////////////////////////////////////
//copy string (pos n to pos m) from s2 to s1
char* StrnmCpy(char *s1, char *s2, size_t n, size_t m)
{
   int8 i;
   char *s;
   
   for (s=s1, i=n, s2+=n; i<=m; i++)
      *s++ = *s2++;
   *s = '\0';
   
   return s1;
}
///////////////////////////////////////////////////////////////////////////////
// find c in s starting from pos st
int8 StrFnd(char *s, char c, size_t st)
{
   int8 l;
   
   for (l=st, s+=st ; *s != '\0' ; l++, s++)
      if (*s == c)
         return l;
   return -1;
}
///////////////////////////////////////////////////////////////////////////////
void GPRMC_decode(char *GPRMCStr, GPRMCInfo *RMCInfo)
{
   int8 p1, p2;
   char TempStr[16];
   
   p1 = StrFnd(GPRMCStr, ',', 0);      //find first comma
   if (p1 == 6)
   {
      //check for valid packet:
      if ( (StrFnd(GPRMCStr, 'A', p1+1) == 18) && (GPRMCStr[0]=='$')) //valid?
      {
         RMCInfo->Valid = 'A';
         
         //Get time
         p1 = StrFnd(GPRMCStr, ',', 0);      //find first comma
         p2 = StrFnd(GPRMCStr, ',', p1+1);   //find next comma
         RMCInfo->DT.Hour = atoi(StrnmCpy(TempStr, GPRMCStr, p1+1, p1+2));   //hour
         RMCInfo->DT.Minute = atoi(StrnmCpy(TempStr, GPRMCStr, p1+3, p1+4)); //min
         RMCInfo->DT.Second = atoi(StrnmCpy(TempStr, GPRMCStr, p1+5, p1+6)); //sec
         
         //Get date
         p1 = StrFnd(GPRMCStr, ',', p2+1);   //find next comma
         p2 = StrFnd(GPRMCStr, ',', p1+1);   //find next comma
         RMCInfo->DT.Day = atoi(StrnmCpy(TempStr, GPRMCStr, p1+1, p1+2));  //dd
         RMCInfo->DT.Month = atoi(StrnmCpy(TempStr, GPRMCStr, p1+3, p1+4));//mm
         RMCInfo->DT.year = atoi(StrnmCpy(TempStr, GPRMCStr, p1+5, p1+6)); //yy
      }
      else                                //not valid
      {
         RMCInfo->Valid = 'V';
      }
   }
}
///////////////////////////////////////////////////////////////////////////////

#INT_RDA
void RDA_isr(void)
{
   c = getc();
   switch (c)
   {
      case '$':
         GPSDataPtr = 0;
      break;
     
      case '\n':
         GPSDataReady = TRUE;
      break;
   }
   
   GPSData[GPSDataPtr++ & 0x7F] = c;
     
}


void main()
{
if (GPSDataReady)
      {
         GPRMC_decode(GPSData, &MyGPRMCInfo);
         if (MyGPRMCInfo.Valid == 'A')
         {
               #ifdef DEBUG_MODE
                     printf("\n\rTime: %d:%d:%d\n\r", MyGPRMCInfo.DT.Hour, MyGPRMCInfo.DT.Minute, MyGPRMCInfo.DT.Second);
                     printf("Date: %d/%d/%d\n\r", MyGPRMCInfo.DT.Day, MyGPRMCInfo.DT.Month, MyGPRMCInfo.DT.Year);
                     printf("Data saved!\n\r");
               #endif
         }
         GPSDataReady = FALSE;
      }
}
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 11, 2012 6:25 am     Reply with quote

first Q. Have you written a simple program that confirms you can talk to and receive data from the GPS ? Something that sends the data to say a PC or other 'terminal' device?

no amount of software will work if the hardware ain't !
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 7:00 am     Reply with quote

temtronic wrote:
first Q. Have you written a simple program that confirms you can talk to and receive data from the GPS ? Something that sends the data to say a PC or other 'terminal' device?

no amount of software will work if the hardware ain't !


I already connected the gps to pc, and I get the data from it and it show the data at the hyper terminal.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 7:57 am     Reply with quote

Ian,
I don't know if I want to help you. You are asking for help in a difficult program but you don't know how to write a simple program. You just want to get a simple answer and then go on without understanding. I do give that kind of support, but then people pay me to do so and it is called work.

The program as you have posted it will never work because you made at least two big errors showing that you have no idea of what you are doing.

I suggest you break down your project in small steps. Finish each step, learn from it and then proceed to the next step:
1) Create a program that blinks a LED every second (your current program can't do this because of the two errors).
2) Extend the program to write a counting value to the LCD every second.
3) Connect the GPS to your PC and note what data it is sending. Do you need all data, or just some lines?
4) You mentioned the GPS was connected to the PC, that means RS232 voltage levels (-15V to +15V). The PIC works at TTL levels (0 - 5V). How are you going to handle the voltage conversion? MAX232?
5) Receive all data from the GPS on the PIC and write this to the LCD every second (it won't make sense but you can see if data from GPS is received and is readable).
6) Implement a data filter on the PIC to only store the text data you are interested in. Display this raw data on the LCD every second.
7) Add more smart code to convert the GPS raw data to texts for your clock.
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 8:01 am     Reply with quote

That test only confirms the GPS and the PC work.

2nd test,which MUST be done....is..
Connect GPS and PC to PIC.
Cut code to read the 'raw' GPS and send all that data to PC.
Confirm that the data is correct.

ONLY after you've done this 2nd test, should you proceed with the 3rd section...read time and display.

hth
jay
lan ahmad



Joined: 23 Jul 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Feb 08, 2013 7:13 am     Reply with quote

This is my coding to display time and date..my problem here is, the routine doesnot repeat. so i get only the fix time..can someone help..

here is my data from gps that i want to extract
Code:
$GPRMC,235852.000,A,0216.8807,N,10216.7840,E,0.83,117.82,171212


Code:
#include <16f876a.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect
#define use_portb_lcd true
#include "flex_lcd.c"
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

unsigned char SBUF;
char time[16], date[16];

#int_RDA
void RDA_isr()
{
static int i, j, start, scount;

  SBUF = getc();

  switch(SBUF)
  {
    case 0x24:  /* '$' */ // Start of a sentence
      start = 1;
      break;
    default:
      break;
  }/* end of switch(SBUF) */

  switch(start)
  {
    case 1:
      if(scount++ >= 4)
      {
        start = 2;
      }
      break;
    case 2:
      if(SBUF == 0x43) /* 'C' */ // this line contains the Date.Time information
      {
        start = 3;
        scount++;
      }
      else
      {
        start = 0;
        scount = 0;
      }
      break;
    case 3:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 4;
      }
      break;
    case 4:
      if(SBUF != 0x2C) /* 'comma' */
      {
        if(i < 6)
        {
          time[i++] = SBUF;// stuff the variable 'time' with the current
          break;
        }
      }
      start = 5;
      break;
     case 5:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 6;
      }
      break;
     case 6:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 7;
      }
      break;
     case 7:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 8;
      }
      break;
     
     case 8:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 9;
      }
      break;
     case 9:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 10;
      }
      break;
     case 10:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 11;
      }
      break;
     case 11:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 12;
      }
      break;
     case 12:
      if(SBUF == 0X2C) /* comma */
      {
        scount++;
        start = 13;
      }
      break;
     case 13:
      if(SBUF != 0x2C) /* 'comma' */
      {
        if(j < 6)
        {
          date[j++] = SBUF;// stuff the variable 'time' with the current
          break;
        }
      }
      break;
    default:
      scount = 0;
      start = 0;
      break;
  } /* end of switch */
}// end of RDA()

void main()
{
lcd_init();
delay_ms(50);

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

printf(lcd_putc,"\f initialize gps");
delay_ms(3000);

while(true)
{
lcd_gotoxy(2,1);
printf(lcd_putc,"Time= %c%c:%c%c:%c%c",time[0], time[1], time[2], time[3], time[4], time[5]);
lcd_gotoxy(2,2);
printf(lcd_putc,"Date= %c%c/%c%c/%c%c",date[0], date[1], date[2], date[3], date[4], date[5]);

}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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