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

Filtering $GPRMC string

Dear all
I am filtering $GPRMC string but i can't able to get any data in the hyperterminal please suggest me my problem in the code.

/*------------------------------------------------------------------------------
Serial.c
------------------------------------------------------------------------------*/
#include <reg52.H>                /* special function register declarations  */
#include <stdio.h>                /* prototype declarations for I/O functions */
  sbit mybit=P1^1 ;

unsigned char RMC_Pos,GPSReceiveCtr,GPSData,Ctr;
unsigned char  GPSArray[110];
void main(void)
{
RMC_Pos=0;
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFA; /* TH1: reload value for 4800 baud @ 11.0592 MHz */
TR1 = 1; /* TR1: timer 1 run */
ES=1;  /* Serial interrupt Enable*/
EA=1;  /* global interrupt enable*/
while(1)
{
if(RMC_Pos==7)
{
  for(Ctr=0;Ctr>GPSReceiveCtr;Ctr++)
  {
    SBUF=GPSArray[Ctr];
  }
}
RMC_Pos=0;
}
}

void serial (void) interrupt 4

{
  mybit=1;
if(RI)
{
      RI=0;
      GPSData = SBUF;
      if(RMC_Pos!=7)
      {
          if( GPSData== '$' && (RMC_Pos == 0) )
          RMC_Pos=1;
          else if( GPSData == 'G' && (RMC_Pos == 1) )
          RMC_Pos=2;
          else if( GPSData == 'P' && (RMC_Pos == 2) )
          RMC_Pos=3;
          else if( GPSData == 'R' && (RMC_Pos == 3) )
          RMC_Pos=4;
          else if( GPSData == 'M' && (RMC_Pos == 4) )
          RMC_Pos=5;
          else if( GPSData == 'C' && (RMC_Pos == 5) )
          {
                        RMC_Pos=6;
            GPSReceiveCtr=0;
          }
          else if( GPSData != '*' && (RMC_Pos == 6) )
          GPSArray[GPSReceiveCtr++]=GPSData;
          else if( GPSData == '*' && (RMC_Pos == 6) )
          RMC_Pos=7;
          else
          RMC_Pos=0;
          if(GPSReceiveCtr > 100) GPSReceiveCtr=100;
                  mybit=0;
        }
    }
if(TI)TI=0;
}

Parents
  • It is a reasonable assumption that the lines:

    /*------------------------------------------------------------------------------
    Serial.c
    ------------------------------------------------------------------------------*/
    #include <reg52.H>                /* special function register declarations  */
    #include <stdio.h>                /* prototype declarations for I/O functions */
      sbit mybit=P1^1 ;
    
    unsigned char RMC_Pos,GPSReceiveCtr,GPSData,Ctr;
    unsigned char  GPSArray[110];
    void main(void)
    {
    RMC_Pos=0;
    SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
    TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
    TH1 = 0xFA; /* TH1: reload value for 4800 baud @ 11.0592 MHz */
    TR1 = 1; /* TR1: timer 1 run */
    ES=1;  /* Serial interrupt Enable*/
    EA=1;  /* global interrupt enable*/
    


    are part of a datasheet, an application example or any of the samples installed with Keil. Nothing wrong with that. These are the only lines in your program that contains any comments. The rest of the code - that is 100% specific to your needs - are totally void of any comments. And this part of the code contains big logic errors. Read my comments from the previous post, and spend time trying to simulate this code. What would happen - step by step - with the contents of the variables?

    I think you should separate your problem into two - one is a working serial communication with send and receive. And test what happens if you send 5-10 characters instantly after each other, without synchronizing with the serial port. The sample code available (Andy gave you several links, and you got examples with the compiler installation) will show solutions for:
    - interrupt-driven input/output, in which case you can insert multiple characters into the output buffer.
    - polled input/output, where you have to poll before each character sent.

    Then work with the second step. Look for magic characters (such as '$' or the line break) to figure out the start of an NMEA string. Make sure that the state machine will always restart if you get to a synchronization character. Process characters one at a time until you have found your character. Then make sure that you know how many characters to you have available - and also that you continue to emit characters until you have received and forwarded the full line.

Reply
  • It is a reasonable assumption that the lines:

    /*------------------------------------------------------------------------------
    Serial.c
    ------------------------------------------------------------------------------*/
    #include <reg52.H>                /* special function register declarations  */
    #include <stdio.h>                /* prototype declarations for I/O functions */
      sbit mybit=P1^1 ;
    
    unsigned char RMC_Pos,GPSReceiveCtr,GPSData,Ctr;
    unsigned char  GPSArray[110];
    void main(void)
    {
    RMC_Pos=0;
    SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
    TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
    TH1 = 0xFA; /* TH1: reload value for 4800 baud @ 11.0592 MHz */
    TR1 = 1; /* TR1: timer 1 run */
    ES=1;  /* Serial interrupt Enable*/
    EA=1;  /* global interrupt enable*/
    


    are part of a datasheet, an application example or any of the samples installed with Keil. Nothing wrong with that. These are the only lines in your program that contains any comments. The rest of the code - that is 100% specific to your needs - are totally void of any comments. And this part of the code contains big logic errors. Read my comments from the previous post, and spend time trying to simulate this code. What would happen - step by step - with the contents of the variables?

    I think you should separate your problem into two - one is a working serial communication with send and receive. And test what happens if you send 5-10 characters instantly after each other, without synchronizing with the serial port. The sample code available (Andy gave you several links, and you got examples with the compiler installation) will show solutions for:
    - interrupt-driven input/output, in which case you can insert multiple characters into the output buffer.
    - polled input/output, where you have to poll before each character sent.

    Then work with the second step. Look for magic characters (such as '$' or the line break) to figure out the start of an NMEA string. Make sure that the state machine will always restart if you get to a synchronization character. Process characters one at a time until you have found your character. Then make sure that you know how many characters to you have available - and also that you continue to emit characters until you have received and forwarded the full line.

Children
No data