|
|
View previous topic :: View next topic |
Author |
Message |
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Mon Sep 08, 2008 6:48 pm |
|
|
ckielstra wrote: | eng.alamin wrote: | if you can make it in one line it will be cool |
eng.alamin wrote: | thanks for this method (buffer[i]-=0x30) i'll use it . | You didn't use it or the switch statement would have been replaced by one line... |
yes sir it will decrease the code line but it's not the problem solution , right now am working to solve the problem then looking back to code management
thanks |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Sep 09, 2008 7:01 am |
|
|
I could be wrong but:-
All though your code needs alot of reworking I think this is your initial problem, which you seem to have not fixed and carried over to your new code :-
"lon = buffer[7]* 1000 + buffer[8]*100 + buffer[9]*10 + buffer[10] "
This is doing 8 bit arrythmatic in parts
assuming buffer[7] to [10] = "2447"
"buffer[7] * 1000" = 2000 (16 bit arrythmatic)
"buffer[8] * 100" = 144 (8 bit arrythmatic)
"buffer[9] * 10" = 40 (8 bit)
"buffer[10]" = 7;
Add them together = 2191 not 2447.
Am I correct in this ? If you posted what answer you actualluy get then you may get a little more help.
If you use litterals "2 * 1000 + 4 * 100 + 4 * 10 + 7" then the compiler will do the math for you and not the PIC!
Now your string is
"$GPGLL,2447.2073,N,12100.5022,E,104548.04,A,A*65 "
Code: |
float lon, lat;
char trem[2], *ptr;
strcpy(term,",");
ptr = strtok(string, term); // ptr = "$GPGLL"
ptr = strtok(0, term); // ptr = 2447.2073
lon = atof(ptr); // lon should = 2447.2073
ptr = strtok(0, term); // ptr = "N"
ptr = strtok(0, term); // ptr = 12100.5022
lat = atof(ptr); // lon should = 12100.5022
|
Any help ? |
|
|
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Tue Sep 09, 2008 2:14 pm |
|
|
Wayne_ wrote: | I could be wrong but:-
All though your code needs alot of reworking I think this is your initial problem, which you seem to have not fixed and carried over to your new code :-
"lon = buffer[7]* 1000 + buffer[8]*100 + buffer[9]*10 + buffer[10] "
This is doing 8 bit arrythmatic in parts
assuming buffer[7] to [10] = "2447"
"buffer[7] * 1000" = 2000 (16 bit arrythmatic)
"buffer[8] * 100" = 144 (8 bit arrythmatic)
"buffer[9] * 10" = 40 (8 bit)
"buffer[10]" = 7;
Add them together = 2191 not 2447.
Am I correct in this ? If you posted what answer you actualluy get then you may get a little more help.
If you use litterals "2 * 1000 + 4 * 100 + 4 * 10 + 7" then the compiler will do the math for you and not the PIC!
Now your string is
"$GPGLL,2447.2073,N,12100.5022,E,104548.04,A,A*65 "
Code: |
float lon, lat;
char trem[2], *ptr;
strcpy(term,",");
ptr = strtok(string, term); // ptr = "$GPGLL"
ptr = strtok(0, term); // ptr = 2447.2073
lon = atof(ptr); // lon should = 2447.2073
ptr = strtok(0, term); // ptr = "N"
ptr = strtok(0, term); // ptr = 12100.5022
lat = atof(ptr); // lon should = 12100.5022
|
Any help ? |
ahhhh Finally
Yes yes you are correct on this ,,,, it is my problem
How can i fix this problem ??
How can i load these two variables from my buffers
----------------
I will try to fit your code into my program right now thank you very much
------ |
|
|
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Tue Sep 09, 2008 2:41 pm |
|
|
hello sir
this is my code after some modification
but output is
this is code
Code: | #include <18f4550.h>
#include <stdlib.h>
#include <MATH.H>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=12000000)
#use rs232(baud=4800, xmit=PIN_b4,rcv=PIN_b0,stream=GPS)
void main()
{
char term[2] , *ptr ;
int string[31];
int buff[8] ;
byte sync;
float lon ;
float lat ;
int x ;
char value1;
char value;
float des ;
amin:
lon = 0 ;
lat = 0 ;
while(TRUE) {
loop :
sync = getc() ;
if (sync == '$' )
{
for (x = 1 ; x <= 6 ; x++)
{
string[x] = getc() ;
}}else{goto loop ;}
if ( string[3] == 'G' && string[4] == 'L' && string[5] == 'L' )
{
for (x = 7 ; x <= 30 ; x++)
{
string[x] = getc() ;
//string[x] -= 48 ;
}
}
else {goto loop ; }
strcpy(term ," ,") ;
ptr = strtok(string ,term) ;
ptr = strtok (0 , term);
lat = atof (ptr);
printf("%f %C ", lat , string[17] );
}
goto amin; }
|
|
|
|
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Tue Sep 09, 2008 4:43 pm |
|
|
will will will this is where iam i guess there is some improvement
this is my code :
this is experimentally code only
Quote: | string[0] result is correct
lat (as string ) result is correct
and there is mistake on lat as float result is not still correct |
this is the code
Code: |
#include <18f4550.h>
#include <stdlib.h>
#include <MATH.H>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=12000000)
#use rs232(baud=4800, xmit=PIN_b4,rcv=PIN_b0)
void main()
{
char term[2] , *ptr ;
char string[31];
float lon ;
float lat ;
int x ;
lon = 0 ;
lat = 0 ;
strcpy(term ," , ") ;
while(TRUE) {
for (x = 0 ; x <= 30 ; x++)
{
string[x] = getc() ;
}
ptr = strtok(string ,term) ;
ptr = strtok(0 , term);
lat = atof(ptr);
printf("%C %S %f %C ", string[0] ,ptr, lat , string[17] );
}
}
|
this is result
[img] http://www8.0zz0.com/2008/09/09/22/509081337.jpg [/img]
PCM programmer where are you man
Last edited by eng.alamin on Tue Sep 09, 2008 5:08 pm; edited 3 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 09, 2008 4:50 pm |
|
|
You still have a goto statement in there. Use a while statement instead.
The formatting isn't very good.
Use the Preview window and fix all the formatting before you post.
(or edit your post later). Clean up the indentations so they are not
jagged. Get rid of the excessive number of blank lines between
sections of the code. One or two blank lines is better. Make it look
neat. Then you'll get more people to look at your code. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Sep 09, 2008 5:13 pm |
|
|
Identation was cleaned up a bit, but could be better.
I tried the program in v4.077 and got the following output: Code: | $ 2447.2073 2447.20 N | This is the expected output.
What is the version number of your compiler? You can find the number at the top of the list file (*.lst). |
|
|
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Tue Sep 09, 2008 5:41 pm |
|
|
ckielstra wrote: | Identation was cleaned up a bit, but could be better.
I tried the program in v4.077 and got the following output: Code: | $ 2447.2073 2447.20 N | This is the expected output.
What is the version number of your compiler? You can find the number at the top of the list file (*.lst). |
yes you right
it's the output
i think my error is in
Code: |
printf("%C %S %f %C ", string[0] ,ptr, lat , string[17] ); |
some how i think (lat) is content of correct answer
am using version 3.241 |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 10, 2008 3:35 am |
|
|
Try one simple change. Instead of '%f' for the float output, use '%7.2f'. There was a fault with some compilers at about this time, where if you used %f, without any 'size' data, it gave a screwy output for some values.
Best Wishes |
|
|
eng.alamin
Joined: 08 Sep 2008 Posts: 17
|
|
Posted: Wed Sep 10, 2008 5:37 am |
|
|
Ttelmah wrote: | Try one simple change. Instead of '%f' for the float output, use '%7.2f'. There was a fault with some compilers at about this time, where if you used %f, without any 'size' data, it gave a screwy output for some values.
Best Wishes |
thank you man %7.2f worked good |
|
|
|
|
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
|