You are on page 1of 64

CHAPTER-1

INTRODUCTION

Department of EEE, TOCE - 2016 Page 1


INTRODUCTION
A distribution transformer or service transformer is transformer that provides the final voltage transformation in
the electric power distribution system, stepping down the voltage used in the distribution lines to the level used
by the customer. Distribution transformers have a long service life if they are operated under good and rated
conditions. However, their life is significantly reduced if they are overloaded, resulting in unexpected failures and
loss of supply to a large number of customers thus effecting system reliability. Overloading and ineffective
cooling of transformers are the major causes of failure in distribution transformers. Most power companies use
SCADA (Supervisory Control And Data Acquisition) which is a system for remote monitoring and control that
operates with coded signals over communication channels for online monitoring of power transformers but
extending the SCADA system for online monitoring of distribution transformers is an expensive proposition.
Instead of scada we are using microcontroller and pic based PLC which is something like tiny PLC controller
which is possible to program in C or assembler instead of the weird PLC relay language . Distribution
transformers are currently monitored manually where a person periodically visits a transformer site for
maintenance and records parameter of importance. This type of monitoring cannot provide information about
occasional overloads and overheating of transformer. All these factors can significantly reduce transformer life.
our system is designed based upon online monitoring of key operational parameters of distribution transformers
can provide useful information about the health of transformers which will help the utilities to optimally use their
transformers and keep the asset in operation for a longer period to avoid this we are receiving parameters like
voltage, current, temperature via GSM (Global System for Mobile communication), which is a digital mobile
telephony system that is widely used in India and other parts of the world. GSM uses a variation of time division
multiple access This system will help us to identify problems before any catastrophic failure. Thus, resulting in a
long life service for transformers. This system is based on plc with pc interface. It is also has the advantages of
significant cost savings, power consumption, easy access and greater reliability.

Department of EEE, TOCE - 2016 Page 2


CHAPTER- 2
HARDWARE DESCRIPTION

Department of EEE, TOCE - 2016 Page 3


2.1 BLOCK DIAGRAM

Department of EEE, TOCE - 2016 Page 4


2.2 HARDWARE SPECIFICATION:-

COMPONENTS NAME SPECIFICATIONS & RATING


TRANSFORMER Primary:
180V-240V
5A/ 50Hz

Secondary:
12V-0-12V
1A/50Hz

GSM SIM900
3.3V/1A
AT Commands
FAN(BLDC MOTOR) 5v/100Ma
BUZZER Sound 5dB
5V/30mA
TEMPERATURE SENSOR LM35
Voltage +35V to −0.2V
Output Voltage +6V to −1.0V
Output Current 10 Ma
Storage Temp.;
TO-46 Package, −60˚C to +180˚C
TO-92 Package, −60˚C to +150˚C
TO-8 Package, −65˚C to +150˚C
TO-220 Package, −65˚C to +150˚C

VOLTAGE SENSOR
GEAR MOTORS 60RPM 12V/1A/50Hz
Department of EEE, TOCE - 2016 Page 5
60RPM 12V/1A/50Hz
10RPM 12V/1A/50Hz
MICROCONTROLLER
LCD DISPLAY 16×2 Text type LCD
RELAY Single channel ,5V/42mA

2.3 BLOCK DIAGRAM EXPLAINATION


2.3.1 POWER SUPPLY UNIT

Step Down Bridge Filter Regulator


Transformer Rectifier Circuit section

FIG.2.2.PSU

Summary of circuit features


Brief description of operation: Gives out well regulated +5V output, output current capability of 100 mA
Circuit protection: Built-in overheating protection shuts down output when regulator IC gets too hot Circuit
complexity: Very simple and easy to build.

Circuit performance:
Very stable +5V output voltage, reliable operation Availability of components: Easy to get, uses only very
common basic components Design testing: Based on datasheet example circuit, I have used this circuit

Department of EEE, TOCE - 2016 Page 6


successfully as part of many electronics projects Applications: Part of electronics devices, small laboratory power
supply Power supply voltage: Unregulated DC 8-18V power supply Power supply current: Needed output current
+ 5 mA Component costs: Few dollars for the electronics components + the input transformer cost.

Calculations of values of capacitors for 5V DC power supply


First of all in addition to these components you would need a step down transformer in order to make the
full-wave rectified output voltage of your bridge rectifier small enough. You can't feed the rectified 220 V,
directly to LM7805, because LM7805 operates in the input ranges of 7 V to 20 V ( and has a maximum input
rating of 35 V).
If we assume that step down transformer reduces the amplitude of 60 Hz sine wave from 220 V to 15 V,
and if we assume that your 5 V power supply will need to output at most I_max = 1 A current, then we can start
making some calculations. We need reservoir capacitor, which will be placed after the bridge rectifier, will have
V_max = 15V on it, which is the amplitude of your sine wave.
From fig see that capacitor discharges during almost the whole period of half-wave rectified wave (in our
case this discharge is caused by the I_max = 1 A load current going into LM7805). The discharge time of
reservoir capacitor in the case of half-wave rectifier is

Tdischarge = T = (1/f) = (1/60 Hz) = 16.6 ms,

however, notice that, in our case we have a more sophisticated rectifier ( Diode bridge) which gives a full-wave
rectified output. So, the discharge time will be

T_discharge = T/2 = (1/2*f) = 8.3 ms.

Now, at the beginning of each discharge period our capacitor is charged up to Vmax=15V. In order to prevent our
capacitor voltage going below Vmin = 7 V (which is the lowest input operating point for LM7805 voltage
regulator) in the end of the discharge period, our capacitor value should be chosen with the equation:

C >= (I_max*T_discharge)/(V_beforedischarge-V_afterdischarge)

Using the values;


Vbeforedischarge = Vmax = 15 V
Vafterdischarge = Vmin = 7 V
Department of EEE, TOCE - 2016 Page 7
Imax = 1 A
Tdischarge = 8.3 ms
we can calculate that:

We can see that if we use a step down transformer which reduces the 230 V input into 20 V instead of 15 V and if
your power supply will require at most Imax = 0.5 A current, we can use an even smaller capacitance with the
value: Cmin = (0.5 A)*(8.3 ms)/(20 V - 7 V) = 0.32 mF
we can see an example design which uses LM7805 just like you are, and they picked a capacitor value of 0.47
mF, which is close to the values we calculated above.Capacitor value should be large enough that it can provide
enough voltage(+2 volts means 7v for 7805) to the regulator IC, means voltage across capacitor should not go
below 7v. I have found a article where Capacitance calculation has been explained well,it may be useful for
others,

Circuit description
This circuit is a small +5V power supply, which is useful when experimenting with digital electronics, and
easy to build. Small inexpensive wall tranformers with variable output voltage are available from any electronics
shop and supermarket. Those transformers are easily available, but usually their voltage regulation is very poor,
which makes then not very usable for digital circuit experimenter unless a better regulation can be achieved in
some way. The following circuit is the answer to the problem.
This circuit can give +5V output at about 150 mA current, but it can be increased to 1 A when good cooling
is added to 7805 regulator chip. The circuit has over overload and terminal protection.
The capacitors must have enough high voltage rating to safely handle the input voltage feed to circuit. The circuit
is very easy to build for example into a piece of veroboard

