In the 1st there was a missing wire this is the good one.
<a href="http://imageshack.us"><img src="http://img392.imageshack.us/img392/8734/esquemaxa1.jpg" border="0" alt="Image Hosted by ImageShack.us"/></a><br/><a href="http://g.imageshack.us/img392/esquemaxa1.jpg/1/"><img src="http://img392.imageshack.us/img392/esquemaxa1.jpg/1/w851.png" border="0"></a>
Xau.
Last edited by camolas; - 14th October 2008 at 15:57.
Hi,
This is for conecting a nokia phone and a pic, you will control the phone from the pic, later i will post a code where you can with a serial gps send a sms with the gps data.
Xau.
Here is my full and working code for a gps/alarme/gsm.
*********************************************
@ Device HS_OSC
define OSC 20
Include "modedefs.bas" ' Include serial modes
Clear
sms var byte[10]
numero VAR BYTE[12]
Lat var byte[11]
Long var byte[11]
TrisB.7=0 ' LIGA GSM
TrisB.6=1 ' IGNIÇÃO
TrisB.5=1 ' SENSORES
TrisB.4=0 ' FEXA PORTAS
TrisB.3=0 ' PISCAS
TrisB.2=0 ' IMOBLIZA
TrisB.1=0 ' ?????????????
TrisB.0=0 ' LED OK VERDE
TrisC.4=1 ' RX BT
TrisC.5=0 ' TX BT
TrisC.6=0 ' TX GSM
TrisC.7=1 ' RX GSM
TrisD.1=1 ' RX GPS
Low PortB.1
Low PortB.2
Low PortB.3
Inicio:
Low PortB.0
Pause 500
High PortB.0
Pause 500
Low PortB.0
Pause 500
High PortB.0
Pause 500
Low PortB.0
Pause 500
High PortB.0
Pause 500
Low PortB.0
Pause 2000
UM:
Low PortB.1
HSEROUT["at",13,10]
HSERIN 10000,UM,[WAIT("OK")]
LCDOut $FE, 1,"ON"
HIGH PortB.0
DOIS:
serin2 portD.1, 188, [WAIT("$GPRMC,"),skip 13, STR LAT\11,skip 1, STR Long\12]
High PortB.1
HSEROUT["AT+CMGF=1",13,10]' Modo Texto
HSERIN 10000,UM,[WAIT("OK")]
HSEROUT["AT+CMGR=1",13,10] ' Ler sms
HSERIN 5000,UM,[WAIT("REC UNREAD"),skip 3, STR numero\13,skip 27,STR sms\10]
IF sms[0]="S" and sms[1]="t" and sms[2]="o" and sms[3]="p" Then
goto Tranca
Endif
IF sms[0]="C" and sms[1]="e" and sms[2]="l" and sms[3]="i" and sms[4]="a" Then
goto Destranca
Endif
IF sms[0]="P" and sms[1]="o" and sms[2]="s" Then
goto PO
Endif
Goto APAGA
Tranca:
High PortB.3 'Piscas
Pause 500
High PortB.2 ' Imobliza
Goto PO
Destranca:
Low PortB.3 'Piscas
Low PortB.2 ' Imobliza
Goto APAGA
Liga: ' LIGA GSM
High PortB.7
Pause 20000
Goto UM
PO: ' Envia localizacao
HSEROUT["AT+CMGS=",34,"+351xxxx32xxx", 34,13] ' Phone number to get the gps sms data
hserin 10000,PO,[WAIT(">")]
HSEROUT["LAT: ",LAT (10),"-", LAT, lat (1),"'",lat (2),Lat(3),".",lat (5),lat(6),lat (7),lat(8),$fe,$c0,"LON: ", Long(11),"-", Long (1),long (2),"'",Long (3),long (4),".",Long (6),long (7),long(8),long (9),13,10]
HSEROUT[26]
APAGA:
HSerout ["AT+CMGD=1",13,10]' apaga sms 1
hserin 10000,APAGA,[WAIT("OK")]
HSerout ["AT+CMGD=2",13,10]
Pause 5000
goto Inicio
End
************************************************** ********
I get sender number (numero VAR BYTE[12]) but cant use it in the HSEROUT["AT+CMGS=",34,"+351xxxx32xxx", 34,13] i try HSEROUT["AT+CMGS=",34,"Str numero", 34,13] but no sucess can the masters give me some hellp?
Thanks
Xau
Last edited by camolas; - 27th October 2008 at 18:28.
Try sending "numero" like you are for "lat" and "Lon", one piece at a time.I get sender number (numero VAR BYTE[12]) but cant use it in the HSEROUT["AT+CMGS=",34,"+351xxxx32xxx", 34,13] i try HSEROUT["AT+CMGS=",34,"Str numero", 34,13] but no sucess
Dave
Always wear safety glasses while programming.
Camola, try the following:
Use a larger array in such a way that you can accomodate the calling string in the initial part of the array:
Arry[0]=65
Arry[1]=84
Arry[2]=43
Arry[3]=67
Arry[4]=77
Arry[5]=71
Arry[6]=83
ArrY[7]=43
The above sequence contains the string AT+CMGS=+
Than you tranfer the sender number (12 bytes) in Arry[8] to Arry[19]. Remember that last byte should always be Arry[20]=13
At this point you can make the call:
For A0=0 to 20
serout Mtx,T9600,[Arry[A0]]
Next A0
Immediatly after the call you have to wait the modem acknowledge ">". Here an example of code:
Flag=0
WSend:
Flag=Flag+1
if Flag>20 then NoSMS
Serin MRx,T9600,500,WSend,[ ">"] , A0
If A0=32 then SendTxt
serout Mtx,T9600,[27]
pause 5000
goto NoSMS
The code above will jump to label "SendTxt" if the modem answer corectly, otherwise it will abort the call with ascii 27 and jump to label "NoSMS"
At label "SendTxt" you will wite your code to send your string.
Naturally you should change Serin/Serout to fit your code
Al.
Last edited by aratti; - 28th October 2008 at 11:19.
Look the ASCII table
A=65
T=84
and so on
the above could also be written like...
Code:Arry[0]="A" Arry[1]="T" // etc etc etc
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Not sure if this will help you now or not, but it might.
http://www.picbasic.co.uk/forum/showthread.php?t=544
Dave
Always wear safety glasses while programming.
Camolas, The array "numero" contain the string so:
For A0=8 to 19
arry[A0]=numero[A0-8]
next A0
Arry[20]=13
But you can put the value directly in arry[8] to arry[19] instead to put it in the array "numero"
Al.
Hi,
Its final and full working code, any questions please asck.
Code:
--------------------------------------------------------------------------
@ Device HS_OSC
define OSC 20 ' Check the spelling of OSC, must be in capital letter
Include "modedefs.bas" ' Include serial modes
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTD
Define LCD_RSBIT 3
Define LCD_EREG PORTD
Define LCD_EBIT 2
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
LCDOut $FE, 1
Clear
sms var byte[10]
numero VAR BYTE[12]
Lat var byte[11]
Long var byte[11]
TrisB.7=0 ' LIGA GSM
TrisB.6=1 ' IGNIÇÃO
TrisB.5=1 ' SENSORES
TrisB.4=0 ' FEXA PORTAS
TrisB.3=0 ' PISCAS
TrisB.2=0 ' IMOBLIZA
TrisB.1=0 ' ?????????????
TrisB.0=0 ' LED OK VERDE
TrisC.4=1 ' RX BT
TrisC.5=0 ' TX BT
TrisC.6=0 ' TX GSM
TrisC.7=1 ' RX GSM
TrisD.1=1 ' RX GPS
Low PortB.1
Low PortB.2
Low PortB.3
Inicio:
Low PortB.0
Pause 500
High PortB.0
Pause 500
Low PortB.0
Pause 500
High PortB.0 'pisca 3 vezez e desliga
Pause 500
Low PortB.0
Pause 500
High PortB.0
Pause 500
Low PortB.0
Pause 2000
UM:
Low PortB.1
HSEROUT["at",13,10]
HSERIN 10000,UM,[WAIT("OK")]
LCDOut $FE, 1,"ON"
HIGH PortB.0
DOIS:
serin2 portD.1, 188, [WAIT("$GPRMC,"),skip 13, STR LAT\11,skip 1, STR Long\12]
High PortB.1
HSEROUT["AT+CMGF=1",13,10]' Modo Texto
HSERIN 10000,UM,[WAIT("OK")]
LCDOut $FE, 1,"ok"
HSEROUT["AT+CMGR=1",13,10] ' Ler sms
HSERIN 5000,UM,[WAIT("REC UNREAD"),skip 3, STR numero\13,skip 27,STR sms\10]
IF sms[0]="S" and sms[1]="t" and sms[2]="o" and sms[3]="p" Then
goto Tranca
Endif
IF sms[0]="C" and sms[1]="e" and sms[2]="l" and sms[3]="i" and sms[4]="a" Then
goto Destranca
Endif
IF sms[0]="P" and sms[1]="o" and sms[2]="s" Then
goto PO
Endif
Goto APAGA
Tranca:
High PortB.3 'Piscas
Pause 500
High PortB.2 ' Imobliza
Goto PO
Destranca:
Low PortB.3 'Piscas
Low PortB.2 ' Imobliza
Goto APAGA
Liga: ' LIGA GSM
High PortB.7
Pause 20000
Goto UM
PO: ' Enia localizacao
HSEROUT["AT+CMGS=",34,STR numero, 34,13]
hserin 10000,PO,[WAIT(">")]
Lo:
HSEROUT["LAT: ",LAT (10),"-", LAT, lat (1),"'",lat (2),Lat(3),".",lat (5),lat(6),lat (7),lat(8),$fe,$c0,"LON: ", Long(11),"-", Long (1),long (2),"'",Long (3),long (4),".",Long (6),long (7),long(8),long (9),13,10]
hserin 10000,lo,[WAIT(">")]
Li:
HSEROUT[26]
hserin 10000,li,[WAIT("OK")]
APAGA:
HSerout ["AT+CMGD=1",13,10]' apaga sms 1
hserin 10000,APAGA,[WAIT("OK")]
HSerout ["AT+CMGD=2",13,10]
Pause 5000
goto Inicio
End
--------------------------------------------------------------------------
Thanks for all the help that you gave me.
Xau.
Your code must hang if there is no enough deposit on the sim card, alternativelay u can see gsm network connectivity available for make more reliable the sms dispachting, i don't know how that cell phone works but if it has log for sms in areas without gsm coverage and the pic still in the Lo loop, once you are back on GSM coverage, simply alll your deposit can be wasted in several hundred SAME message !!
but . . . is just my point of view...
Last edited by bethr; - 1st December 2008 at 04:27. Reason: spell
Hi,
Thanks for the inputs, for the deposit there is no problem because in my code i delet the "REC UNREAD" sms
"APAGA:
HSerout ["AT+CMGD=1",13,10]' apaga sms 1
hserin 10000,APAGA,[WAIT("OK")]
HSerout ["AT+CMGD=2",13,10]
Pause 5000"
The gsm coverage is very good point that you have made it need to be changed in a futer update.
I have been in a wardware problem now this works very good in a QL200-A4 board but in my home made pcb not (some times works some not..) the pic cant get the phone Tx (i see it in hyperterminal that phone gets the pic Tx e reply but pic cant get it) i have put a 10K pulldown and up in phones Tx but no sucess.Need hellp on that if you mates can hellp me thanks.
Xau.
Camola, remove the resistors from the serial line and use a Max232.
Al.
All progress began with an idea
Hi Al,
Ive removed the res and wired like this but no sucess
<a href="http://imageshack.us"><img src="http://img509.imageshack.us/img509/3451/maxpt7.jpg" border="0" alt="Image Hosted by ImageShack.us"/></a><br/><a href="http://g.imageshack.us/img509/maxpt7.jpg/1/"><img src="http://img509.imageshack.us/img509/maxpt7.jpg/1/w677.png" border="0"></a>
Thanks,
Xau
Camola, I don't see the pinout in your diagram so I don't know if you have wired it correctly. See the attached schematic for a correct wiring.
Al.
All progress began with an idea
Camola, modem connection should not be crossed (I don't know with nokia) but try, if it doesn't work invert Rx with Tx at the phone cable.
Before to connect the max232 to the phone, make sure that is a standard RS232. If the phone has a 3.3 volts system you will blowup the phone communication line. In this case you should use a different approch.
Remember that if you connect the max232 to the PC serial port then Rx and Tx should be crossed. The connection given in the schematic are for a PC serial connection.
Al.
Last edited by aratti; - 3rd December 2008 at 05:29.
All progress began with an idea
What are the stop bits and parity of a phone?
Dave
Always wear safety glasses while programming.
Have you tried connecting to a PC with a terminal program like the one in Micro Code Studio?
Dave
Always wear safety glasses while programming.
Camola, I am a little confuse. I did a bit of research on google and it seems that
nokia 6210 has a USB connection. Are you sure your phone has a serial connection?
Al.
All progress began with an idea
Camola, from your code it seems that you are using portC.6 and PortC.7 for communication with cellphone. If this is correct then:
Connect pic portC.6 to max232 pin 11 (TTL Tx)
Connect pic portC.7 to max232 pin 12 (TTL Rx)
Connect max232 pin 14 to phone serial cable pin 3 (Should be Rx ?)
Connect max232 pin 13 to phone serial cable pin 2 (should be Tx ?)
Connect circuit ground to phone serial cable pin 5
(If you connect it to the PC I assume you have a 9 pins DB female connector)
It should work. If it doesn't invert connections at the serial cable pins 2 & 3
Al.
Last edited by aratti; - 4th December 2008 at 15:47.
All progress began with an idea
Hi,
I have used Serin2 and works not in any 16f877a port it works on B.7 as Rx and in B.6 as Tx.
Serout2 PortB.6, 84,["AT",13,10]
Serin2 PortB.7,84, [wait ("ok")]
High PortB.0
Dont work in C.7 and C6, C4 and C5 big mess.....
Can i used 2 diferents Serin2 and Serout2 in same code because i need to control phone and gps i was using hserin/out to phone and Serin2/out2 for gps.
Thanks
Last edited by camolas; - 4th December 2008 at 17:35.
Did you powered the cable working with hyperterminal? If not you don't need to do it with max232.Yes it have and there are nokia cables to conect it to pc rs232 i have one from nokia and works fine with hyperterminal.
Al.
All progress began with an idea
Yes you can. But when you service one device you don't see the others (If device A will send data while you are servicing device B, device A data will be lost"Can i use in same code more the one Serout2/in2 on diferent ports to control phone and gps and others serial devices?
Al.
Last edited by aratti; - 4th December 2008 at 22:44.
All progress began with an idea
I have not done phones, but the others many times.
As long as the pin is set for digital SERIN/OUT/2 will work on any pin that is an I/O, You can have as many pins as you want taking turns doing serial.
You can mix and match SERIN, SERIN2, and HSERIN.
If you are slick, you can HSERIN on the hardware and SEROUT on another.
Dave
Always wear safety glasses while programming.
..............
Last edited by camolas; - 5th December 2008 at 20:24.
Have you correctly placed the label "UM:" in your code?
Al.
Last edited by aratti; - 5th December 2008 at 20:29.
All progress began with an idea
Bookmarks