PDA

View Full Version : Interfacing GPS receiver module with PIC16F876



theblackhourse
- 7th July 2008, 12:34
hi all

iam trying send an sms containing the GPS coordinates by connecting both using
pic 16f876 i found the circute and the code but it steel not working and i really don't know why.i have tryed all the AT commands on the hyperterminal and it is working good.that is the circuit and the code.

below the code and the circuit
************************


define OSC 20
device 16f876a ,hs_osc,wdt_off, BOD_ON, pwrt_on, lvp_off, protect_on

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 64
DEFINE HSER_CLROERR 1


Led1 var portb.6
Led2 var portb.7
GPS var portb.4

high Led1
high Led2

counter1 var byte
dim RX[64] as byte
dim TX[21] as byte
dim charcount as byte
dim txcounter as byte
dim rxcounter as byte
dim temp1 as byte
dim temp2 as byte




RX[1]="$"
RX[2]="G"
RX[3]="P"
RX[4]="R"
RX[5]="M"
RX[6]="C"
RX[7]=","
'131532
RX[14]=","
'A
RX[16]=","
'3048.34
RX[24]=","

RX[26]=","

RX[35]=","

RX[37]=","

RX[43]=","

RX[49]=","

RX[56]=","

RX[62]=","

COUNTER1=0

PAUSE 2000

CHECKMOBILE:

hserout ["at",13]

hserin 1000,checkmobile,[wait("ok")]

low Led1

pause 1000

mainloop:

high Led2

serin2 GPS,188,[wait("RMC,"),RX[8],RX[9],RX[10],RX[11],RX[12],RX[13],_
wait(","),RX[15],_
wait(","),RX[17],RX[18],RX[19],RX[20],RX[21],RX[22],RX[23],_
wait(","),RX[25],_
wait(","),RX[27],RX[28],RX[29],RX[30],RX[31],RX[32],RX[33],Rx[34],_
wait(","),RX[36],_
wait(","),RX[38],RX[39],RX[41],RX[41],RX[42],_
wait(","),RX[44],RX[45],RX[46],RX[47],RX[48],_
wait(","),RX[50],RX[51],RX[52],RX[53],RX[54],RX[55],_
wait(","),RX[57],RX[58],RX[59],RX[60],RX[61],_
wait(","),RX[63]]



low Led2

For Counter1 = 1 To 40

Toggle led2
Pause 100
Next

Low Led2

Pause 1000

send:

Txstatus2:

HIGH led1
hserout ["AT",13]

HSerin 1000,Txstatus2,[wait("ok")]

Low Led1
pause 500
Counter1 = 0

txstatus3:
High Led1
HSerout ["AT+CMGS=140",13]
HSerin 1000,txstatus3,[wait(">")]
LOW Led1
Pause 500

transmit3:
high Led1

HSerout ["0011000a8110121723750000aa3f"]

charcount = 1

FOR Counter1 = 1 TO 8
txcounter = 0
'______________________________
TX[txcounter] = rx[charcount]
temp1 = tx[txcounter]
charcount = charcount + 1
Temp2 = RX [charcount]
temp1.7 = temp1.7 OR temp2.0
TX[txcounter] = temp1
txcounter = txcounter + 1

'_______________________________

temp2 = temp2 >> 1
temp1=temp2
charcount = charcount + 1
temp2 = RX[charcount]
temp1.7 = temp1.7 OR temp2.2
temp1.1 = temp1.6 OR temp2.1
temp1.5 = temp1.5 OR temp2.0
TX[txcounter] = temp1
txcounter = txcounter + 1
'_______________________________

temp2 = temp2 >> 2
temp1 = temp2
charcount = charcount + 1
temp2 = rx[charcount]
temp1.7 = temp1.7 OR temp2.2
temp1.6 = temp1.6 OR temp2.1
temp1.5 = temp1.5 OR temp2.0
tx[txcounter] = temp1
txcounter = txcounter + 1
'_______________________________

