Vous êtes sur la page 1sur 77

CHAPTER 1

INTRODUCTION
1.1 Objective

Street lighting is an indispensable part of a city’s infrastructure, the main function of


which is to illuminate the city’s streets during the dark hours of the day. It is important for the
public and city governance to guarantee switching ON or OFF the street lights. In the
beginning, street lighting was switched on at dusk and switched off at dawn by manual
operation, and then the smart controller was used to switch street lighting on and off
automatically through preset timers at sunrise or sunset times or based on the ambient light
intensity in controller surroundings at each power substation. Although the smart controller
can automatically turn ON or OFF the streetlight, there are several cases of street lighting on
during daytime hours and off during night time hours. Such things often occur because of the
wrong settings of the smart controller or due to the accumulation of the light sensor, any one
or both maybe the cause.

In order to find out failure of streetlights and reduce power consumption, the
maintenance operator needs to patrol street by street at night and day. This increases the
maintenance and management cost. The main consideration for computing this system is to
achieve optimum utilization and reduce wastage of power along with providing security. The
main objective of this project is to develop a system that gives a centralized control of street
lights switching at desired times and secure the data through encryption.

Energy savings combined with reduced maintenance costs are prime benefits of street
light control and management. Energy saving is equivalent to the production of energy.
Modern technology has also been utilized in realizing this project. Any loss of power by
street light shall have a significant effect on load management, since lighting accounts for
around 20% of the world’s total electricity consumption. The energy loss in distribution
system especially in street lights in India is of great concern. But it is very often seen that
most of the lamppost lights remains switched-on during day time also. It is one of the major
sources of power loss for the country. Hence the main objective of this work is aimed to
design and implement a reliable system for street light control to avoid huge power loss and
also to secure the transmitted data through Advanced Encryption Standard (AES) technique.

-1-
1.2 Project Overview

The project is developed in response to a need for centralized remote control of street
lights switching at desired time. For manual control of street light in any one location needs
at least one employee. The salary and other perks depend of the geographic location and skill
of the employee. The proposed system not only saves the employee cost but also results in
terms of great energy saving. Hence this system is technically reliable and economically
beneficial. And also provides security for data by encryption using Advanced Encryption
Standard for controlling operations.

1.3 Block diagram of FM based street light controller

The block diagram of FM based Street Light Controller mainly consists of two sections

(i) Transmitter section


(ii) Receiver section.

1.3.1 Block diagram of Transmitter

The transmitter block diagram consists of five main sections as shown in fig.1.1. They are
(i) Keypad, (ii) DTMF encoder, (iii) Microcontroller-FRDM KL25Z and (iv) FM
Transmitter

Fig. 1.1 Block diagram of Transmitter

-2-
(i) Keypad

The controller uses telephone type keypad with 12 press-to-on switches. These
switches are arranged in four rows and three columns using seven lines that are
terminated at corresponding inputs of DTMF encoder.

(ii) DTMF Encoder

The DTMF encoder chip UM91214B generates 12 distinct dual-tone signals


corresponding to the switch pressed. This DTMF signals are used as the basic ON-OFF
codes for operating the Street lights. The DTMF signals are generated as required by the
user of the system.

(iii)Microcontroller-FRDM KL25Z

The FRDM-KL25Z is an ultra-low-cost development platform enabled by the


Kinetis L series KL2x MCU family built on the ARM® Cortex™-M0+ processor.
Features include easy access to MCU I/O, battery-ready, low-power operation, a
standard-based form factor with expansion board options and a built-in debug interface
for flash programming and run-control.

(iv) FM Transmitter

A three stage FM transmitter is used to transmit the DTMF signals in analog form.
Transmitter is tuned to required Bandwidth and the same is tuned at FM Receiver to
receive signals. The FM transmitter’s range is designed for 88MHz to 108MHz which is
the normal FM range.

1.3.2 Block diagram of Receiver

The Receiver block diagram consists of five main sections as shown in Fig.1.2. They are

(i) FM Receiver, (ii) Micro controller KL25Z, (iii) DTMF Decoder, (iv) Micro Controller,
(v) Hex Buffer Inverter and ,(vi) Relay Driver

-3-
fig. 1.2 Block diagram of Receiver

(i) FM Receiver

A FM receiver is used to receive the transmitted DTMF signals from FM transmitter


and the same signals are transmitted to DTMF decoder section. The FM receiver is also
set in the range of 88MHz to 108MHz same as the FM transmitter.

(ii) Microcontroller-FRDM KL25Z

The FRDM-KL25Z is an ultra-low-cost development platform enabled by the


Kinetis L series KL4x MCU family built on the ARM® Cortex™-M0+ processor.
Features include easy access to MCU I/O, battery-ready, low-power operation, a
standard-based form factor with expansion board options and a built-in debug interface
for flash programming and run-control.

(iii) DTMF Decoder

A DTMF decoder chip MT8870 is an 18 pin package and is used for decoding the
DTMF signals received from the FM receiver in digital form. The DTMF signals are
decoded using this IC. These decoded signals are the digitized codes.

(iv) Micro Controller

The AT89C51 Microcontroller is a 40 pin package is used to program the DTMF


signals to be displayed in the LCD screen and also to program a logic zero and logic one
to switch for operating the power switch ON/OFF accordingly. This microcontroller is
used in timer mode 2 for its 8bit and the auto re-loads features.

-4-
(v) Hex Buffer Inverter

The Hex Buffer Inverter SN74HC05N is used to buffer the current to the required
level so as to switch ON/OFF the power switch and to keep the power switch in OFF
position initially when the whole kit is in ON position. This Hex buffer has the inverting
logic so as to give logic zero output when the system is initially in ON position.

(vi) Relay Driver

The power switch here is a Relay driver ULQ2004A used to turn ON/OFF the Street
lights. This relay driver switches ON and OFF as the logic high and logic low signals are
given to the input pins of the relay driver respectively.

1.4 ENCRYPTION OF DATA


Encryption is a technique that uses math to transform information in a way that makes it
unreadable to anyone except those with special knowledge, usually referred to as a "key."
There are many applications of encryption, but some of the most important uses help protect
the security and privacy of files on your computer, information passing over the Internet, or
left sitting in a file on someone else's computer. If encryption is used properly, the
information should only be readable by you and people that receive the key from you.
Encryption provides a very strong technical protection against many kinds of threats — and
this protection is often easy to obtain.

In cryptography, encryption is the process of encoding messages or information in such a


way that only authorized parties can read it. Encryption does not of itself prevent
interception, but denies the message content to the interceptor. In an encryption scheme, the
message or information, referred to as plaintext, is encrypted using an encryption algorithm,
generating cipher text that can only be read if decrypted. For technical reasons, an
encryption scheme usually uses a pseudo-random encryption key generated by an algorithm.
It is in principle possible to decrypt the message without possessing the key, but, for a well-
designed encryption scheme, large computational resources and skill are required. An
authorized recipient can easily decrypt the message with the key, provided by the originator
to recipients but not to unauthorized interceptors.

-5-
1.4.1 DEFINITIONS
(i) Encryption key: A sequence of values that are used with a cipher algorithm to
encrypt a message. The choice of random (or cryptographically pseudorandom) keys,
a secure key exchange mechanism, frequent key refreshments, and good secrecy
protection of keys are all essential ingredients for the security of the integrity
verification mechanism.

(ii) Plaintext: An unencrypted message.


(iii)Private key: (RFC 2828) The secret component of a pair of cryptographic keys used
for asymmetric cryptography. In a public key cryptosystem that key of a user's key
pair which is known only by that user.

(iv) Public key: A public key which encrypts a message. (RFC 2828) The publicly-
discloseable component of a pair of cryptographic keys used for asymmetric
cryptography. In a public key cryptosystem, that key of a user's key pair which is
publicly known

(v) Public key encryption: An encryption mechanism where two keys are used. A public
key is used to encrypt the message and a secret private key to decrypt the message.

(vi) Symmetric encryption algorithm: The encryption key and the decryption key are
interrelated and may even be the same.

(vii) Stream cipher: A symmetric encryption algorithm that processes the data a
bit or a byte at a time with a key resulting in a randomized ciphertext or plaintext. Some
commonly used stream cipher algorithms are RC4 and W7.