Department of EEE, TOCE - 2016 Page 8


FIG.2.3.Circuit diagram of the power supply

FIG.2.4.Pinout of the 7805 regulator IC.

Component list
1. 7805 regulator IC
2. 100 uF electrolytic capacitor, at least 25V voltage rating
3. 10 uF electrolytic capacitor, at least 6V voltage rating
4. 100 nF ceramic or polyester capacitor
5. If you need more than 150 mA of output current, you can update the output current up to 1A doing the
following modifications.
6. Change the transformer from where you take the power to the circuit to a model which can give as much
current as you need from output.
7. Put a heatsink to the 7805 regulator (so big that it does not overheat because of the extra losses in the
Department of EEE, TOCE - 2016 Page 9
regulator)

2.3.2 DISTRIBUTION TRANSFORMER

Department of EEE, TOCE - 2016 Page 10


FIG.2.12.DISTRIBUTION TRANSFORMER
A distribution transformer or service transformer is a transformer that provides the final voltage
transformation in the electric power distribution system, stepping down the voltage used in the distribution lines
to the level used by the customer. The invention of a practical efficient transformer made AC power distribution
feasible; a system using distribution transformers was demonstrated as early as 1882.
If mounted on a utility pole, they are called pole-mount transformers. If the distribution lines are located at
ground level or underground, distribution transformers are mounted on concrete pads and locked in steel cases,
thus known as pad-mount transformers
Distribution transformers normally have ratings less than 200 kVA, although some national standards can
describe units up to 5000 kVA as distribution transformers. Since distribution transformers are energized for 24
hours a day (even when they don't carry any load), reducing iron losses has an important role in their design. As
they usually don't operate at full load, they are designed to have maximum efficiency at lower loads. To have a
better efficiency, voltage regulation in these transformers should be kept to a minimum. Hence they are designed
to have small leakage reactance.

Department of EEE, TOCE - 2016 Page 11


Fig:-PARTS OF TRANSFORMER
Distribution transformers are made using a core made from laminations of sheet steel stacked and either glued
together with resin or banded together with steel straps. Where large numbers of transformers are made to
standard designs, a wound C-shaped core is economic to manufacture. A steel strip is wrapped around a former,
pressed into shape and then cut into two C-shaped halves, which are re-assembled on the copper windings.
The primary coils are wound from enamel coated copper or aluminum wire and the high current, low
voltage secondaries are wound using a thick ribbon of aluminum or copper. The windings are insulated with
resin-impregnated paper. The entire assembly is baked to cure the resin and then submerged in a powder coated
steel tank which is then filled with transformer oil (or other insulating liquid), which is inert and non-conductive.
The transformer oil cools and insulates the windings, and protects the transformer winding from moisture, which
will float on the surface of the oil. The tank is temporarily depressurized to remove any remaining moisture that
would cause arcing and is sealed against the weather with a gasket at the top.
Formerly, distribution transformers for indoor use would be filled with a polychlorinated biphenyl (PCB)
liquid. Because these liquids persist in the environment and have adverse effects on animals, they have been
banned. Other fire-resistant liquids such as silicones are used where a liquid-filled transformer must be used
indoors. Certain vegetable oils have been applied as transformer oil; these have the advantage of a high fire point
and are completely biodegradable in the environment.Pole-mounted transformers often include accessories such
as surge arresters or protective fuse links. A self-protected transformer includes an internal fuse and surge

Department of EEE, TOCE - 2016 Page 12


arrester; other transformers have these components mounted separately outside the tank. Pole-mounted
transformers may have lugs allowing direct mounting to a pole, or may be mounted on crossarms bolted to the
pole. Aerial transformers, larger than around 75 Kva, may be mounted on a platform supported by one or more
poles.A three-phase service may use three identical transformers, one per phase.Transformers designed for
below-grade installation can be designed for periodic submersion in water. Distribution transformers may include
an off-load tap changer to allow slight adjustment of the ratio between primary and secondary voltage, to bring
the customer voltage within the desired range on long or heavily loaded lines.
Pad-mounted transformers have secure locked and bolted grounded metal enclosures to discourage
unauthorized access to live internal parts. The enclosure may also include fuses, isolating switches, load-break
bushings, and other accessories as described in technical standards. Pad-mounted transformers for distribution
systems typically range from around 100 to 2000 Kva, although some larger units are also used.

2.3.3 COOLING FAN-BLDC MOTOR

The Cooling Fans are designed for long and dependable service for use in cooling transformers
and other equipment. The Fans are intended mainly for outside use and are designed and
manufactured to withstand harsh weather conditions. They have an excellent performance record
and proven reliability. These are operated only if transformer gets overheated ,the program is
made to run the fan for the predefined voltage practically these fans are fitted to transformers as
shown in below figure.

Department of EEE, TOCE - 2016 Page 13


2.3.4 LIQUID CRYSTAL DISPLAY (LCD)
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of
applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and
circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being:
LCDs are economical; easily programmable; have no limitation of displaying special & even custom (unlike in
seven segments), animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2
such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely,
Command and Data. The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value
of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.

Pin Diagram:

Department of EEE, TOCE - 2016 Page 14


Pin Description:

Pin No Function Name


1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
3 Contrast adjustment; through a variable resistor VEE
4 Selects command register when low; and data register when Register Select
5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulse is given Enable
7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led-

2.3.5 GSM(Global system for mobile communication)

Department of EEE, TOCE - 2016 Page 15


Introduction:

GSM (Global System for Mobile) / GPRS (General Packet Radio Service) TTL -Modem is SIM900 Quad-
band GSM / GPRS device, works on frequencies 850 MHZ, 900 MHZ, 1800 MHZ and 1900 MHZ. It is very
compact in size and easy to use as plug in GSM Modem. The Modem is designed with 3V3 and 5V DC TTL
interfacing circuitry, which allows User to directly interface with 5V Microcontrollers (PIC, AVR, Arduino, 8051,
etc.) as well as 3V3 Microcontrollers (ARM, ARM Cortex XX, etc.). The baud rate can be configurable from
9600115200 bps through AT (Attention) commands. This GSM/GPRS TTL Modem has internal TCP/IP stack to
enable User to connect with internet through GPRS feature. It is suitable for SMS as well as DATA transfer
application in mobile phone to mobile phone interface. The modem can be interfaced with a Microcontroller using
USART (Universal Synchronous Asynchronous Receiver and Transmitter) feature (serial communication). Global
system for mobile communication (GSM) is a globally accepted standard for digital cellular communication. GSM is
the name of a standardization group established in 1982 to create a common European mobile telephone standard that
would formulate specifications for a pan-European mobile cellular radio system operating at 900 MHz. It is
estimated that many countries outside of Europe will join the GSM Partnership. GSM was devised as a cellular
system specific to the 900 MHz band, called "The Primary Band". The primary band includes two sub bands of 25
MHz each, 890 to 915 MHz and 935 MHz to 960 MHz. GSM-PLMN has allocated 124 duplex carrier frequencies
over the following bands of operation.

 Uplink frequency band: 890 to 915 MHz(MS transmits , BTS receives).


 Downlink frequency band: 935 to 960 MHz(BTS transmits ,MS receives).
 Carrier spacing :- 200 KHz.

Department of EEE, TOCE - 2016 Page 16


Architecture of the GSM network
A GSM network is composed of several functional entities, whose functions and interfaces are
specified. Figure 1 shows the layout of a generic GSM network. The GSM network can be divided into
three broad parts. The Mobile Station is carried by the subscriber. The Base Station Subsystem controls the
radio link with the Mobile Station. The Network Subsystem, the main part of which is the Mobile services
Switching Center (MSC), performs the switching of calls between the mobile users, and between mobile
and fixed network users. The MSC also handles the mobility management operations. The Mobile Station
and the Base Station Subsystem communicate across the Um interface, also known as the air interface or
radio link. The Base Station Subsystem communicates with the Mobile services Switching Center across
the A interface.

Department of EEE, TOCE - 2016 Page 17


Mobile Station

The mobile station (MS) consists of the mobile equipment (the terminal) and a smart card called the Subscriber
Identity Module (SIM). The SIM provides personal mobility, so that the user can have access to subscribed services
irrespective of a specific terminal. By inserting the SIM card into another GSM terminal, the user is able to receive
calls at that terminal, make calls from that terminal, and receive other subscribed services.

The mobile equipment is uniquely identified by the International Mobile Equipment Identity (IMEI). The SIM
card contains the International Mobile Subscriber Identity (IMSI) used to identify the subscriber to the system, a
secret key for authentication, and other information. The IMEI and the IMSI are independent, thereby allowing
personal mobility. The SIM card may be protected against unauthorized use by a password or personal identity
number.

Base Station Subsystem

The Base Station Subsystem is composed of two parts, the Base Transceiver Station (BTS) and the Base Station
Controller (BSC). These communicate across the standardized Abis interface, allowing (as in the rest of the system)
operation between components made by different suppliers.

The Base Transceiver Station houses the radio transceivers that define a cell and handles the radio-link
protocols with the Mobile Station. In a large urban area, there will potentially be a large number of BTSs
deployed, thus the requirements for a BTS are ruggedness, reliability, portability, and minimum cost.

Department of EEE, TOCE - 2016 Page 18


The Base Station Controller manages the radio resources for one or more BTSs. It handles radio-
channel setup, frequency hopping, and handovers. The BSC is the connection between the mobile station
and the Mobile service Switching Center (MSC).

Network Subsystem

The central component of the Network Subsystem is the Mobile services Switching Center (MSC). It acts like
a normal switching node of the PSTN or ISDN, and additionally provides all the functionality needed to handle a
mobile subscriber, such as registration, authentication, location updating, handovers, and call routing to a roaming
subscriber. The MSC provides the connection to the fixed networks (such as the PSTN or ISDN). Signaling between
functional entities in the Network Subsystem uses Signaling System Number 7 (SS7), used for trunk signaling in
ISDN and widely used in current public networks.

The Home Location Register (HLR) and Visitor Location Register (VLR), together with the MSC,
provide the call-routing and roaming capabilities of GSM. The HLR contains all the administrative
information of each subscriber registered in the corresponding GSM network, along with the current
location of the mobile. The location of the mobile is typically in the form of the signalling address of the
VLR associated with the mobile station. There is logically one HLR per GSM network, although it may be
implemented as a distributed database.

The Visitor Location Register (VLR) contains selected administrative information from the HLR,
necessary for call control and provision of the subscribed services, for each mobile currently located in the
geographical area controlled by the VLR. The geographical area controlled by the MSC corresponds to that
controlled by the VLR. Note that the MSC contains no information about particular mobile stations --- this
information is stored in the location registers.

The other two registers are used for authentication and security purposes. The Equipment Identity
Register (EIR) is a database that contains a list of all valid mobile equipment on the network, where each
mobile station is identified by its International Mobile Equipment Identity (IMEI). An IMEI is marked as
invalid if it has been reported stolen or is not type approved. The Authentication Center (AuC) is a
protected database that stores a copy of the secret key stored in each subscriber's SIM card, which is used
for authentication and encryption over the radio channel.

Department of EEE, TOCE - 2016 Page 19


Features:

 Quad Band GSM/GPRS : 850 / 900 / 1800 / 1900 MHz


 Built in RS232 to TTL or viceversa Logic Converter (MAX232)
 Configurable Baud Rate
 SMA (SubMiniature version A) connector with GSM L Type Antenna
 Built in SIM (Subscriber Identity Module) Card holder · Built in Network Status LED
 Inbuilt Powerful TCP / IP (Transfer Control Protocol / Internet Protocol) stack for internet
data transfer through GPRS (General Packet Radio Service)
 Audio Interface Connectors (Audio in and Audio out)
 Most Status and Controlling pins are available
 Normal Operation Temperature : -20 °C to +55 °C
 Input Voltage : 5V to 12V DC

 LDB9 connector (Serial Port) provided for easy interfacing

Hardware Description

SIMCom SIM900A GSM Module:

This is actual SIM900 GSM module which is manufactured by SIMCom. Designed for global market,
SIM900 is a quad-band GSM/GPRS engine that works on frequencies GSM 850MHz, EGSM 900MHz,
DCS 1800MHz and PCS 1900MHz. SIM900 features GPRS multislot class 10/ class 8 (optional) and
supports the GPRS coding schemes CS-1, CS-2, CS-3 and CS-4. With a tiny configuration of 24mm x
24mm x 3mm, SIM900 can meet almost all the space requirements in User’s applications, such as M2M,
smart phone, PDA and other mobile devices.

MAX232 IC:

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, so that devices works on TTL logic can share the
data with devices connected through Serial port (DB9 Connector).

Serial port / DB9 connector:

Department of EEE, TOCE - 2016 Page 20


User just needs to attach RS232 cable here so that it can be connected to devices which has Serial
port / DB9 Connector.

Power Supply Socket:

This power supply socket which actually named as AC/DC Socket provides the functionality to user to
connect external power supply from Transformer, Battery or Adapter through DC jack. User can provide
maximum of 12V AC/DC power supply through AC/DC socket. This is power supply designed into
maximum protection consideration so that it can even prevent reverse polarity DC power supply as well as
DC conversion from AC power Supply. It also includes LM317 Voltage Regulator which provides an
output voltage adjustable over a1.2V to 37

Power On/Off and GSM On Switch:

Power On/Off switch is type of push-on push-off DPDT switch which is used for only make power
supply on/off provided through AC/DC Socket indicated by ‘Power LED’. GSM On Switch is type of Push
on DPST tactile switch which is used for only to make GSM module ‘On’ indicated by ‘Module On/Off
LED’ while initiating with Network indicated by ‘Network Indication LED’.

SIM (Subscriber Identity Module) Card Slot:

This onboard SIM card slot provide User functionality of insert a SIM (GSM only) card of any
service provider. Process of inserting and locking SIM card into SIM card slot is given in this manual.
While inserting in and removing out SIM card from SIM card slot, User needs to take precaution that
power supply should be OFF so that after making Power supply ON it will be easy to reinitialize with SIM
for this module.

Indicator LEDs:

Indicator LEDs just used to indicate status accordingly. These are three LEDs represents Power
On/Off Status, Network Status and Module On/Off Status respectively. Power LED will keep on until the
power supply is enable to this board by using push-on push-off switch. Network Status LED will show
whether inserted SIM card successfully connected to service provider’s Network or not, in short signal
strength. Module On/Off indicator LED will show status of GSM module’s power on/off.

Department of EEE, TOCE - 2016 Page 21


RXD, TXD and GND pins (JP2):

These pins are used to connect devices which needs to be connected to GSM module through USART
(Universal Synchronous Asynchronous Receiver and Transmitter) communication. Devices may be like
Desktop or Laptop Computer System, Microcontrollers, etc. RXD (Receive Data) should be connected to
TXD (Transmit Data) of other device and viceversa, whereas GND (Ground) should be connected to other
device’s GND pin to make ground common for both systems

Audio Connectors:
Audio Connectors deals with Audio related operations. These pins already shown in hardware description
diagram. These are eight pins in a group of two each denoted by SV4. GND (0V Supply) and VCC (+5V Supply)
are used to have source for external device. MIC+ and MIC- used to connect Microphone (abbr. as Mic) through
which user can give audio input while calling. SP- and SP+ used to connect Speaker (can be connected to
amplifier circuit if necessary) through which User can hear audio output. LN-L and LN-R used to connect Line in
to GSM module.

Debugger (DBG-R and DBG-T) Connectors (J2):


These connectors are 2-wire null modem interface DBG_TXD and DBG_RXD. These pins can be used for
debugging and upgrading firmware. User generally no need to deal with these pins

Inserting SIM card into SIM card Slot/Holder:


Here is the process how to insert SIM card into SIM card slot. User just need to unlock SIM card cover by
sliding back. Then user need to open this cover and insert SIM card according to slot. Put down cover on SIM
card and then lock by sliding forward.

Department of EEE, TOCE - 2016 Page 22


Power On/Off and Module On/Off process:
Here is the process how User should make power supply on/off and module on/off. First of all User need to
connect external power supply by using Battery / Adapter / Transformer. Now User needs to press Power On/Off
switch (It is push-on push-off switch, thus User need to push it to make power on and push it again to make
power supply off). Two LEDs will glow, one is Power On/Off indicator LED and another one is Network Status
LED (which glows continuous to indicate no network or searching for network). After this User needs to press
Module on switch (denoted as PWR) for at least 2 seconds. As soon as Module On/Off LED will glow User can
release this switch, Network LED will blink to indicate signal strength.

Note: If message sending, receiving, calling functions are failed due to weak signal strength then User needs to
check SIM card’s service provider’s availability in coverage area, its not mean that GSM Module is not working
properly

Connecting GSM module with RS232 (SB9-DB9) Serial Cable:


User can connect GSM interfacing board either through Serial port or through Serial to USB converter.
Here is process to connect RS232 cable to GSM interfacing board.

Connecting GSM Module with Serial to USB converter through RXD, TXD and GND:

Department of EEE, TOCE - 2016 Page 23


This module is designed in a way so that User can connect this module without Serial cable, this module can
be connected to any of Serial to USB converter module or cable. Here we have shown demo how to connect this
interfacing board with CP2102 Serial to USB converter Module through RXD, TXD and GND. Connect CP2102
Serial to USB converter module to PC through USB cable, connect one end of USB cable to PC’s USB connector
and connect another end of USB to CP2102 module’s USB connector

Connect three Single Berg Wires to CP2102 modules’s RXD, TXD and GND pin. Then connect RXD wire to
TXD of GSM module and TXD wire to RXD of GSM module. Make GND common by connecting GND wire to
GND pin of GSM module.

Testing GSM Module on Terminal Software: Terminal software used share the data through Serial port.
Hence here also User need this software to test GSM module. For demo purpose we are going to show demo for
how to send SMS and how to dial a call through ‘Realterm’ software. First of all install Realterm, it will create
its own shortcut on Desktop. Then double click on Realterm icon.

Window will appear.

Department of EEE, TOCE - 2016 Page 24


Select Baud Rate as ‘9600’.

Select COM port through


which GSM module is
connected. (This can be known
from ‘Computer Management
> Device Manager’)

Department of EEE, TOCE - 2016 Page 25


Click on ‘Open’ to open the port or to start communication. Click on Change button.

To initialize GSM module type ‘AT’ in capital letters and then press enter key on keyboard. If there are no errors
occur in this communication then it will send ‘OK

Department of EEE, TOCE - 2016 Page 26


To send SMS type following commands AT+CMGF=1, press enter key, It will return ‘OK’ then proceed,
AT+CMGS=“9876543210” <user can put any 10 digit number> type message after getting letter ‘>’ after end of
SMS press Ctrl+z on keyboard If it returns ‘+CMGS: 203’ (or any other number)‘OK’ then SMS sent
successfully.

Department of EEE, TOCE - 2016 Page 27


2.3.6. RELAY

Department of EEE, TOCE - 2016 Page 28


A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism,
but other operating principles are also used. Relays find applications where it is necessary to control a circuit by a
low-power signal, or where several circuits must be controlled by one signal. The first relays were used in long
distance telegraph circuits, repeating the signal coming in from one circuit and re-transmitting it to another.
Relays found extensive use in telephone exchanges and early computers to perform logical operations. A type of
relay that can handle the high power required to directly drive an electric motor is called a contactor. Solid-state
relays control power circuits with no moving parts, instead using a semiconductor device triggered by light to
perform switching. Relays with calibrated operating characteristics and sometimes multiple operating coils are
used to protect electrical circuits from overload or faults; in modern electric power systems these functions are
performed by digital instruments still called "protection relays".

Relay Controller

This board allows you to control high voltage and high current loads with your microcontroller project. This
board is fully assembled with standard spaced mounting holes for easy integration into your new or existing
projects. Simply connect your low voltage and high voltage leads, and start controlling your robotics, household
automation, or other controller dependent projects right out of the box! This board is great for applications where
you want to safely isolate your microcontroller logic from your high voltage or high current circuits (and the
noise they create for) up to 2 channels. The Quick-Relay 2 board is small (2” x 2” x 0.75“ tall), with an integrated
circuit that protects your microcontroller from any kickback voltages that may occur from inductive loads in your
switched circuits. This board is capable of controlling two channels, using up to 12 volts to switch 120VAC,

Department of EEE, TOCE - 2016 Page 29


240VAC, or 30VDC – compatible for use with all common microcontrollers in the hobbyist market. Features
high quality components - includes a heavy duty PCB with high current traces, heavy duty connectors that are
capable of handling larger wires, sealed relays, and protection circuitry that will keep your microcontroller safe
and your project running without fail.

Features:
• High quality components.
• Heavy duty PCB and traces to ensure reliable performance.
• High capacity connectors to accommodate larger gauge wire.
• Small form factor (2” x 2” x 0.75”) featuring four (4) 0.15” mounting holes.
• LED indicator for each channel
• Made in the U.S.A.

Specifications:

•Compatible with 3.3v and 5v logic


•SPDT 12v sealed Omron relays
•Minimum input of 1.2v for switching
•Typical supply voltage: 12v (9v min.)

•Maximum switching voltage: 250v/125v


•Maximum switching current: 10A AC/8A DC
•Operating time: 10ms
•Release time: 5ms
•Life expectancy: 10,000,000 cycles •Operating
Temperature: -40˚C to 85˚C
•Input terminal block accepts up to 16AWG wire
•Relay terminal block accepts up to 14AWG wire

How to use this controller:

•Connect +12Vdc and Ground to the marked pins.


•Connect Channel 1 and Channel 2 to different pins on your microcontroller
Department of EEE, TOCE - 2016 Page 30
•VCC to the common terminal (COM).
•Connect positive input of your load into the normally open () or normally closed () output from channel 1 or channel
2, depending on your desired behavior.
•Connect the return side of your load to ground.
•When the controlling pin voltage runs HIGH, current will flow from the common terminal (COM) through the
normally open (NO) pin and will not flow through the normally closed (NC) pin on either channel.
•When the controlling pin voltage is set LOW, current will flow from the common terminal (COM) through
the normally closed (NC) and will not flow through the normally open (NO) pin.

2.3.7. BUZZER

Features

 sealed: yes
 operating power: 3-6V DC / 25mA
 extremely compact, ultrathin construction
 no electrical noise
 low current consumption yet high sound pressure level

Specifications

 tone type: single


 operating voltage: 3-6V DC

Department of EEE, TOCE - 2016 Page 31


 rated voltage: 5V DC
 current consumption: 25mA
 osc. frequency: 3.2kHz
 sound level: 87dB
 connector type: pcb
 body color: gray
 weight: 0.056oz

2.3.8 SENSORS

TEMPRATURE SENSOR(LM35)

PIN DIAGRAM:-

Pin Description:

Pin No Function Name


1 Supply voltage; 5V (+35V to -2V) Vcc
2 Output voltage (+6V to -1V) Output
3 Ground (0V) Ground

Department of EEE, TOCE - 2016 Page 32


RATING
 Supply Voltage +35V to −0.2V
 Output Voltage +6V to −1.0V
 Output Current 10 mA Storage Temp.;
 TO-46 Package, −60˚C to +180˚
 TO-92 Package, −60˚C to +150˚C
 TO-8 Package,−65˚C to +150˚C
 TO-220 Package, −65˚C to +150˚C
 Lead Temp.
 TO-46 Package, (Soldering, 10 seconds) 300˚C

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor
circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can
be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than
0.1 oC temperature rise in still air.
 

The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to
every oC rise/fall in ambient temperature,i.e., its scale factor is 0.01V/ oC.

The LM35 can be applied easily in the same way as other integrated-circuit temperature sensors.
It can be glued or cemented to a surface and its temperature will be within about 0.01˚C of the
surface temperature. This presumes that the ambient air temperature is almost the same as the
surface temperature; if the air temperature were much higher or lower than the surface
temperature, the actual temperature of the LM35 die would be at an intermediate temperature
between the surface temperature and the air temperature. This is expecially true for the TO-92
plastic package, where the copper leads are the principal thermal path to carry heat into the
device, so its temperature might be closer to the air temperature than to the surface temperature.
To minimize this problem, be sure that the wiring to the LM35, as it leaves the device, is held at
the same temperature as the surface of interest. The easiest way to do this is to cover up these

Department of EEE, TOCE - 2016 Page 33


wires with a bead of epoxy which will insure that the leads and wires are all at the same
temperature as the surface, and that the LM35 die’s temperature will not be affected by the air
temperature.

These devices are sometimes soldered to a small light-weight heat fin, to decrease the
thermal time constant and speed up the response in slowly-moving air. On the other hand, a small
thermal mass may be added to the sensor, to give the steadiest reading despite small deviations in
the air temperature.

2.3.9 8051 MICROCONTROLLER


2.3.9.1 INTRODUCTION
A decade back the process and control operations were totally implemented by the Microprocessors only. But
now a days the situation is totally changed and it is occupied by the new devices called Microcontroller. The
development is so drastic that we can’t find any electronic gadget without the use of a microcontroller. This
microcontroller changed the embedded system design so simple and advanced that the embedded market has
become one of the most sought after for not only entrepreneurs but for design engineers also.

What is a Microcontroller?

A single chip computer or A CPU with all the peripherals like RAM, ROM, I/O Ports, Timers ,
ADCs etc... on the same chip. For ex: Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X etc…
A microcontroller is a highly integrated single chip, which consists of on chip CPU (Central Processing
Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable Programmable Read Only Memory),
I/O (input/output) – serial and parallel, timers, interrupt controller. For example, Intel 8051 is 8-bit
microcontroller and Intel 8096 is 16-bit microcontroller. The block diagram of Microcontroller is shown in Fig.2.

Department of EEE, TOCE - 2016 Page 34


Fig.2.Block Diagram of a Microcontroller

Department of EEE, TOCE - 2016 Page 35


Features
• Compatible with MCS ® -51 Products
• 8K Bytes of In-System Programmable (ISP) Flash Memory
-Endurance: 10,000 Write/Erase Cycles
• 4.0V to 5.5V Operating Range
• Fully Static Operation: 0 Hz to 33 MHz
• Three-level Program Memory Lock
• 256 x 8-bit Internal RAM
• 32 Programmable I/O Lines
• Three 16-bit Timer/Counters
• Eight Interrupt Sources
• Full Duplex UART Serial Channel
• Low-power Idle and Power-down Modes
• Interrupt Recovery from Power-down Mode
• Watchdog Timer
• Dual Data Pointer
• Power-off Flag
• Fast Programming Time
• Flexible ISP Programming (Byte and Page Mode)
• Green (Pb/Halide-free) Packaging Option

Description
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system
programmable Flash memory. The device is manufactured using Atmel’s high-density nonvolatile memory
technology and is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip Flash
allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory
programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the
Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to
many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash,
256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-
level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the
AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable

Department of EEE, TOCE - 2016 Page 36


power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and
interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the
oscillator, disabling all other chip functions until the next interrupt or hardware reset.

2. Pin Configurations

Block Diagram

Department of EEE, TOCE - 2016 Page 37


Department of EEE, TOCE - 2016 Page 38
4. Pin Description
1. VCC-Supply voltage.
2. GND-Ground.
3. Port 0
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When
1s are written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be
the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode,
P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes
during program verification. External pull-ups are required during program verification.
Department of EEE, TOCE - 2016 Page 39
4. Port 1
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL
inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pull-ups and can be used as inputs.
As inputs, Port 1 pins that are externally being pulled low will source current (I IL ) because of the internal pull-
ups.In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the
timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the following table.Port 1 also receives the
low-order address bytes during Flash programming and verification.

5. Port 2
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers cansink/source four TTL
inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pull-ups and can be used as inputs.
As inputs, Port 2 pins that are externally being pulled low will source current (I IL ) because of the internal
pullups.Port 2 emits the high-order address byte during fetches from external program memory and during
accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses
strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.Port 2 also receives the high-order
address bits and some control signals during Flash programming and verification.
Port Pin Alternate Functions
P1.0 T2 (external count input to Timer/Counter 2), clock-out
P1.1 T2EX (Timer/Counter 2 capture/reload trigger and direction control)
P1.5 MOSI (used for In-System Programming)
P1.6 MISO (used for In-System Programming)
P1.7 SCK (used for In-System Programming)
6. Port 3

Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL
inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pull-ups and can be used as inputs.
As inputs, Port 3 pins that are externally being pulled low will source current (I IL ) because of the pullups. Port 3
Department of EEE, TOCE - 2016 Page 40
receives some control signals for Flash programming and verification.Port 3 also serves the functions of various
special features of the AT89S52, as shown in the following table.

7. RST
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin
drives high for 98 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH)
can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.
8. ALE/PROG
Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during
accesses to external memory. This pin is also the program pulse input (PROG) during Flash
programming.In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator
frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is
skipped during each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of
SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin
is weakly pulled high Setting the ALE-disable bit has no effect if the microcontroller is in external execution
mode.

