 |
 |
| View previous topic :: View next topic |
| Author |
Message |
gamal eldeen
Joined: 29 May 2012 Posts: 29 Location: Alexandria - Egypt
|
|
Posted: Fri Aug 03, 2012 5:07 am |
|
|
now i use ...RDA_isr...
and i think it work but when i remove my GPS module the LCD still show the same data before !!!!!
why??? what is the wrong in the code ???????????????????
| Code: |
#int_RDA
void RDA_isr(void)
{
if (kbhit())
{
data = fgetc(PORT1); // Check the string '$GPGGA,'
if(data=='$')
{
data = fgetc(PORT1);
if(data=='G')
{
data = fgetc(PORT1);
if(data=='P');
{
data = fgetc(PORT1);
if(data=='G');
{
data = fgetc(PORT1);
if(data=='G')
{
data = fgetc(PORT1);
if(data=='A')
{
data = fgetc(PORT1);
if(data==',')
{
i=0;
data=0;
for(i=0;data!=',';++i)
{
data = fgetc(PORT1);
}
if(data==',')
{
i=0;
data=0;
for(i=0;i<=40;++i)
{
data = fgetc(PORT1);
Lat_Value[i]=data;
data =0;
}
}
}
}
}
}
}
}
}
}
else {
i=0;
data=0;
for(i=0;i<=40;++i)
{
Lat_Value[i]=0;
}
}
}
void main()
{
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
while(1)
{
lcd_gotoxy(1,1);
printf(LCD_PUTC,"LTD: %c%c%c%c%c%c%c%c%c %c",Lat_Value[0],Lat_Value[1],Lat_Value[2],Lat_Value[3],Lat_Value[4],Lat_Value[5],Lat_Value[6],Lat_Value[7],Lat_Value[8],Lat_Value[10]);
lcd_gotoxy(1,2);
printf(LCD_PUTC,"LNG:%c%c%c%c%c%c%c%c%c%c %c",Lat_Value[12],Lat_Value[13],Lat_Value[14],Lat_Value[15],Lat_Value[16],Lat_Value[17],Lat_Value[18],Lat_Value[19],Lat_Value[20],Lat_Value[21],Lat_Value[23]);
}
}
|
|
|
 |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 03, 2012 7:28 am |
|
|
Hi,
You've taken a baby step forward by starting to use the serial interrupt capability on your PIC, but your implementation is all wrong.... First, you don't need to use 'kbhit' inside the serial ISR - if the interrupt fires, it's because you've received a character. Second, and much more significant, is that the serial interrupt is only intended to receive a single character. What you should be doing is receiving only one character inside the serial ISR, and then stuffing it into a buffer for later decoding. You are trying to receive the entire NMEA string in one pass of the interrupt! There are several ways to implement serial buffering. You can look for the start character of '$', set your buffer index to zero, and then continue putting characters into your buffer until a <CR> or <LF> is received indicating that the string is complete. This would be a 'linear buffer'. Another technique would be to use a 'circular buffer' as described in the CCS example program 'ex_sisr.c'.
Have you searched (I mean REALLY searched!!) the forum for help with your project??? Receiving serial data from a GPS has got to be one of the most popular projects of all time on the forum, and it's been discussed (literally!) hundreds of times here. You seem to be intent on 're-inventing the wheel', and re-discovering all the most common mistakes that others have already made before you!
To answer your specific question of why the data remains the same on the LCD when you disconnect the GPS, is that your program undoubtedly hangs inside the ISR waiting for a new character that will never come. There is also nothing inside your main code that implements a 'time-out' if no data is received after a specific amount of time. In short, you've got a lot of work to do on your code!!
John |
|
 |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 03, 2012 12:01 pm |
|
|
Hi,
I just went back and reviewed the earlier posts in this thread, and realized that ckielstra provided a very clear road map to vastly improving your code back on page 2, but you have chosen to ignore it?? Why ask for advise from the forum members if you won't follow it?
John |
|
 |
|
|
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
|