Hello everyone,
I'm trying to build an application that will simply trigger relays using sms on GSM module.
What I have done so far (basically)..
1. Get GSM signal and manufacturer
2. Send sms
Now I'm trying to read incoming messages but with interrupt (with DT's). but it seems that when I send a message to the GSM the following block of code does not function
The following code is what I'm testing...I strip out the other codes within the main loop just to simply...
I think the GetBytes sub program triggers on boot up because it displays Hserout ["Went here",13]...after that when it enters to the main loop and try to send sms to the device it never get the interrupt.
Can anyone spot what I'm missing? I've been going nuts with it the whole week :frown:
Regards,
tacbanon
I'm trying to build an application that will simply trigger relays using sms on GSM module.
What I have done so far (basically)..
1. Get GSM signal and manufacturer
2. Send sms
Now I'm trying to read incoming messages but with interrupt (with DT's). but it seems that when I send a message to the GSM the following block of code does not function
Code:
Getbytes:
HSEROUT ["Went here!!",13]
i=i+1 ' coubt how many time it pass here
cntr = 0
While RCIF = 1 ' clear the buffer
HSERIN 50,error,[Wait("P")] ' test it
Hserout ["Got it!!",13]
Wend
@INT_return
Code:
'****************************************************************
'* Name : HACS.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 10/20/2012 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
;__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
; create the transmition interrupt
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _Getbytes, PBP, no
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
;
;------------------------------------------------------------------------
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
define OSC 48
TRISA = %00001111
PortA = %00000000
TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output
ADCON1 = %00001111
TRISD = %00000111
PortD = %00000000
PORTD = %00000000 ; set to PORTD low
LedA var PortD.0 ;assign var LedA to PortD.0
LedB var PortD.1 ;assign var LedB to PortD.1
LedC var PortD.2 ;assign var LedC to PortD.2
Load1 var PortD.3
Load2 var PortD.4
Load3 var PortD.5
'CONFIGURE DISPLAY
pause 100
ln1 con $80
ln2 con $C0
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 1
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
; setup serial port line for transmition
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
'------------------------------------------------------Transmition-------------
But0 var PortA.0
But1 var PortA.1
But2 var PortA.2
But3 var PortA.3
Led1 var PortC.0
Led2 var PortC.1
Led3 var PortC.2
Led1 = 0
Led2 = 0
Led3 = 0
flag1 var bit
flag1 = 0
flag2 var bit
flag2 = 0
flag3 var bit
flag3 = 0
Pswd var byte[5]
Data @0, 5,"12345"
ArrayNum var byte[12]
'------------------------------------------------------------------------------
cntr var byte 'count error occur
cntr = 0
i var byte
i = 0
PortB = %00000000
SerialData var byte[10]
LCDOUT $Fe,1
'--------------------------------------------------------------
pause 1000
LCDOUT $Fe,ln2 , "System loading.."
pause 5000
Gosub ButtOption1
;----Initialize text mode--------
HSEROUT ["AT+CMGF=",49,13,10]
HSERIN 5000, GSM_CHECK_ERR, [WAIT("OK")]
LCDOUT $Fe,1 , "HASMS-CMS"
pause 1000
LCDOUT $Fe,192, "Init Text MODE"
pause 1000
LCDOUT $Fe,ln2, " " ' clear second line
Lcdout $FE, ln2,"system ready..."
cntr = 0
PAUSE 2000
LCDOUT $Fe,ln2, " " ' clear second line
@ INT_ENABLE RX_INT ; enable RX_INT interrupts
'--------------Main program start here--------------
Main
LCDOUT $Fe, ln1, "HASMS-CMS", Dec3 i
LCDOUT $Fe,ln2 , "Listening...", DEC3 cntr
if cntr < 254 then
cntr = cntr + 1
else
cntr = 0
Endif
pause 2000
GOTO Main
'--------------Main program end here--------------
GSM_CHECK_ERR:
cntr = cntr + 1
LCDOUT $Fe, ln1, "HASMS-CMS"
pause 1000
LCDOUT $Fe, ln2, "GSM Error #", DEC3 cntr
pause 1000
return
Getbytes:
HSEROUT ["Went here",13]
i=i+1 ' count how many time it pass here
cntr = 0
While RCIF = 1 ' clear the buffer
HSERIN 50,error,[Wait("P")] 'test it
Hserout ["Got it!!",13]
Wend
@INT_return
error:
Hserout ["Error",13]
goto Main
ButtOption1:
LCDOUT $Fe,1 , "GSM Info"
LCDOUT $Fe, ln2, "processing... "
pause 1200
High PortD.4
pause 1200
Low PortD.4
'------------------- Determine Signal
HSEROUT ["AT+CSQ",13,10]
HSERIN 1000, GSM_CHECK_ERR, [WAIT("+CSQ: "),STR Serialdata\4]
LCDOUT $Fe,1 , "GSM Info"
LCDOUT $Fe,ln2, "SIGNAL:",STR Serialdata\4
cntr = 0
'------------------- Determine Manufacturer
PAUSE 3000
HSEROUT ["AT+CGMI",13,10] 'Ask model name
HSERIN 5000, GSM_CHECK_ERR, [WAIT("SIMCOM"),STR Serialdata\4]
LCDOUT $Fe,1 , "GSM Info"
LCDOUT $Fe,ln2, "MANUF:SIMCOM",STR Serialdata\4
cntr = 0
pause 3000
LCDOUT $Fe,1 ' Clear LCD
return
END
Can anyone spot what I'm missing? I've been going nuts with it the whole week :frown:
Regards,
tacbanon