9. PSEN
Program Store Enable (PSEN) is the read strobe to external program memory.When the AT89S52 is executing
code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN
activations are skipped during each access to external data memory.
10. EA/VPP
Department of EEE, TOCE - 2016 Page 41
External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external
program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA
will be internally latched on reset. EA should be strapped to V CC for internal program executions.This pin also
receives the 12-volt programming enable voltage (V PP ) during Flash programming.

11. XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
12. XTAL2
Output from the inverting oscillator amplifier.

Special Function Registers


A map of the on-chip memory area called the Special Function Register (SFR) space is shown in Table 5-1.Note
that not all of the addresses are occupied, and unoccupied addresses may not be implemented on the chip. Read
accesses to these addresses will in general return random data, and write accesses will have an indeterminate
effect. User software should not write 1s to these unlisted locations, since they may be used in future products to
invoke new features. In that case, the reset or inactive values of the new bits will always be 0.

Timer 2 Registers:
Control and status bits are contained in registers T2CON (shown in Table 5-2) and T2MOD (shown in Table 10-
2) for Timer 2. The register pair (RCAP2H, RCAP2L) are the Capture/Reload registers for Timer 2 in 16-bit
capture mode or 16-bit auto-reload mode.Interrupt Registers: The individual interrupt enable bits are in the IE
register. Two priorities can be set for each of the six interrupt sources in the IP register

