First I wrote a couple of codes to test the AT commands with SEROUT2 and Tx Command between my PC and the PIC16F77A (CPU) on the easypic4 using hyperterminal.
These are the codes:
INCLUDE "modedefs.bas"
'PIC16F877A specific
@ __CONFIG _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
'This is a simple program to drive a servo using easypic4 and pushbuttons.
'PORTB.0 - Set to drive the servo clockwise to the center.
'PORTB.1 - Set to drive the servo clockwise to the end.
'PORTB.3 - Set to drive the servo counter-clockwise to the end.
'Connections:
'PIC-PIN : Servo
'PortC.1 : Control wire
'Vcc(5V) : Power Wire(Red wire)
'Gnd(0V) : Black wire
'************************************************* *********************
'Defines
Define LOADER_USED 1 'Use tiny boot loader
DEFINE USE_LFSR 1
DEFINE OSC 20
' LCD Defines
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTD ' LCD register select port
DEFINE LCD_RSBIT 2 ' LCD register select bit
DEFINE LCD_EREG PORTD ' LCD enable port
DEFINE LCD_EBIT 3 ' LCD enable bit
DEFINE LCD_RWREG PORTD ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_BITS 4 ' LCD bus size 4 or 8
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
'Set tris & system registers
TRISA=%00000000 ' Set Port A pins as Output
TRISB=%11111111 ' Set Port B pins as Input
TRISC=%00000000 ' Set Port C pins as Output
TRISD=%00000000 ' Set Port D pins as Output
TRISE=%00000000 ' Set Port E pins as output
'Program variables
position var byte
'Input/output port assignments
PB_UP VAR PORTB.3 'Push button to move servo up
PB_center VAR PORTB.0 'Push button to move servo to center
PB_down VAR PORTB.1 'Push button to move servo down
Tx var PORTC.6 ' Tx Rs232 to Terminal
Rx var PORTC.7 ' Rx Rs232 from Terminal
'Main program
PORTC.1 = 0
InitModem:
pause 1000
lcdout $Fe,01,"Init Modem"
gosub init
pause 1000
lcdout $Fe,01,"Modem Init Done"
pause 1000
lcdout $FE, 01, "Ready to start"
'Read input
Read_input:
if PORTB.0 = 1 then
position = 0
endif
if PORTB.1 = 1 then
position = 1
endif
if PORTB.3 = 1 then
position = 2
endif
if position = 0 then
pulsout PORTC.1, 750
endif
if position =1 then
pulsout PORTC.1, 300
endif
if position =2 then
pulsout PORTC.1, 1150
endif
pause 50
goto Read_input
'SMS subroutines
Init:
' Subroutine to initialise the GSM modem
Serout2 Tx,84,["AT+CLIP=1",13] ' CLIP command
Pause 500
Serout2 Tx,84,["AT+CNMI=3,0",13] ' SMS now not polled
Pause 500
Serout2 Tx,84,["AT+CMGF=1",13] ' Set Text Mode
Pause 500
SERout2 Tx,84,["AT+CMGS=",34,"+6598755989", 34,13]
'Preferred Message Storage: ME on Phone
Serout2 Tx,84,["AT+CPMS=",34,"ME",34,13] ' Changed for GR47
Pause 4000
'Set the storage to SIM
Serout2 Tx,84,["AT+CPBS=",34,"SM",34,13]' Otherwise cannot read memory location
Pause 1000
'SERIN2 Tx,84,5000,Problem,[Wait ("OK")] ' Loopback to NotReady
'Select Character Set “UTF-8” : Universal text format, 8 bits
PAUSE 1000
Serout2 Tx,84,["AT+CSCS=",34,"UTF-8",34,13] ' for @ sign problem
pause 1000
Serout2 Tx,84,["AT&W",13] 'Store User Profile to non volatile memory
pause 1000
Serout2 Tx,84,["AT+CMGD=1,4",13]
pause 3000
Return
Next I need to change the above codes to SERIN and Rx and "additional codes" so that my GSM modem can receive an sms from a handphone in order to trigger the servo motor.
This is where my problem comes in. Any help would be appreciated. Thanks.




Bookmarks