PDA

View Full Version : Why first time string doesn't come properly?



FromTheCockpit
- 1st November 2009, 22:16
Hi, here is my code:

ab:
DEBUGIN 2000,ab,[WAIT("$GPRMC"),skip 14,DEC2 ladeg,DEC2 lamin,skip 1,DEC4 lasec,skip 3,DEC3 lodeg,DEC2 lomin,skip 1,DEC4 losec]
pause 1000
DEBUG "Latitude Deg ",DEC2 ladeg," Min ", DEC2 lamin," Sec ",DEC2 lasec,10,"Longitude Deg ",DEC3 lodeg, " Min ", DEC2 lomin," Sec ",DEC2 losec,13,10,10
pause 1000
goto ab

It grabs the data from GPS string and throws it on my computer screen. Everytime I power the PIC again, the first data string comes like this:

bѥՑDeg 51 Min 34 Sec 10 ' Only appears at first response only
Longitude Deg 000Min 07 Sec 32

After the first time it starts appearing fine

Latitude Deg 51 Min 34 Sec 10
Longitude Deg 000Min 07 Sec 32

I dont seem to understand it as if there is a problem with the code or hardware it should be a regular output, but junk characters only appear first time only.
Can someone tell me why this is happening? Thanks

Jerson
- 2nd November 2009, 02:19
Do a dummy serout in your initialization routine before you start reading/writing to the screen
Simply DEBUG 0 should do it. I've seen this issue covered earlier, so, it may help to search here. This happens because the DEBUG port is not initialized till first used by DEBUG.

Ioannis
- 2nd November 2009, 09:30
Set the port to HIGH state prior every serial command. Even better before TRIS command.

That is a good practice, to set the outputs before TRIS commands,so you have no glitches at the outputs.

Ioannis