Memory Organization
MCS-51 devices have a separate address space for Program and Data Memory. Up to 64K
bytes each of external Program and Data Memory can be addressed.

Program Memory
If the EA pin is connected to GND, all program fetches are directed to external memory.On the AT89S52, if EA
Department of EEE, TOCE - 2016 Page 42
is connected to V CC , program fetches to addresses 0000H through 1FFFH are directed to internal memory and
fetches to addresses 2000H through FFFFH are to external memory.

Data Memory
The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the
Special Function Registers. This means that the upper 128 bytes have the same addresses as the SFR space but
are physically separate from SFR space.When an instruction accesses an internal location above address 7FH, the
address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR
space. Instructions which use direct addressing access the SFR space. For example, the following direct
addressing instruction accesses the SFR at location 0A0H(which is P2).
MOV 0A0H, #data
Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, thefollowing indirect
addressing instruction, where R0 contains 0A0H, accesses the data byte ataddress 0A0H, rather than P2 (whose
address is 0A0H).
MOV @R0, #data
Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available
as stack space.

Watchdog Timer (One-time Enabled with Reset-out)


The WDT is intended as a recovery method in situations where the CPU may be subjected to software upsets. The
WDT consists of a 14-bit counter and the Watchdog Timer Reset (WDTRST) SFR. The WDT is defaulted to
disable from exiting reset. To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST
register (SFR location 0A6H). When the WDT is enabled, it will increment every machine cycle while the
oscillator is running. The WDT timeout period is dependent on the external clock frequency. There is no way to
disable the WDT except through reset (either hardware reset or WDT overflow reset). When WDT overflows, it
will drive an output RESET HIGH pulse at the RST pin.

