here is my code as my board could not read serin and serout, i have no choice but to use other alternative like hserout.


'************************************************* ******************************
' Hardware Defines *
'************************************************* ******************************
'PIC16F876A specific
;__config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF


DEFINE LOADER_USED 1
DEFINE OSC 20

DEFINE HSER_BAUD 9600
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 129
DEFINE HSER_CLROERR 1

'************************************************* ******************************
' Define program variables *
'************************************************* ******************************
NumLen var byte ' Tel Number length
PhoneNo var byte[16]' Phone Number string
SPhoneNo var byte[16]' Phone number in SMS
Index var byte ' Index of the SMS
Cmd var byte[7] ' The command
X var byte ' Temp Var
MsgType var byte
position var byte



'************************************************* ******************************
' Inputs / Outputs & Port Assignments *
'************************************************* ******************************
Tx var PORTB.6 ' Tx Rs232 to Terminal
Rx var PORTB.7 ' Rx Rs232 from Terminal

'************************************************* ******************************
' Set TRIS and system REGISTERS *
'************************************************* ******************************

TRISB=%11111111 ' Port B input
TRISC=%00000000 ' Port C output


'Message to be send: LOCK and UNLOCK

InitModem:
pause 1000
gosub init

pause 1000

Begin:
MsgType = 0

LOOP:
PORTC.7 = 0
GOSUB ChkSMS
GoSUB Read_input

PAUSE 10000
IF MsgType=0 then
GOTO LOOP
endif
END

'************************************************* ******************************
' Subroutines *
'************************************************* ******************************

'************************************************* ******************************
' SMS Subroutines
'************************************************* ******************************
Init:
' Subroutine to initialise the module

HSerout2 [Tx,84,"AT",13] ' CLIP command
SERIN2 Rx,84,5000, Problem,[Wait ("OK",13)] ' Loopback to NotReady
HSerout2 [Tx,84,"AT+CLIP=1",13] ' CLIP command
Pause 500
HSerout2 [Tx,84,"AT+CNMI=3,0",13] ' SMS now not polled
Pause 500
HSerout2 [Tx,84,"AT+CMGF=1",13] ' Set Text Mode
Pause 500
'Preferred Message Storage: ME on Phone
HSerout2 [Tx,84,"AT+CPMS=",34,"ME",34,13] ' Changed for GR47
Pause 4000
'Set the storage to SIM
HSerout2 [Tx,84,"AT+CPBS=",34,"SM",34,13] ' Otherwise cannot read memory loc1
SERIN2 Rx,84,5000, Problem,[Wait ("OK",13)] ' Loopback to NotReady
'Select Character Set “UTF-8” : Universal text format, 8 bits
HSerout2 [Tx,84,"AT+CSCS=",34,"UTF-8",34,13] ' for @ sign problem
pause 1000
HSerout2 [Tx,84,"AT&W",13] 'Store User Profile to non volatile memory
pause 1000
'HSerout2 Tx,84,"AT+CMGD=1,4",13
'pause 1000

Return


ChkSMS:
HSEROUT2 [Tx,84,"AT+CMGL=",34,"ALL",34,13]
SERIN2 Rx,84,2500,OutSMS,[Wait("MG")]
gosub rdsms

OutSMS: 'no sms received
return

RdSMS:
' at+cmgl="ALL"
' +CMGL: 1,"REC UNREAD","+60123288328","PEC 9720 A","03/05/09,12:10:59+32",145,5
' Test1
' +CMGL: 2,"REC UNREAD","+60123288328","PEC 9720 A","03/05/09,12:13:27+32",145,5
' Test2
'
' OK

SERIN2 Rx,84,1500,KL_SMS,[Wait(":"),Skip 1,DEC Index]
SERIN2 Rx,84,1500,KL_SMS,[Wait(34),Wait(","),Skip 2,STR PhoneNo\12,Wait(10),STR Cmd\4]
SERIN2 Rx,84,4000,WAITOK,[Wait("OK")]

gosub chknumlen ' check number length again

pause 10000
Gosub SendMsg

KL_SMS:
' If I got an SMS I have to Kill it now

IF Index=0 Then return
pause 5000
HSerout2 [Tx,84,"AT+CMGD=",DEC Index,13]
index=0
pause 1000
RETURN

'************************************************* ******************************
ChkNumLen:
' Here I check the Length of Phone Number String
' Now determine the PhoneNo string length by looking for the inv commas

For x=1 to 15
IF PhoneNo[x]=34 Then
NumLen=x
return
Endif
Next x
NumLen=16 ' cant Find so must be 16
if PhoneNo[0]=34 then Numlen=0 ' we look for ""
return

'************************************************* ******************************
SendMsg:

GoSub ChkMsgType

Select case MsgType
case 1:
GOSUB LOCK
CASE 2:
GOSUB UNLOCK
end select
pause 10000
MsgType=0
'HSEROUT2 Tx,84,["AT+CMGS=",34,STR PhoneNo\NumLen, 34,13]
'HSERIN2 Rx,84,4000,Problem, [Wait(">")]
'Select case 1
' case 1:
' HSEROUT2 Tx,84,["Message received OK", $1a]
' CASE 2:
' HSEROUT2 Tx,84,["Message received Fail", $1a]
'end select
RETURN

'************************************************* *****************************
ChkMsgType:
IF Cmd[0]="L" && Cmd[1]="O" && Cmd[2]="C" && Cmd[3]="K" Then
MsgType = 1
RETURN
ENDIF
IF Cmd[0]="U" && Cmd[1]="N" && Cmd[2]="L" && Cmd[3]="O" && Cmd[4]="C" && Cmd[5]="K" Then
MsgType = 2
RETURN
ENDIF
MsgType=0
return

'************************************************* *****************************

LOCK:

PORTC.7 = 1
pause 5000
RETURN

UNLOCK:

PORTC.7 = 0
pause 5000
RETURN

''*************** Manual control of servo using push-buttons*******************

Read_input:

if PORTB.7 = 0 then
PORTC.6 = 0
endif

if PORTB.7 = 1 then
PORTC.6 = 1
endif

pause 50
goto Read_input

'************************************************* *****************************
BKERROR:
GOTo BKERROR
WAITOK:
GOTo WAITOK

'************************************************* ******************************
Problem:
Pause 1000
GOTO Problem