Hi,
Nokia 7110 only work for me in 19600 bauds...
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
Code:'--------------------------------------------------------------------- ' provjeri sms inbox '--------------------------------------------------------------------- main: p: HSerout ["ATZ",13,10] ' pocni komunikaciju,resetuj modem! HSERIN 4000,p,[WAIT("OK")] tm: HSerout ["AT+CMGF=1",13,10] 'postavi text mod HSERIN 2000,tm,[WAIT("OK")] m: HSEROUT["AT+CPMS=",34,"SM",34,13,10] 'ciljana memory lokacija HSERIN 2000,m,[WAIT("OK")] ws: gosub sc1 'odi provjeri temperaturu HSEROUT["AT+CMGL",13,10] 'filter za query LCDOUT $FE,1,"cekaj sms!" HSERIN 5000,ws,[WAIT("REC UNREAD"),skip 3,str telbr\12,skip 12,str TIME\6,skip 8,STR PORUKA\3\13]'trazi unread lcdout $FE,1,telbr[6],telbr[7],telbr[8],telbr[9],telbr[10],telbr[11] pause 3000 tbr[6]="8" tbr[7]="3" tbr[8]="1" tbr[9]="0" tbr[10]="x"'your phone number last two digits, oli zadnje dvije cifre vaseg broja tbr[11]="y" broj=1 for x=6 to 11 if TELBR[x]<>tbr[x] then broj=0 next x lcdout $FE,$c0,tbr[6],tbr[7],tbr[8],tbr[9],tbr[10],tbr[11] pause 2000 IF broj=0 then gosub s4 grijanje[1]="U" 'turn on heating grijanje[2]="G" istaporuka2=1 FOR K=0 to 1 if poruka[K+1]<>grijanje[K+1] then istaporuka2=0 next K if istaporuka2=1 then gosub s1 'ako se sve poklapa idi na slanje poruka 'ukljucene poreosaca grijanj[1]="I" 'turn off heating grijanj[2]="G" IstaPoruka1=1 FOR L=0 to 1 if poruka[L+1]<>grijanj[L+1] then IstaPoruka1=0 'ako se slova iz naredbe ne poklapaju next L 'istaporuk1=0 if IstaPoruka1=1 then gosub s2 'ako se sve poklapa idi na slanje poruka 'iskljucenje poreosaca tmp[1]="T" 'ask for temperature in object tmp[2]="P" IstaPoruka3=1 FOR J=0 to 1 if poruka[J+1]<>tmp[J+1] then IstaPoruka3=0 'ako se slova iz naredbe ne poklapaju next j 'istaporuk1=0 if IstaPoruka3=1 then gosub s3 'ako se sve poklapa idi na slanje poruka 'temperatura u objektu ' ------------------------------------------------------------ ' brisanje poruke iz memeorije ' ------------------------------------------------------------ mm: HSEROUT["AT+CPMS=",34,"SM",34,13,10] 'ciljana memory lokacija HSERIN 2000,mm,[WAIT("OK")] d: HSEROUT["AT+CMGD=1",13,10] 'brisi poruku iz mem loc SM sa indexom 1 HSERIN 2000,d,[WAIT("OK")] LCDOUT $FE,1,"sms izbrisan!" pause 1500 GOTO ws 'subrutines '--------------------------------------------------------------- ' 'subrutine za on/off-i potrosca i obavjest korisnika o poduzetoj akciji 'i provjeru pristigle poruke '--------------------------------------------------------------- s2: if IstaPoruka1=1 then low portd.0 LCDOUT $FE,1,"isklj grijanje!" HSerout ["AT",13,10] Pause 1000 HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode Pause 1000 HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10] pause 500 HSerout [str poruka\3,str time\6,10,13] s21: HSerout [26] hserin 6000,s21,[WAIT("OK")] return s1: if istaporuka2=1 then high portd.0 LCDOUT $FE,1,"uklj grijanje!" HSerout ["AT",13,10] Pause 1000 HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode Pause 1000 HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10] pause 500 HSerout [str poruka\3,str time\6,13,10] s11: HSerout [26] hserin 6000,s11,[WAIT("OK")] return '-------------------------------------------------------------- 'temperatura sa ds1820 '-------------------------------------------------------------- sc1: OWOut ow, 1, [$CC, $44] ' pocni temp konverziju wc: OWIn ow, 4, [cr] ' provjeri da'l se jos konvertuje If cr = 0 Then wc OWOut ow, 1, [$CC, $BE] ' ocitaj temp OWIn ow, 0, [temp.LOWBYTE, temp.HIGHBYTE, Skip 4, cr, cpc] ' izracunaj temp u C na 2 decimale temp = (((temp >> 1) * 100) - 25) + (((cpc - cr) * 100) / cpc) Lcdout $fe, 1,"Trenutna temp:"' prikazi temp lcdout $FE,$c0,128,DEC (temp / 100), ".", DEC2 temp, " C"'"izaberite temp " if temp >= posttemp then gosub s3 ' ako je uslov ispunjen salji upozorenje pause 2000 ' goto sc1 return '----------------------------------------------------------------- 'prekoracenje temperature salji sms s3 pozorenja i pogresan korisnik s4 '----------------------------------------------------------------- s3: LCDOUT $FE,1, "Salji temp!" HSerout ["AT",13,10] Pause 1000 HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode Pause 1000 HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10] pause 500 HSerout ["Temp:",dec (temp/100),10,13] s31: HSerout [26] hserin 6000,s31,[WAIT("OK")] return s4: LCDOUT $FE,1,"nemate prava!" HSerout ["AT",13,10] Pause 1000 HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode Pause 1000 HSerout ["AT+CMGS=",34,str telbr\12,34,",129",13,10] pause 500 HSerout ["nemate prava",str time\6,13,10] s12: HSerout [26] hserin 6000,s12,[WAIT("OK")] goto mm End
Do you have any problem with this program, or ist an example?
I have say to that is long enough! I have a little difficulty followng the s1, s12 named subs. Better use names to understand after a month what this sub do.
Ioannis
After a lot of experimenting with the SMS subject, I noticed all by chance, that when my provider sent an SMS for advertisment purposes, the program could not handle it properly because in Hserin line to get the SMS, a 10 digit number was expected and not the 4 digit one.
Keep in mind that the "defaults" may not always be default enough!
Here is my test subroutine:
At the 3rd command line where HSerin 5000,ex_sms4,[wait... is executed, the command waits for +30 which is the country code for Greece, then I get 10 digits for the phone that is sending the SMS.Code:read_sms: Lcdout com,line1,"Reading SMS" HSerout ["AT+CMGL=",34,"ALL",34,13] '"ALL" is for Wavecom module. Read all SMS ' Read Caller ID etc. The timeout value in the HSERIN statement is important. ' it takes some time before the phone replies to the AT+CMGL command HSerin 5000,ex_sms4,[wait("READ"),wait("+30"),str cc_phone\10,wait(44,44,34),SKIP 23,STR array\15\13] 'Number is waitstr command\10 LCDOut com,1,"Read 1 SMS" pause 1000 sms_delete: LCDOut com,1,"Deleting SMS" HSerout ["AT+CMGD=1,4",13] 'Delete all messages HSerin 19000,ex_sms2,[wait("OK")] 'Wait for OK (null) LCDOut com,line1,"Deleted SMS " Pause 1000 return ex_sms2: 'No new message or timeout error LCDOut com,line2,"Error",rep " "\11:Pause 1000 return ex_sms4: 'Wrong Number! LCDOut com,line2,"Error phone Nbr":Pause 1000 goto sms_delete
But if the sender has only 4 digits I now through the timeout, jump to ex_sms4 and after an LCD message, the new and irrelevant SMS is deleted.
Hope this helps all that deal with SMS stuff.
Ioannis
Bookmarks