Using the WDT


To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location

Department of EEE, TOCE - 2016 Page 43


0A6H). When the WDT is enabled, the user needs to service it by writing 01EH and 0E1H to WDTRST to avoid
a WDT overflow. The 14-bit counter overflows when it reaches 16383 (3FFFH), and this will reset the device.
When the WDT is enabled, it will increment every machine cycle while the oscillator is running. This means the
user must reset the WDT at least every 16383 machine cycles. To reset the WDT the user must write 01EH and
0E1H to WDTRST. WDTRST is a write-only register. The WDT counter cannot be read or written. When WDT
overflows, it will generate an output RESET pulse at the RST pin. The RESET pulse dura- tion is 98xTOSC,
where TOSC = 1/FOSC. To make the best use of the WDT, it should be serviced in those sections of code that
will periodically be executed within the time required to prevent a WDT reset.

WDT During Power-down and Idle


In Power-down mode the oscillator stops, which means the WDT also stops. While in Powerdown mode, the user
does not need to service the WDT. There are two methods of exiting Power-down mode: by a hardware reset or
via a level-activated external interrupt which is enabled prior to entering Power-down mode. When Power-down
is exited with hardware reset, servicing the WDT should occur as it normally does whenever the AT89S52 is
reset. Exiting Power-down with an interrupt is significantly different. The interrupt is held low long enough
forthe oscillator to stabilize. When the interrupt is brought high, the interrupt is serviced. To preventthe WDT
from resetting the device while the interrupt pin is held low, the WDT is not started until the interrupt is pulled
high. It is suggested that the WDT be reset during the interrupt service for the interrupt used to exit Power-down
mode.To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best to reset the
WDT just before entering Power-down mode.Before going into the IDLE mode, the WDIDLE bit in SFR AUXR
is used to determine whether the WDT continues to count if enabled. The WDT keeps counting during IDLE
(WDIDLE bit = 0) as the default state. To prevent the WDT from resetting the AT89S52 while in IDLE mode,
the user should always set up a timer that will periodically exit IDLE, service the WDT, and reenter IDLE mode.
With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and resumes the count upon exit from
IDLE.

