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

Problem of using PIC18F458 to receive gps NMEA code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dream10101tysh



Joined: 17 Apr 2013
Posts: 3

View user's profile Send private message

Problem of using PIC18F458 to receive gps NMEA code
PostPosted: Wed Apr 17, 2013 7:09 am     Reply with quote

I use pic18f458 to receive gps NMEA message. The objective is to get the latitude , longitude and UTC real time and transmitted via RS232 to RF modem. The problem is that the RDA_ISR is not working after I disable it. I just wanna to check the rcv() function is ran completely. After that, the RDA_ISR is re-enabled. I am a beginner and not sure whether it is possible to use this 8-bit pic to complete this project. Any suggestions are important to me. Thank you!

Code:

#include <18f458.h>
#include <stdlib.h>
#fuses    HS
#use     delay(clock = 20000000)
#use     rs232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#priority RDA
#define  bsize 128

unsigned char UART_ReceiveBuffer[bsize], UART_IsReceived=0, buf[110], len=0, out[31], header[4]={255,254,253,252},mm;

void rcv()
{
   unsigned char ii,jj;
   for(ii = 0; ii < len; ++ii)
   {
      for(jj = 0; jj<110; jj++)
         {
         buf[jj] = buf[jj+1];
         }
         buf[109] = UART_ReceiveBuffer[ii];
         
      if(buf[0]==36 && buf[3]==71 && buf[4]==71 && buf[5]==65)
      {
         unsigned char kk=0;
         for(kk=0;kk<6;kk++)
         {
            out[kk]=buf[kk+7]; //6bytes(UTC)
         }
         for(kk=0;kk<12;kk++)
         {
            out[kk+6]=buf[kk+17]; //12bytes(Latitude)
         }
         for(kk=0;kk<13;kk++)
         {
            out[kk+18]=buf[kk+30]; //13bytes(Longitude)
         }
      } 
   }
len=0;

}



#INT_RDA
void RDA_isr(void)
{
   UART_ReceiveBuffer[len] = getc();
   ++len;
   if(len>=120)
   UART_IsReceived = 1;
   disable_interrupts(GLOBAL);
   disable_interrupts(INT_RDA);
}


void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      if(UART_IsReceived==1)
         {
         UART_IsReceived=0;
         rcv(); 
         enable_interrupts(INT_RDA);
         enable_interrupts(GLOBAL);
         }

         printf("%c%c",header[0],header[1]);
     
            for(mm=0;mm<6;mm++)
            {
               printf("%c",out[mm]);
            }
             for(mm=6;mm<18;mm++)
            {
               printf("%c",out[mm]);
            }
             for(mm=18;mm<31;mm++)
            {
               printf("%c",out[mm]);
            }
           
          delay_ms(1000);
                               
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19454

View user's profile Send private message

PostPosted: Wed Apr 17, 2013 7:49 am     Reply with quote

ERRORS.

Problem is if you disable the UART, and data arrives (it will), the UART goes into an error state, and is locked. The 'ERRORS' keyword, in #use rs232, makes the compiler add code to clear this.

Search the forum.

Other comments:

#priority does nothing unless you have multiple interrupts.

Then you have the big problem that your data won't be where you expect it to be in the stream. Since you have missed characters. Use a circular buffer, and look for the characters that define the start of the message. There are complete code examples for decoding GPS strings here, and in the code library.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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