Code:
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
DEFINE OSC 48
DEFINE HSER_RCSTA 90h ' enable serial port,
DEFINE HSER_TXSTA 36 ' enable transmit, * we change 20h to 36 for 115200
DEFINE HSER_BAUD 115200
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output
' Serial communication definition
' ===============================
'
ADCON1 = %00001111 'Set up ADCON1 register no matter what you're doing!!!!!!
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
'*****************************************************************************
Serialdata var byte[25]
INTCON2.7 = 0 ' Enable PORTB pull-ups
TRISB = %11111000
TRISC = %10000000
led1 var PortC.0
TRISD = %00000000
Serout2 PORTD.5, 84, [$1B,$63,$30]
Serout2 PORTD.5, 84, [$1B,$45,"SMS DEBUG PORT"]
main:
PORTB = 0 ' PORTB lines low to read buttons
TRISB = %11111000
If PORTB.6 = 0 Then ' If 3rd button pressed...
PORTB.2 = 1 ' 3rd LED on
Serout2 PORTD.5, 84, [$1B,$45, "SMS DEBUG PORT"]
Serout2 PORTD.5, 84, [$D, "Button 3 "]
pause 500
Serout2 PORTD.5, 84, [$1B,$45,"SMS DEBUG PORT"]
GOSUB GSM_SIGCHECK
Endif
If PORTB.5 = 0 Then ' If 2nd button pressed...
PORTD.1 = 1 ' 2nd LED on
Serout2 PORTD.5, 84, [$1B,$45, "SMS DEBUG PORT"]
Serout2 PORTD.5, 84, [$D, "Button 2 "]
pause 500
Serout2 PORTD.5, 84, [$1B,$45,"SMS DEBUG PORT"]
gosub GSM_MODEL
Endif
pause 240 ' pause to avoid sending repetation
goto main
End 'End program
GSM_SIGCHECK:
HSEROUT ["AT+CSQ",13] 'Send AT to modem followed by a CR
HSERIN 4000, GSM_CHECK, [WAIT("AT+CSQ"),STR Serialdata\13] 'Check OK reply, wait 5sec max.
Serout2 PORTD.5, 84, [$D, STR Serialdata\13]
High PORTB.0 ' 1st LED on
PAUSE 1000
low PORTB.0
RETURN
GSM_CHECK_ERR:
Serout2 PORTD.5, 84, [$D, "GSM ERROR"]
Return
GSM_MODEL:
HSEROUT ["AT+CGMI",13] 'Ask model name
HSERIN 4000, GSM_MODEL, [WAIT("AT+CGMI"),STR Serialdata\13] 'Check model name "SIMCOM_Ltd"
Serout2 PORTD.5, 84, [$D, STR Serialdata\13]
High PORTB.0 ' 1st LED on
PAUSE 1000
low PORTB.0
return
After pressing each button (response displayed to the LCD) I need to press the RESET button of the LABX2 everytime.
Bookmarks