The Flijndael whose name is based on the names of its two Belgian inventors. Joan
Daemen and Vincent Rijmen, is a Block cipher. This means that it works on fixed-length
group of bits, which are called Block. It takes an input block of a certain size, usually 128
bits and produces a corresponding output block of the same size. The transformation requires
a second input, which is the secret key. It is important to know that the secret key can be of
any size (depending on the cipher used, and that AES uses three different key sizes: 128, 192
and 256 bits.

-6-
1.4.2 Types of Standard Encryption techniques:

• Data Encryption Standard(DES)


• Triple Data Encryption Standard(3DES)
• Advanced Encryption Standard(AES)

1.5 Thesis outline


In view of the proposed thesis work, explanations of theoretical aspects used in this
work are presented as per the sequence described below.
Chapter 1 Describes a brief review of the project and block diagram.
Chapter 2 Describes the hardware implementation of the project and circuit diagrams.
Chapter 3 Describes the software implementation of the project.
Chapter 4 Describes the result and analysis of the project.
Chapter 5 Conclusion of the project is presented. The Future scope of the project is also
discussed. Next to these chapters are references.

-7-
CHAPTER 2
HARDWARE IMPLEMENTATION
The project comprises of mainly of two sections. One is the transmitter section and
the second, the receiver section. The transmitter section consists of Keypad,DTMF Encoder,
Amplifier and FM transmitter. The receiver section consists of FM receiver, micro controller,
DTMF decoder, Relay Driver, Relays and a LCD display. These components are discussed in
hardware implementation.

2.1 DTMF Generator

DTMF is a signalling system for identifying the keys or better say the number dialled on
a pushbutton or DTMF keypad. The early telephone systems used pulse dialling or loop
disconnect signalling. This was replaced by Multi Frequency (MF) dialling. DTMF is a
multi-frequency tone dialling system used by the push button keypads in telephone and
mobile sets to convey the number or key dialled by the caller.

The DTMF generator or encoder generates a sinusoidal tone which is mixture of the row and
column frequencies. The DTMF encoder chip UM91214B is a 18 pin package as shown in
Fig. 2.1. Its general description can be given as it is a single-chip, silicon gate, CMOS
integrated circuit for a 3.8 MHz crystal or ceramic resonator. It provides Dialling Pulse (DP)
or Dual Tone Multi-Frequency (DTMF) dialling. When you press a button in the telephone
set keypad, a connection is made that generates a resultant signal of two tones at the same
time. These two tones are taken from a row frequency and a column frequency. The resultant
frequency signal is called “Dual Tone Multiple Frequency”. These tones are identical and
unique.

Fig. 2.1 Pin configuration of UM91214B DTMF encoder

-8-
A DTMF signal is the algebraic sum of two different audio frequencies, and can be
expressed as follows:

f (t )  A0 sin( 2 *  * f a * t )  B0 sin( 2 *  * f b * t )  ... … (1)

Where fa and fb are two different audio frequencies with A and B as their peak
amplitudes and f (t) as the resultant DTMF signal. fa belongs to the low frequency group and
fb belongs to the high frequency group.

The frequencies are chosen such that they are not the harmonics of each other. The
frequencies associated with various keys on the keypad are as shown in table 2.1.

Table 2.1 keypad frequencies

1209HZ 1336HZ 1477HZ


697HZ 1 2 3
770HZ 4 5 6
852HZ 7 8 9
941HZ * 0 #

The generation of a DTMF tone is done in the following way.

Whenever a key is pressed the row frequency and the column frequency are added and
then the tone is generated with dual frequency. The DTMF generating circuit is shown in Fig.
2.2. For example when you press the digit 5 in the keypad it generates a resultant tone signal
which is made up of frequencies 770Hz and 1336Hz. These signals are digital signals which
are symmetrical with the sinusoidal wave.

Fig. 2.2 DTMF tone generation

-9-
2.1.1 Keypad

The DTMF keypad is laid out in a 4×3 matrix as shown in fig. 2.3, with each row
representing a low frequency, and each column representing a high frequency. Pressing a
single key (such as ‘1’) will send a sinusoidal tone for each of the two frequencies (697 and
1209 hertz (Hz)). The original keypads had levers inside, so each button activated two
contacts. The multiple tones are the reason for calling the system multi frequency. These
tones are then decoded by the switching center to determine which key was pressed.

Fig. 2.3 Keypad

The circuit board consists of 7 digital I/O lines on a ‘downstream’ 9-way D-type plug.
These routes each bit to a particular line of the keypad. Columns 1, 2 and 3 are routed to bits
0, 1, and 2 respectively. Rows 1, 2, 3 and 4 are routed to bits 5, 6, 7 and 8 respectively. The
internal connections of the keypad are as shown in fig. 2.4. The controller uses telephone-
type keypad with 12 press-to-on switches. These switches are arranged in four rows (R1
through R4) and three columns (C1 through C3) using seven lines that are terminated at
corresponding inputs of DTMF encoder UM91214B.

Fig. 2.4 Internal connection of keypad

- 10 -
2.1.2 Time response of each tone of DTMF keypad

The generation of a DTMF tone is done in the following way. Whenever a key is
pressed the row frequency and the column frequency are added and then the tone is generated
with dual frequency.
When key 1 is pressed the row frequency 697Hz and the column frequency 1209Hz
are added and then tone is generated with dual frequency. The time response of the tone is as
shown in symbol(a) of the below fig. 2.5 When key 2 is pressed the row frequency 697Hz
and the column frequency 1336Hz are added and then tone is generated with dual frequency.
The time response of the tone is as shown in the symbol(b) of the below figure When key 3 is
pressed the row frequency 697Hz and the column frequency 1477Hz are added and then tone
is generated with dual frequency. The time response of the tone is as shown in the symbol(c)
of the below figure similarly the dual frequency tones are generated for remaining keys. The
response of all keys is as shown below.

Plots of DTMF signals at output of Tone

V=1V, Time=1ms on CRO

Fig. 2.5 Time response of different keys

- 11 -
2.2 FM Transmitter

Frequency Modulation is a type of modulation technique used in communication to


modulate the carrier signal in accordance with the amplitude of a message signal.
In frequency modulation (FM), during the positive portion of the audio signal the frequency
of the carrier gradually increases; during the negative period the carrier frequency is
decreased. The louder the sound is being used for modulation, the greater will be the change
in frequency. A maximum deviation of 75 KHz above and below the carrier frequency is
permitted at maximum volume in FM broadcasts. The FM radio band goes from 88 to
108MHZ (megahertz, or millions of cycles per second).

To keep from interfering with each other FM stations must be 200KHZ apart within
the same geographic area. However, since the signal of FM stations cover only limited
distances, the same frequency can be used in different geographic areas of the country. FM
stations range in power from 100 watts to 100,000 watts. They cover distances of 24-105 km
(15-65 miles), because FM relies on line-of-sight transmission.

2.2.1 Description:

The product crust is made of high-quality aluminium, which also is the heating panel
of power amplifier RD06HVF1, with blue backlight LCD to display five digits of frequency.
The motherboard is applied with chip BH1415F, which is the new-generation integrated NC
FM stereo radio chip by ROHM, built-in PLL frequency, audio pre-emphasis, limiter and low
pass filter circuit.

The control board is designed with high performance MCU STC series, its
performance is better than AT89C2051. With microphone and audio input of the amplifier,
adjustable input level. Transmitting power can switch between 1W and 7W. Good shielding,
compact structure, small size, generous appearance.

2.2.2 Technical Specification:

(i) Power supply voltage: DC 12V


(ii) Operating current: 2.5A
(iii)Frequency range: 76 ~ 108Mhz
(iv) Frequency step: 100kHz
(v) Frequency stabilization method: PLL

- 12 -
(vi) Frequency stability: ¡À 10 ppm (-10¡ãC to +60¡ãC )
(vii) Frequency deviation: Less than ¡À 75kHz (100%)
(viii) Working method: Continuous
(ix) Clutter and Harmonic: Less than -60dB
(x) SNR: More than 60dB
(xi) Stereo channels crosstalk: -50dB
(xii) Audio frequency response: 20 to 15000Hz
(xiii) Audio distortion: Less than 2%
(xiv) Modulation: 15%
(xv) Input level:-15dBV (adjustable)
(xvi) RF output impedance: 50 Ohm
(xvii) RF output power: 1W/7W (Power can be switched)
(xviii) Reference range: 3Km - 8Km (A barrier-free environment)

Fig 2.6 Fm Transmitter

2.3 FM Receiver

The FM receiver is mainly used to receive the transmitted encoded DTMF signal. It is
a one-chip FM/AM radio IC designed for radio-cassette tape recorders and headphone tape
recorders, and has the following functions, which is present in the FM receiver and designed
to function as a FM receiver.
Operation:

When the transmitted carrier reaches the receiving antenna, a small voltage is induced into it.
This may be as small as 0.1 microvolt, but is typically 50 microvolt’s in a standard AM
broadcast receiver. The RF amplifier selects and amplifies the desired station from many. It is
adjustable so that the selection frequency can be altered. This is called TUNING. The
selected frequency is fed to the mixer. The output of an oscillator is also fed to the mixer. The

- 13 -
mixer and oscillator form a Frequency changer circuit. The output from the mixer is the
intermediate frequency (IF). The IF is a fixed frequency of 10.7 MHz. No matter what the
frequency of the selected radio station is, the IF is always 10.7 MHz

The IF signal is fed into the IF amplifier. The advantage of the IF amplifier is that its
frequency and bandwidth are fixed, no matter what the frequency of the incoming signal is.
This makes the design and operation of the amplifier much simpler. The amplified IF signal
is fed to the demodulator. This circuit recovers the audio signal and discards the RF carrier.
Some of the audio is fed back to the oscillator as an Automatic frequency control voltage.
This ensures that the oscillator frequency is stable in spite of temperature changes. The audio
signal voltage is increased in amplitude by a voltage amplifier. The power level is increased
sufficiently to drive the loudspeaker by the power amplifier. The Receiver modules are as
shown in Fig. 2.10.

Remote

Fig. 2.10 Components of Receiver module


2.3.1 Circuit diagram of FM receiver

A high quality FM receiver circuit based on CXA1019 IC is as shown in Fig.2.11.


CXA1019 is a bipolar silicon monolithic FM/AM radio receiver IC. The circuit inside
CXA1019 include RF amplifier, mixer, oscillator, IF amplifier, quadrature detection circuit,
tuning LED driver electronic volume control, detector etc. FM section of the IC is only
utilized in this circuit. The IC can be powered from anything between 3 to 7V DC and can
drive an 8 ohm loudspeaker.

- 14 -
Fig. 2.11 FM Receiver circuit

Circuit description:

Inductors L1, L2 and capacitors C4, C6, C7 forms the tank circuit for the ICs built in
oscillator section. The IF output available at pin 15 is grounded through resistor R1. C1 is the
AC bypass capacitor for R1. Capacitor C16 is meant for ripple filtering. LED D1 is a tuning
indicator. Output of the built-in detector stage (pin24) is coupled to the input (pin 25) of the
built in AF amplifier stage through capacitor C19, POT R2 and capacitor C18. The POT R2
can be used as a volume control because it controls the input given to the audio amplifier
stage. Capacitor C15 couples the audio output to the speaker and C14 is a noise bypass
capacitor. C5 is just a power supply filter while C20 couples the antenna to the FM RF input
(pin13) of the IC. The FM intermediate frequency output available at pin 15 is filtered using
the 10MHz ceramic filter and applied to the FM intermediate frequency input pin18.
Capacitor C2 is used for bypassing noise from the audio power amplifier section inside the
IC. The output of this power amplifier section is around 500mW. Capacitor C1 and
transformer T1 are related to the FM discriminator circuitry inside the IC. Resistor R3 is the
feedback capacitor for the AGC section.

- 15 -
2.4 UART- Universal Asynchronous Receiver/Transmitter

UART is a piece of computer hardware that translates that transfers data


between parallel and serial forms. UART is usually an individual (or part of an) integrated
circuit used for serial communications over a computer or peripheral device serial port.

The universal asynchronous receiver/transmitter (UART) takes bytes of data and


transmits the individual bits in a sequential fashion. At the destination, a second UART re-
assembles the bits into complete bytes. Each UART contains a shift register, which is the
fundamental method of conversion between serial and parallel forms. Serial transmission of
digital information (bits) through a single wire or other medium is less costly than parallel
transmission through multiple wires.

Communication may be simplex (in one direction only, with no provision for the
receiving device to send information back to the transmitting device), full duplex (both
devices send and receive at the same time) or half duplex (devices take turns transmitting and
receiving).

2.4.1 Character framing

Bit
1 2 3 4 5 6 7 8 9 10 11
number

Start
5–8 data bits Stop bit(s)
bit

Data Data Data Data Data Data Data Data


Start Stop
0 1 2 3 4 5 6 7

The start bit signals the receiver that a new character is coming. The next five to nine
bits, depending on the code set employed, represent the character. If a parity bit is used, it
would be placed after all of the data bits. The next one or two bits are always in
the mark (logic high, i.e., '1') condition and called the stop bit(s). They signal the receiver that
the character is completed. Since the start bit is logic low (0) and the stop bit is logic high (1)
there are always at least two guaranteed signal changes between characters.

- 16 -
2.4.2 Receiver

All operations of the UART hardware are controlled by a clock signal which runs
at a multiple of the data rate, typically 8 times the bit rate. The receiver tests the state of the
incoming signal on each clock pulse, looking for the beginning of the start bit.

2.4.3 Transmitter

Transmission operation is simpler as the timing does not have to be determined


from the line state, nor is it bound to any fixed timing intervals. As soon as the sending
system deposits a character in the shift register (after completion of the previous character),
the UART generates a start bit, shifts the required number of data bits out to the line,
generates and sends the parity bit (if used), and sends the stop bits.

2.4.4 Synchronous Serial Transmission

Synchronous serial transmission requires that the sender and receiver share a
clock with one another, or that the sender provide a strobe or other timing signal so that the
receiver knows when to “read” the next bit of the data. In most forms of serial Synchronous
communication, if there is no data available at a given instant to transmit, a fill character must
be sent instead so that data is always being transmitted. Synchronous communication is
usually more efficient because only data bits are transmitted between sender and receiver, and
synchronous communication can be more costly if extra wiring and circuits are required to
share a clock signal between the sender and receiver.

A form of Synchronous transmission is used with printers and fixed disk devices in
that the data is sent on one set of wires while a clock or strobe is sent on a different wire.
Printers and fixed disk devices are not normally serial devices because most fixed disk
interface standards send an entire word of data for each clock or strobe signal by using a
separate wire for each bit of the word. In the PC industry, these are known as Parallel
devices.

The standard serial communications hardware in the PC does not support


Synchronous operations. This mode is described here for comparison purposes only.

- 17 -
Stop mode

The UART will remain functional during Stop mode, provided the asynchronous
transmit

and receive clock remains enabled. The UART can generate an interrupt or DMA request

to cause a wakeup from Stop mode.

Wait mode

The UART can be configured to Stop in Wait modes, when the DOZEEN bit is set.

2.4.5 UART Transmitter Block Diagram

- 18 -
2.4.6 UART Receiver Block Diagram

2.4.7 Functional description

The UART supports full-duplex, asynchronous, NRZ serial communication and

comprises a baud rate generator, transmitter, and receiver block. The transmitter and

receiver operate independently, although they use the same baud rate generator. The

following describes each of the blocks of the UART.

2.4.8 Baud rate generation

A 13-bit modulus counter in the baud rate generator derive the baud rate for both the

receiver and the transmitter. The value from 1 to 8191 written to SBR[12:0] determines

the baud clock divisor for the asynchronous UART baud clock. The SBR bits are in the

UART baud rate registers, BDH and BDL. The baud rate clock drives the receiver, while

the transmitter is driven by the baud rate clock divided by the over sampling ratio.

Depending on the over sampling ratio, the receiver has an acquisition rate of 4 to 32

- 19 -
samples per bit time.

Baud rate generation is subject to two sources of error:

(i) Integer division of the module clock may not give the exact target frequency.
(ii) Synchronization with the asynchronous UART baud clock can cause phase shift.

2.5 DTMF Decoder

The MT8870D DTMF decoder is a complete DTMF receiver consisting of digital


decoder. The decoder uses digital counting techniques to detect and decode all 16 DTMF
tone pairs into a four bit binary code. This output 4–bit code is given as the input to the
Microcontroller. Using the DTMF decoder, it is very easy to decode the DTMF dial-tones
found on telephone lines with touch tone phones. The DTMF decoder is also used for
receiving data transmissions over the air in amateur radio frequency bands.

2.5.1 Working of IC MT8870

The MT-8870 is a full DTMF Receiver that integrates both band split filter and
decoder functions into a single 18-pin DIP. Block diagram of IC MT8870 as shown in Fig
2.12. Its filter section uses switched capacitor technology for both the high and low group
filters and for dial tone rejection. Its decoder uses digital counting techniques to detect and
decode all 16 DTMF tone pairs into a 4-bit code. External component count is minimized by
provision of an on-chip differential input amplifier, clock generator, and latched tri-state
interface bus. Minimal external components required include a low-cost 3.579545 MHz
crystal, a timing resistor, and a timing capacitor. The MT-8870-02 can also inhibit the
decoding of fourth column digits.

MT-8870 operating functions include a band split filter that separates the high and
low tones of the received pair, and a digital decoder that verifies both the frequency and
duration of the received tones before passing the resulting 4-bit code to the output bus. The
low and high group tones are separated by applying the dual-tone signal to the inputs of two
6th order switched capacitor band pass filters with bandwidths that correspond to the bands
enclosing the low and high group tones.

- 20 -
Fig. 2.12 Block diagram of IC MT8870

The filter also incorporates notches at 350 and 440 Hz, providing excellent dial tone
rejection. Each filter output is followed by a single-order switched capacitor section that
smoothest the signals prior to limiting. Signal limiting is performed by high gain comparators
provided with hysteresis to prevent detection of unwanted low-level signals and noise. The
MT-8870 decoder uses a digital counting technique to determine the frequencies of the
limited tones and to verify that they correspond to standard DTMF frequencies.

When the detector recognizes the simultaneous presence of two valid tones (known as
signal condition), it raises the Early Steering flag (ESt). Any subsequent loss of signal
condition will cause ESt to fall. Before a decoded tone pair is registered, the receiver checks
for valid signal duration (referred to as character- recognition-condition). This check is
performed by an external RC time constant driven by ESt. A short delay to allow the output
latch to settle, the delayed steering output flag (StD) goes high, signalling that a received tone
pair has been registered. The contents of the output latch are made available on the 4-bit
output bus by raising the three state control input (OE) to logic high. Inhibit mode is enabled
by a logic high input to pin 5 (INH). It inhibits the detection of 1633 Hz. The output code will
remain the same as the previous detected code. On the M- 8870 models, this pin is tied to
ground (logic low).The input arrangement of the MT-8870 provides a differential input

- 21 -
operational amplifier as well as a bias source (VREF) to bias the inputs at mid-rail. Provision
is made for connection of a feedback resistor to the op-amp output (GS) for gain adjustment.
The internal clock circuit is completed with the addition of a standard 3.579545 MHz crystal.

2.5.2 DTMF decoding circuit

The decoder circuit is designed using the MT8870D DTMF receiver IC as shown in
fig. 2.13. The purpose of this device is to decode the DTMF signals that are available at the
input stage from the FM receiver. With the help of some passive elements, the 8870 IC
generates BCD codes for the corresponding DTMF signals. It uses same oscillator frequency
used in the remote section so same crystal oscillator with frequency of 3.85MHz is used in
this IC. The output BCD code from this circuit is fed to the Microcontroller.

The Circuit Diagram of DTMF decoder is as shown in fig. 2.13, the significance of each pin
is as follows:
Gain Select: Gives the access to output of the front-end differential amplifier for connection
of feedback resistor.
Power Down: A Logic High powers down the device and inhibits the oscillator.
Three state output Enable: A Logic High enables the outputs Q1 to Q4 Internal pull up.

Fig. 2.13 DTMF decoding circuit


Delayed Steering output: It presents logic high when a received tone pair has been
registered and the output latch is updated. It returns logic low when the voltage on St/Gt falls.

- 22 -
Early Steering output: It presents logic high immediately when the digital algorithm detects
a recognizable tone pair. Any momentary loss of signal condition will cause Est to return to
logic low.
Steering input / Guard time output: A voltage greater than VTst detected at St Causes the
device to register the detected tone pair. The Gt output acts to reset the external steering time
constant and its state is a function of Est and the voltage on St.

The MT8870 decoder has to be decoding the encoded hybrid frequency code. It will
generate four bit digital output depending upon which key is pressed at the transmitter side.
The coded digital output and their corresponding keys are as shown in Table 2.3. This four
digit output is directly given to 89C51 microcontroller.

Table 2.3 Functional table of the 8870 DTMF decoder IC

F (Low) F(high) KEY TOE Q4 Q3 Q2 Q1


697 1209 1 1 0 0 0 1
697 1336 2 1 0 0 1 0
697 1447 3 1 0 0 1 1
770 1209 4 1 0 1 0 0
770 1336 5 1 0 1 0 1
770 1447 6 1 0 1 1 0
852 1209 7 1 0 1 1 1
852 1336 8 1 1 0 0 0
852 1447 9 1 1 0 0 1
941 1209 0 1 1 0 1 0
941 1336 * 1 1 0 1 1
941 1447 # 1 1 1 0 0

2.5.3 The main features of DTMF MT8870D are as follows

It is a Complete DTMF Receiver with Low power consumption, internal gain setting
amplifier, adjustable guard time, power-down mode and inhibit mode.

- 23 -
Applications

(i) Receiver Systems


(ii) Paging Systems
(iii)Repeater /Mobile Radio Systems
(iv) Credit Card Systems
(v) Remote Control Systems
(vi) Telephone Answering Machine

2.6 Microcontroller (AT89C51)

The AT89C51 is a low-power, high-performance CMOS 8-bit microcontroller


intended for use in sophisticated real-time applications such as instrumentation,
industrial control and intelligent computer peripherals. It has 64kB Flash and 1024
bytes of data RAM. The Flash program memory supports both parallel programming and in
serial In-System Programming (ISP). The P89V51RD2 is also In-Application Programmable
(IAP), allowing the Flash program memory to be reconfigured even while the application is
running.

The generic 8051 architecture supports a Harvard architecture, which contains


two separate buses for both program and data. So, it has two distinctive memory
spaces of 64K X 8 size for both programmed and data.

It is based on an 8 bit central processing unit with an 8 bit Accumulator and


another 8 bit B register as main processing blocks. Other portions of the
architecture include few 8 bit and 16 bit registers and 8 bit memory locations.

2.6.1Features

The 8051 microcontroller consists of following features

(i) 4K Bytes of In-System Reprogrammable Flash Memory


(ii) Fully Static Operation: 0 Hz to 24 MHz,
(iii)Three-level Program Memory Lock,
(iv) 128 x 8-bit Internal RAM,

- 24 -
(v) 64K program and data memory address space,
(vi) 32 Programmable I/O Lines and Two 16-bit Timer/Counters,
(vii) Six Interrupt Sources,
(viii) Programmable Serial Channel,
(ix) Low-power Idle and Power-down Modes,
(x) On chip clock oscillator and 12MHz clock

2.7 Liquid Crystal Display (LCD)

The alphanumeric 16character X 2line LCD as shown in Fig 2.17 requires 8data lines
and also 3 control signals and they are interfaced to 8051.By using 2 ports, port 2&3 data
pins are connected to LCD as data bus. Port2 can be basically used as I/O port i.e. it can be
programmed as an input or as an output port.

That means if it is programmed as output port, suppose if it is required to read data


from LCD immediately it is not possible. Before reading the data it is required to make the
port as an input port. Data reading from LCD gives an erroneous reading & should not be
implemented. Because of this port0 is made as input / output port depending on the situation.
The control signals are connected to port 3 pins. They are EN bar & RS bar, RW bar. At
different instance such as data write / command write / data read etc. Various signals are to be
provided as indicated by the by the LCD manufacturers.

To interface the LCD, to the Micro controller it require an 8 bit and also three control
signals differentiate the data from the control words send to the LCD. The Micro controller
has to send the necessary control words followed by the data to be displayed.

The control signals to the LCD are also provided by the Micro controller. This is also
done through pins 3.5, 3.6&3.7.Through program necessary control signals are passed to the
LCD by using the bits of the port. The remaining can be used for some other purpose if there
is a need. The software controls the necessary ports and performs the task it is designed for.
The software and associated hardware perform the LCD interface.

- 25 -
Fig. 2.17 16x2 Dot matrix LCD

Fig. 2.18 Circuit diagram of LCD


2.8 Hex buffer inverter (SN74HC05N)

The hex buffer inverter chip SN74HC05Nis a 14 pin package as shown in fig. 2.19.
These devices contain six independent hex inverters with high voltage open-collector outputs
for interfacing with high-level circuits (such as MOS) or for driving high-current loads (such
as lamps or relays) and also characterized for use as inverter buffers for driving TTL inputs.
They perform the Boolean function Y = A. The open-collector outputs require pull-up
resistors to perform correctly. These outputs can be connected to other open-collector outputs
to implement active-low wired-OR or active-high wired-AND functions. Open-collector
devices are often used to generate higher VOH levels.

Fig. 2.19 Circuit diagram of SN74HC05N


2.8.1 Function table

These SN74HCO5N contain six independent hex inverters with open-collector


outputs. They perform the Boolean function Y = A as shown in Table 2.5

- 26 -
Table 2.5 Functional table for SN74HC05N

Input Output
A Y
L H
H L

H = HIGH Logic Level


L = LOW Logic Level
2.8.2 Absolute Maximum Ratings:

(i) Supply Voltage - 7V


(ii) Input Voltage - 7V
(iii)HIGH Level Output Voltage - 7V
(iv) Operating Free Air Temperature Range - 0oC to +70oC
(v) Storage Temperature Range - 85oC to +150oC

2.8.3 Logic diagram (positive logic):

Fig. 2.20 Logic diagram of SN74HC05N

2.8.4 Recommended operating conditions

The minimum, normal and maximum values of VCC, VIH, VIL, VOH, IOL, TA of
SN54HC05N are shown in the table 2.6.

Table 2.6 Operating conditions of SN74HC05N

Symbol SN54HC05N SN74HC05N Unit

- 27 -
Min Nom Max Min Nom Max

Vcc 4.5 5 5.5 4.5 5 5.5 Volts

VIH 2 2 Volts

VIL 0.7 0.8 Volts

5.5 5.5 Volts

IOL 4 8 mA

TA -55 125 0 70 0C

2.9 Relay driver

The relay driver ULQ2004A is high-voltage, high-current Darlington transistor


arrays. Each consists of seven npn Darlington pairs that feature high-voltage outputs with
common-cathode clamp diodes for switching inductive loads. The collector-current rating of
a single Darlington pair is 500 mA. The Darlington pairs can be paralleled for higher current
capability. Applications include relay drivers, hammer drivers, lamp drivers, display drivers
(LED and gas discharge), line drivers, and logic buffers. The ULQ2004A-Q1 has a 10.5-kΩ
series base resistor to allow operation directly from CMOS devices that use supply voltages
of 6 V to 15 V.

2.9.1 Logic diagram of ULQ2004A

The pin diagram of ULQ2004A is as shown in the Fig. 2.21. These Darlington
arrays are furnished in 16 pin package. It consists of seven npn Darlington pairs that feature
high-voltage outputs with common-cathode clamp diodes for switching inductive loads.
Current required by relay coils is usually more than 100mA and microcontroller can’t supply
this much of current to relay by itself. So we have to use relay driver to handle this current
requirement. Darlington transistor can handle more current than single transistor. The relay
will stay off when microcontroller does not output +5V to relay driver chip. UL series are
electrically identical and share a common terminal number assignment.

- 28 -
Fig. 2.21 Logic diagram of ULQ2004A

2.9.2 Absolute maximum ratings at 25°C free-air temperature

(i) Collector-emitter voltage 50 V


(ii) Clamp diode reverse voltage 50 V
(iii)Input voltage, VI 30 V
(iv) Peak collector current 500 mA
(v) Output clamp current, IOK 500 mA
(vi) Total emitter-terminal current –2.5 A
(vii) Package thermal impedance, θJA 73°C/W
(viii) Operating free-air temperature range, TA, –40°C to 105°C
(ix) Lead temperature 1,6 mm (1/16 inch) from case for 10 seconds 260°C
(x) Storage temperature range, Tstg –65°C to 150°C

2.10 Relay

A relay is an electrically operated switch. Current flowing through the coil of the
relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil
current can be on or off so relays have two switch positions and they are double throw
(changeover) switches.

- 29 -
+12V

NO
Protection Relay
Diode coil COM
NC
Relay contacts

Transistor
Input
0V

Fig. 2.22 circuit diagram of relay

2.11 Microcontroller FRDM KL25Z


The FRDM-KL25Z is an ultra-low-cost development platform enabled by the Kinetics L
series KL2x MCU family built on the ARM® Cortex™-M0+ processor. Features include
easy access to MCU I/O, battery-ready, low-power operation, a standard-based form factor
with expansion board options and a built-in debug interface for flash programming and run-
control. The FRDM-KL25Z is supported by a range of Freescale and third-party development
software.

Features

(i) MKL25Z256VLL4MCU – 48 MHz, 128 KB flash, 16 KB SRAM, segment LCD,


USB OTG (FS) , 80 LQFP
(ii) Capacitive touch slider, MMA8451Q accelerometer, MAG3110 magnetometer
(iii)Flexible power supply options – USB, coin cell battery, external source
(iv) Easy access to MCU I/O
(v) Battery-ready, power-measurement access points
(vi) Form factor compatible with Arduino ™ R3 pin layout
(vii) OpenSDA debug interface
(viii) Mass storage device flash programming interface (default) – no tool
installation required to evaluate demo apps
(ix) P&E debug interface provides run-control debugging and compatibility with IDE
tools
(x) CMSIS-DAP interface: new ARM standard for embedded debug interface

- 30 -
2.12 CIRCUIT DESCRIPTION
2.12.1 Circuit description of Transmitter

The controller uses telephone-type keypad with 12 press-to-on switches. Theses


switches are arranged in four rows (R1through R4) and three columns (C1 through C3) using
seven lines that are terminated at corresponding inputs of DTMF encoder UM91214B.The
whole circuit is operated at the power of 12V given from the power supply. A zener diode D1
is connected across the supply terminal pin no.6 of IC UM91214B. This encoder IC requires
a voltage of 3V and 3V backup Vcc for this IC is supplied by using 3.2v zener diode. The
crystal X1 of 3.59MHz with two capacitors C1 and C2 is connected with crystal terminals (3,
4 pins of 91214B IC).The pins of IC 91214B from 12 to 14 produces high frequency column
group and pins from 15 to 18 produces the low frequency row group. By pressing any key in
the keyboard corresponding DTMF signal is available in its output pin at pin no.7 (tone) as
shown in Fig. 2.25. This signal is than routed to the microcontroller KL25Z for encryption
purpose using Advanced Encryption Standard technique. This encrypted data is transmitted
via low-power FM transmitter.

2.12.2 Circuit description of Receiver

Receiving antenna of the FM receiver intercepts part of this radiation, change it back
to the form of electrical signals, and feed it to a receiver. These incoming signals are mixed
with a signal from a local oscillator to produce intermediate frequencies (IF) that are equal to
the arithmetical sum and difference of the incoming and local frequencies. One of those
frequencies is fed to an amplifier. These amplified signals are feed it to circuits that
demodulate it, i.e., separate the signal wave itself from the carrier wave.

The output of FM receiver is connected to microcontroller KL25Z for decryption of


the data and the decrypted signals are fed as input to DTMF decoder chip MT8870. These
received DTMF signals are decoded and provide the binary output according to the switch
pressed at the transmitter side. It also provides Std signal that indicates the receipt of a valid
DTMF code. It uses same oscillator frequency used in the remote section so same crystal
oscillator with frequency of 3.85MHz is used in this IC.

The binary output of the DTMF decoder is connected with four pins of the microcontroller
(p1.0-p1.4). LCD is interface with port P2. Port P1 is utilized to drive relays through relay

- 31 -
driver IC ULQ4440Aas shown in Fig. 2.26. This four digit output is directly sent to 89C51
microcontroller. It will collect this code and start comparing with inbuilt code. When it
founds perfect match it will switches to that subroutine and perform that particular task (i.e.
switches on/off street lights) and also displays the coded DTMF signal on the LCD. Separate
password is provided to each relay to switching on/off the street lights. For example to switch
on relay 2, the password”2345” has to be transmitted by the transmitter. By using coded
DTMF signals we can control the street lights.

- 32 -
CHAPTER 3
SOFTWARE IMPLEMENTATION

The software used in this project is Keil micro vision for the simulation of the
program. The Integrated Development Environment used is Keil uV3 version for AT89C51.
The explanation of used tools, flow of program written, frame formats used in designing
software is given in this chapter.

3.1 Keil Software

There are various high level language compilers for 8051 or enhanced versions of
8051 from various vendors. The most popular is the C language compiler. As the modern C
compilers are efficient, assembly language is seldom used nowadays. It is common to have a
complete program written solely in C including interrupt service routines. C language, being
a high level language, has many important advantages over assembly language like
portability, automatic proper handling of various data types including data arithmetic, ease of
data organization, ease of expressing program logic, etc. It is much easier to write a program
in C than in assembly language. C language programming is also much less error prone.

All C compilers for 8051 have extensions to cater to the 8051 architecture. Important
ones are the various memory spaces (internal RAM, code space, and external RAM space),
special function registers and bit variables.

Keil is a German based Software development company. It provides several


development tools mentioned below
(i) IDE (Integrated Development environment)
(ii) Project Manager
(iii)Simulator
(iv) Debugger
(v) C Cross Compiler , Cross Assembler, Locator/Linker

Keil Software provides software development tools for the 8051 family of
microcontrollers. These tools can generate embedded applications for the multitude of 8051
derivatives. Keil provides following tools for 8051 development
(i) C51 Optimizing C Cross Compiler,

- 33 -
(ii) A51 Macro Assembler,
(iii)8051 Utilities (linker, object file converter, library manager),
(iv) Source-Level Debugger/Simulator,
(v) µVision for Windows Integrated Development Environment.

The keil 8051 tool kit includes three main tools, assembler, compiler and linker.
Assembler: Assembles 8051 assembly program
Compiler: Compiles C source code into an object file
Linker: Creates an absolute object module suitable for in-circuit emulator

The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time


Kernels, Single-board Computers, and Emulators support all 8051 derivatives and help to
completed projects on schedule.

3.2 Simulator or Debugger

The simulator or Debugger in KEIL can perform a very detailed simulation of a


microcontroller along with external signals. It is possible to view the precise execution time
of a signal assembly instruction, or a single line of C code, all the way up to the entire
application, simply by entering the crystal frequency. A window can be opened for each
peripheral on the device, showing the state of the peripheral. This enables quick trouble
shooting of miss-configured peripherals. Breakpoints may be set on either assembly
instructions or lines of C code, and execution may be stepped through one instruction or C
line at a time. The contents of all the memory areas may be viewed along with ability to find
specific variables. In addition the registers may be viewed allowing a detailed view of what
the microcontroller is doing at any point in time.

3.3 Programming Microcontroller

A compiler for a high level language helps to reduce production time. To program the
AT89C51 Microcontroller the Keil uvision3 is used. The programming is done strictly in the
embedded C language. Keil uvision3 is a suite of executable, open source software
development tools for the Microcontrollers hosted on the windows platform.

The compiler converts the C program into machine language file (.hex). This is the
only language the microcontroller will understand, because it contains the original program
code converted into a hexadecimal format. During this step there are some warnings about

- 34 -
eventual errors in the program. This is shown in Fig. 3.1. If there are no errors and warnings
then run the program, the system performs all the required tasks and behaves as expected the
software developed. If not, the whole procedure will have to be repeated again. Fig. 3.2
shows expected outputs for given inputs when run compiled program.

Fig 3.1 Keil IDE Environment window showing Compilation of source code

One of the difficulties of programming microcontrollers is the limited amount of


resources the programmer has to deal with. In personal computers resources such as RAM
and processing speed are basically limitless when compared to microcontrollers. In contrast,
the code on microcontrollers should be as low on resources as possible. The physical
realization of Mobile Unit through hardware implementation is made and a firmware has
been discussed to make the integrated devices to interact with each other.

- 35 -
Fig. 3.2 Run the compiled program

3.4 ADVANCED ENCRYPTION STANDARD:


Advanced Encryption Standard (AES) is a Symmetric key cryptography and it is an
iterated block cipher with a fixed block size of 128 bit and a variable key length i.e. it may
be 128,192 or 256 bits. The different transformations operate on the intermediate results
called state. The state is a rectangular array of bytes and since the block size is 128 bits,
which is 16 bytes, the rectangular array is of dimensions 4x4. (In the Rijndael version with
variable block size, the row size is fixed to four and the number of columns varies. The
number of columns is the block size divided by 32 and denoted as Nb). The cipher key is
similarly pictured as a rectangular array with four rows. The number of columns of the cipher
key, denoted as Nc, is equal to the key length divided by 32.

AES uses variable number of rounds which are fixed: A key of size 128 Bytes has 10
rounds. A key of size 192 Bytes has 12 rounds. A key of size 256 Bytes has 14 rounds. An
algorithm starts with a random number, in which the key and data encrypted with it are
scrambled though four mathematical operation processes. The key that is used to encrypt
the number must also be used to decrypt it. For encryption each rounds has four operations
Sub Bytes, Shift Rows, Mix Columns and AddRoundKey respectively and for
decryption it use inverse of these function.

- 36 -
3.4.1 . DESCRIPTION OF THE AES ALGORITHM:

AES is an iterated block cipher with a fixed block size of 128 and a variable key length.
The different transformations operate on the intermediate results, called state. The state is a
rectangular array of bytes and since the block size is 128 bits, which is 16 bytes, the
rectangular array is of dimensions 4x4. (In the Rijndael version with variable block size, the
row size is fixed to four and the number of columns varies. The number of columns is the
block size divided by 32 and denoted Nb). The cipher key is similarly pictured as a
rectangular array with four rows. The number of columns of the cipher key, denoted Nk, is
equal to the key length divided by 32.

During each round, the following operations are applied on the state:
1. Sub Bytes: every byte in the state is replaced by another one, using the Rijndael
S-Box
2. Shift Row: every row in the 4x4 array is shifted a certain amount to the left
3. Mix Column: a linear transformation on the columns of the state
4. Add Round Key: each byte of the state is combined with a round key, which is a
different key for each round and derived from the Rijndael key schedule.

3.4.2 AES OPERATIONS: SUB-BYTES, SHIFT ROWS, MIX COLUMN


AND ADD ROUND KEY

The Add Round Key operation:

In this operation, a Round Key is applied to the state by a simple bitwise XOR.
The Round Key is derived from the Cipher Key by the means of the key schedule.
The Round Key length is equal to the block key length (=16 bytes).

- 37 -
A graphical representation of this operation can be seen below:

Pseudo code
AddRoundKey(int round)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
}
}