UART
The UART in the AT89S52 operates the same way as the UART in the AT89C51 and AT89C52.

Timer 0 and 1
Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in the AT89C51 and
AT89C52

Department of EEE, TOCE - 2016 Page 44


Timer 2
Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The type of operation is
selected by bit C/T2 in the SFR T2CON (shown in Table 5-2). Timer 2 has three operating modes: capture, auto-
reload (up or down counting), and baud rate generator. The modes are selected by bits in T2CON, as shown in
Table 10-1. Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is
incremented every machine cycle. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12
of the oscillator frequency.

In the Counter function, the register is incremented in response to a 1-to-0 transition at its corresponding external
input pin, T2. In this function, the external input is sampled during S5P2 of every machine cycle. When the
samples show a high in one cycle and a low in the next cycle, The count is incremented. The new count value
appears in the register during S3P1 of the cycle following the one in which the transition was detected. Since two
machine cycles (24 oscillator periods) are required to recognize a 1-to-0 transition, the maximum count rate is
1/24 of the oscillator frequency. To ensure that a given level is sampled at least once before it changes, the
level should be held for at least one full machine cycle.

Capture Mode
In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 is a 16-bit timer
or counter which upon overflow sets bit TF2 in T2CON. This bit can then be used to generate an interrupt. If
EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0 transition at external input T2EX also causes the
current value in TH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, the transition
at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt. The capture
mode is illustrated in Figure 10-1.

