hserin and sms controller
hello
here is my problem, i want to read sms message from nokia phone and if sms message is present, activate some output pin on pic. here is some sample code that was faound on som previous thread on this forum
checksms:
HSerout ["AT",13,10]' start modem
Pause 1000
HSerout ["AT+CMGF=1",13,10]'set text mod
Pause 500
'hserout ["AT+CPMS=SM",13,10]'optional set memory location
loop:
HSerout ["AT+CMGL",13,10]'list new sms msg
pause 500
' read
HSerin 1800,loop,[wait("REC UNREAD"),skip 3,STR CALL\13,skip 4,STR GSMT\17,skip 6, STR GSMMSG\16\13]
if gsmmsg(1)=$41 THEN' msg sent to phone is leter A
HIGH PORTB.6
PAUSE 1000
ENDIF
GOTO LOOP
end
thx in advance for any help!!!!!!!!!!!!!
thx ionnis i appreciate for your reply
thx in advance, i use pic 16F887 and 4 MHz XT osc, i can send msg, delet it, but with reading is not going well, i noticed that teh voltage on rx line of pic is about 2.3 - 2.4 V, and i asume that is not sufficient. i tried with this code but nothing happends!
Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 20/02/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
ansel=$00
anselh=$00
OUTPUT PORTB
PORTB=%00000000
' Def
define OSC 4
DEFINE HSER_SPBRG 25
DEFINE HSER_TXSTA 24h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1
sms VAR BYTE[16]
I VAR BYTE
HIGH PORTB.7
PAUSE 2000
LOW PORTB.7
' check sms
begin:
HSerout ["AT",13,10]' start comm
HSERIN 2000,begin,[WAIT("OK")]
textmod:
HSerout ["AT+CMGF=1",13,10]'set text mod
HSERIN 2000,textmod,[WAIT("OK")]
mem:
HSEROUT["AT+CPMS=",34,"ME",34,13,10]' mem location
HSERIN 2000,mem,[WAIT("OK")]
query:
'HSEROUT["AT+CMGL=",34,"REC READ",34,13,10]' filter for query
HSEROUT["AT+CMGL=",34,"REC READ",34,13,10]' filter for query
HSERIN 5000,query,[WAIT("REC READ"),skip 41, STR sms\16\13]
I=0
WHILE I <> 13' count until 13
if sms[i]=$44 THEN ' searching for letter A ?
GOTO turnon:
ELSE
GOSUB back:
I=I+1
ENDIF
WEND
goto query:
turnon:
High PortB.6
pause 1000
low portb.6
return
back:
RETURN
End
simple device for sms controll of biomas heating device
Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 18/03/2009 *
'* Version : 3.0 *
'* Notes : lcd menu working fine, four temepratures in this *
'* : example, but u can easy update that, one phone *
'* : authorized number,response from phone works fine *
'* : *
'****************************************************************
'****************************************************************
'* Name : UNTITLED.BAS *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'* Date : 21/04/2009 *
'* Version : 2.0 *
'* Notes : pic16F887, lcd 2X16 and ds1820 digital thermo. *
'* : for remote (SMS) control of biomase heating device*
'* : with nokia 6210 and DL3P from www.atrox.at and *
'* : with help from author of www.elektronika.ba,and Ioannis *
'* Autor : Muamer Halilovic, www.mtskola.com *
'****************************************************************
'
'pic defines
'------------------------------------------------------------------------
@ DEVICE pic16F887, WDT_OFF ' Watchdog Timer
@ DEVICE pic16F887, PWRT_ON ' Power-On Timer
@ DEVICE pic16F887, MCLR_ON ' Master Clear Options (Internal)
@ DEVICE pic16F887, BOD_ON ' Brown-Out Detect
@ DEVICE pic16F887, LVP_OFF ' Low-Voltage Programming
@ DEVICE pic16F887, CPD_OFF ' Data Memory Code Protect
@ DEVICE pic16F887, PROTECT_OFF ' Program Code Protection
'
'konfigurisi AN pinove kao digital I/O, portd kao I
'------------------------------------------------------------------------
ansel=$00
anselh=$00
TRISD=$00
portd=$00
'
' Definisanje hser-a (transmit-recive) i lcd-a u 4 bitnom modu
'------------------------------------------------------------------------
define OSC 4
DEFINE HSER_SPBRG 25
DEFINE HSER_TXSTA 24h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1
DEFINE LCD_BITS 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_LINES 2
'
'definisanje varijabli
'------------------------------------------------------------------------
high portd.7 ' aktiviranje uređaja
pause 1000
low portd.7
SYMBOL sel = PORTA.0 ' Sw 1 "trenutno stanje u objektu"
symbol res = porta.1 'sw 2 "meni"
SYMBOL enter = PORTA.2 ' Sw 3 "enter"
T1 VAR BYTE
T1=20
'----------------------------------------------------------------
' promjenjive
'----------------------------------------------------------------
MENU VAR BYTE ' zeljeni MENU
POSI VAR BYTE ' Pozicija na LCD
temp Var Word ' temperatura kao word
cr Var Byte ' ostatak
cpc Var Byte ' broji po stepenu C
ow Var PORTE.2 ' One-wire data pin
i var byte ' brojac
posttemp var word ' zeljena temperatura
PORUKA VAR BYTE[3] ' poruka kao array
TELBR VAR BYTE[12] 'broj kao array
TIME VAR BYTE [6] 'vrijeme kao array
grijanje var byte 'grijanje kao bajt za ukljucenje i iskljucenje potrosaca
grijanj var byte 'grijanje kao bajt za ukljucenje i iskljucenje potrosaca
tmp var byte
tbr var byte 'predefinisani broj korinsika
IstaPoruka3 VAR byte 'varijabla za upoređivanje
IstaPoruka1 var byte 'varijabla za upoređivanje
istaporuka2 var byte 'varijabla za upoređivanje
broj var byte
x var byte 'brojac x
K VAR BYTE 'brojac k
L VAR BYTE 'brojac L
J VAR BYTE 'brojac J
'----------------------------------------------------------------
' incijalizacija
'----------------------------------------------------------------
'low portc.6
low porte.2
PAUSE 300 ' LCD inicijalizacija
LCDOUT $FE,1 ' ocisti LCD
MENU = 1 ' Inicijalizacija variablli
x=0
K=0
L=0
J=0
LCDOUT $FE,130," DOBRO DOSLI"
'lcdout $FE,$c0,128, "izaberite temp "
lcdout $FE,$c0,"enter"," "," sel"," "," temp"
'-------------------------------------------------------------------------------------
' meni switc select temp
'-------------------------------------------------------------------------------------
PAUSE T1
poc:
IF sel = 1 THEN
gosub sc1
else
goto poc
endif
izbor:
if res = 1 then 'ako je res pritisnut
LCDOUT $FE,1 'ocisti lcd
MENU = MENU + 1 'povecavaj vrijednost
gosub amenu 'idi na Amenu (odabir za prikaz na display)
pause 200
endif
IF MENU = 5 THEN MENU = 1
for i = 1 to 4
if menu = i and enter=1 then gosub sc
next i
GOTO izbor
'----------------------------------------------------------------------
'odabir za prikaz na displeju
'----------------------------------------------------------------------
AMENU:
SELECT CASE MENU
CASE 2
POSI = 129 : LCDOUT $FE,128,">" : LCDOUT $FE,POSI,"1."," 28.00" , " C"
POSI = 193 : LCDOUT $FE,POSI,"2."," 30.00" , " C"
CASE 3
POSI = 129 : LCDOUT $FE,128,">" : LCDOUT $FE,POSI,"2."," 30.00" , " C"
POSI = 193 : LCDOUT $FE,POSI,"3."," 32.00" , " C"
CASE 4
POSI = 129 : LCDOUT $FE,128,">" : LCDOUT $FE,POSI,"3."," 32.00", " C"
POSI = 193 : LCDOUT $FE,POSI,"4."," 34.00" , " C"
CASE 5
POSI = 129 : LCDOUT $FE,128,">" : LCDOUT $FE,POSI,"4."," 34.00", " C"
POSI = 193 : LCDOUT $FE,POSI,"1."," 28.00", " C"
END SELECT
RETURN
'---------------------------------------------------------------------
'prikaz izabrane temperature
'---------------------------------------------------------------------
sc:
select case menu
case 2
posttemp=$0AF0' postemp = 2800
LCDOUT $FE,1, "Max temp:","28.00 C"
pause 2000
case 3
posttemp=$0BB8
LCDOUT $FE,1, "Max temp:" , "30.00 C"
pause 2000
case 4
posttemp=$0C80
LCDOUT $FE,1, "Max temp:" , "32.00 C"
pause 2000
case 1
posttemp=$0D48
LCDOUT $FE,1, "Max temp:", "34.00 C"
pause 2000
end select
'goto main
How to invert hardware serial port
Quote:
Originally Posted by
Ioannis
Hserout/Hserin pressume that you have included inverters in your circuit (like the common MAX232, which obviously there are not).
I would use a 3.3 driver for the UART like MAX3232 for example.
The above was an older post. Since then, a way to invert the hardware serial port has been spotted in the 400+ page datasheets of the PIC18 devices.......
See http://www.picbasic.co.uk/forum/showthread.php?t=10361 for a little more information.
To command it to do so:
Code:
BSF BAUDCON,RXDTP
BSF BAUDCON,TXCKP
Pretty cool stuff. I have tried it on a few projects, including a bootloader, and it works great. Nice to eliminate the max232 hardware when you can.