temp2 = temp2 >> 3
temp1 = temp2
charcount = charcount + 1
temp2 = rx[charcount]
temp1.7 = temp1.7 OR temp2.3
temp1.6 = temp1.6 OR temp2.2
temp1.5 = temp1.5 OR temp2.1
temp1.4 = temp1.4 OR temp2.0
tx[txcounter] = temp1
txcounter = txcounter + 1
'_________________________________

temp2 = temp2 >> 4
temp1 = temp2
charcount = charcount + 1
temp2 = rx[charcount]
temp1.7 = temp1.7 OR temp2.4
temp1.6 = temp1.6 OR temp2.3
temp1.5 = temp1.5 OR temp2.2
temp1.4 = temp1.4 OR temp2.1
temp1.3 = temp1.3 OR temp2.0
tx[txcounter] = temp1
txcounter = txcounter + 1
'__________________________________

temp2 = temp2 >> 5
temp1 = temp2
charcount = charcount + 1
temp2 = rx[charcount]
temp1.7 = temp1.7 OR temp2.5
temp1.6 = temp1.6 OR temp2.4
temp1.5 = temp1.5 OR temp2.3
temp1.4 = temp1.4 OR temp2.2
temp1.3 = temp1.3 OR temp2.1
temp1.2 = temp1.2 OR temp2.0
tx[txcounter] = temp1
txcounter = txcounter + 1
'__________________________________

temp2 = temp2 >> 6
temp1 = temp2
charcount = charcount + 1
temp2 = rx[charcount]
temp1.7 = temp1.7 OR temp2.6
temp1.6 = temp1.6 OR temp2.5
temp1.5 = temp1.5 OR temp2.4
temp1.4 = temp1.4 OR temp2.3
temp1.3 = temp1.3 OR temp2.2
temp1.2 = temp1.2 OR temp2.1
temp1.1 = temp1.1 OR temp2.0
tx[txcounter] = temp1
txcounter = txcounter + 1

charcount = charcount + 1

HSerout [HEX2 TX[0], HEX2 TX[1], HEX2 TX[3],HEX TX[4],HEX2 TX[5],HEX2 TX[6]]

NEXT

HSerout [26]

low Led1

Pause 60000

GOTO mainloop

skimask
- 7th July 2008, 20:43
For one thing, you're using both HSERIN and SERIN. Which is it? Can't really have both without resetting the serial port pins back and forth between the serial module and general purpose I/O.
And, 2nd, you do realize this is a PicBasicPro forum, not a Proton Basic forum, right? PicBasicPro doesn't do DIMs and I'm not sure, but I don't think Proton does PAUSE.
So, again, which is it?

BrianT
- 8th July 2008, 23:05
I am not sure you can use the explicit array approach (Rx[26] = "," etc) as the NMEA sentences are variable length and what might be a comma this time may not be a comma when the field data changes.

I posted code to decode/parse GPS sentences a year or two back.
Have a look at:-

http://www.picbasic.co.uk/forum/show...ghlight=parser

HTH
BrianT

Dave
- 9th July 2008, 12:18
theblackhourse, This section of code does not look right...
'_______________________________

temp2 = temp2 >> 1
temp1=temp2
charcount = charcount + 1
temp2 = RX[charcount]
temp1.7 = temp1.7 OR temp2.2
temp1.1 = temp1.6 OR temp2.1
temp1.5 = temp1.5 OR temp2.0
TX[txcounter] = temp1
txcounter = txcounter + 1
'_______________________________

I beleive the line "temp1.1 = temp1.6 OR temp2.1" should be "temp1.6 = temp1.6 OR temp2.1" Also I think with a little thought you can get this series of lines down to about 10 or so...

Dave Purola,
N8NTA

camerart
- 6th August 2014, 08:17
Hi,

How are you getting on with your tracker project?

Camerart