Вы находитесь на странице: 1из 7

Interface GSM module with PIC..

The Global System for Mobile (GSM) communication is the Second Generation of mobile technology. Although the world is mo ing towards Third and !ourth generation but GSM has been the most successful and wides"read technology in the communication sector. GSM technology "a ed a new way for mobile communication. This "ro#ect e$"lains the interfacing of a GSM Module with a PIC microcontroller. It also co ers 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#ecti es 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 "ro ision of these four o"erations has been "ro ided by means of four tactile switches. ,ach switch corres"onds to each of the abo e functions. AT Commands used to "erform the abo e o"erations ha e been gi en 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 con erter MA0+-+ is em"loyed to con ert 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 con erter 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 ta es fo!r choices as fo!r in"!ts

//Choice //Choice //Choice //Choice +define +define +define +define +define +define +define

1 & ) 4

# # # #

Test the sim"le $T Command% Find o!t the IM'I n!m(er of the GSM Modem% Connect a call to a GSM mo(ile n!m(er% Send a te*t message to a mo(ile n!m(er%

F,'- 1&000000 (a!d ./00 s"(rg01al!e 222F,'-//43/(a!d3413 rs 5$T$%F0 rw 5$T$%F1 en 5$T$%F& 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 5$T6907 T,IS$907 5$T$907 T,IS=90*FF7 5$T=907 SP6,G9s"(rg01al!e7 the (a!d rate ,CST$%SP'?917 and ,* "ins3 TCST$%TC'?917 ,CST$%C,'?917 PI'1%,CI'917 I?TCD?%GI'917 I?TCD?%P'I'917

// Set Port 6 as o!t"!t "ort

// Fill SP6,G register to set // To acti1ate serial "ort 2T* // // // // // $cti1ate Transmissiom $cti1ate ,ece"tion 'na(le ,ece"tion interr!"t 'na(le Glo(al interr!"t 'na(le Peri"heral interr!"t

lcd0ini237 while213 B 907 lcdcmd20*8037 while2starting0te*tE FG9H@0H3 B lcddata2starting0te*tE F37 >>7 I //Chec //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 o!t"!t237 =elaJ0ms2100037 gsm0cmd2sms37 o!t"!t237 t*0data20*1$37 =elaJ0ms2100037 in"!ts

gsm0cmd2sms0write37

I I 1oid gsm0cmd2!nsigned char 8string3 B i907;907 while2stringEiFG9H@0H3 B tem"907 if2stringEiF990*5C3 i>>7 t*0data2stringEiF37 i>>7 while2tem"G9137 I tem"907 t*0data2enter37 eJ while2tem"G9137 I 1oid o!t"!t21oid3 B lcdcmd20*0137 i9417flag907 while2iK;3 B if2flagL13 B flag907 =elaJ0ms250037 lcdcmd20*0137 lcdcmd20*8037 I if2dataEiF990*0$3 do!(le 'nter

// ?ot to send H@H cahracter // Send (J serial comm!nication

// Send $SCII code for H'nterH

// To "rint data on 5C=

// This condition is to a1oid

// 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 f!nction B TC,'G9serial0data7 while2PI,1%TCIF99037 I 1oid interr!"t23 B dataE;F9,C,'G7 ,ece"tion interr!"t occ!rs 1al!e9,C,'G7 ;>>7 tem"917 I 1oid lcd0ini23 B lcdcmd20*)837 5*O font lcdcmd20*0C37 lcdcmd20*0137 lcdcmd20*0/37 lcdcmd20*8037 I // Transmit data

// Store the data into arraJ when

// Config!re the 5C= in 84(it mode: & line and // // // // =is"laJ Dn and C!rsor Dff Clear dis"laJ screen Increment c!rsor Set c!rsor "osition to 1st line: 1st col!mn

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

Вам также может понравиться