3.4.3.The Shift Row operation:

In this operation, each row of the state is cyclically shifted to the left, depending on the row
index.
The 1st row is shifted 0 positions to the left.
The 2nd row is shifted 1 position to the left.
The 3rd row is shifted 2 positions to the left.
The 4th row is shifted 3 positions to the left.

- 38 -
A graphical representation of this operation can be found below:

Pseudo code
void ShiftRows()
{
unsigned char temp;

// Rotate first row 1 columns to left


temp=state[1][0];
state[1][0]=state[1][1];
state[1][1]=state[1][2];
state[1][2]=state[1][3];
state[1][3]=temp;

// Rotate second row 2 columns to left


temp=state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;

temp=state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;

// Rotate third row 3 columns to left


temp=state[3][0];
state[3][0]=state[3][3];
state[3][3]=state[3][2];
state[3][2]=state[3][1];

- 39 -
state[3][1]=temp;
}

3.4.4.The Sub Bytes operation:

The Sub Bytes operation is a non-linear byte substitution, operating on each byte of the
state independently. The substitution table (S-Box) is invertible and is constructed by the
composition of two transformations:
1. Take the multiplicative inverse in Rijndael's finite field
2. Apply an affine transformation which is documented in the Rijndael documentation. Since
the S-Box is independent of any input, pre-calculated forms are used. Each byte of the state is
then substituted by the value in the S-Box whose index corresponds to the value in the state:
a(i,j) = SBox[a(i,j)]
The inverse of Sub Bytes is the same operation, using the inversed S-Box, which is also
precalculated.