Auto-reload (Up or Down Counter)

Department of EEE, TOCE - 2016 Page 45


Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This feature is
invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD (see Table 10-2). Upon reset, the
DCEN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or down,
depending on the value of the T2EX pin.

Figure Timer 2 automatically counting up when DCEN = 0. In this mode, two options are selected by bit EXEN2
in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow
also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in
Timer in Capture ModeRCAP2H and RCAP2L are preset by software. If EXEN2 = 1, a 16-bit reload can be
triggered either by an overflow or by a 1-to-0 transition at external input T2EX. This transition also sets the EXF2
bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled. Setting the DCEN bit enables Timer 2 to
count up or down, as shown in Figure 10-2. In this mode, the T2EX pin controls the direction of the count. A
logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow

Department of EEE, TOCE - 2016 Page 46


also causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and
TL2,respectively.A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal
the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded
into the timer registers.The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a
17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.

Department of EEE, TOCE - 2016 Page 47


Baud Rate Generator
Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON (Table
5-2). Note that the baud rates for transmit and receive can be different if Timer 2 is used for the
receiver or transmitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK
puts Timer 2 into its baud rate generator mode, as shown in Figure 11-1. The baud rate generator mode is similar
to the auto-reload mode, in that a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value
in registers RCAP2H and RCAP2L, which are preset by software.

Interrupts
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts
(Timers 0, 1, and 2), and the serial port interrupt. These interrupts are all shown in Figure 13-1. Each of these
interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register
IE. IE also contains a global disable bit, EA, which disables all interrupts at once. Note that Table 13-1 shows that
bit position IE.6 is unimplemented. User software should not write a 1 to this bit position, since it may be used in
future AT89 products. Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON.
Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine
may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be
cleared in software.The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers
overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag,TF2, is set at
S2P2 and is polled in the same cycle in which the timer overflows.

Department of EEE, TOCE - 2016 Page 48


PROGRAMMING CODE:
Gsm programming
#include <reg51.h>
#include <string.h>
#include <stdio.h>
#include <intrins.h>
#include "adc8591.h"

Department of EEE, TOCE - 2016 Page 49


//----------------------------------LCD Declarations--------------------------------------//
void initlcd(void);
void cmd_lcd(unsigned char command);
void data_lcd(unsigned char data2lcd);
void lcd_shortdelay(void);
void delay_ms(unsigned char milliseconds);
void printnum_lcd(unsigned char message, unsigned char row, unsigned char col); //ascii to decimal
void printnum_lcdm(unsigned char message, unsigned char row, unsigned char col);
void printnum_lcd1(unsigned char message, unsigned char row, unsigned char col); //ascii to decimal
void printnum_lcdm1(unsigned char message, unsigned char row, unsigned char col);
void printlcd(unsigned char *message, unsigned char row, unsigned char col);
void printchar(unsigned char message1, unsigned char row, unsigned char col);
void printlcd1(unsigned char *message, unsigned char row, unsigned char col);
void function();

sbit enable=P3^4;
sbit regsel=P3^5;

sbit SWITCH=P0^1;
sbit relay11=P0^7;
sbit fan=P0^5;

sbit m1=P2^0;
sbit m2=P2^1;
sbit m3=P2^2;
#define LCD_PORT P1
#define CLR_LCD cmd_lcd(0x01); delay_ms(5)
#define RETURN_HOME_LCD cmd_lcd(0x02); delay_ms(5)

code char CHECK_READY[] = {'A','T','\r','\0'};


code char MSG_FORMAT[] = "AT+CMGF=1\r";
code char SEND_SMS_CMD[] = {'A','T','+','C','M','G','S','=','"','\0'};

Department of EEE, TOCE - 2016 Page 50


code char END_SMS_CMD[] = {'"','\r','\0'};
code char PHONE_NO[] = "7204874137";
code char R_SMS[]={'\r','A','T','+','C','M','G','R','=','4','\r','\0'};
code char d_sms[]={'A','T','+','C','M','G','D','=','4','\r','\0'};
code char setop[]={'A','T','+','C','N','M','I','=','2',',','1','\r','\0'};

unsigned char wordstr,ok,enter,motor_relay1;


