After googling i found code that send and recieve sms by Using the PIC16F877 and Siemens S25 GSM-phone can any one modify it to use with Nokia 6210 the code:
DEVICE WDT_OFF & PWRT_OFF & PROTECT_OFF
' ***** Define Oscillator speed in MHz, default is 4 MHz xtal.
Define OSC 8 '3 (3.58) 4 8 10 12 16 20 24 25 32 33 40
' ***** Define LOADER_USED to allow use of the boot loader
'Define LOADER_USED 1 'this will not affect normal program operation.
' ***** Define LCD registers and bits
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' ***** Define ADCIN parameters
Define adc_bits 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50
' ****create the variables
advalue var Word 'mesured value for Voltmeter input
rs232t var PortA.5 'TXD to GSM-phone
rs232r var PortA.4 'RXD from GSM-phone
Sensor_1 var PortC.0 'Sensor-1
Sensor_2 var PortC.1 'Sensor-2
Sensor_3 var PortC.2 'Sensor-3
Config_Sw var PortC.3 'Config switch
Output_1 var PortB.0 'Output-1
Output_2 var PortB.1 'Output-2
Output_3 var PortB.2 'Output-3
Output_4 var PortB.3 'Output-4
Msg_nr_Sent var bit[4]
Msg_nr var byte
SDin var word
Timer1 var bit
Msec_Timer1 var word
Sec_Timer1 var byte
Min_Timer1 var byte
Cnt var byte
Cnt2 var word
' ****create the constants
Baud con 32 '19200,8,N,1 (true, driven) (SIEMENS S25)
cm con 44 'comma (,)
qt con 34 'quote (")
Timer1_Time con 60 '60 min.
'****** set port direction to inputs/outputs
ADCON1 = %10000100 'make PORTA.0,1,3 analog, PORTA.2,4,5 digital, and right justify result
TRISA = %011111 'make PORTA.5 pin output PORTA.1,2,3,4 pins input
TRISB = %11110000 'make PORTB.0,1,2,3 pins output, PORTB.4,5,6,7 pin input
TRISC = %11111111 'make PORTC all input
TRISD = %00001111 'make PORTD.4,5,6,7 pins outputs, PORTD.0,1,2,3 pin input
TRISE = %100 'make PORTE.0,1 pins output, PORTE.2 pin input
'****** initialize
PORTA = 0 : PORTA.5 = 1 'turn off PORTA pins, and SEROUT2 bug fix
PORTB = $ff 'turn off PORTB pins,
PORTC = 0 'turn off PORTC pins,
PORTD = 0 'turn off PORTD pins,
PORTE = 0 'turn off PORTE pins,
Msg_nr_Sent[1] = 0
Msg_nr_Sent[2] = 0
Msg_nr_Sent[3] = 0
PAUSE 500 'wait for LCD init.
'gosub Reset_Timer1
Cnt2 = 0
Main:
pause 1
'gosub Update_Timer1
Cnt2 = Cnt2 + 1
Select case Cnt2
case 1
LCDOut $fe,1,"-<< PIC-SMS >>-",$fe,$c0,"(C)F-San"
case 3000
gosub Check_SIM
LCDOut $fe,1,"CHECKING: SMS &",$fe,$c0,"..SENSOR inputs"
gosub Chk_Incoming_SMS
case 6000
gosub Disp_BATT_Voltage
case 9000
Cnt2 = 0
end select
gosub Chk_Sensors
goto Main
Chk_Sensors:
Msg_nr = 0
if (Sensor_1 = 0) and (Msg_nr_Sent[1] = 0) then Msg_nr = 1 'is this message sent prev.?
if (Sensor_2 = 0) and (Msg_nr_Sent[2] = 0) then Msg_nr = 2
if (Sensor_3 = 0) and (Msg_nr_Sent[3] = 0) then Msg_nr = 3
if Config_Sw = 0 then Write_Config
if Msg_nr > 0 then
gosub Check_SIM
gosub Send_SMS
endif
return
Check_SIM:
SerOut2 rs232t,Baud,["AT+CMGF=0",13]
SerIn2 rs232r,Baud,500,SIM_Error,[wait("OK")]
Return
SIM_Error:
LCDOut $fe,1,"NO RESPONS!",$fe,$c0,"CHECK SIM/PHONE"
Pause 3000
Goto Main
Update_Timer1:
Msec_Timer1 = Msec_Timer1 + 1 'count msec.
if Msec_Timer1 >= 1000 then
'one second elapsed
Msec_Timer1 = 0
Sec_Timer1 = Sec_Timer1 + 1 'count sec.
if Sec_Timer1 >= 60 then
'one minute elapsed
Sec_Timer1 = 0
Min_Timer1 = Min_Timer1 + 1 'count min.
if Min_Timer1 >= Timer1_Time then
Min_Timer1 = 0
Timer1 = 1
endif
endif
endif
return
Reset_Timer1:
Timer1 = 0
Msec_Timer1 = 0
Sec_Timer1 = 0
Min_Timer1 = 0
return
Disp_BATT_Voltage:
'This part measures voltage (0-5VDC) and display on LCD with 2 decimal places,
'uses the */ operator to scale the ADC result from 0-1023 to 0-500.
'The */ performs a divide by 256 automatically, allowing math which
'would normally exceed the limit of a word variable.
'
' Connect analog input to channel-0 (RA0)
ADCIN 0, AdValue ' Read channel 0 to adval (0-1023)
AdValue = (AdValue */ 500)>>2 ' equates to: (adval * 500)/1024
'Voltage divider
'+12Vo---|33K|---o---|5K-Pot|---oGND
AdValue = AdValue' * 10
'$fe, 1 = Clear LCD, $fe, $c0 = Move to line 2
LCDOut $fe, 1, "BATT.Voltage:", $fe, $c0, "DC Volts= ", DEC (AdValue/100), ".", DEC2 AdValue 'Display the decimal value
return
Send_SMS:
LCDOut $fe,1,"SENDING SMS..",$fe,$c0,"SENSOR-",dec Msg_nr," ACTIV."
SerOut2 rs232t,Baud,["AT+CMSS=",dec Msg_nr,13]
SerIn2 rs232r,Baud,10000,No_Resp,[wait("OK")]
LCDOut $fe,$c0,"MESSAGE SENT OK."
pause 3000
Msg_nr_Sent[Msg_nr] = 1 'Don't Send this Message again.
return
Write_Config:
LCDOut $fe,1,"INS. MASTER SIM",$fe,$c0,"then Press Conf."
gosub Config_Loop
gosub Check_SIM
gosub Clear_SMS_Memories
gosub Save_Master_SMS
gosub Write_Phone_Book
LCDOut $fe,1,"INS. SLAVE SIM",$fe,$c0,"then Press Conf."
gosub Config_Loop
gosub Check_SIM
gosub Clear_SMS_Memories
gosub Save_Slave_SMS
GOTO LCD_Cls
Config_Loop:
if Config_Sw = 0 then Config_Loop
cnt2 = 0
while (Cnt2 < 9000) and (Config_Sw = 1)'wait 1.5 min.
pause 10
cnt2 = cnt2 + 1
wend
if Cnt2 = 9000 then LCD_Cls
Return
Clear_SMS_Memories:
LCDOut $fe,1,"CLEAR SMS MEMORY"
Cnt = 0
while Cnt < 5 'Erase SMS mem. locations (1..5)
SerOut2 rs232t,Baud,["AT+CMGD=",dec (Cnt+1),13]
SerIn2 rs232r,Baud,1000,No_Resp,[wait("OK")]
LCDOut $fe,$c0,"MEM: ",dec (Cnt+1),"/5"
Pause 500
Cnt = Cnt + 1
wend
Return
Save_Master_SMS:
LCDOut $fe,1,"WRITING SMS MSG."
Cnt = 0
while Cnt < 2
SerOut2 rs232t,Baud,["AT+CMGW=26",13] 'PDU length
SerIn2 rs232r,Baud,500,No_Resp,[wait(">")]
'Project/SLAVE GSM-phone number, int.format: "7421436587" = "+47 12345678", (+47 is norwegian + 8 numbers)
SerOut2 rs232t,Baud,["0011FF0A91","7421436587","0000A7","0E","D4BADC"]
if Cnt = 00 then SerOut2 rs232t,Baud,["FD341"] 'TurnOFF(1-4,A)
if Cnt = 01 then SerOut2 rs232t,Baud,["DD7A3"] 'Turn-ON(1-4,A)
SerOut2 rs232t,Baud,["A51B1168D154C01",26,13]
SerIn2 rs232r,Baud,1000,No_Resp,[wait("OK")]
LCDOut $fe,$c0,"MASTER-MSG: ",dec (Cnt+1),"/2"
Pause 500
Cnt = Cnt + 1
wend
return
Write_Phone_Book:
LCDOut $fe,1,"WRITING PH. BOOK",$fe,$c0,"-< PIC-SMS >-"
pause 2000 'Project/SLAVE GSM-phone number, int.format, (+47 is norwegian + 8 numbers)
SerOut2 rs232t,Baud,["AT+CPBW=1",cm,qt,"+4712345678",qt,cm,"145",cm,qt,"-< PIC-SMS >-",qt,13]
SerIn2 rs232r,Baud,1000,No_Resp,[wait("OK")]
return
Save_Slave_SMS:
LCDOut $fe,1,"WRITING SMS MSG."
Cnt = 0
while Cnt < 3
SerOut2 rs232t,Baud,["AT+CMGW=57",13] 'PDU length
SerIn2 rs232r,Baud,500,No_Resp,[wait(">")]
'MASTER GSM-phone number, int.format: "7478563412" = "+47 87654321", (+47 is norwegian + 8 numbers)
SerOut2 rs232t,Baud,["0011FF0A91","7478563412","0000FF","32","416650DA0C81A665F7FC2D6F"]'ALARM!
if Cnt = 00 then SerOut2 rs232t,Baud,["C5"]'Sensor-1 activated.
if Cnt = 01 then SerOut2 rs232t,Baud,["C9"]'Sensor-2 activated.
if Cnt = 02 then SerOut2 rs232t,Baud,["CD"]'Sensor-3 activated. -<< Sent by PIC-SMS >>-
SerOut2 rs232t,Baud,["40E1313D6D0FD3CB6417A8C5E381A665371D24CE83A0C9616BDA9C827CBE16",26,13]
SerIn2 rs232r,Baud,2000,No_Resp,[wait("OK")]
LCDOut $fe,$c0,"SLAVE-MSG: ",dec(Cnt+1),"/3"
Pause 500
Cnt = Cnt + 1
wend
return
No_Resp:
LCDOut $fe,$c0,"-<< No response!"
LCD_Cls:
Pause 1000
LCDOut $fe,1
GoTo Main
Send_AT_CMGR:
SerOut2 rs232t,Baud,["AT+CMGR=4",13] 'Request first SMS
return
Chk_Incoming_SMS:
gosub Send_AT_CMGR
SerIn2 rs232r,Baud,500,Incoming_MSG,[wait(",,0")]
return '(Siemens S25, "+CMGR: 0,,0" mem.location empty)
Incoming_MSG:
LCDOut $fe,1,"INCOMING SMS.."
SDin = 0
Chk_Phone_nr:
pause 1000
gosub Send_AT_CMGR
SerIn2 rs232r,Baud,1000,Wrong_NR,[wait("7478563412")] 'Wait for the correct number, Master GSM.phone nr.
Chk_TurnON:
pause 1000
gosub Send_AT_CMGR
SerIn2 rs232r,Baud,1000,Chk_TurnOFF,[wait("D4BADCDD7A3A51B1168D154C"),hex4 SDin] 'Wait for "Turn-ON(1-4,A),n"
goto Outputs_ON
Chk_TurnOFF:
pause 1000
gosub Send_AT_CMGR
SerIn2 rs232r,Baud,1000,Wrong_ID,[wait("D4BADCFD341A51B1168D154C"),hex4 SDin] 'Wait for "TurnOFF(1-4,A),n"
goto Outputs_OFF
Outputs_ON:
select case SDin
case 50432 '1
Output_1 = 0
LCDOut $fe,$c0,"Output-1: ON"
GoTo Command_OK
case 51456 '2
Output_2 = 0
LCDOut $fe,$c0,"Output-2: ON"
GoTo Command_OK
case 52480 '3
Output_3 = 0
LCDOut $fe,$c0,"Output-3: ON"
GoTo Command_OK
case 53504 '4
Output_4 = 0
LCDOut $fe,$c0,"Output-4: ON"
GoTo Command_OK
case 34049,1281 'a,A
Output_1 = 0 : pause 1
Output_2 = 0 : pause 1
Output_3 = 0 : pause 1
Output_4 = 0 : pause 1
LCDOut $fe,$c0,"All Outputs: ON"
GoTo Command_OK
case else
goto Wrong_ONcmd
end select
Outputs_OFF:
select case SDin
case 50432 '1
Output_1 = 1
LCDOut $fe,$c0,"Output-1: OFF"
GoTo Command_OK
case 51456 '2
Output_2 = 1
LCDOut $fe,$c0,"Output-2: OFF"
GoTo Command_OK
case 52480 '3
Output_3 = 1
LCDOut $fe,$c0,"Output-3: OFF"
GoTo Command_OK
case 53504 '4
Output_4 = 1
LCDOut $fe,$c0,"Output-4: OFF"
GoTo Command_OK
case 34049,1281 'a,A
Output_1 = 1 : pause 1
Output_2 = 1 : pause 1
Output_3 = 1 : pause 1
Output_4 = 1 : pause 1
LCDOut $fe,$c0,"All Outputs: OFF"
GoTo Command_OK
case else
goto Wrong_OFFcmd
end select
Command_OK:
Pause 1000
goto Delete_SMS
Wrong_NR:
LCDOut $fe,$c0,"Wrong Phone-NR."
goto Delete_SMS
Wrong_ID:
LCDOut $fe,$c0,"Wrong ID."
goto Delete_SMS
Wrong_ONcmd:
LCDOut $fe,$c0,"Wrong ON Cmd."
goto Delete_SMS
Wrong_OFFcmd:
LCDOut $fe,$c0,"Wrong OFF Cmd."
Delete_SMS:
Pause 1000
LCDOut $fe,$c0,"Deleting SMS MSG"
Pause 1000
SerOut2 rs232t,Baud,["AT+CMGD=4",13]
SerIn2 rs232r,Baud,1000,No_Resp,[wait("OK")]
LCDOut $fe,$c0,"MSG. Deleted "
return
end
Posted on: January 22, 2008, 01:58:25 13:58 - Automerged
any help please!!!!I want do thise project using nokia 6210