A graphical representation of this operation can be found below:

- 40 -
Pseudo code

void SubBytes()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[i][j] = getSBoxValue(state[i][j]);

}
}
}

3.4.5.The Mix Column operation:

This section involves advance mathematical calculations in the Rijndael's finite


field. It corresponds to the matrix multiplication with:

- 41 -
2311
1231
1123
3112
And that the addition and multiplication operations are different from the normal ones.

Pseudo code
#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))
void MixColumns()
{
int i;
unsigned char Tmp,Tm,t;
for(i=0;i<4;i++)
{
t=state[0][i];
Tmp = state[0][i] ^ state[1][i] ^ state[2][i] ^ state[3][i] ;
Tm = state[0][i] ^ state[1][i] ; Tm = xtime(Tm); state[0][i] ^= Tm ^ Tmp ;
Tm = state[1][i] ^ state[2][i] ; Tm = xtime(Tm); state[1][i] ^= Tm ^ Tmp ;
Tm = state[2][i] ^ state[3][i] ; Tm = xtime(Tm); state[2][i] ^= Tm ^ Tmp ;
Tm = state[3][i] ^ t ; Tm = xtime(Tm); state[3][i] ^= Tm ^ Tmp ;
}
}

- 42 -
3.4.5.THE RIJNDAEL KEY SCHEDULE

