Upload
shiox1989
View
1.490
Download
1
Embed Size (px)
DESCRIPTION
fully working on proteus
Citation preview
PROJECT REPORT ON
ELECTION VOTING VIA SMS
BY
ROHANSGAVANKAR (0713085)
RONAKPKAMDAR (0713087)
SHASHANKSKATKAR (0713094)
UNDER THE GUIDANCE OF
Prof SHARVARI PDESHMANE
IN PARTIAL FULFILLMENT OF
BE ELECTRONICS amp TELECOMMUNICATION
DEGREE OF UNIVERSITY OF MUMBAI
DEPARTMENT OF ELECTRONICS amp TELECOMMUNICATION
KJSOMAIYA COLLEGE OF ENGINERING VIDYAVIHAR MUMBAI-400077
(2010-2011)
KJSOMAIYA COLLEGE OF ENGINEERING
VIDYAVIHAR MUMBAI-400077
DEPARTMENT OF ELECTRONICS ampTELECOMMUNICATION
CERTIFICATE
This is to certify that the following students
bull Rohan S Gavankar (EXTC B-85)
bull Ronak P Kamdar (EXTC B-87)
bull Shashank S Katkar (EXTC B-94)
have successfully completed the project Titled ldquo ELECTION VOTING VIA SMS rdquo
towards the partial fulfillment of degree of Bachelor of Engineering in Electronics
and Telecommunications of the University of Mumbai during academic year 2010-
2011
----------------- -------------------
Name amp Designation Name amp Designation
Internal Guide External Guide
-------------------
Prof(Mrs) JMKundargi
Head of the Department
-------------------
Dr (Mrs) Medha Dixit
Principal
---------------------- -------------------------
INTERNAL EXAMINER EXTERNAL EXAMINER
ABSTRACT
Using SMS Based Voting machine we can vote from our home just by sending a
sms a specified format from our mobile The entire voters will be provided with a
unique password (pin) and identificat ion number For voting we have to send a
sms in a predefined format The voting machine will receive this messages and
decode the message and verify the the Pin number and identificat ion number if
both number matches the voting machine will accept the vote else the message is
rejected by the machine The voting machine is implemented using P89V51RD2
microcontroller A GSM MODEM is used to receive messages from voters The
microcontroller accepts this message and verifies the message and keep updates
An LCD is used to display the result
1
ACKNOWLEDGMENT
We wish to express my sincere gratitude to Prof J M Kundargi (Head of EXTC
Department) for providing us an opportunity to do our project work on ldquoELECTION
VOTING VIA SMSrdquo This project bears on imprint of many people We sincerely
thank our project guide Prof SharvariPDeshmane for channelizing us towards the
successful completion of our project We also wish to express our gratitude to the
officials and other staff members of KJSCE who rendered their help during the period
of our project work Our special thanks to Prof MrunalPChandane for her vital
insights and kind co-operation to the completion of our project work Last but not the
least we thank our family for giving us life in first place for educating us with
aspects from both arts and sciences for unconditional support and encouragement to
pursue our interests even when the interests went beyond boundaries of language
field and geography
2
TABLE OF CONTENTS
Sr No Page Title Page No
1 Title page i
2 Certificate ii
3 Abstract iii
4 Acknowledgment iv
5 Introduction 4
6 Chapter 1Introduction to P89V51RD2 Microcontroller
11 General Description 5
12 Features 6
13 Block diagram 7
14 Pin diagram 8
15 Pin description 9
16 Memory organization 12
17 Flash Memory in Application Programming 13
7 Chapter 2Max 232 IC 14
21 Explanation 15
8 Chapter 3GSM Module 16
31 Features 17
32 AT Commands 18
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
KJSOMAIYA COLLEGE OF ENGINEERING
VIDYAVIHAR MUMBAI-400077
DEPARTMENT OF ELECTRONICS ampTELECOMMUNICATION
CERTIFICATE
This is to certify that the following students
bull Rohan S Gavankar (EXTC B-85)
bull Ronak P Kamdar (EXTC B-87)
bull Shashank S Katkar (EXTC B-94)
have successfully completed the project Titled ldquo ELECTION VOTING VIA SMS rdquo
towards the partial fulfillment of degree of Bachelor of Engineering in Electronics
and Telecommunications of the University of Mumbai during academic year 2010-
2011
----------------- -------------------
Name amp Designation Name amp Designation
Internal Guide External Guide
-------------------
Prof(Mrs) JMKundargi
Head of the Department
-------------------
Dr (Mrs) Medha Dixit
Principal
---------------------- -------------------------
INTERNAL EXAMINER EXTERNAL EXAMINER
ABSTRACT
Using SMS Based Voting machine we can vote from our home just by sending a
sms a specified format from our mobile The entire voters will be provided with a
unique password (pin) and identificat ion number For voting we have to send a
sms in a predefined format The voting machine will receive this messages and
decode the message and verify the the Pin number and identificat ion number if
both number matches the voting machine will accept the vote else the message is
rejected by the machine The voting machine is implemented using P89V51RD2
microcontroller A GSM MODEM is used to receive messages from voters The
microcontroller accepts this message and verifies the message and keep updates
An LCD is used to display the result
1
ACKNOWLEDGMENT
We wish to express my sincere gratitude to Prof J M Kundargi (Head of EXTC
Department) for providing us an opportunity to do our project work on ldquoELECTION
VOTING VIA SMSrdquo This project bears on imprint of many people We sincerely
thank our project guide Prof SharvariPDeshmane for channelizing us towards the
successful completion of our project We also wish to express our gratitude to the
officials and other staff members of KJSCE who rendered their help during the period
of our project work Our special thanks to Prof MrunalPChandane for her vital
insights and kind co-operation to the completion of our project work Last but not the
least we thank our family for giving us life in first place for educating us with
aspects from both arts and sciences for unconditional support and encouragement to
pursue our interests even when the interests went beyond boundaries of language
field and geography
2
TABLE OF CONTENTS
Sr No Page Title Page No
1 Title page i
2 Certificate ii
3 Abstract iii
4 Acknowledgment iv
5 Introduction 4
6 Chapter 1Introduction to P89V51RD2 Microcontroller
11 General Description 5
12 Features 6
13 Block diagram 7
14 Pin diagram 8
15 Pin description 9
16 Memory organization 12
17 Flash Memory in Application Programming 13
7 Chapter 2Max 232 IC 14
21 Explanation 15
8 Chapter 3GSM Module 16
31 Features 17
32 AT Commands 18
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
ABSTRACT
Using SMS Based Voting machine we can vote from our home just by sending a
sms a specified format from our mobile The entire voters will be provided with a
unique password (pin) and identificat ion number For voting we have to send a
sms in a predefined format The voting machine will receive this messages and
decode the message and verify the the Pin number and identificat ion number if
both number matches the voting machine will accept the vote else the message is
rejected by the machine The voting machine is implemented using P89V51RD2
microcontroller A GSM MODEM is used to receive messages from voters The
microcontroller accepts this message and verifies the message and keep updates
An LCD is used to display the result
1
ACKNOWLEDGMENT
We wish to express my sincere gratitude to Prof J M Kundargi (Head of EXTC
Department) for providing us an opportunity to do our project work on ldquoELECTION
VOTING VIA SMSrdquo This project bears on imprint of many people We sincerely
thank our project guide Prof SharvariPDeshmane for channelizing us towards the
successful completion of our project We also wish to express our gratitude to the
officials and other staff members of KJSCE who rendered their help during the period
of our project work Our special thanks to Prof MrunalPChandane for her vital
insights and kind co-operation to the completion of our project work Last but not the
least we thank our family for giving us life in first place for educating us with
aspects from both arts and sciences for unconditional support and encouragement to
pursue our interests even when the interests went beyond boundaries of language
field and geography
2
TABLE OF CONTENTS
Sr No Page Title Page No
1 Title page i
2 Certificate ii
3 Abstract iii
4 Acknowledgment iv
5 Introduction 4
6 Chapter 1Introduction to P89V51RD2 Microcontroller
11 General Description 5
12 Features 6
13 Block diagram 7
14 Pin diagram 8
15 Pin description 9
16 Memory organization 12
17 Flash Memory in Application Programming 13
7 Chapter 2Max 232 IC 14
21 Explanation 15
8 Chapter 3GSM Module 16
31 Features 17
32 AT Commands 18
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
1
ACKNOWLEDGMENT
We wish to express my sincere gratitude to Prof J M Kundargi (Head of EXTC
Department) for providing us an opportunity to do our project work on ldquoELECTION
VOTING VIA SMSrdquo This project bears on imprint of many people We sincerely
thank our project guide Prof SharvariPDeshmane for channelizing us towards the
successful completion of our project We also wish to express our gratitude to the
officials and other staff members of KJSCE who rendered their help during the period
of our project work Our special thanks to Prof MrunalPChandane for her vital
insights and kind co-operation to the completion of our project work Last but not the
least we thank our family for giving us life in first place for educating us with
aspects from both arts and sciences for unconditional support and encouragement to
pursue our interests even when the interests went beyond boundaries of language
field and geography
2
TABLE OF CONTENTS
Sr No Page Title Page No
1 Title page i
2 Certificate ii
3 Abstract iii
4 Acknowledgment iv
5 Introduction 4
6 Chapter 1Introduction to P89V51RD2 Microcontroller
11 General Description 5
12 Features 6
13 Block diagram 7
14 Pin diagram 8
15 Pin description 9
16 Memory organization 12
17 Flash Memory in Application Programming 13
7 Chapter 2Max 232 IC 14
21 Explanation 15
8 Chapter 3GSM Module 16
31 Features 17
32 AT Commands 18
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
2
TABLE OF CONTENTS
Sr No Page Title Page No
1 Title page i
2 Certificate ii
3 Abstract iii
4 Acknowledgment iv
5 Introduction 4
6 Chapter 1Introduction to P89V51RD2 Microcontroller
11 General Description 5
12 Features 6
13 Block diagram 7
14 Pin diagram 8
15 Pin description 9
16 Memory organization 12
17 Flash Memory in Application Programming 13
7 Chapter 2Max 232 IC 14
21 Explanation 15
8 Chapter 3GSM Module 16
31 Features 17
32 AT Commands 18
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
3
Sr no
Page Title
Pg no
8 33 General Syntax of Extended AT Commands 21
34 Result code of AT commands 24
35 SMS tutorial 28
9 Chapter 4 Hitachi LCD display
47
41 Features 48
10 Chapter 5 Block diagram 50
51 Block diagram explanation 51
52Circuit diagram 52
53 Circuit diagram explanation 53
54 Flowchart 56
55 Hardware used 58
56 Software used 60
11 References 61
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
4
LIST OF TABLES amp FIGURES
Sr No Title Page No
11 P89V51RB2RC2RD2 BLOCK DIAGRAM 7
12 P89V51RD2 Pin diagram 8
13 P89V51RD2 pin description 9
14 P89V51RD2 pin description 10
15 P89V51RD2 pin description 11
16 Internal and External data memory structure of
P89V51RD2
12
21 Max 232 IC 14
31 SIM 300 GSM Module 16
32 The screenshot of MS HyperTerminals Connection
Description dialog box in Win 98
40
33 The screenshot of MS HyperTerminals Connect To
dialog box in Windows 98
41
34 The screenshot of MS HyperTerminals Properties
dialog box in Windows 98
43
35 The screenshot of MS HyperTerminals main
window in Windows 98
44
41 Hitachi LCD display 47
51 Block Diagram 50
52 Circuit diagram 52
531 7805 voltage regulator 54
532 Bridge Rectifier 55
54 Flowchart 56
551 89CXX test board kit 58
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
5
1INTRODUCTION
India is worldrsquos largest democracy Fundamental right to vote or simply voting in
elections forms the basis of Indian democracy In India all earlier elections a voter
used to cast his vote by using ballot paper This is a longtime-consuming process and
very much prone to errors This situation continued till election scene was completely
changed by electronic voting machine No more ballot paper ballot boxes stamping
etc all this condensed into a simple box called ballot unit of the electronic voting
machine Cell phone based voting machine is capable of saving considerable printing
stationery and transport of large volumes of electoral material It is easy to transport
store and maintain It completely rules out the chance of invalid votes Its use results
reduction of polling time resulting in fewer problems in electoral preparations law
and order candidates expenditureetc and easy and accurate counting without any
mischief at the counting centre The aim of our project is to design amp develop a
mobile based voting machine
This Project focuses onto implement GSM (Global System for Mobile
Communication) based Voting System This system is implemented using an
embedded microcontroller The embedded microcontroller used here is P89V51RD2
Actually the aim of the project is to implement an Automatic Voting system GSM
Based voting machine is fully controlled system There is no chance of any mistake
Primarily the system functions with the help of different technologies like the
traditional cellular network such as Global System for Mobile Communications
(GSM) and other radio frequency medium Today GSM fitted Banks cars
ambulances fleets and police vehicles are common sights The functional units of our
projects are GSM MODEM LCD display P89V51RD2
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
6
CHAPTER 1 INTRODUCTION TO P89V51RD2
MICROCONTROLLER
1 1 General description
The P89V51RB2RC2RD2 are 80C51 microcontrollers with 163264 kB Flash and
1024 bytes of data RAM A key feature of the P89V51RB2RC2RD2 is its X2 mode
option The design engineer can choose to run the application with the conventional
80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per
machine cycle) to achieve twice the throughput at the same clock frequency Another
way to benefit from this feature is to keep the same performance by reducing the
clock frequency by half thus dramatically reducing the EMI The Flash program
memory supports both parallel programming and in serial In-System Programming
(ISP) Parallel programming mode offers gang-programming at high speed reducing
programming costs and time to market ISP allows a device to be reprogrammed in
the end product under software control The capability to fieldupdate the application
firmware makes a wide range of applications possible The P89V51RB2RC2RD2 is
also In-Application Programmable (IAP) allowing the Flash program memory to be
reconfigured even while the application is running
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
7
12 Features
1 80C51 Central Processing Unit
2 5 V Operating voltage from 0 MHz to 40 MHz
3 163264 kB of on-chip Flash user code memory with ISP (In-System
Programming) and IAP (In-Application Programming)
4 Supports 12-clock (default) or 6-clock mode selection via software or ISP
SPI (Serial Peripheral Interface) and enhanced UART
5 PCA (Programmable Counter Array) with PWM and CaptureCompare functions
6 Four 8-bit IO ports with three high-current Port 1 pins (16 mA each)
7 Three 16-bit timerscounters
8 Programmable watchdog timer
9 Eight interrupt sources with four priority levels
10 Second DPTR register
11 Low EMI mode (ALE inhibit)
12 TTL- and CMOS-compatible logic levels
13 DIP40 PLCC44 and TQFP44 packages
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
8
13 Block Diagram
Figure 11
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
9
14 Pin diagram
Figure 12
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
10
15 Pin Description
Figure 13
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
11
Figure 14
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
12
Figure 15
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
13
16 Memory Organization
Figure 16
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
14
17 Flash Memory in Application programming
171 Flash Organization
The P89V51RB2RC2RD2 program memory consists of a 163264 kB block An In-
System Programming (ISP) capability in a second 8 kB block is provided to allow
the user code to be programmed in-circuit through the serial port There are three
methods of erasing or programming of the Flash memory that may be used First the
Flash may be programmed or erased in the end-user application by calling low-level
routines through a common entry point (IAP) Second the on-chip ISP boot loader
may be invoked This ISP boot loader will in turn call low-level routines through the
same common entry point that can be used by the end-user application Third the
Flash may be programmed or erased using the parallel method by using a
commercially available EPROM programmer which supports this device
172 Boot Block
When the microcontroller programs its own Flash memory all of the low level details
are handled by code that is contained in Block 1 A user program calls the common
entry point in the Block 1 with appropriate parameters to accomplish the desired
operation Boot block operations include erase user code program user code program
security bits etc A Chip-Erase operation can be performed using a commercially
available parallel programer This operation will erase the contents of this Boot Block
and it will be necessary for the user to reprogram this Boot Block (Block 1) with the
Philips-provided ISPIAP code in order to use the ISP or IAP capabilities of this
device
173 In-System Programming
In-System Programming is performed without removing the microcontroller from the
System The In-System Programming facility consists of a series of internal hardware
resources coupled with internal firmware to facilitate remote programming of the
P89V51RB2RC2RD2 through the serial port This firmware is provided by Philips
and embedded within each P89V51RB2RC2RD2 device The Philips In-System
Programming facility has made in-circuit programming in an embedded application
The ISP function uses five pins (VDD VSS TxD RxD and RST) Only a small
Connector needs to be available to interface your application to an external circuit in
Order to use this feature
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
15
CHAPTER 2 MAX 232 IC
Figure 21
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
16
21 Features
The MAX232 is an integrated circuit that converts signals from an RS-232 serial port
to signals suitable for use in TTL compatible digital logic circuits The MAX232 is a
dual driverreceiver and typically converts the RX TX CTS and RTS signals The
drivers provide RS- 232 voltage level outputs (approx plusmn 75 V) from a single +5V
supply via on-chip charge pumps and external capacitors This makes it useful for
implementing RS-232 in devices that otherwise do not need any voltages outside the 0
V to + 5 V range as power supply design does not need to be made more complicated
just for driving the RS-232 in this case The receivers reduce RS-232inputs (which
may be as high as plusmn 25 V) to standard 5 V TTL levels These receivers have atypical
threshold of 13 V and a typical hysteresis of 05 V The later MAX232A is
backwards compatible with the original MAX232 but may operate at higher baud
rates and can use smaller external capacitors plusmn 01 F in place of the 10 F capacitors
used with the original device The newer MAX3232 is also backwards compatible
but operates at a broader voltage range from 3 to 55V
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
17
CHAPTER 3 GSM MODULE
Figure 31
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
18
31 Features
A GSM modem is a wireless modem that works with a GSM wire less network A
wireless modem behaves like a dial-up modem The main difference between them is
that a dial- up modem sends and receives data through a fixed telephone line while a
wireless modem Sends and receives data through radio waves A GSM modem can be
an external device or a PC Card PCMCIA Card Typically an external GSM modem
is connected to a computer through a serial cable or a USB cable A GSM modem in
the form of a PC Card PCMCIA Card is designed for use with a laptop computer It
should be inserted into one of the PC Card PCMCIA Card slots of a laptop computer
Like a GSM mobile phone a GSM modem requires a SIM card from a wireless
carrier in order to operate As mentioned below of this SMS tutorial l computers use
AT commands to control modems Both GSM modems and dial-up modems support a
common set of standard AT commands You can use a GSM modem just like a dial-
up modem In addition to the standard AT commands GSM modems support an
extended set of AT commands These extended AT commands are defined in the
GSM standards With the extended AT commands you can do things like
1 Reading writing and deleting SMS messages
2 Sending SMS messages
3 Monitoring the signal strength
4 Monitoring the charging status and charge level of the battery
5 Reading writing and searching phone book entries
The number of SMS messages that can be processed by a GSM modem per minute is
very low -- only about six to ten SMS messages per minute
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
19
32 AT Commands
AT commands are instructions used to control a modem AT is the abbreviation of
ATtention Every command line starts with AT or at Thats why modem
commands are called AT commands Many of the commands that are used to control
wired dial-up modems such as ATD (Dial) ATA (Answer) ATH (Hook control) and
ATO (Return to online data state) are also supported by GSMGPRS modems and
mobile phones Besides this common AT command set GSMGPRS modems and
mobile phones support an AT command set that is specific to the GSM technology
which includes SMS-related commands like AT+CMGS (Send SMS message)
AT+CMSS (Send SMS message from storage) AT+CMGL (List SMS messages) and
AT+CMGR (Read SMS messages)
Note that the starting AT is the prefix that informs the modem about the start of a
command line It is not part of the AT command name For example D is the actual
AT command name in ATD and +CMGS is the actual AT command name in
AT+CMGS However some books and web sites use them interchangeably as the
name of an AT command
Here are some of the tasks that can be done using AT commands with a GSMGPRS
modem or mobile phone
Get basic information about the mobile phone or GSMGPRS modem For
example name of manufacturer (AT+CGMI) model number (AT+CGMM)
IMEI number (International Mobile Equipment Identity) (AT+CGSN) and
software version (AT+CGMR)
Get basic information about the subscriber For example MSISDN
(AT+CNUM) and IMSI number (International Mobile Subscriber Identity)
(AT+CIMI)
Get the current status of the mobile phone or GSMGPRS modem For
example mobile phone activity status (AT+CPAS) mobile network
registration status (AT+CREG) radio signal strength (AT+CSQ) battery
charge level and battery charging status (AT+CBC)
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
20
Establish a data connection or voice connection to a remote modem (ATD
ATA etc)
Send and receive fax (ATD ATA AT+F)
Send (AT+CMGS AT+CMSS) read (AT+CMGR AT+CMGL) write
(AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications
of newly received SMS messages (AT+CNMI)
Read (AT+CPBR) write (AT+CPBW) or search (AT+CPBF) phonebook
entries
Perform security-related tasks such as opening or closing facility locks
(AT+CLCK) checking whether a facility is locked (AT+CLCK) and changing
passwords (AT+CPWD)
(Facility lock examples SIM lock [a password must be given to the SIM card
every time the mobile phone is switched on] and PH-SIM lock [a certain SIM
card is associated with the mobile phone To use other SIM cards with the
mobile phone a password must be entered])
Control the presentation of result codes error messages of AT commands
For example you can control whether to enable certain error messages
(AT+CMEE) and whether error messages should be displayed in numeric
format or verbose format (AT+CMEE=1 or AT+CMEE=2)
Get or change the configurations of the mobile phone or GSMGPRS modem
For example change the GSM network (AT+COPS) bearer service type
(AT+CBST) radio link protocol parameters (AT+CRLP) SMS center address
(AT+CSCA) and storage of SMS messages (AT+CPMS)
Save and restore configurations of the mobile phone or GSMGPRS modem
For example save (AT+CSAS) and restore (AT+CRES) settings related to
SMS messaging such as the SMS center address
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
21
Note that mobile phone manufacturers usually do not implement all AT commands
command parameters and parameter values in their mobile phones Also the behavior
of the implemented AT commands may be different from that defined in the standard
In general GSMGPRS modems designed for wireless applications have better
support of AT commands than ordinary mobile phones
In addition some AT commands require the support of mobile network operators For
example SMS over GPRS can be enabled on some GPRS mobile phones and GPRS
modems with the +CGSMS command (command name in text Select Service for MO
SMS Messages) But if the mobile network operator does not support the transmission
of SMS over GPRS you cannot use this features There are two types of AT
commands basic commands and extended commands
Basic commands are AT commands that do not start with + For example D (Dial)
A (Answer) H (Hook control) and O (Return to online data state) are basic
commands
Extended commands are AT commands that start with + All GSM AT commands
are extended commands For example +CMGS (Send SMS message) +CMSS (Send
SMS message from storage) +CMGL (List SMS messages) and +CMGR (Read SMS
messages) are extended commands [4]
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
22
33 General Syntax of Extended AT Commands
The general syntax of extended AT commands is straightforward The syntax rules
are provided below The syntax of basic AT commands is slightly different We will
not cover the syntax of basic AT commands in this SMS tutorial since all SMS
messaging commands are extended AT commands
Syntax rule 1 All command lines must start with AT and end with a carriage return
character (We will use ltCRgt to represent a carriage return character in this SMS
tutorial) In a terminal program like HyperTerminal of Microsoft Windows you can
press the Enter key on the keyboard to output a carriage return character
Example To list all unread inbound SMS messages stored in the message storage
area type AT then the extended AT command +CMGL and finally a carriage
return character like this
AT+CMGLltCRgt
Syntax rule 2 A command line can contain more than one AT command Only the
first AT command should be prefixed with AT AT commands in the same
command-line string should be separated with semicolons
Example To list all unread inbound SMS messages stored in the message storage area
and obtain the manufacturer name of the mobile device type AT then the extended
AT command +CMGL followed by a semicolon and the next extended AT
command +CGMI
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
23
AT+CMGL+CGMIltCRgt
An error will occur if both AT commands are prefixed with AT like this
AT+CMGLAT+CGMIltCRgt
Syntax rule 3 A string is enclosed between double quotes
Example To read all SMS messages from message storage in SMS text mode (at this
time you do not need to know what SMS text mode is More information will be
provided later in this SMS tutorial) you need to assign the string ALL to the
extended AT command +CMGL like this
AT+CMGL=ALLltCRgt
Syntax rule 4 Information responses and result codes (including both final result
codes and unsolicited result codes) always start and end with a carriage return
character and a linefeed character
Example After sending the command line AT+CGMIltCRgt to the mobile device
the mobile device should return a response similar to this
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
24
The first line is the information response of the AT command +CGMI and the second
line is the final result code ltCRgt and ltLFgt represent a carriage return character and
a linefeed character respectively The final result code OK marks the end of the
response It indicates no more data will be sent from the mobile device to the
computer PC
When a terminal program such as HyperTerminal of Microsoft Windows sees a
carriage return character it moves the cursor to the beginning of the current line
When it sees a linefeed character it moves the cursor to the same position on the next
line Hence the command line AT+CGMIltCRgt that you entered and the
corresponding response will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CGMI
Nokia
OK
331 Information Response and Final Result Code
Dont forget the meanings of information response and final result code stated above
since you will see these two terms frequently as you go through this SMS tutorial
AT+CGMI lt-- Command line entered
Nokia lt-- Information response
OK lt-- Final result code [4]
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
25
34 Result codes of AT commands
Result codes are messages sent from the GSMGPRS modem or mobile phone to
provide you information about the execution of an AT command and the occurrence
of an event Two types of result codes are useful to you when dealing with AT
commands for SMS messaging
Final result codes
Unsolicited result codes
341 Final Result Codes of AT Commands
A final result code marks the end of an AT command response It is an indication that
the GSMGPRS modem or mobile phone has finished the execution of a command
line Two frequently used final result codes are OK and ERROR Only one final result
code will be returned for each command line Thus you will not see both OK and
ERROR in the response of a command line
342 The OK Final Result Code
The OK final result code indicates that a command line has been executed
successfully by the GSMGPRS modem or mobile phone It always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Lets say you send the command line
AT+CMGL+CGMIltCRgt to your GSMGPRS modem The AT command
+CMGL is used to list SMS messages stored in the message storage area and the
AT command +CGMI is used to get the manufacturer name of the GSMGPRS
modem If everything works properly without any errors the command line together
with the response returned should be something similar to this
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
26
AT+CMGL+CGMIltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtNokialtCRgtltLFgt
ltCRgtltLFgtOKltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMI
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
Nokia
OK
343 The ERROR Final Result Code
The ERROR final result code indicates that an error occurs when the GSMGPRS
modem or mobile phone tries to execute a command line After the occurrence of an
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
27
error the GSMGPRS modem or mobile phone will not p rocess the remaining AT
commands in the command-line string
Below are some common causes of error
The syntax of the command line is incorrect
The value specified to a certain parameter is invalid
The name of the AT command is spelt incorrectly
The GSMGPRS modem or mobile phone does not support one or more of the
AT commands command parameters or parameter values in the command-
line string
Like the OK final result code the ERROR final result code always starts and ends
with a carriage return character and a linefeed character
Here is an example for illustration Suppose you want to instruct your GSMGPRS
modem to list SMS messages from the message storage area and get the manufacturer
name of the GSMGPRS modem You intend to type the command line
AT+CMGL+CGMIltCRgt but make a careless mistake by typing +CMFL instead
of +CMGL The GSMGPRS modem will return the ERROR final result code as
shown below
AT+CMFL+CGMIltCRgt
ltCRgtltLFgtERRORltCRgtltLFgt
As an error occurs when the GSMGPRS modem processes +CMFL the
GSMGPRS modem stops the execution of the command line and so the second AT
command +CGMI is not processed
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
28
If you type the second AT command +CGMI incorrectly instead of the first AT
command +CMGL the GSMGPRS modem will output the result of the execution
of the AT command +CMGL before outputting the ERROR final result code like
this
AT+CMGL+CGMUltCRgt
ltCRgtltLFgt+CMGL 1REC
UNREAD+85291234567061111003029+32ltCRgtltLFgt
Welcome to our SMS tutorialltCRgtltLFgt
ltCRgtltLFgtERRORltCRgtltLFgt
As mentioned earlier when a terminal program such as HyperTerminal of Microsoft
Windows sees a carriage return character it moves the cursor to the beginning of the
current line When it sees a linefeed character it moves the cursor to the same
position on the next line Hence the command line you entered together with the
response returned will be displayed like this in a terminal program such as
HyperTerminal of Microsoft Windows
AT+CMGL+CGMU
+CMGL 1REC UNREAD+85291234567061111003029+32
Welcome to our SMS tutorial
ERROR [4]
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
29
35 SMS tutorial
In general there are two ways to send SMS messages from a computer PC to a
mobile phone
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to instruct the mobile phone or
GSMGPRS modem to send SMS messages
2 Connect the computer PC to the SMS center (SMSC) or SMS gateway of a
wireless carrier or SMS service provider Then send SMS messages using a
protocol interface supported by the SMSC or SMS gateway
351 The 1st Way Sending SMS Messages from a Computer Using a Mobile Phone
or GSMGPRS Modem
The SMS specification has defined a way for a computer to send SMS messages
through a mobile phone or GSMGPRS modem A GSMGPRS modem is a wireless
modem that works with GSMGPRS wireless networks A wireless modem is similar
to a dial-up modem The main difference is that a wireless modem transmits data
through a wireless network whereas a dial-up modem transmits data through a copper
telephone line Most mobile phones can be used as a wireless modem However some
mobile phones have certain limitations comparing to GSMGPRS modems
To send SMS messages first place a valid SIM card from a wireless carrier into a
mobile phone or GSMGPRS modem which is then connected to a computer There
are several ways to connect a mobile phone or GSMGPRS modem to a computer For
example they can be connected through a serial cable a USB cable a Bluetooth link
or an infrared link The actual way to use depends on the capability of the mobile
phone or GSMGPRS modem For example if a mobile phone does not support
Bluetooth it cannot connect to the computer through a Bluetooth link
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
30
After connecting a mobile phone or GSMGPRS modem to a computer you can
control the mobile phone or GSMGPRS modem by sending instructions to it The
instructions used for controlling the mobile phone or GSMGPRS modem are called
AT commands (AT commands are also used to control dial-up modems for wired
telephone system) Dial-up modems mobile phones and GSMGPRS modems support
a common set of standard AT commands In addition to this common set of standard
AT commands mobile phones and GSMGPRS modems support an extended set of
AT commands One use of the extended AT commands is to control the sending and
receiving of SMS messages
The following table lists the AT commands that are related to the writing and sending
of SMS messages
AT command Meaning
+CMGS Send message
+CMSS Send message from storage
+CMGW Write message to memory
+CMGD Delete message
+CMGC Send command
+CMMS More messages to send
One way to send AT commands to a mobile phone or GSMGPRS modem is to use a
terminal program A terminal programs function is like this It sends the characters
you typed to the mobile phone or GSMGPRS modem It then displays the response it
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
31
receives from the mobile phone or GSMGPRS modem on the screen The terminal
program on Microsoft Windows is called HyperTerminal Below shows a simple
example that demonstrates how to use AT commands and the HyperTerminal
program of Microsoft Windows to send an SMS text message The lines in bold type
are the command lines that should be entered in HyperTerminal The other lines are
responses returned from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGW=+85291234567
gt A simple demo of SMS text messaging
+CMGW 1
OK
AT+CMSS=1
+CMSS 20
OK
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
32
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5 and 6 The AT command +CMGW is used to write an SMS text
message to the message storage of the GSM GPRS modem +85291234567
is the recipient mobile phone number After typing the recipient mobile phone
number you should press the Enter button of the keyboard The GSM GPRS
modem will then return a prompt gt and you can start typing the SMS text
message A simple demo of SMS text messaging When finished press
Ctrl+z of the keyboard
Line 7 +CMGW 1 tells us that the index assigned to the SMS text message
is 1 It indicates the location of the SMS text message in the message storage
Line 9 The result code OK indicates the execution of the AT command
+CMGW is successful
Line 10 The AT command +CMSS is used to send the SMS text message
from the message storage of the GSM GPRS modem 1 is the index of the
SMS text message obtained from line 7
Line 11 +CMSS 20 tells us that the reference number assigned to the SMS
text message is 20
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
33
Line 13 The result code OK indicates the execution of the AT command
+CMSS is successful
To send SMS messages from an application you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program does You can write the source code in C
C++ Java Visual Basic Delphi or other programming languages you like However
writing your own code has a few disadvantages
You have to learn how to use AT commands
You have to learn how to compose the bits and bytes of an SMS message For
example to specify the character encoding (eg 7-bit encoding and 16-bit
Unicode encoding) of an SMS message you need to know which bits in the
message header should be modified and what value should be assigned
Sending SMS messages with a mobile phone or GSMGPRS modem has a
drawback -- the SMS transmission speed is low As your SMS messaging
application becomes more popular it has to handle a larger amount of SMS
traffic and finally the mobile phone or GSMGPRS modem will not be able to
take the load To obtain a high SMS transmission speed a direct connection to
an SMSC or SMS gateway of a wireless carrier or SMS service provider is
needed However AT commands are not used for communicating with an
SMS center or SMS gateway This means your have to make a big change to
your SMS messaging application in order to move from a wireless-modem-
based solution to a SMSC-based solution
In most cases instead of writing your own code for interacting with the mobile phone
or GSMGPRS modem via AT commands a better solution is to use a high- level
SMS messaging API (Application programming interface) SDK (Software
development kit) library The API SDK library encapsulates the low-level details
So an SMS application developer does not need to know AT commands and the
composition of SMS messages in the bit-level Some SMS messaging APIs SDKs
libraries support SMSC protocols in addition to AT commands To move from a
wireless-modem-based SMS solution to a SMSC-based SMS solution usually you
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
34
just need to modify a configuration file property file or make a few changes to your
SMS messaging applications source code
Another way to hide the low-level AT command layer is to place an SMS gateway
between the SMS messaging application and the mobile phone or GSMGPRS
modem (This has been described in the section What is an SMS Gateway earlier)
Simple protocols such as HTTP HTTPS can then be used for sending SMS messages
in the application If an SMSC protocol (eg SMPP CIMD etc) is used for
communicating with the SMS gateway instead of HTTP HTTPS an SMS messaging
API SDK library can be very helpful to you since it encapsulates the SMSC
protocols details
Usually a list of supported unsupported mobile phones or wireless modems is
provided on the web site of an SMS messaging API SDK library or an SMS
gateway software package Remember to check the list if you are going to use an
SMS messaging API SDK library or an SMS gateway software package
352 Major Drawback of Sending SMS Messages through a Mobile Phone or
GSMGPRS Modem -- Low SMS Sending Rate
Using a mobile phone or GSMGPRS modem to send SMS messages has a major
drawback that is the SMS sending rate is too low Only 6-10 SMS messages can be
sent per minute (when the SMS over GSM mode is used) The performance is not
affected by the connection between the computer and the mobile phone or
GSMGPRS modem (ie the SMS sending rate is about the same no matter the mobile
phone or GSMGPRS modem is connected to the computer through a serial cable
USB cable Bluetooth link or infrared link) and does not depend on whether a mobile
phone or GSMGPRS modem is used (ie the SMS sending rate is about the same no
matter a mobile phone or a GSMGPRS modem is used) The determining factor for
the SMS sending rate is the wireless network
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
35
353 How to receive SMS messages using ComputerPC
In general there are three ways to receive SMS messages using your computer PC
1 Connect a mobile phone or GSMGPRS modem to a computer PC Then use
the computer PC and AT commands to get the received SMS messages from
the mobile phone or GSMGPRS modem
2 Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier
Any SMS messages received will be forwarded to your computer PC using a
protocol interface supported by the SMSC or SMS gateway
3 Get access to the SMS gateway of an SMS service provider Any SMS
messages received will be forwarded to your computer PC using a protocol
interface supported by the SMS gateway
3531 The 1st Way Using a Computer to Receive SMS Messages through a Mobile
Phone or GSMGPRS Modem
Receiving SMS messages through a mobile phone or GSMGPRS modem has a major
advantage over the other two ways -- wireless carriers usually do not charge any fees
for receiving incoming SMS messages with their SIM cards The disadvantage of
receiving SMS messages this way is that a mobile phone or GSMGPRS modem
cannot handle a large amount of SMS traffic One way to overcome this is to load
balance the SMS traffic with a pool of mobile phones or GSMGPRS modems Each
mobile phone or GSMGPRS modem will have its own SIM card and mobile phone
number
In terms of programming sending and receiving SMS messages through a mobile
phone or GSMGPRS modem are similar What you need to do is to send instructions
(in the form of AT commands) to the mobile phone or GSMGPRS modem
The following table lists the AT commands that are related to the receiving and
reading of SMS messages
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
36
AT command Meaning
+CNMI New message indications
+CMGL List messages
+CMGR Read messages
+CNMA New message acknowledgement
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received
by a GSM GPRS modem or mobile phone The lines in bold type are the command
lines that should be entered in HyperTerminal The other lines are responses returned
from the GSM GPRS modem or mobile phone
AT
OK
AT+CMGF=1
OK
AT+CMGL=ALL
+CMGL 1REC READ+85291234567061111003029+32
Hello welcome to our SMS tutorial
+CMGL 2REC READ+85291234567061111003220+32
A simple demo of SMS text messaging
OK
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
37
Here is a description of what is done in the above example
Line 1 AT is sent to the GSM GPRS modem to test the connection The
GSM GPRS modem sends back the result code OK (line 2) which means
the connection between the HyperTerminal program and the GSM GPRS
modem works fine
Line 3 The AT command +CMGF is used to instruct the GSM GPRS
modem to operate in SMS text mode The result code OK is returned (line
4) which indicates the command line AT+CMGF=1 has been executed
successfully If the result code ERROR is returned it is likely that the GSM
GPRS modem does not support the SMS text mode To confirm type
AT+CMGF= in the HyperTerminal program If the response is +CMGF
(01) (0=PDU mode and 1=text mode) then SMS text mode is supported If
the response is +CMGF (0) then SMS text mode is not supported
Line 5-9 The AT command +CMGL is used to list all SMS text messages in
the message storage of the GSM GPRS modem There are two SMS text
messages in the message storage Hello welcome to our SMS tutorial and
A simple demo of SMS text messaging +85291234567 is the sender
mobile phone number 061111003029+32 and 061111003220+32
tell us when the SMS text messages were received by the SMSC +32 is the
time zone Note that the unit is a quarter of an hour So +32 means GMT+8
hours since 32 quarters of an hour = 8 hours REC READ indicates both of
the SMS text messages have been read before
Line 11 The result code OK indicates the execution of the AT command
+CMGL is successful
To enable an application to receive SMS messages you have to write the source code
for connecting to and sending AT commands to the mobile phone or GSMGPRS
modem just like what a terminal program (such as HyperTerminal of Microsoft
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
38
Windows) does You can write the source code in C C++ Java Visual Basic Delphi
or other programming languages you like
However like what we have discussed in the earlier section The 1st Way Sending
SMS Messages from a Computer Using a Mobile Phone or GSMGPRS Modem
usually a better solution is to use a high- level SMS messaging API (Application
programming interface) SDK (Software development kit) library instead of writing
your own code for interacting with the mobile phone or GSMGPRS modem via AT
commands The API SDK library encapsulate the low-level details So an SMS
application developer does not need to know AT commands and the composition of
SMS messages in the bit- level Some SMS messaging APIs SDKs libraries support
SMSC protocols in addition to AT commands To move from a wireless-modem-
based SMS solution to a SMSC-based SMS solution usually you just need to modify
a configuration file property file or make a few changes to your SMS messaging
applications source code
Another high- level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSMGPRS modem The SMS messaging
application can then use simple protocols such as HTTP HTTPS for receiving SMS
messages If an SMSC protocol (eg SMPP CIMD etc) is used for communicating
with the SMS gateway instead of HTTP HTTPS an SMS messaging API SDK
library can be very helpful to you since it encapsulates the SMSC protocols details
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
39
354 How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile
Phone or GSMGPRS Modem
Microsoft HyperTerminal is a small program that comes with Microsoft Windows
You can use it to send AT commands to your mobile phone or GSMGPRS modem It
can be found at Start -gt Programs -gtAccessories -gt Communications -
gt HyperTerminal If you cannot find it and you are using Windows 98 then probably
you have not installed it You can go to Control Panel -gt AddRemove Programs -
gtWindows Setup tab -gt Communications list box item -gt Details button to install MS
HyperTerminal
Before you start programming your SMS application you may want to check if your
mobile phone GSMGPRS modem and SIM card are working properly first The MS
HyperTerminal is a handy tool when it comes to testing your GSM devices It is a
good idea to test your GSM devices beforehand When a problem occurs sometimes
it is difficult to tell what causes the problem The cause can be your program the
GSM device or the SIM card If you test your GSM device and SIM card with MS
HyperTerminal and they operate properly then it is very likely that the problem is
caused by your program
For Linux users minicom can be used instead of HyperTerminal
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
40
356 The Procedure for Sending AT Commands to a Mobile Phone or GSMGPRS
Modem Using MS HyperTerminal
To use MS HyperTerminal to send AT commands to your mobile phone or
GSMGPRS modem you can follow the procedure below
1 Put a valid SIM card into the mobile phone or GSMGPRS modem You can
obtain a SIM card by subscribing to the GSM service of a wireless network
operator
2 Connect your mobile phone or GSMGPRS modem to a computer and set up
the corresponding wireless modem driver You should find the wireless
modem driver in the CD or disk that was provided by the manufacturer If the
manufacturer does not provide such CD or disk with your mobile pho ne or
GSMGPRS modem you can go to the manufacturers web site and see
whether the wireless modem driver can be downloaded there If the wireless
modem driver cannot be found on the web site you can still use Windows
standard modem driver
3 Run MS HyperTerminal by selecting Start -gt Programs -gt Accessories -
gt Communications -gtHyperTerminal
4 In the Connection Description dialog box enter a name and choose an icon
you like for the connection Then click the OK button
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
41
Figure 32
5 In the Connect To dialog box choose the COM port that your mobile phone or
GSMGPRS modem is connecting to in the Connect using combo box For
example choose COM1 if your mobile phone or GSMGPRS modem is
connecting to the COM1 port Then click the OK button
(Sometimes there will have more than one COM port in the Connect
using combo box To know which COM port is used by your mobile phone or
GSMGPRS modem follow the procedure below
In Windows 98
Go to Control Panel -gt Modem Then click the Diagnostics tab In the list box
you can see which COM port the mobile phone or GSMGPRS modem is
connected to
In Windows 2000 and Windows XP
Go to Control Panel -gt Phone and Modem Options Then click
the Modems tab In the list box you can see which COM port the mobile
phone or GSMGPRS modem is connected to)
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
42
Figure 33
6 The Properties dialog box comes out Enter the correct port settings for your
mobile phone or GSMGPRS modem Then click the OK button
(To find the correct port settings that should be used with your mobile phone
or GSMGPRS modem one way is to consult the manual of your mobile
phone or GSMGPRS modem Another way is to check the port settings used
by the wireless modem driver that you installed earlier
To check the port settings used by the wireless modem driver on Windows 98
follow these steps
a Go to Control Panel -gt Modem
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears The Maximum speeds field on
the General tab corresponds to HyperTerminals Bits per second field Click
the Connection tab and you can find the settings for data bits parity and stop
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
43
bits Click the Advanced button and you can find the setting for flow control
To check the port settings used by the wireless modem driver on Windows
2000 and Windows XP follow these steps
a Go to Control Panel -gt Phone and Modem Options -gt Modems tab
b Select your mobile phone or GSMGPRS modem in the list box
c Click the Properties button
d The Properties dialog box appears Click the Advanced tab and then click
the Change Default Preferences button
e The Change Default Preferences dialog box appears The Port speed field
on the General tab corresponds to HyperTerminals Bits per second field You
can also find the setting for flow control on the General tab On
the Advanced tab you can find the settings for data bits parity and stop bits)
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
44
Figure 34
7 Type AT in the main window A response OK should be returned from the
mobile phone or GSMGPRS modem
Type AT+CPIN in the main window The AT command AT+CPIN is
used to query whether the mobile phone or GSMGPRS modem is waiting for
a PIN (personal identification number ie password) If the response is
+CPIN READY it means the SIM card does not require a PIN and it is
ready for use If your SIM card requires a PIN you need to set the PIN with
the AT command AT+CPIN=ltPINgt
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
45
Figure 35
If you get the responses above your mobile phone or GSMGPRS modem is wo rking
properly You can start typing your own AT commands to control the mobile phone
or GSMGPRS modem
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
46
35 Checking if the GSMGPRS Modem or Mobile Phone Supports the Use of AT
Commands to Send Receive and Read SMS Messages
After testing the communication between the PC and GSMGPRS modemmobile
phone the next thing that you may want to do is to check if the GSMGPRS modem
or mobile phone supports the use of AT commands to send receive and read SMS
messages Most GSMGPRS modems support all three functions However only
some mobile phones support all of them
Sending SMS Messages
To find out whether a GSMGPRS modem or mobile phone supports the sending of
SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-originated SMS messages are supported
2 Perform test operations to check whether +CMGS (command name in text
Send Message) andor +CMSS (command name in text Send Message from
Storage) are supported
(You may want to check the AT commands +CMGW [command name in text
Write Message to Memory] and +CMGD [command name in text Delete
Message] in addition as they are sometimes used together with +CMSS)
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
47
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSMGPRS modem or mobile phone supports the receiving
and reading of SMS messages through AT commands you have to
1 Use the AT command +CSMS (command name in text Select Message
Service) to check whether mobile-terminated SMS messages are supported
2 Perform test operations to check whether +CNMI (command name in text
New Message Indications to TE) +CMGL (command name in text List
Messages) andor +CMGR (command name in text Read Message) are
supported
If the GSMGPRS modem or mobile phone supports the +CNMI AT command it can
send a notification or directly forward the message to the PC whenever a new SMS
message arrives
If the GSMGPRS modem or mobile phone does not support +CNMI but supports
+CMGL andor +CMGR the PC has to poll the GSMGPRS modem or mobile phone
repeatedly in order to know if any new SMS messages have arrived [4]
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
48
CHAPTER 4 HITACHI LCD DISPLAY
Figure 41
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
49
41 Features
An HD44780 Character LCD is a de facto industry standard liquid crystal display
(LCD) display device designed for interfacing with embedded systems These screens
come in a variety of configurations including 8x1 which is one row of eight
characters 16x2 and 20x4 The most commonly manufactured configuration is 40x4
characters which requires two individually addressable HD44780 controllers with
expansion chips as the HD44780 can only address up to 80 characters These LCD
screens are limited to text only and are often used in copiers fax machines laser
printers industrial test equipment networking equipment such as routers and storage
devicesCharacter LCDs use a standard 14-pin interface and those with backlights
have 16 pins The pin outs are as follows
1 Ground
2 VCC (+33 to +5V)
3 Contrast adjustment (VO)
4 Register Select (RS) RS=0 Command RS=1 Data
5 ReadWrite (RW) RW=0 Write RW=1 Read
6 Clock (Enable) Falling edge triggered
7 Bit 0 (Not used in 4-bit operation)
8 Bit 1 (Not used in 4-bit operation)
9 Bit 2 (Not used in 4-bit operation)
10 Bit 3 (Not used in 4-bit operation)
11 Bit 4
12 Bit 5
13 Bit 6
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
50
14 Bit 7
15 Backlight Anode (+)
16 Backlight Cathode (-)
Character LCDs can operate in 4-bit or 8-bit mode In 4 bit mode pins 7 through 10
are unused and the entire byte is sent to the screen using pins 11 through 14 by
sending 4-bits (nibble) at a time
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
51
CHAPTER 5 BLOCK DIAGRAM
Figure 51
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
52
51 Block diagram explanation
511 Working of Block Diagram
A mobile interfaced to P89V51RD2 microcontroller The user has his
password stored in front of his id number in the memory of microc The User has to send
his voting information via sms to the mobile interfaced to the microcontroller The microc
will consider a vote if the password of a person matches to his election id When a
vote gets approved it gets locked and the user account will be expired The mobile
interfaced to the microc will send an acknowledgment message when the vote is granted
if something goes wrong then microc will send a negative acknowledgment message via
sms to the user
If the password of the person is entered in the same order there will be a positive vote
given to the candidate to which the voter is voting If the password is in the reverse
manner there will be a negative voting against the candidate voted This is done in
order to reduce the risk of forcible voting
The factor of negative voting is kept to be 13 rd ie 13 rd vote will be subtracted
from the candidatersquos vote to compensate the cheating This factor is determined after a
lot of probability work done so that no one can determine the winner just on the basis
of negative voting This cannot help in judging the output of the election
Thus we can completely rely on the system
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
53
52 Circuit diagram
Figure 15
Figure 52
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
54
53 Circuit diagram explanation
Here port 2 is connected to the lcd to display data from the microcontroller to the lcd The virtual terminal is used to send and receive data via serial port and is used instead of a GSM module
The HEX file of the program is loaded into the controller and the clock frequency and
baud rates of all the devices are adjusted so that they work in synchronization
Some pins of port 0 are used to give the write and latching commands to the lcd
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
55
531 POWER SUPPLY
7805 VOLTAGE REGULATOR The 78xx (also sometimes known as LM78xx)
series of devices is a family of self-contained fixed linear voltage regulator integrated
circuits The 78xx family is a very popular choice for many electronic circuits which
require a regulated power supply due to their ease of use and relative cheapness
When specifying individual ICs within this family the xx is replaced with a two-digit
number which indicates the output voltage the particular device is designed to
provide (for example the 7805 has a 5 volt output while the 7812 produces 12 volts)
The 78xx line are positive voltage regulators meaning that they are designed to
produce a voltage that is positive relative to a common ground There is a related line
of 79xx devices which are complementary negative voltage regulators 78xx and 79xx
ICs can be used in combination to provide both positive and negative supply voltages
in the same circuit if necessary78xx ICs have three terminals and are most
commonly found in the TO220 form factor although smaller surface-mount and
larger TO3 packages are also available from some manufacturers These devices
typically support an input voltage which can be anywhere from a couple of volts over
the intended output voltage up to a maximum of 35 or 40 volts and can typically
provide up to around 1 or 15 amps of current (though smaller or larger packages may
have a lower or higher current rating)
Figure 531
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
56
532 BRIDGE RECTIFIER
A diode bridge is an arrangement of four diodes in a bridge configura tion that
provides the same polarity of output for either polarity of input When used in its most
common application for conversion of an alternating current (AC) input into direct
current a (DC) output it is known as a bridge rectifier A bridge rectifier provides
full-wave rectification from a two-wire AC input resulting in lower cost and weight
as compared to a rectifier with a 3-wire input from a transformer with a center-tapped
secondary winding
Figure 532
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
57
54 Flowchart
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
58
Figure 54
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
59
55 Hardware used
551 89Cxx test board kit
Figure 551
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
60
551 List of components
QTY ON PCB Componentrsquos
1 CON 1A 5 82 WAY DC TERMINAL
CON 1C DC SOCKET [OPTIONAL]
2 CON 2 3 3 PIN RELIMATE CONNECTOR
4 CON 4 5 6 7 10 PIN FRCMALE BOX TYPE
4 CON 8 9 10 11 10 PIN RELIMATE CONNECTOR
2 CON12 14 2 PIN RELIMATE CONNECTOR
2 C 1 5 33Pf DISC CAPACITOR
5 C 2 7 8 9 10 10uf 50V ELECTROLYTIC CAPACITOR
1 C 3 100uf 16V ELECTROLYTIC CAPACITOR
1 C 4 1000uf 25V ELECTROLYTIC CAPACITOR
1 DC1 01uf BOX CAPACITOR
1 D1 W04 RECTIFIER BRIDGE
1 ON OFF SPDT PCB MOUNT SLIDE SWITCH
1 P1 9 PIN DCONNECTOR FEMALE RIGHT ANGLE
1 RESET 4 PIN TACTILE MICRO SWITCH
3 R1 3 4 4K7 9PIN RESISTOR ARRAY
1 R2 8K2 14W RESISTOR
1 U1 7805 VOLTAGE REGULATOR IC
1 U2 40 PIN IC SOCKET
1 U3 IC MAX232 IC
1 U3 16 PIN IC SOCKET
1 U4 20 PIN IC SOCKET
1 Y1 110592 MHz CRYSTAL [5 ]
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
61
56 Software used
561 Keil uvision 40
Keil Software is used provide you with software development tools for 8051 based
microcontrollers With the Keil tools you can generate embedded applications for
virtually every 8051 derivative The supported microcontrollers are listed in the μ-
vision
562 Proteus Professional V76
Proteus is software for microprocessor simulation schematic capture and printed
circuit board (PCB) design It is developed by Labcenter Electronics
The XGameStation Micro Edition was designed using Labcenters Proteus schematic
entry and PCB layout tools
5621 System components
ISIS Schematic Capture - a tool for entering designs
PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5
simulator combined with a digital simulator
ARES PCB Layout - PCB design system with automatic component placer rip-up
and retry auto-router and interactive design rule checking
VSM - Virtual System Modelling lets cosimulate embedded software for popular
micro-controllers alongside hardware design
System Benefits Integrated package with common user interface and fully context
sensitive help [3]
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
62
11 REFERENCES
Sr No Name Type
1 httpwwwembedtronicscom Website
2 httpwwwedaboardcom Website
3 httpwwwwikipediaorg Website
4 httpwwwdevelopershomecom Website
5 httpwww8051projectsnet Website
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
63
PROGRAM includeltreg51hgt
includeltstringhgt
xdata unsigned char cmti[50]store message and other details in external memory
unsigned char mem[5]storing index of message
unsigned char message[9]storing full message
xdata unsigned char phno[20]
xdata unsigned char id[3]pwd[3]cand[3]revpwd[3]msg[5]pid[5]b
xdata unsigned char gsm_cmd3[15]=AT+CMGR=
xdata unsigned char gsm_cmd4[15]=AT+CMGD=
xdata unsigned char gsm_cmd5[30]=AT+CMSS=1
xdata unsigned char person1[]=01ab
xdata unsigned char person2[]=02cd
xdata unsigned char person3[]=03ef
xdata unsigned char person4[]=04gh
xdata unsigned char person5[]=05ij
xdata unsigned char gsm_cmd6[30]=AT+CMSS=2
unsigned int total=0
unsigned char c1c2c3acount for how much vote each candidate has got
unsigned int l
signed int jk
sbit LCD_D7=P2^7
sbit LCD_rs=P0^0
sbit LCD_rw=P0^1
sbit LCD_en=P0^2
prototype declaration
void init()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
64
void serialtx(unsigned char)
void trans(unsigned char )
char serialrx(void)
void acquire(void)
void extract(void)
void gsminit(void)
void phone(void)
void seperations(void)
void LCD_delay(unsigned char)
void LCD_init(void)
void LCD_set(void)
void LCD_sendcommand(unsigned char)
void LCD_senddata(unsigned char)
void LCD_sendstring(unsigned char )
void winner(void)
void gsminit(void)
unsigned char gsm_cmd1[]=AT
unsigned char gsm_cmd2[]=AT+CMGF=1
trans(rn) r-entern-new line
trans(gsm_cmd1)gsm to mc
trans(rn)
trans(gsm_cmd2)
trans(rn)
void init()
P0=0x00baud rate setting
P1=0x00
TMOD=0X20
TH1=0XFD
SCON=0X50
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
65
TR1=1
void serialtx(unsigned char x)
SBUF=x
while(TI==0)
TI=0
void trans(unsigned char x)
while(x=0)whnever space is encountered stop serial tx
serialtx(x)
x++
char serialrx(void)
while(RI==0)
RI=0
return(SBUF)
void acquire(void)
unsigned char i=0
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
66
while(SBUF=r)store indication of msg
while(RI==0)
cmti[i]=SBUF
i++
RI=0
cmti[i]=0
void extract(void)
unsigned char i=0
unsigned char j=0
while(cmti[i]=)after encountering store the details after itie the index
i++
i++
while(cmti[i]=0)
mem[j]=cmti[i]
i++
j++
mem[--j]=0
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
67
void getit() 01ab02 is stored in msg variable
unsigned char i
i=0
do
while(RI==0)
cmti[i]=SBUFphno and extra details are saved in cmti
i++
RI=0
while(SBUF=0x0D)
cmti[--i]=0
i=0
do
while(RI==0)
message[i]=SBUF
i++
RI=0
while(SBUF=0X0D)
message[--i]=0
void phone(void)
unsigned char i=0j=0
while(cmti[i]=)
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
68
i++
i++
while(cmti[i]=)
phno[j]=cmti[i]phno is bw 2 commas extract it
i++
j++
phno[--i]=0
void seperations(void)
unsigned int i
for(i=0ilt2i++)
id[i]=message[i]
pwd[i]=message[i+2]
cand[i]=message[i+4]
id[i]=0
pwd[i]=0
cand[i]=0
for(i=0ilt2i++)
revpwd[1- i]=pwd[i]
revpwd[i]=0
strcpy(pidid)
strcat(pidrevpwd)
strcpy(msgid)
strcat(msgpwd)
a=10id[0]+id[1]
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
69
void LCD_delay(unsigned char val) A simple for loop for delay of 5ms
unsigned char ijk
i = val
for (i=0iltvali++)
for(j=0jlt100j++)
for(k=0klt100k++)
void LCD_init()
LCD_delay(4) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD startup
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
70
void LCD_set()
P2=0x38 Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x08 Display off Cursor off
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x01 Clear LCD
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x06 Entry mode auto increment with no shift
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x0C Display on Cursor off
LCD_rs=0 Selected command register
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
71
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
P2=0x80 Select line 1
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in data register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendcommand(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=0 Selected command register
LCD_rw=0 We are writing in instruction register
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_senddata(unsigned char var)
P2=var Function set 2 Line 8-bit 5x7 dots
LCD_rs=1 Selected data register
LCD_rw=0 We are writing
LCD_en=1 Enable H-gtL
LCD_en=0
LCD_delay(1) Wait for LCD to process the command
void LCD_sendstring(unsigned char var)
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
72
while(var) till string ends
LCD_senddata(var++) send characters one by one
void winner(void)
j=c1-c2
k=c3-c2
if(jgt0)
j=c1-c3
if(jgt0)
l=c13
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND1)
else
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
if(klt0)
l=c23
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND2)
else
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
73
l=c33
LCD_sendcommand(0xC0)
LCD_sendstring(WINNER=CAND3)
void main()
init()
gsminit()
LCD_init()
LCD_set()
while(1)
while(serialrx()=C)
while(serialrx()=M)
while(serialrx()=T)
while(serialrx()=I)
acquire()
trans(rn)
trans(cmti)
trans(rn)
extract()
trans(mem)
trans(rn)
trans(gsm_cmd3)
trans(mem)
trans(rn)
getit()
trans(rn)
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
74
trans(message)
trans(rn)
phone()
trans(phno)
trans(rn)
trans(gsm_cmd4)
trans(mem)
trans(rn)
seperations()
trans(id)
trans(rn)
trans(pwd)
trans(rn)
trans(cand)
trans(rn)
trans(msg)
trans(rn)
trans(pid)
trans(rn)
trans(gsm_cmd5)
trans(phno)
trans(rn)
trans(gsm_cmd6)
trans(phno)
trans(rn)
switch(id[1])
case1
if(strcmp(msgperson1)==0)
if(strcmp(cand01)==0)
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
75
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson1)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
76
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case2
if(strcmp(msgperson2)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
77
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson2)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
78
break
case3
if(strcmp(msgperson3)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson3)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
79
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
case4
if(strcmp(msgperson4)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
80
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson4)==0)
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
81
else
trans(gsm_cmd6)
trans(phno)
break
case5
if(strcmp(msgperson5)==0)
if(strcmp(cand01)==0)
c1++c1++c1++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2++c2++c2++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3++c3++c3++
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(pidperson5)==0)
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
82
if(strcmp(cand01)==0)
c1--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand02)==0)
c2--
trans(gsm_cmd5)
trans(phno)
total++
else if(strcmp(cand03)==0)
c3--
trans(gsm_cmd5)
trans(phno)
total++
else
trans(gsm_cmd6)
trans(phno)
break
default
trans(gsm_cmd6)
trans(phno)
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()
83
break
for(b=0blt10b++)
LCD_sendstring( hi )
LCD_sendcommand(0xC0)
LCD_sendstring( hello )
winner()