Sei sulla pagina 1di 10

Interface GSM module with PIC..

The Global System for Mobile (GSM) communication is the Second Generation of mobile technology.
Although the world is moing towards Third and !ourth generation but GSM has been the most
successful and wides"read technology in the communication sector. GSM technology "aed a new way
for mobile communication.
This "ro#ect e$"lains the interfacing of a GSM Module with a PIC microcontroller. It also coers a way to
dial a particular GSM mobile number as well as send a message to it using AT Commands with the
hel" of PIC%&!'(().
Objectives:
This "ro#ect has following ob#ecties which are fulfilled using AT Commands*
%. Test the sim"le AT Command.
+. !ind out the IM,I number of the GSM Modem.
-. Connect a call to a GSM mobile number (.ial a number).
'. Send a text message to a mobile number.

The "roision of these four o"erations has been "roided by means of four tactile switches. ,ach switch
corres"onds to each of the aboe functions. AT Commands used to "erform the aboe o"erations hae
been gien below along with their out"ut. (!or com"lete list of AT Commands su""orted by GSM Modem/
refer the list in tutorial on AT Commands.
As e$"lained earlier (refer GSM interfacing with &)(%)/ a line conerter MA0+-+ is em"loyed to conert
the 1S+-+ logic data of GSM Module to TT2 logic so that it can be "rocessed by the microcontroller. In
this "ro#ect/ instead of 1S+-+ logic data/ TT2 logic out"ut has been ta3en and thus PIC%&!'(() has
been directly connected with GSM Modem without any line conerter in between. The following diagram
shows the TT2 in"ut and out"ut of GSM modem used.