The Key Schedule is responsible for expanding a short key into a larger key, whose parts
are used during the different iterations. Each key size is expanded to a different size:
A 128 bit key is expanded to a 176 byte key.
A 192 bit key is expanded to a 208 byte key.
A 256 bit key is expanded to a 240 byte key.
There is a relation between the cipher key size, the number of rounds and the Expanded Key
size. For an 128-bit key, there is one initial AddRoundKey operation plus there are 10 rounds
and each round needs a new 16 byte key, therefore we require 10+1 Round Keys of 16 byte,
which equals 176 byte. The same logic can be applied to the two other cipher key sizes. The
general formula is that:
ExpandedKeySize = (nbrRounds+1) * BlockSize

• Rotate: The 4-byte word is cyclically shifted 1 byte to the left:

• Rcon: Just note that the Rcon values can be pre-calculated, which results in a simple
substitution (a table lookup) in a fixed Rcon table.

• S-Box: The Key Schedule uses the same S-Box substitution as the main algorithm
body.

• The Key Schedule Core: In the below code, word has a size of 4 bytes and i is the
iteration counter from the Key Schedule

KeyScheduleCore (word)
{
Rotate(word);
SBoxSubstitution (word);
word[0] = word[0] XOR RCON[i];
}

3.4.6 THE KEY EXPANSION