volatile int q,a,b,c,f;
volatile char v[17];
unsigned char d[4];
void serial_init()
{
/*SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0XFD;
TR1 = 1;*/
SCON = 0x50;
IE=0x90;
TMOD = 0x21;
TH1 = 0xFD;
TH0 = 0x4B;
TL0 = 0XFD;
TR0 = 1;
TR1 = 1;

void voltage()
{ int i;
for(i=0;i<=5;i++)
{

Department of EEE, TOCE - 2016 Page 51


SBUF = v[i];
while(!TI);
TI = 0;
}
}
void current()
{ int i;
for(i=6;i<=8;i++)
{
SBUF = v[i];
while(!TI);
TI = 0;
}
}

void temp()
{ int i;
for(i=15;i<=17;i++)
{
SBUF = v[i];
while(!TI);
TI = 0;
}
}

void transmit(char *datas)


{
unsigned char i;

Department of EEE, TOCE - 2016 Page 52


for(i=0;i<strlen(datas);i++)
{
SBUF = datas[i];
while(!TI);
TI = 0;
}
}

void receive_OK()
{

do
{

}while(ok!='K');
}

void check_sim_status()
{

cmd_lcd(0x01);
printlcd(" VERIFING FOR",0,0);
printlcd(" SIM",1,0);
delay_ms(3000);
transmit(CHECK_READY);
receive_OK();
}
void wait_for_prompt()
{

do

Department of EEE, TOCE - 2016 Page 53


{

}while(enter!='>');
}
void send_sms()
{
cmd_lcd(0x01);
printlcd(" SENDING SMS TO",0,0);
printlcd("MAPPING SERVER",1,0);
delay_ms(3000);
transmit(SEND_SMS_CMD);
transmit(PHONE_NO);
transmit(END_SMS_CMD);
wait_for_prompt();
transmit("voltage: ");
voltage();
transmit(" volt ");
transmit(" ");
transmit("\r");
transmit("current: ");
current();
transmit(" mA ");
transmit(" ");
transmit("\r");
transmit("Temp: ");
temp();
transmit(" cel ");
transmit("\r");

Department of EEE, TOCE - 2016 Page 54


SBUF = 26;
while(!TI);
TI = 0;
receive_OK();

void rx()interrupt 4
{
wordstr=SBUF;
if(wordstr=='K')
{ok='K'; RI=0; enter='M';}

else if(wordstr=='>')
{enter='>';RI=0; ok='k';}

if(wordstr=='N')
{relay11=1;RI=0;}

if(wordstr=='F')
{relay11=0;RI=0;}

RI=0;

Department of EEE, TOCE - 2016 Page 55


//----------------------------------MAIN program--------------------------------------//
main()
{
relay11=0X00;
fan=0x00;
a=0;
b=0;
c=0;
f=0;

serial_init();

initlcd(); //lcd initialization


cmd_lcd(0x01);
printlcd(" low cost distribut ",0,0);
printlcd("transformer monit",1,0);
delay_ms(3000);
delay_ms(3000);
cmd_lcd(0x01);
printlcd(" controlling in ",0,0);
printlcd("remote area using",1,0);
delay_ms(3000);
delay_ms(3000);
cmd_lcd(0x01);
printlcd(" PLC via GSM ",0,0);
delay_ms(3000);
delay_ms(3000);
cmd_lcd(0x01);
printlcd(" PROJECT DONE ",0,0);
printlcd(" BY",1,0);
delay_ms(3000);
delay_ms(3000);

Department of EEE, TOCE - 2016 Page 56


cmd_lcd(0x01);
printlcd(" bopanna k.m",0,0);
printlcd(" vithal reddy ",1,0);
delay_ms(3000);
delay_ms(3000);
cmd_lcd(0x01);
printlcd(" sai prakash .l ",0,0);
printlcd(" dharshan .b.g ",1,0);
delay_ms(3000);
delay_ms(3000);
check_sim_status();

transmit(MSG_FORMAT);
while(1)
{
cmd_lcd(0x01);
printlcd(" reading",0,0);
printlcd(" values",1,0);
delay_ms(3000);
delay_ms(3000);
i2c_read(0x9E,0x43,&d[0]); //read ADC RESULT from channel 0
PUT 0X44
i2c_read(0x9E,0x42,&d[1]);
i2c_read1(0x9E,0x41,&d[2]); //read ADC RESULT from channel 0
PUT 0X44
//i2c_read(0x9E,0x41,&d[3]);
delay_ms(3000);
printnum_lcd(d[0], 1, 6);
// printnum_lcdm(d[1], 0, 6);
printnum_lcd1(d[2], 1, 6);
// printnum_lcdm1(d[3], 0, 6);
if(d[2]>=40)

Department of EEE, TOCE - 2016 Page 57


{
fan=1;
}
if(d[2]<39)
{
fan=0;
}
if(m1==1)
{
a=2;
}
if(m2==1)
{
b=2;
}
if(m3==1)
{
c=2;
}
if(m1==0)
{
a=0;
}
if(m2==0)
{
b=0;
}
if(m3==0)
{
c=0;
}

Department of EEE, TOCE - 2016 Page 58


function();
delay_ms(3000);
cmd_lcd(0x01);
printlcd(" transmitting",0,0);
printlcd(" values",1,0);
delay_ms(3000);
send_sms();
cmd_lcd(0x01);
ok='l';
transmit(R_SMS);
receive_OK();
ok='l';
transmit(d_sms);
receive_OK();
ok='l';
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);

}
}

//----------------------------------Ascii to decimal--------------------------------------//
void printnum_lcd(unsigned char num, unsigned char row, unsigned char col)
{

Department of EEE, TOCE - 2016 Page 59


unsigned char x1, x2, dig3, dig4, dig5;
unsigned int volts,num1,x3;
cmd_lcd(0x80+(0x40*row)+ col);
volts=num*25;
num=volts/10000;
v[0]=num+0x30;
num1=volts%10000;
x3=num1/1000;
v[1]=x3+0x30;
x2=num1%1000;
v[2]='.';
x1=x2/100;
v[3]=x1+0x30;
dig3=x1%100;
dig4=dig3/10;
v[4]=dig4+0x30;
dig5=dig3%10;
v[5]=dig4+0x30;
}

void function()
{
f=a+b+c;
v[6]=f+0x30;
v[7]=0+0x30;
v[8]=0+0x30;
if(f==6)
{
relay11=1;
}
else

Department of EEE, TOCE - 2016 Page 60


{

relay11=0;
}
}

void printnum_lcdm(unsigned char num, unsigned char row, unsigned char col)
{

unsigned char x1, x2, dig3, dig4, dig5;


unsigned int x3;
cmd_lcd(0x80+(0x40*row)+ col);
x3=num/100;
x2=num%100;
x1=x3%100;
dig3=x1%10;
dig4=x2/10;
dig5=x2%10;
v[6]=dig3+0x30;
v[7]=dig4+0x30;
v[8]=dig5+0x30;

}
void printnum_lcd1(unsigned char num, unsigned char row, unsigned char col)
{

unsigned char x1, x2, dig3, dig4, dig5;


unsigned int x3;
cmd_lcd(0x80+(0x40*row)+ col);
x3=num/100;
x2=num%100;
x1=x3%100;

Department of EEE, TOCE - 2016 Page 61


dig3=x1%10;
dig4=x2/10;
dig5=x2%10;
v[15]=dig3+0x30;
v[16]=dig4+0x30;
v[17]=dig5+0x30;

}
//----------------------------------initialise lcd--------------------------------------//

void initlcd()
{
enable=0;
delay_ms(20);
cmd_lcd(0x30);
delay_ms(5);
cmd_lcd(0x30);
cmd_lcd(0x30);
cmd_lcd(0x38);
cmd_lcd(0x08);
CLR_LCD;
cmd_lcd(0x06);
cmd_lcd(0x0e);
}

void cmd_lcd(unsigned char command)


{
LCD_PORT=command;
regsel=0;
enable=1;

Department of EEE, TOCE - 2016 Page 62


lcd_shortdelay();enable=0;
}

void data_lcd(unsigned char databyte)


{
LCD_PORT=databyte;
regsel=1;
enable=1;

lcd_shortdelay();enable=0;
}

void lcd_shortdelay(void)
{
unsigned char t=23;
while(t--);
}

void delay_ms(unsigned char ms)


{
unsigned char t1;
unsigned int t2;

for(t1=0; t1<ms; t1++){


for(t2=0; t2<711; t2++);
}
}

void printlcd(unsigned char *message, unsigned char row, unsigned char col)
{
cmd_lcd(0x80 + (0x40*row) + col);

Department of EEE, TOCE - 2016 Page 63


for(; *message; message++)
data_lcd(*message);

void printlcd1(unsigned char *message, unsigned char row, unsigned char col)
{
cmd_lcd(0x94 + (0x40*row) + col);

for(; *message; message++)


data_lcd(*message);

void printchar(unsigned char message1, unsigned char row, unsigned char col)
{
cmd_lcd(0x80 + (0x40*row) + col);

data_lcd(message1);

Department of EEE, TOCE - 2016 Page 64

You might also like