Code:-
//Program to interface GSM Modem with PIC18F4550 Microcontroller
//This code taes fo!r choices as fo!r in"!ts
//Choice 1 # Test the sim"le $T Command%
//Choice & # Find o!t the IM'I n!m(er of the GSM Modem%
//Choice ) # Connect a call to a GSM mo(ile n!m(er%
//Choice 4 # Send a te*t message to a mo(ile n!m(er%
+define F,'- 1&000000
+define (a!d ./00
+define s"(rg01al!e 222F,'-//43/(a!d3413
+define rs 5$T$%F0
+define rw 5$T$%F1
+define en 5$T$%F&
+define lcd"ort 5$T6
1oid t*0data2!nsigned char37
!nsigned char r*0data237
1oid lcd0ini237
1oid lcdcmd2!nsigned char37
1oid lcddata2!nsigned char37
1oid gsm0cmd2!nsigned char 837
1oid o!t"!t21oid37
!nsigned char 1al!e907
int i90:;::tem":flag:choice7
!nsigned char 8starting0te*t9<'nter choice9<7
!nsigned char 8dial0te*t9<=ialing%%%<7
!nsigned char 8at0cmd9<$T<7
!nsigned char 8imei0cmd9<$T>GS?<7
!nsigned char 8call0cmd9<$T=.*********7<7 // Pro1ide a 104=igit Mo(ile
?!m(er
!nsigned char 8sms0format9<$T>CMGF91<7
!nsigned char 8sms0write9<$T>CMGS9@<**********@<<7 // 104=igit Mo(ile ?!m(er
!nsigned char 8sms9<Aello<7
!nsigned char 8sms0re"ort9<SMS Sent%%%<7
!nsigned char sms0terminate90*1$7
!nsigned char enter90*0=7
!nsigned char 8data7
1oid main23
B
T,IS6907 // Set Port 6 as o!t"!t "ort
5$T6907
T,IS$907
5$T$907
T,IS=90*FF7
5$T=907
SP6,G9s"(rg01al!e7 // Fill SP6,G register to set
the (a!d rate
,CST$%SP'?917 // To acti1ate serial "ort 2T*
and ,* "ins3
TCST$%TC'?917 // $cti1ate Transmissiom
,CST$%C,'?917 // $cti1ate ,ece"tion
PI'1%,CI'917 // 'na(le ,ece"tion interr!"t
I?TCD?%GI'917 // 'na(le Glo(al interr!"t
I?TCD?%P'I'917 // 'na(le Peri"heral interr!"t
lcd0ini237
while213
B
907
lcdcmd20*8037
while2starting0te*tEFG9H@0H3
B
lcddata2starting0te*tEF37
>>7
I
//Chec in"!ts
//Choice 1
if2PD,T=%F03
B
gsm0cmd2at0cmd37
o!t"!t237
=elaJ0ms2100037
I
//Choice &
if2PD,T=%F13
B
gsm0cmd2imei0cmd37
o!t"!t237
=elaJ0ms2100037
I

//Choice )
if2PD,T=%F&3
B
gsm0cmd2call0cmd37
o!t"!t237
=elaJ0ms2100037
I
//Choice 4
if2PD,T=%F)3
B
gsm0cmd2sms0format37
o!t"!t237
=elaJ0ms2100037
gsm0cmd2sms0write37
o!t"!t237
=elaJ0ms2100037
gsm0cmd2sms37
o!t"!t237
t*0data20*1$37
=elaJ0ms2100037
I
I
I
1oid gsm0cmd2!nsigned char 8string3
B
i907;907
while2stringEiFG9H@0H3
B
tem"907
if2stringEiF990*5C3 // ?ot to send H@H cahracter
i>>7
t*0data2stringEiF37 // Send (J serial comm!nication
i>>7
while2tem"G9137
I
tem"907
t*0data2enter37 // Send $SCII code for H'nterH
eJ
while2tem"G9137
I
1oid o!t"!t21oid3 // To "rint data on 5C=
B
lcdcmd20*0137
i9417flag907
while2iK;3
B
if2flagL13
B
flag907
=elaJ0ms250037
lcdcmd20*0137
lcdcmd20*8037
I
if2dataEiF990*0$3 // This condition is to a1oid
do!(le 'nter
// d!ring e*ec!tion of a command
B
flag>>7
lcdcmd20*c037
I
if2dataEiF99HLHMMdataEiF99H<H3 // ?ot to "rint this character
B
i>>7
lcdcmd20*c037
I
if2dataEiFG90*0=NNdataEiFG90*0$NNdataEiFG90*1$3 //
Condition to "rint the data
// e*ce"t H'nterH:H?ew
lineH and HS!(mitH
B
lcddata2dataEiF37
i>>7
I
else
i>>7
=elaJ0ms2)0037
I
lcdcmd20*0137
I
1oid t*0data2!nsigned char serial0data3 // Transmit data
f!nction
B
TC,'G9serial0data7
while2PI,1%TCIF99037
I
1oid interr!"t23
B
dataE;F9,C,'G7 // Store the data into arraJ when
,ece"tion interr!"t occ!rs
1al!e9,C,'G7
;>>7
tem"917
I
1oid lcd0ini23
B
lcdcmd20*)837 // Config!re the 5C= in 84(it mode: & line and
5*O font
lcdcmd20*0C37 // =is"laJ Dn and C!rsor Dff
lcdcmd20*0137 // Clear dis"laJ screen
lcdcmd20*0/37 // Increment c!rsor
lcdcmd20*8037 // Set c!rsor "osition to 1st line: 1st col!mn
I
1oid lcdcmd2!nsigned char cmdo!t3
B
lcd"ort9cmdo!t7 //Send command to lcd"ort9PD,T6
rs907
rw907
en917
=elaJ0ms21037
en907
I
1oid lcddata2!nsigned char datao!t3
B
lcd"ort9datao!t7 //Send data to lcd"ort9PD,T6
rs917
rw907
en917
=elaJ0ms21037
en907
I
one more code
d little bit of my code.. check this code ...
Code (text):
/8Aeader88888888888888888888888888888888888888888888888888888
Microcontroller91/f8OO
Cloc910 MhP
Pro;ect Title#$ir Poll!tion Control Qsing GSM/GP,S
=e1elo"ed 6J#Sathiesh R!mar%S
=ate#)1/01/&0108/
1oid Calc!lation2!nsigned int 3 7
1oid Gsm0SMS0Init237
1oid Gsm0SMS0,ead237
1oid Gsm0SMS0Send237
// 5C= mod!le connections
s(it 5C=0,S at ,640(it7
s(it 5C=0'? at ,650(it7
s(it 5C=0=4 at ,600(it7
s(it 5C=0=5 at ,610(it7
s(it 5C=0=/ at ,6&0(it7
s(it 5C=0=O at ,6)0(it7
s(it 5C=0,S0=irection at T,IS640(it7
s(it 5C=0'?0=irection at T,IS650(it7
s(it 5C=0=40=irection at T,IS600(it7
s(it 5C=0=50=irection at T,IS610(it7
s(it 5C=0=/0=irection at T,IS6&0(it7
s(it 5C=0=O0=irection at T,IS6)0(it7
// 'nd 5C= mod!le connections
!nsigned char ch7 //
char ,ecei1e7
!nsigned int adc0rd7 // =eclare 1aria(les
char 8te*t7 //
long tlong7 //
!nsigned int i:;7
char ret!rn0gsmE&F7
char Gsm0,ecei1eE100F7
char Gsm0MsgE10F7
char !art0rdEF9<$T<7
char !art0rd1EF9<$T>CMGF91<7
char !art0rd&EF9<$T>CMG,91< 7
char !art0rd)EF9<$T>CMGS9<7
char Mo(ile0?oEF9<>.1.444O&1/)8< 7
char Send0MsgEF9<TD?<7
1oid main23
B
I?TCD? 9 07 // $ll interr!"ts disa(led
$=CD?1 9 0*8&7 // $/= 1oltage reference is SCC
T,IS$ 9 0*FF7 // $ll "ort $ "ins are config!red as
in"!ts
T,ISC90*807
=elaJ0ms2&00037 // ,est of "ins are config!red as
digital
Q$,T10Init2./0037 // InitialiPe Q$,T mod!le at ./00 ("s
=elaJ0ms210037 // Uait for Q$,T mod!le to sta(iliPe
5cd0Init237 // 5C= dis"laJ initialiPation
5cd0Cmd205C=0CQ,SD,0DFF37 // 5C= command 2c!rsor off3
5cd0Cmd205C=0C5'$,37 // 5C= command 2clear 5C=3
te*t 9 <$ir Poll!tion <7 // =efine the first message
5cd0D!t21:1:te*t37 // Urite the first message in the first
line
delaJ0ms250037
te*t 9 <Sensor Sal!e<7 // =efine the second message
5cd0D!t2&:1:te*t37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
te*t 9 <GSM<7 // =efine the third message
while 213
B
5cd0D!t21:1:te*t37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
Gsm0SMS0Init237
I
I
1oid Gsm0SMS0Init23
B
if 2Q$,T10T*0Idle23 99 13
B
5cd0D!t2&:1:<$T<37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
for2i907iK917i>>3
B
Q$,T10Urite2!art0rdEiF37 //$T
I
Q$,T10Urite20*0=37 //'nter

//delaJ0ms2500037
while213
B
5cd0D!t2&:1:<In while<37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
if 2Q$,T10=ata0,eadJ233
B // If data is recei1ed:
5cd0D!t2&:1:<In IF<37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
for2i907iK917i>>3
B
ret!rn0gsmEiF 9 Q$,T10,ead237 // read the recei1ed data:
,ecei1ed DR
I
5cd0D!t2&:1:<DR<37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
/8 Q$,T10Urite2ret!rn0gsmE0F37
5cd0D!t2&:1:<DR ,'S'?=<37 // =efine the first message
delaJ0ms250037
5cd0Cmd205C=0C5'$,37 8/
// Q$,T10Urite2ret!rn0gsmE1F37
I
I
/8if2ret!rn0gsmE0F990*4F NN ret!rn0gsmE1F990*463
B
if 2Q$,T10T*0Idle23 99 13
B
for2i907iK987i>>3
B
Q$,T10Urite2!art0rd1EiF37 //$T>CMGF91
I
Q$,T10Urite20*0=37 //'nter
5cd0D!t21:1:<$T>CMGF91<37
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
I
if 2Q$,T10=ata0,eadJ233
B // If data is recei1ed:
for2i907iK917i>>3
B
ret!rn0gsmEiF 9 Q$,T10,ead237 // read the recei1ed
data:DR
I
5cd0D!t2&:1:<,ecei1ed DR<37
delaJ0ms250037
5cd0Cmd205C=0C5'$,37
I
I 8/
I
I

Potrebbero piacerti anche