KeyExpansion(byte Key[4*Nk] word W[Nb*(Nr+1)])


{

- 43 -
for(i = 0; i < Nk; i++)
W[i] = (Key[4*i],Key[4*i+1],Key[4*i+2],Key[4*i+3]);
for(i = Nk; i < Nb * (Nr + 1); i++)
{
temp = W[i - 1];
if (i % Nk == 0)
temp = SubByte(RotByte(temp)) ^ Rcon[i / Nk];
W[i] = W[i - Nk] ^ temp;
}
}
3.5 Implementation:

The AT89C51 Microcontroller 40 pin package is used to program the DTMF signals
to be displayed in the LCD screen and also to program a logic zero and logic one to switch
for operating the power switch ON or OFF accordingly. Energy-efficient lighting demands
less electricity, which reduces polluting power plant emissions. Some materials used in
lamps, such as mercury, are toxic to the environment and must be handled carefully. Light
shining into the sky causes light pollution. We are working to reduce lighting energy use,
toxic materials, and light pollution.

This microcontroller is used in timer mode 2 for its 8bit and the auto re-loads features.
When a key in the telephone pad is pressed the external interrupt is set. Once it is set the
controller takes the data from the receiver port stores in a variable. Print the data on the LCD
screen. Now we need to check whether the timer is expired or not, if expired store the value
in an array else check with the previous data and if both are same it displays the next value in
the LCD in the same position and the store the value in the array.
Check the array size to be 4 or not? If not verify the external interrupt else compare
the array with passwords and set accordingly as shown in table 3.1.

- 44 -
Table 3.1 Key pressed-relay function

Key Password Relay Bulbs


1234 ON password1 Rly1 ON 1,2 ON
4321 OFF password2 Rly1 OFF 1,2 OFF
2345 ON password3 Rly2 ON 3,4 ON
5432 OFF password4 Rly2 OFF 3,4 OFF
3456 ON password5 Rly3 ON 5,6 ON
6543 OFF password6 Rly3 OFF 5,6 OFF
1111 ON password7 Rly1, Rly2, Rly3 ON ALL ON
2222 OFF password8 Rly1, Rly2, Rly3 OFF ALL OFF

- 45 -
CHAPTER 4

ANALYSIS AND RESULTS

FM switch project for controlling the street lights has been completed successfully.
The photograph shown below represents the results taken while performing the load test.

4.1 Transmitter section

The FM transmitter is connected with the DTMF generator through echo coupler.
Here the DTMF signal is generated in the encoder and then the analog DTMF signal is given
to the transmitter’s micro phone by using echo coupler and is transmitted in the analog form.
Transmitter module with echo coupler is as shown in Fig. 4.1.

Table 4.1Key pressed-relay function

Fig. 4.1 Transmitter modules

- 46 -
4.2 Receiver section

The receiver is connected to the DTFM decoder. The transmitted analog DTMF
signals are received by the receiver and then decoded with the DTMF decoder. Then an
ON/OFF signal is generated by the 8051 microcontroller and is given to the relay driver
through hex buffer inverter. The Receiver module is as shown in Fig. 4.3.

Lights

Fig 4.3 Receiving module with controlling lights

4.3 Load test of the Receiver Section

The load is connected near the end of the system and they switch ON
or OFF by the given signal to the relay1, relay2 and relay3 through relay driver.
Fig. 4.4 Lights

- 47 -
4.4 Tested outputs

4.4.1 Output of the kit when ON code is given to all relays

The resultant output at the end of the receiver section when keys”1111” is pressed in
the keypad at evening 6 o’clock in transmitter section. The code received matches with ON
password7 and all 100 watt lamps are turned ON as all relays switches ON.

Fig. 4.5 Output for ON password

ON code of all relays display on LCD

The ON code for all Relays is displayed on LCD after decoding at receiver end when
keys”1111” are pressed in the keypad at the transmitter section. The code displayed on LCD
is “JMPT”.

Fig. 4.6 LCD Output for ON password

- 48 -
4.4.2 Output of the kit when OFF code is given to relay2

The resultant output at the end of the receiver section when keys”5432” is pressed in
the keypad at 10 o’clock in the night in transmitter section. The code received matches with
OFF password4 and two 100 watt lamps are turned OFF as the relay2 switches OFF. By this
code 75% of bulbs will be glow.

Fig. 4.7 Output for OFF password

OFF code of relay2 display on LCD

The OFF code for Relay2 is displayed on LCD after decoding at receiver end when
keys”5432” are pressed in the keypad at the transmitter section. The code displayed on LCD
is “JGDA”.

Fig. 4.8 LCD Output for OFF password

- 49 -
4.4.3 Output of the kit when OFF code is given to relay3

The resultant output at the end of the receiver section when keys”6543” is pressed in
the keypad at 12 o’clock in the night in transmitter section. The code received matches with
OFF password6 and the two 100 watt lamps are turned OFF as the relay3 switches OFF. By
this code 50% of bulbs will be glow.

Fig. 4.9 Output for OFF password

OFF code of relay3 display on LCD

The ON code for Relay3 is displayed on LCD after decoding at receiver end when
keys”6543” are pressed in the keypad at the transmitter section. The code displayed on LCD
is “MJGD”.

Fig. 4.10 LCD Output for OFF password

- 50 -
4.4.4 Output of the kit when OFF code is given to all relays

The resultant output at the end of the receiver section when keys”8765” is pressed in
the keypad at morning 6 o’clock in transmitter section. The code received matches with OFF
password8 and all 100 watt lamps are turned OFF as all relays switches OFF.

Fig. 4.11 Output for OFF password

OFF code of all relays display on LCD

The OFF code for all Relays to switch OFF is displayed on LCD after decoding at
receiver end when keys”8765” are pressed in the keypad at the transmitter section. The code
displayed is “TPMJ”.

Fig. 4.12 LCD Output for OFF password

- 51 -
4.4.5 Outputs of the kit when Transmitter and Receiver are seperated by 57metres
apart

Outputs of the kit when Transmitter and Receiver are seperated by 100 metres apart

- 52 -
AES Encrypted Output

AES Decrypted Output

- 53 -
4.5 Comparision between AES , DES and Triple DES:

Advance Encryption Standard (AES) and Triple DES (TDES or 3DES) are commonly
used block ciphers. Whether you choose AES or 3DES depend on your needs. In this section
it would like to highlight their differences in terms of security and performance (Seleborg,
2004) .Since 3DES is based on DES algorithm, it will talk about DES first. DES was
developed in 1977 and it was carefully designed to work better in hardware than software.
DES performs lots of bit manipulation in substitution and permutation boxes in each of 16
rounds. For example, switching bit 30 with 16 is much simpler in hardware than software.
DES encrypts data in 64 bit block size and uses effectively a 56 bit key. 56 bit key space
amounts to approximately 72 quadrillion possibilities. Even though it seems large but
according to today’s computing power it is not sufficient and vulnerable to brute force attack.
Therefore, DES could not keep up with advancement in technology and it is no longer
appropriate for security. Because DES was widely used at that time, the quick solution was to
introduce 3DES which is secure enough for most purposes today.3DES is a construction of
applying DES three times in sequence. 3DES with three different keys (K1, K2 and K3) has
effective key length is 168 bits (The use of three distinct key is recommended of 3DES.).
Another variation is called two-key (K1 and K3 is same) 3DES reduces the effective key size
to 112 bits which is less secure. Two-key 3DES is widely used in electronic payments
industry. 3DES takes three times as much CPU power than compare with its predecessor
which is significant performance hit. AES outperforms 3DES both in software and in
hardware .The Rijndael algorithm has been selected as the Advance Encryption Standard
(AES) to replace 3DES. AES is modified version of Rijndael algorithm Advance Encryption
Standard evaluation criteria among others was :

