programa sms

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

programa sms

Mensagempor jguazeli » 07 Jan 2007 16:15

De uma olhada neste programa ele monitor 2 sensores e envia uma msg. sms "INVASAO SETORX" e liga/desliga dois Reles com a msg. sms "L1" , "D1" e desliga o Rele da sirene com a msg. sms "S0"

O celular que usei foi os da siemens A60 e C55




@ DEVICE WDT_OFF&PWRT_ON&MCLR_OFF&BOD_OFF&LVP_OFF
DEFINE OSC 20
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
'************************ Define pinos de I/O *********************************
TX VAR PORTB.2
RX VAR PORTB.1
Sensor_1 VAR PORTA.3
Sensor_2 VAR PORTA.4
SAIDA_1 VAR PORTA.1
SAIDA_2 VAR PORTA.0
SIRENE VAR PORTA.2
'************************ variaveis da memoria Ram *****************************
CONT_S1 VAR BIT
SMS VAR BYTE[8]
F_S VAR BYTE[12]
BF VAR BYTE[54]
'**************************** Constantes ***************************************
Baud CON 32 '188=4800,8,N,1 | 84=9600,8,N,1 | 32=19200,8,N,1
ASPAS CON 34
'**************************** Configuarcao do pinos I/O ************************
CMCON = 7
TRISA = %11000
PORTA = 0
'********************* tela de apresentação ************************************
LCDOut $fe,1,"<<<Alarme GSM>>>",$fe,$c0,"de: Jesus Aguiar"
Pause 3000
'***************************** inicialiaza o celular ***************************
INICIO:
sirene=1
pause 500
sirene=0
pause 500
sirene=1
pause 500
sirene=0
pause 500
LCDOut $fe,1,"Alarme Desligado"
'***************************** rotina principal *******************************
loop:
if sensor_2 = 0 then goto main
goto loop

MAIN:
'LCDOut $fe,1,"Monito. sensores",$fe,$c0,"& mensagens SMS."
SerOut2 TX,Baud,["AT+CNMI=1,1,0,0,1",13]
SerIn2 RX,Baud,1500,CEL_ERRO,[wait("OK")]
SerOut2 TX,Baud,["AT+CPBR=1",13]
SerIn2 RX,Baud,1500,CEL_ERRO,[wait("+CPBR: 1,",ASPAS),STR F_S\12]

CONT_S1=1
Pause 2000
sirene=1
pause 500
sirene=0
pause 500
ligado:
LCDOut $fe,1,"Alarme Ligado.",$fe,$c0,"Fone",STR F_S\12
MONITOR:
IF (Sensor_1 = 1)AND (CONT_S1=1) Then
SIRENE=1
CONT_S1=0
GoSub ENVIA_SMS
EndIF
IF (Sensor_2 = 0) Then goto inicio
GoSub AGUARDA_SMS
GoTo MONITOR

'******************** mensagem de erro da inicializacao do celular *************
CEL_ERRO:
LCDOut $fe,1,"CMD sem resposta",$fe,$c0,"Verif. o Celular"
GoTo INICIO
'******************************** fim ******************************************

'********************** Envia mensagem SMS *************************************
ENVIA_SMS:
LCDOut $fe,1,"Enviando SMS...."
SerOut2 TX,Baud,["AT+CMGS=29",13]
SerIn2 RX,Baud,500,NAO_RESP,[wait(">")]
' SerOut2 TX,Baud,["0011000C91",STR F_S\12,"0000AA1149A735380D3E41C422685AA43EA5",HEX SENSOR,26]
SEROUT2 TX,BAUD, ["0011000C91",STR F_S\12,"0000AA114F50901994368B2062720A0D4A9F55",26]
SerIn2 RX,Baud,5000,NAO_RESP,[wait("OK")]
LCDOut $fe,$c0,"Mensagem env. OK"
Pause 5000
GoTo ligado
Return

ENVIA_SMS_OK:
LCDOut $fe,1,"Enviando SMS...."
PAUSE 5000
SerOut2 TX,Baud,["AT+CMGS=23",13]
SerIn2 RX,Baud,500,DELETA,[wait(">")]
SerOut2 TX,Baud,["0011000C91",STR F_S\12,"0000AA0AC36733E8243E41CF25",26]
SerIn2 RX,Baud,5000,DELETA,[wait("OK")]
LCDOut $fe,$c0,"Mensagem env. OK"
Pause 5000
RETURN

NAO_RESP:
LCDOut $fe,$c0,"CMD sem resposta"
Pause 5000
GoTo MAIN
'*******************************************fim*********************************

'****************** Apaga mensagem SMS recebida. *******************************
DELETA:
SerOut2 TX,Baud,["AT+CMGD=",STR SMS[6],13]
SerIn2 RX,Baud,2000,NAO_RESP,[wait("OK")]
LCDOut $fe,1,"SMS ",SMS[6]," Deletada."
Pause 5000
GOTO ligado
Return
'************************************ fim **************************************

'***************** Recebe e trata Mensagem SMS recebida ************************
AGUARDA_SMS:
SerIn2 RX,Baud,500,MONITOR,[wait("+CMTI:"),STR SMS\8]
pause 1000
if (sms[2]="M") then serout2 tx,baud,["AT+CPMS=",ASPAS,"ME",ASPAS,13]
PAUSE 2000
SerOut2 TX,Baud,["AT+CMGR=",STR SMS[6],13]
SerIn2 RX,Baud,2500,MONITOR,[wait("0791"),STR BF\54]
IF (BF[48]="0") AND (BF[49]="2") AND (BF[50]="C") AND (BF[51]="C") AND (BF[52]="1") AND (BF[53]="8") Then
SAIDA_1=1
GoSub ENVIA_SMS_OK
GoSub DELETA
EndIF
IF (BF[48]="0") AND (BF[49]="2") AND (BF[50]="C") AND (BF[51]="4") AND (BF[52]="1") AND (BF[53]="8") Then
SAIDA_1=0
GoSub ENVIA_SMS_OK
GoSub DELETA
EndIF
IF (BF[48]="0") AND (BF[49]="2") AND (BF[50]="4") AND (BF[51]="C") AND (BF[52]="1") AND (BF[53]="9") Then
SAIDA_2=1
GoSub ENVIA_SMS_OK
GoSub DELETA
EndIF
IF (BF[48]="0") AND (BF[49]="2") AND (BF[50]="4") AND (BF[51]="4") AND (BF[52]="1") AND (BF[53]="9") Then
SAIDA_2=0
GoSub ENVIA_SMS_OK
GoSub DELETA
EndIF
IF (BF[48]="0") AND (BF[49]="2") AND (BF[50]="5") AND (BF[51]="3") AND (BF[52]="1") AND (BF[53]="8") Then
SIRENE=0
GoSub ENVIA_SMS_OK
GoSub DELETA
EndIF
Return
'************************************** fim ***********************************
End
gauzeli
jguazeli
Bit
 
Mensagens: 6
Registrado em: 12 Nov 2006 09:59
Localização: Alegrete

Mensagempor David Henrique » 14 Ago 2008 17:49

Existe algum treinamento dessa linguagem? Estou começando com o GSM e não sei nada. Preciso enviar um email com os valores de uma variável interna... como eu faço?
David Henrique
Nibble
 
Mensagens: 68
Registrado em: 17 Jun 2008 08:05


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

cron

x