(i) Security
(ii) Software & Hardware performance
(iii)Suitability in restricted-space environments and resistance to power analysis and other
implementation attacks
.
Rijndael was submitted by Joan Daemen and Vincent Rijmen. When considered together
Rijndael’s combination of security, performance, efficiency, implementability, and flexibility
made it an appropriate selection for the AES. By design AES is faster in software and works
efficiently in hardware. It works fast even on small devices such as smart phones; smart cards

- 54 -
etc. AES provides more security due to larger block size and longer keys. AES uses 128 bit
fixed block size and works with 128, 192 and 256 bit keys. Rijndael algorithm in general is
flexible enough to work with key and block size of any multiple of 32 bit with minimum
of128 bits and maximum of 256 bits. AES is replacement for 3DES according to NIST both
ciphers will coexist until the year2030 allowing for gradual transition to AES. Even though
AES has theoretical advantage over 3DES for speed and efficiency in some hardware
implementation 3DES may be faster where support for 3DES is mature

- 55 -
CHAPTER 5

CONCLUSION AND FUTURE SCOPE

5.1 CONCLUSION

In this paper, a design of the street lighting controller based on FM for urban street
light monitoring and control system was presented. The features such as the controller
manual deployment and energy unlimited were summarized. The controller hardware was
designed usingAT89C51 microcontroller, Power switch which is designed by using relay
driver and Echo coupler. The controller software were developed using Embedded C on
windows operate system. The controller has primary and secondary switching on and off,
various control strategy, fault detection features are applied. Streetlight department can
reduce energy consumption, lower management and maintenance cost, and improve public
satisfaction to streetlight through FM technology.

5.2 FUTURE SCOPE

The system can also be used for switching more number of street lights by using
contactor instead of a SPDT relay to switch ON or OFF more number of street lights at same
time. The present project can be enhanced by using FM technology. The street lights can be
controlled (ON or OFF) from different areas and can also know the status of them by using
Tran’s receivers. This project represents an approach to the problem of efficiently and
optimally operating scarce resources in the provision of public services namely street
lighting. The system can be operated from a central location through FM broadcast for
switching ON/OFF large number of street lights. With all above discussions it is concluded
that the cost of the systems is very less and faster in operation. Provides security for data by
encryption using Advanced Encryption Standard for controlling operations.

- 56 -
REFERENCES

(i) Jing Chunguo, Wang Yan, “Design of street light pole controller based on WSN”, The
Tenth International Conference on Electronic Measurement & Instruments,2001
(ii) Tuljappa M Ladwa*, Sanjay M Ladwa, “Control of remote domestic system using
DTMF”, ICICI-BME 2009
(iii)Yun Chan Cho and Jae WookJeon, “Remote Robot control System based on DTMF
sof Mobile Phone” ,IEEE International Conference INDIN 2008, July 2008.
(iv) M. A. Wazed, N. Nafis, M. T. Islam, “Design and fabrication of Automatic Street
light control system” ,ISSN, 2010
(v) Wang Guijuan, Wang Zuoxun, Zhang Yingchun,“New intelligent control terminal of
solar street lights”, 2011 Fourth International Conference on Intelligent Computation
Technology and Automation
(vi) R. Sharma, K. Kumar, and S. Viq, “DTMF Based Remote Control System”, IEEE
International Conference ICIT 2006, pp. 2380-2383, December 2006.
(vii) DTMF Based Programmable FM Remote laser cutting machine with 89C51
(viii) M J. Callahan, Jr., “Integrated DTMF receiver,” ZEEE J. Solzd-State
Czrcuzts, vol. Sc-14, pp. 85-90, Feb. 1979.
(ix) http://multyremotes.com/DTMF-FM-Remote-control.htm
(x) [10]. http://www.docstoc.com/docs/122699945/DTMF-Robots
(xi) [11].Ali Mazidi, Janice Gillispie Mazidi: The 8051 Microcontroller Architecture,
Programming, and applications.
(xii) [12] R.C. Luo, T.M. Chen, and C.C. Yih, “Intelligent autonomous mobile
robot control through the Internet”, IEEE International Symposium ISIE
2000, vol. 1, pp. 6- 11, December 2000.

- 57 -
APPENDIX(A)
Subbytes

Shift Row

- 58 -
Mix Columns

Round Key

- 59 -
- 60 -
APPENDIX (B)
CODE FOR ENCRYPTION THROUGH UART:

#include "MKL25Z4.h"
#include "MemMapPtr_KL25Z4.h"
#include "uart.h"
#include "string.h"
#define Nb 4 //columns
int Nr=0; //rounds
int Nk=0; // key bit size
unsigned char in[16], out[16], state[4][4];
unsigned char RoundKey[240];
unsigned char Key[32]; // key input
unsigned char temp[32] = {0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00}; //stores key
unsigned char temp2[32]= {0x00 ,0x04 ,0x12 ,0x14 ,0x12 ,0x04 ,0x12 ,0x00 ,0x0c
,0x00 ,0x13 ,0x11 ,0x08 ,0x23 ,0x19 ,0x19}; //sotres plain text

void initialize(void);//intializations
void idelay(int);
/********************************************************************/
int getSBoxValue(int num)
{
int sbox[256] = {
//0 1 2 3 4 5 6 7 8 9 A B C D E F
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7,
0xab, 0x76, //0
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4,
0x72, 0xc0, //1
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8,
0x31, 0x15, //2
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27,
0xb2, 0x75, //3
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3,
0x2f, 0x84, //4
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c,
0x58, 0xcf, //5
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c,
0x9f, 0xa8, //6
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff,
0xf3, 0xd2, //7
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d,
0x19, 0x73, //8

- 61 -
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e,
0x0b, 0xdb, //9
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95,
0xe4, 0x79, //A
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a,
0xae, 0x08, //B
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd,
0x8b, 0x8a, //C
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1,
0x1d, 0x9e, //D
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55,
0x28, 0xdf, //E
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54,
0xbb, 0x16 }; //F
return sbox[num];
}

int Rcon[255] = {
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab,
0x4d, 0x9a,
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
0x91, 0x39,
0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83,
0x1d, 0x3a,
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
0x6c, 0xd8,
0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
0xfa, 0xef,
0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33,
0x66, 0xcc,
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,
0x80, 0x1b,
0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
0xd4, 0xb3,
0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25,
0x4a, 0x94,
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20,
0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
0x97, 0x35,
0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61,
0xc2, 0x9f,
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01,
0x02, 0x04,

- 62 -
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
0xbc, 0x63,
0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4,
0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8,
0xcb }; //field GF(28)
void KeyExpansion()
{
int i,j;
unsigned char temp[4],k;
for(i=0;i<Nk;i++)
{
RoundKey[i*4]=Key[i*4];
RoundKey[i*4+1]=Key[i*4+1];
RoundKey[i*4+2]=Key[i*4+2];
RoundKey[i*4+3]=Key[i*4+3];
}

while (i < (Nb * (Nr+1)))


{
for(j=0;j<4;j++)
{
temp[j]=RoundKey[(i-1) * 4 + j];
}
if (i % Nk == 0)
{
// Function RotWord()
{
k = temp[0];
temp[0] = temp[1];
temp[1] = temp[2];
temp[2] = temp[3];
temp[3] = k;
}

// SubWord() is a function that takes a four-byte input word and


// Function Subword()
{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}

- 63 -
temp[0] = temp[0] ^ Rcon[i/Nk];
}
else if (Nk > 6 && i % Nk == 4)
{
// Function Subword()
{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}
}
RoundKey[i*4+0] = RoundKey[(i-Nk)*4+0] ^ temp[0];
RoundKey[i*4+1] = RoundKey[(i-Nk)*4+1] ^ temp[1];
RoundKey[i*4+2] = RoundKey[(i-Nk)*4+2] ^ temp[2];
RoundKey[i*4+3] = RoundKey[(i-Nk)*4+3] ^ temp[3];
i++;
}
}
void AddRoundKey(int round)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
}
} // adds roundkey to state XOR function

void SubBytes()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[i][j] = getSBoxValue(state[i][j]);

}
}
}
void ShiftRows()

- 64 -
{
unsigned char temp;

// Rotate first row 1 columns to left


temp=state[1][0];
state[1][0]=state[1][1];
state[1][1]=state[1][2];
state[1][2]=state[1][3];
state[1][3]=temp;

// Rotate second row 2 columns to left


temp=state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;

temp=state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;

// Rotate third row 3 columns to left


temp=state[3][0];
state[3][0]=state[3][3];
state[3][3]=state[3][2];
state[3][2]=state[3][1];
state[3][1]=temp;
}
#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))
void MixColumns()
{
int i;
unsigned char Tmp,Tm,t;
for(i=0;i<4;i++)
{
t=state[0][i];
Tmp = state[0][i] ^ state[1][i] ^ state[2][i] ^ state[3][i] ;
Tm = state[0][i] ^ state[1][i] ; Tm = xtime(Tm); state[0][i] ^= Tm ^ Tmp ;
Tm = state[1][i] ^ state[2][i] ; Tm = xtime(Tm); state[1][i] ^= Tm ^ Tmp ;
Tm = state[2][i] ^ state[3][i] ; Tm = xtime(Tm); state[2][i] ^= Tm ^ Tmp ;
Tm = state[3][i] ^ t ; Tm = xtime(Tm); state[3][i] ^= Tm ^ Tmp ;
}
}
void Cipher()
{
int i,j,round=0;

- 65 -
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] = in[i*4 + j];
}
}
for(round=1;round<Nr;round++)
{
SubBytes();
ShiftRows();
MixColumns();
AddRoundKey(round);
}
SubBytes();
ShiftRows();
AddRoundKey(Nr);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
out[i*4+j]=state[j][i];
}
}
}

int main (void)


{

int i;
initialize();
//uart0_init( UART0_BASE_PTR,8000,9600);
uart_init( UART1_BASE_PTR,24000,9600);
Nr=128;
Nk = Nr / 32;
Nr = Nk + 6;

for(i=0;i<Nk*4;i++)
{
Key[i]=temp[i];
in[i]=temp2[i];

- 66 -
}
KeyExpansion();
Cipher();

for(i=0;i<Nb*4;i++)
{
uart_putchar(UART1_BASE_PTR,out[i]);
}
}

/********************************************************************/

void initialize(void)
{
SIM_SCGC4 = 0X10001C30;//UART CLOCKS ENABLED
SIM_SCGC5 = 0x00003E00;//enabling clock of all ports
//PIN DECLARATIONS AS GPIO

PORTB_PCR18 = 0x00000100;
PORTB_PCR19 = 0x00000100;

PORTD_PCR1 = 0x00000100;
//uart pin declaration
PORTE_PCR0 = 0x00000300;
PORTE_PCR1 = 0x00000300;

//DATA DIRECTION
FGPIOB_PDDR = 0x000C0000;
FGPIOD_PDDR = 0x00000002;

//DEFAULT OFF STATE

FGPIOB_PDOR = 0x000C0000;
FGPIOD_PDOR = 0x00000002;
}
void idelay(int x)
{
int i,j;
for (i = 0; i < x+1;i++){ for(j = 0; j<8000;j++)
{
}
}
}

- 67 -
Code For Decrypting Through UART:

#include "MKL25Z4.h"
#include "MemMapPtr_KL25Z4.h"
#include "uart.h"
#include "string.h"
#define Nb 4
int Nr=0;
// The number of 32 bit words in the key. It is simply initiated to zero. The actual value is
recieved in the program.
int Nk=0;
// in – it is the array that holds the CipherText to be decrypted.
// out – it is the array that holds the output of the for decryption.
// state – the array that holds the intermediate results during decryption.
unsigned char in[16], out[16], state[4][4];
// The array that stores the round keys.
unsigned char RoundKey[240];
// The Key input to the AES Program
unsigned char Key[16];
unsigned char temp[16]={0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00};
unsigned char temp2[16]={0x5a ,0x6f ,0x4b ,0x67 ,0x57 ,0xb7 ,0xa5 ,0xd2 ,0xc4
,0x30 ,0x91 ,0xed ,0x64 ,0x9a ,0x42 ,0x72};

void initialize(void);//intializations
void idelay(int);
/********************************************************************/
int getSBoxInvert(int num)
{
int rsbox[256] =
{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3,
0xd7, 0xfb
, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde,
0xe9, 0xcb
, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa,
0xc3, 0x4e
, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b,
0xd1, 0x25
, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65,
0xb6, 0x92
, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d,
0x9d, 0x84

- 68 -
, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3,
0x45, 0x06
, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13,
0x8a, 0x6b
, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4,
0xe6, 0x73
, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75,
0xdf, 0x6e
, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18,
0xbe, 0x1b
, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd,
0x5a, 0xf4
, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80,
0xec, 0x5f
, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9,
0x9c, 0xef
, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53,
0x99, 0x61
, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21,
0x0c, 0x7d };

return rsbox[num];
}

int getSBoxValue(int num)


{
int sbox[256] = {
//0 1 2 3 4 5 6 7 8 9 A B C D E F
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7,
0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4,
0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8,
0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27,
0xb2, 0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3,
0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c,
0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c,
0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff,
0xf3, 0xd2,

- 69 -
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d,
0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e,
0x0b, 0xdb,
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95,
0xe4, 0x79,
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a,
0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd,
0x8b, 0x8a,
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1,
0x1d, 0x9e,
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55,
0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54,
0xbb, 0x16 };
return sbox[num];
}

int Rcon[255] = {
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab,
0x4d, 0x9a,
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
0x91, 0x39,
0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83,
0x1d, 0x3a,
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
0x6c, 0xd8,
0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
0xfa, 0xef,
0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33,
0x66, 0xcc,
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,
0x80, 0x1b,
0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
0xd4, 0xb3,
0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25,
0x4a, 0x94,
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20,
0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
0x97, 0x35,
0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61,
0xc2, 0x9f,

- 70 -
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01,
0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
0xbc, 0x63,
0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4,
0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8,
0xcb };

void KeyExpansion()
{
int i,j;
unsigned char temp[4],k;
for(i=0;i<Nk;i++)
{
RoundKey[i*4]=Key[i*4];
RoundKey[i*4+1]=Key[i*4+1];
RoundKey[i*4+2]=Key[i*4+2];
RoundKey[i*4+3]=Key[i*4+3];
}
while (i < (Nb * (Nr+1)))
{
for(j=0;j<4;j++)
{
temp[j]=RoundKey[(i-1) * 4 + j];
}
if (i % Nk == 0)
{

// This function rotates the 4 bytes in a word to the left once.


// [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
// Function RotWord()
{
k = temp[0];
temp[0] = temp[1];
temp[1] = temp[2];
temp[2] = temp[3];
temp[3] = k;
}

// SubWord() is a function that takes a four-byte input word and


// applies the S-box to each of the four bytes to produce an output word.
// Function Subword()

- 71 -
{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}
temp[0] = temp[0] ^ Rcon[i/Nk];
}
else if (Nk > 6 && i % Nk == 4)

{
// Function Subword()
{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}
}
RoundKey[i*4+0] = RoundKey[(i-Nk)*4+0] ^ temp[0];
RoundKey[i*4+1] = RoundKey[(i-Nk)*4+1] ^ temp[1];
RoundKey[i*4+2] = RoundKey[(i-Nk)*4+2] ^ temp[2];
RoundKey[i*4+3] = RoundKey[(i-Nk)*4+3] ^ temp[3];
i++;
}
}

// This function adds the round key to state.


// The round key is added to the state by an XOR function.
void AddRoundKey(int round)
{
int i,j;
for(i=0;i<4;i++)
{

for(j=0;j<4;j++)
{
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
}
}

// The SubBytes Function Substitutes the values in the


// state matrix with values in an S-box.

- 72 -
void InvSubBytes()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[i][j] = getSBoxInvert(state[i][j]);
}
}
}
// The ShiftRows() function shifts the rows in the state to the left.
// Each row is shifted with different offset.
// Offset = Row number. So the first row is not shifted.
void InvShiftRows()

{
unsigned char temp;
// Rotate first row 1 columns to right
temp=state[1][3];
state[1][3]=state[1][2];
state[1][2]=state[1][1];
state[1][1]=state[1][0];
state[1][0]=temp;

// Rotate second row 2 columns to right


temp=state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;
temp=state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;

// Rotate third row 3 columns to right


temp=state[3][0];
state[3][0]=state[3][1];
state[3][1]=state[3][2];
state[3][2]=state[3][3];
state[3][3]=temp;

}
// xtime is a macro that finds the product of {02} and the argument to xtime modulo {1b}
#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))

- 73 -
// Multiplty is a macro used to multiply numbers in the field GF(2^8)
#define Multiply(x,y) (((y & 1) * x) ^ ((y>>1 & 1) * xtime(x)) ^ ((y>>2 & 1) *
xtime(xtime(x))) ^ ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ ((y>>4 & 1) *
xtime(xtime(xtime(xtime(x))))))

// MixColumns function mixes the columns of the state matrix.


// The method used to multiply may be difficult to understand for beginners.
// Please use the references to gain more information.
void InvMixColumns()
{
int i;
unsigned char a,b,c,d;
for(i=0;i<4;i++)
{
a = state[0][i];
b = state[1][i];
c = state[2][i];
d = state[3][i];
state[0][i] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d,
0x09);
state[1][i] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d,
0x0d);
state[2][i] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d,
0x0b);
state[3][i] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d,
0x0e);
}
}
// InvCipher is the main function that decrypts the CipherText.
void InvCipher()
{
int i,j,round=0;
//Copy the input CipherText to state array.
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] = in[i*4 + j];
}
}
// Add the First round key to the state before starting the rounds.
AddRoundKey(Nr);

// There will be Nr rounds.

- 74 -
// The first Nr-1 rounds are identical.
// These Nr-1 rounds are executed in the loop below.
for(round=Nr-1;round>0;round--)
{
InvShiftRows();
InvSubBytes();
AddRoundKey(round);
InvMixColumns();
}
// The last round is given below.
// The MixColumns function is not here in the last round.

InvShiftRows();
InvSubBytes();
AddRoundKey(0);

// The decryption process is over.


// Copy the state array to output array.

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
out[i*4+j]=state[j][i];
}
}
}

int main (void)


{

int i;
initialize();
//uart0_init( UART0_BASE_PTR,8000,9600);
uart_init( UART1_BASE_PTR,24000,9600);
Nr=128;
Nk = Nr / 32;
Nr = Nk + 6;

for(i=0;i<Nk*4;i++)
{

- 75 -
Key[i]=temp[i];
in[i]=temp2[i];
}
//The Key-Expansion routine must be called before the decryption routine.
KeyExpansion();
// The next function call decrypts the CipherText with the Key using AES algorithm.
InvCipher();

for(i=0;i<Nb*4;i++)
{
uart_putchar(UART1_BASE_PTR,out[i]);
}
}

/********************************************************************/

void initialize(void)
{
SIM_SCGC4 = 0X10001C30;//UART CLOCKS ENABLED
SIM_SCGC5 = 0x00003E00;//enabling clock of all ports
//PIN DECLARATIONS AS GPIO

PORTB_PCR18 = 0x00000100;
PORTB_PCR19 = 0x00000100;

PORTD_PCR1 = 0x00000100;
//uart pin declaration
PORTE_PCR0 = 0x00000300;
PORTE_PCR1 = 0x00000300;

//DATA DIRECTION
FGPIOB_PDDR = 0x000C0000;
FGPIOD_PDDR = 0x00000002;

//DEFAULT OFF STATE

FGPIOB_PDOR = 0x000C0000;
FGPIOD_PDOR = 0x00000002;

- 76 -
void idelay(int x)
{
int i,j;
for (i = 0; i < x+1;i++){
for(j = 0; j<8000;j++)
{
}
}
}

- 77 -

Vous aimerez peut-être aussi