Sei sulla pagina 1di 84

VIRTUAL SCRIBBLING PAD

Project report is submitted in Partial fulfillment of the requirements for


the award of the degree.

BACHELOR OF TECHNOLOGY

IN

ELECTRONICS AND COMMUNICATION


ENGINEERING

Under the guidance of

M.Tech
Assistant Professor,
Department of Electronics and communication Engineering
CONTENTS

ABSTRACT

CHAPTER 1. INTRODUCTION

1.1 Background

1.2 Overview of Project

1.3 Software used

1.4 Block Diagram of Virtual Scribbling Pad

1.5 Component Specifications

CHAPTER 2. THEORITICAL ANALYSIS

2.1 Digital Image Processing

2.2 Various Techniques in Digital Image Processing

2.3 Applications

2.4 Concepts used in our Project

CHAPTER 3. DETAILED STUDY

3.1 Optical character recognition

3.2 Types of Images

3.3 Conversion of Image Formats

CHAPTER 4. MATLAB

4.1 Overview of MATLAB

4.2 Matlab Fundamentals

4.3 The Matlab System


4.4 Basic Commands

4.5 File Types

4.6 Matlab Windows

CHAPTER 5 MICROCONTROLLER

5.1 Microcontroller (AT89C51)

5.2 Necessity of Microcontroller

5.3 Typical Microcontroller Features

5.4 Why AT89C51?

5.5 Microcontroller Architecture

CHAPTER 6 SERIAL COMMUNICATION

6.1 Introduction

6.2 What is RS-232C?

6.3 Power Supply

CHAPTER 7 LIQUID CRYSTAL DISPLAY

7.1 LCD Module

7.2 Flow Chart

7.3 Keil Software

CHAPTER 8 METHODOLOGY OF WORK

8.1 Flow Chart

8.2 Program

CHAPTER 9 CONCLUSION
ABSTRACT

From the past days man is inventing various things to lead a comfortable & luxurious life.
Not only inventing newer things but also he is continuously attempting to implement new
technologies into that field. In this attempt he got success in finding out a computer,
which can be undoubtedly called, his fantasy.

After invention of the revolutionary devices like the computer, most of us still use
pen and paper for any information interchange. Typing, for the most part, is reserved for
final productions. For quick notes, drafts, and ideas it is easier to jot them down on paper.
This is a project based on Image processing technique, to have a digital copy of
everything written on paper without the need of special papers or a scanner.

With the image processing technique, everything (i.e., alpha-numeric data) you
write down on paper will now also show up on the computer screen. Best of all, it will
work with any paper up to letter (A4) size. Here the concept is to capture the image of
some specific area and from that captured image; the characters are extracted using
optical character recognition technique which is implemented in Matlab. The extracted
characters are displayed on the computer screen.

Applications:

• Mobile Phone
• PDA’s
• Digital Accessories
Advantages:

• Useful for quick information interchange


• Eliminates time wastage in making soft copy from hard copy
• Simple and easy to operate

Technologies:

• Digital Camera
• Image processing techniques
• MATLAB
CHAPTER 1

INTRODUCTION
1.1 BACKGROUND

The future is here. As the technology is improving, so is the lifestyle,


people are becoming so sophisticated that they are even ready to buy leisure. A search for
latest, cheapest and reliable technology is still on. Virtual systems, which were once
dream, are now in front of our eyes, standing. Virtual Scribbling Pad, the latest of
technologies has already shown its presence.

This Virtual Scribbling Pad saves time and effort. The main application of
which is in the cell phones, PDAs and other hand held devices. The core of our project is
Matlab software, which uses digital image processing techniques.

1.2 OVERVIEW OF PROJECT

The concept is to capture the image of some specific area and from that captured
image; the characters are extracted using optical character recognition technique
which is implemented in MATLAB. The extracted characters are displayed on the
computer screen.

Step1. A simple web cam is used as a part of the sensor module. Using Optical
Character Recognition technique which is implemented in MATLAB, the characters
are extracted.

Step2.The extracted character is recognized by comparing with a trained set of


images using DIP techniques and then displayed on the computer screen.
1.3 SOFTWARE USED

MATLAB is a high-performance language for technical computing. It


integrates computation, visualization, and programming in an easy-to-use environment
where problems and solutions are expressed in familiar mathematical notation. Typical
uses include Math and computation Algorithm development Data acquisition Modeling,
simulation, and prototyping Data analysis, exploration and visualization, Scientific and
Engineering graphics Application development, including graphical user interface
building MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would
take to write a program in a scalar no interactive language such as C or FORTRAN.

The name MATLAB stands for matrix laboratory. In university environments, it


is the standard instructional tool for introductory and advanced courses in mathematics,
engineering, and science. In industry, MATLAB is the tool of choice for high-
productivity research, development, and analysis. MATLAB features a family of add-on
application-specific solutions called toolboxes. Very important to most users of
MATLAB, toolboxes allow you to learn and apply specialized technology.
1.4 BLOCK DIAGRAM OF VIRTUAL SCRIBBLING PAD

LCD
Webca PC Micro
(MATLAB) Controller
(AT89C51)

Scribbling Pad
1.5 COMPONENT SPECIFICATION

The main component used in this project is the PC (Personal Computer)


with a Webcam so that this Camera captures the characters written on the scribbling pad
and gives it to PC using a USB cable. The sensing unit here is the Webcam.

The Computer uses image processing techniques on the captured image


by using the MATLAB software to get the desired character. This is the processing unit
specified in the block diagram.

The recognized character displayed on the PC is sent to Microcontroller


using serial communication to display it on the LCD. This is the display unit specified in
the block diagram.
CHAPTER 2

THEORITICAL ANALYSIS

2.1 DIGITAL IMAGE PROCESSING

An image may be defined as a two dimensional function f(x, y), where x


and y are spatial (plane) coordinates and the amplitude of ‘f’ is called the intensity or
gray level of the image at that point. The monochrome image or single color image such
as black and white photograph is represented as a two dimensional light intensity
function f(x,y), where x and y denote spatial co ordinates and the value of ‘f ‘ at any
point(x,y) is proportional to the brightness (or gray level) of the image at that point .
Similarly it is possible to represent a three color image such as the classic color
photograph by three functions fR(x,y), fG(x,y),fB(x,y) expressing the intensity of each of
the three primary colors red, green, blue at that point(x,y) on the image.

Vision is the most advanced of our senses, so it is not surprising that


images play the single most roles in human perception .However, unlike humans, who are
limited to the visual band of the electromagnetic spectrum, ranging from gamma to radio
waves. They can operate on images generated by sources that humans are not accustomed
to associating with images.

These include ultrasound, electron microscopy and computer generated


images. Thus digital image processing encompasses a wide and varied field of
applications.

Therefore any form of processing, which converts a continuous image


(input) into another continuous image (output) is known as “analog image processing“.
This includes calculations carried out on analog computers as well as optical processing
techniques. Digital image processing technology evolved rapidly because of several
advantages is carried out by digital computer, which converts a discrete input image into
a discrete output image by sampling and quantization techniques. Therefore digital image
is an image of f(x, y) that has been digitized both in spatial co ordinates and brightness.

Thus when x, y and the amplitude values of ‘f’ are all finite, discrete
quantities, then we call the image a “Digital Image”. In a broader sense “digital image
processing” is of any two dimensional data. A digital image is composed of a finite
number of elements are referred to as picture elements, image elements, and pixels. Pixel
is the term most widely used to denote the elements of a digital image.

There are many steps in the processing of a digital image. The first step in
the processing is the image acquisition i.e., to acquire a digital image. It involves the
conversion of a scene into a digital representation by various sensors like micro
densitometries, image dissectors, vidicon cameras and photosensitive solid-state arrays
(photo sites and charge-coupled devices). A typical line-scan CCD sensor contains a row
of photo sites, two transfer gates used to clock the contents of the image elements into so
called transport registers and an output gate used to clock the contents of the transport
registers into amplifier. The amplifier outputs a voltage signal proportional to the row of
photo sites.

After a digital image has been obtained, the next step deals with
preprocessing of that image. The key function of preprocessing is to improve the image in
ways that increase the chances for the success of the other processes by dealing with
techniques for enhancing contrast, removing noise and isolating regions. Segmentation
partitions an input image into its constituent parts or objects. The raw pixel data, the
output of segmentation is transformed into a form suitable for computer processing and
this processing is done by representation block. Description also called “feature
solution”, deals with extracting features that result in some quantitative information of
interest or features that are basic for differentiating one class objects from another.
Recognition is a process that assigns a label to an object based on the information
provided by its recognized objects. Finally, the knowledge base controls the interaction
between various modules, i.e., in the above figure knowledge about an input image is
coded into an image processing system in the form of knowledge database.

2.2 VARIOUS TECHNIQUES IN DIGITAL IMAGE PROCESSING

The term digital processing generally refers to processing of a two-dimensional


picture by a digital computer. A digital image is an array of real or complex numbers
represented by a finite number of bits.
An image given in the form of a transparency, slide photograph or chart is
first digitized and stored as a matrix of binary bits in computer memory. This digitized
image can then be processed and /or displayed on a high-resolution television monitor.

Types of Digital Image Processing Techniques:

1. Image representation and modeling


2. Image enhancement
3. Image resolution
4. Image analysis
5. Image reconstruction
6. Image data compression

1) Image representation and Modeling:

An important consideration in image representation is the fidelity or


intelligibility criteria for measuring the quality of an image or the performance of a
processing technique. Specification of such measures requires models of perception of
contrast, spatial frequencies, and color and so on. Knowledge of a fidelity criterion helps
in designing the imaging sensor because it tells us the variables that should be measured
most accurately.

The fundamental requirement of digital processing is that images be


sampled and quantized. The sampling rate (number of pixel per unit area) has to be large
enough to preserve the useful information in an image. It is determined by the bandwidth
of the image.
2) Image Enhancement:

In image enhancement the goal is to accentuate certain image features for


subsequent analysis or for image display. Examples include contrast and edge
enhancement pseudo coloring, noise filtering sharpening and magnifying. Image
enhancement is useful in feature extraction, image analysis and visual information
display. The enhancement process itself does not increase the inherent information
content in the data. It simply emphasizes certain specified image characteristics.
Enhancement algorithms are generally interactive and application-dependent.

Image enhancement techniques such as contrast stretching; map each gray


level into another gray level by a predetermined transformation. An example is the
histogram equalization method, where the input gray levels are mapped so that the output
gray level distribution is uniform. This has been found to be a powerful method of
enhancement of low contrast images. Other enhancement techniques perform local
neighborhood operations as in convolution, transform operation as in the discrete Fourier
transform, and other operation in pseudo coloring where a gray level image is mapped
into a color image by assigning different colors to different features

3) Image restoration:

Image restoration refers to removal or minimization of known degradations


in an image. This includes de-blurring of images degraded by the limitation of a sensor or
its environment, noise filtering and correction of geometric distortion or non-linearities
due to sensors.

A fundamental result in filtering theory used commonly for image


restoration is called the wiener filter. This filter gives the best linear mean square estimate
of the object from the observations. It can be implemented in frequency domain via the
fast unitary transform, in spatial domain by two dimensional recursive techniques similar
to Kalman filtering or by FIR non-recursive filters. It can also be implemented as a semi-
recursive filter that employs a unitary transform in one of the dimension and recursive
filter in the other.

Several other image restoration methods such as least squares, constraint


least squares and interpolation methods can be shown to belong to the class of wiener
filtering algorithms. Other method such as maximum likely hood, maximum entropy and
maximum a posteriori are non-linear techniques that require iterative solutions.

4) Image Analysis:

Image analysis is concerned with making quantitative measurements from an


image to produce a description of it. Image analysis techniques require extraction of
certain features that aid in the identification of the object. Segmentation techniques are
used to isolate the desired object from the scene so that measurements can be made on it
subsequently. Quantitative measurements of object features allow classification and
description of the image.

5) Image Reconstruction:

Image reconstruction from projects is a special class of image restoration


process where a low (or high) D dimensional object is reconstructed from several single
projections.
2.3 APPLICATIONS

Today there is almost every area of technical endeavor impacted in some


way by digital image processing. It is used in

• Remote Sensing Via Satellite:

(a) Tracking of earth resources

(b) Geographical mapping

(c) Prediction of Agricultural crops

(d) Urban growth and

(e) Weather

• Spacecrafts:

It includes recognition and analysis of objects contained in images obtained from


deep space probe mission.

• Image transmission and storage:

(a) In broadcast television

(b) Teleconferencing

(c) Communication over computer network

(d) Closed circuit television based security-monitoring system.

• Medical Processing:
(a) Processing of x-ray images.

(b) Processing of ultrasonic scanned images

• Radar:

To detect the presence of targets.

2.4 CONCEPTS USED IN OUR PROJECT

• Image Acquisition
• Image Processing
2.4.1 IMAGE ACQUISITION

Image Acquisition is a process that attaches the image to the specimen.


The Image could be obtained from an external device such as the camera or scanner or
from a previously created image file.

Steps involved for Image Acquisition:-

Step 1: Install and configure your image acquisition device

Step 2: Retrieve information of your image acquisition device.

Matlab Command: - imaqhwinfo

Step 3: Create a video input

Matlab Command: - x = videoinput(“winvideo”)

Step 4: Preview the video input

Matlab Command: - preview(x)

Step 5: Acquire the video image

Matlab Command: - y = getsnapshot(x)

Step 6: Acquire the video image figure

Matlab Command: - imshow(y)

Step 7: Close the video object


Matlab Command: - close (or) delete

2.4.2 IMAGE PROCESSING

Image processing is any form of information processing for which the


input is an image, such as photographs or frames of video; the output is not necessarily an
image, but can be for instance a set of features of the image. Most image-processing
techniques involve treating the image as a two-dimensional signal and applying standard
signal-processing techniques to it.

The Image Processing Toolbox is a collection of functions that extend the


capability of the MATLAB numeric computing environment. The toolbox supports a
wide range of image processing operations, including

• Spatial image transformations


• Morphological operations
• Neighborhood and block operations
• Linear filtering and filter design
• Transforms
• Image analysis and enhancement
• Image registration
• Deblurring
• Region of interest operations
CHAPTER 3
DETAILED STUDY

3.1 OPTICAL CHARACTER RECOGNITION


Full form of OCR is “Optical Character Recognition”. It is a computer
program designed to convert scanned or digital images of handwritten or typewritten text
into machine-editable text, or to translate pictures of characters into a standard encoding
scheme representing them (e.g. ASCII or Unicode). OCR began as a field of research in
pattern recognition, artificial intelligence and machine vision. Though academic research
in the field continues, the focus on OCR has shifted to implementation of proven
techniques.

. In recent years, it has become possible to scan in paper copies of documents


so as to form computerized images of such documents, analyze images in the text areas of
the documents so as to recognize individual characters in the text data, and form
computer readable files of character codes corresponding to the recognized characters.
With the advent of optical imaging capabilities and optical character recognition (OCR)
software, data placed on a form can be digitized by such instruments as a scanner or fax
machine and the digitized data can be interpreted as text by the OCR software. A number
of optical character recognition (OCR) systems are known. Typically, such systems
comprise apparatus for scanning a page of printed text and performing a character
recognition process on a bit-mapped image of the text, which is a pixel-by-pixel
representation of the overall image in a binary form. The recognition system reads
characters of a character code line by framing and recognizing the characters within the
image data.

During the recognition process, the document is analyzed for several key
factors such as layout, fonts, text and graphics. The document is then converted into an
electronic format that can be edited with application software. The output image is then
supplied to a computer or other processing device, which performs an OCR algorithm on
the scanned image. The document can be of many different languages, forms and
features. The purpose of the OCR algorithm is to produce an electronic document
comprising a collection of recognized words that are capable of being edited.

There are two basic methods used for OCR: matrix matching and feature
extraction. Matrix matching compares what the OCR device sees as a character against a
library of character matrices or templates. When an image matches one of these
prescribed templates within a given level of accuracy, the OCR application assigns that
image the corresponding American Standard Code for Information Interchange (ASCII)
symbol. Feature extraction, also known as intelligent character recognition (ICR), is OCR
without strict matching to prescribed templates. The amount of computing intelligence
that is applied by a device varies the results for ICR applications.

The application looks for general features such as open areas, closed shapes,
diagonal lines, line intersections, etc. The character recognition device recognizes
characters by a very high recognition rate if the characters are written clearly in directed
regions of a sheet etc., of a document, on which the region for writing letters is specified.
OCR systems are capable of segmenting the electrical image data into blocks, lines and
words upon recognizing these features. An OCR program can differentiate between text
objects and non-text objects (such as the background) in an image based on intensity
differences between the text objects and the background.

Optical character recognition (OCR) systems employ various strategies for


isolating small portions of the image as connected components, segmenting a connected
component into one or several character images and recognizing each such image as
representing a specific character. An optical character recognition device is generally only
capable of recognizing characters printed in a font that the OCR device has been trained
to recognize. Devices such as an optical scanner or an optical reader may be utilized to
input data into a data processing system for analysis or processing. Pattern recognition
classifiers are used in sorting scanned characters into a number of output classes.

During operation, the system receives an input image associated with one of a
plurality of classes. The relationship of the image to each class is analyzed via a
classification technique based upon the training parameters. In general, the operation of
optical character recognition systems involves placing text on a scanner and obtaining a
pixel bitmap of the page to be read, converting that image to text using an OCR program
in the personal computer to which the scanner is attached. Automated scanning and
processing with OCR systems improves document processing efficiency by automating
the previously slow, labor-intensive and costly procedure of manually processing the
information contained on these forms. Document processors employing OCR devices
have been widely utilized to facilitate processing of pre-formatted business forms and
documents.

Optical character recognition (OCR) techniques are used in automated mail


processing scanning or reading, sorting, handling, and distributing systems to
accommodate and process an ever-increasing range of individually diverse mail products,
pieces, articles, or units. Optical character recognition is commonly used in the currency
processing field for lifting the serial number or code from processed notes. OCR
technology is used, for example, for identifying specific notes processed by a high speed
currency processing machine by lifting a note's serial code using a camera device and
then recording the serial code to the note processed.

3.2 TYPES OF IMAGES


An image is defined as combination of pixels or picture elements. An image
may also be defined as a two dimensional function f(x, y), where x and y are spatial
(plane) coordinates and the amplitude of ‘f’ is called the intensity or gray level of the
image at that point.

RGB Image

The purpose of this model is to facilitate the specification of colors in some


standard, generally accepted way. In essence, a color model is a specification of a
coordinate system and a subspace within that system where each color is represented by a
single point.

The most commonly used color model is RGB (red, green, blue) model for color
monitors and a bread class of color video cameras.

RGB values are at three corners; cyan, magenta, and yellow are at three other
corners; black is at the origin; and white is at the corner farthest form the origin. In this
model, the gray scale extends form back to white along the line joining these two points.
The different colors in this model are points on or inside the cube, and are defined by
vectors extending form the origin.

Example: - RGB Image

Grayscale image
Grayscale is obtained by eliminating the hue and saturation information while
retaining the luminance.

An intensity image is a data matrix, I, whose values represent intensities within some
range. MATLAB stores an intensity image as a single matrix, with each element of the
matrix corresponding to one image pixel. The matrix can be of class double, uint8, or
uint16. While intensity images are rarely saved with a color map, MATLAB uses a color
map to display them. The elements in the intensity matrix represent various intensities, or
gray levels, where the intensity 0 usually represents black and the intensity 1, 255, or
65535 usually represents full intensity, or white.

Example: - Grey scale Image.

Binary image
In a binary image, each pixel assumes one of only two discrete values. Essentially,
these two values correspond to on and off. A binary image is stored as a logical array of
0's (off pixels) and 1's (on pixels), i.e., a complete black & white image.

This image format stores an image as a matrix but can only color a pixel black or
white (and nothing in between). It assigns a 0 for black and a 1 for white.

Example: - A Binary Image

3.3 CONVERSION OF IMAGE FORMATS


3.3.1 RGB TO GRAY CONVERSION

For converting RGB to Gray.

Command: - J = rgb2gray(I)

Input - I Output - J

RGB Image Grey Scaled Image

RGB Image Grey Scaled Image

3.3.2 IMAGE TO BLACK-WHITE CONVERSION


Convert image to binary image, based on threshold.

Command: - Z = im2bw(x)

Input

Output

3.3.3 IMFILL
Command: - imfill(I,’holes’)

Input

Output

3.3.4 IMCLOSE
The operation performed is, it closes an image

COMMAND: - I = imclose(J)

Input

Output

3.3.5 IMAGE RESIZING


To change the size of an image, use the imresize function. Using imresize,
you can specify the size of the output image.
CHAPTER 4

MATLAB
MATLAB is a software package for high-performance numerical computation and
visualization. It provides an interactive environment with hundreds of built-in functions
for technical computations, graphics, and animation. Biggest of all, it also provides
extensibility with its own high-level programming language

4.1 Overview of MATLAB

It integrates computation, visualization, and programming in an easy-to-use


environment where problems and solutions are expressed in familiar mathematical
notation. Typical uses include

• Math and computation


• Algorithm development
• Data acquisition
• Modeling, simulation, and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would
take to write a program in a scalar no interactive language such as C or Fortran. The
name MATLAB stands for matrix laboratory. MATLAB was originally written to provide
easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the
state of the art in software for matrix computation.

MATLAB features a family of add-on application-specific solutions called toolboxes.


Very important to most users of MATLAB, toolboxes allow you to learn and apply
specialized technology. Toolboxes are comprehensive collections of MATLAB functions
(M-files) that extend the MATLAB environment to solve particular classes of problems.
Areas in which toolboxes are available include signal processing, control systems, neural
networks, fuzzy logic, wavelets, simulation, and many others.
4.2 Matlab Fundamentals

Matlab is a versatile program which allows you to use a computer to solve a


vast number of problems in science and mathematics both numerically and through
visualization. Some of the strengths of Matlab are:

• Flexibility to solve a large number of problems


• Good tools for visualization
• Can be used on most computer systems (Mac, PC, Unix Workstation, Cray, ...)
• Used at many colleges, universities and industry in many different disciplines
(science, math, computer science, finance)
• The scripting language is relatively easy to learn, and is complementary with
traditional programming languages (BASIC, FORTRAN, C, Pascal)

What can we use Matlab for?

1. Simple calculations
2. Plotting and analyzing mathematical relationships (2D and 3D)
3. List & Matrix Operations
4. Writing script files (a type of programming)
5. Symbolic manipulation of equations
6. Advanced visualization, animation and GUI interface tools

4.3 The MATLAB System

The MATLAB system consists of these main parts:

• Desktop Tools and Development Environment — Startup and shutdown, the desktop,
and other tools that help you use MATLAB
• Mathematics — Mathematical operations
• Data Analysis — Data analysis, including data fitting, Fourier analysis, and time-series
tools
• Programming — The MATLAB language and how to develop MATLAB applications
• Graphics — Tools and techniques for plotting, graph annotation, printing, and
programming with Handle Graphics
• 3-D Visualization — Visualizing surface and volume data, transparency, and viewing
and lighting techniques
• Creating Graphical User Interfaces — GUI-building tools and how to write callback
functions
• External Interfaces — MEX-files, the MATLAB engine, and interfacing to Java, COM,
and the serial port

4.4 Basic Commands


To exit the Matlab, try the following commands under Matlab prompt:

>> exit
Or >> quit

After enter the Matlab, you can get on-screen information about the Matlab commands
with help. Typing

>> help
produces a listing of all HELP topics and Matlab commands (includes commands related
to all the toolboxes available on the path). If you know the name of the function you want
help on, you can type:

>> help topic


Or >> help function name

In addition, you can learn more features of Matlab by running the demo:

>> demo

MATLAB’s built-in functions provide excellent tools for linear algebra


computations, data analysis, signal processing, optimization, numerical solution of
ordinary differential equations (ODEs), quadrature, and many other types of scientific
computations. Most of these functions use state-of-the art algorithms. The user, however,
is not limited to the built-in functions; he can write his own functions in the MATLAB
language. Once written, these functions behave just like the built-in functions.
MATLAB’s language is very easy to learn and to use.

There are also several optional ‘Toolboxes’ available from the


developers of MATLAB. These Toolboxes are collections of functions written for special
applications such as symbolic computation, Image processing, Statistics, Control System
Design, Neural Networks, etc.

The basic building block of MATLAB is the matrix. The fundamental


data-type is the array. Vectors, scalars, real matrices and complex matrices are all
automatically handled as special cases of the basic data-type. The built-in functions are
optimized for vector operations. Consequently, vectorized commands or codes run much
faster in MATLAB.

The features of MATLAB are its ease of extendability, through user-


written programs. MATLAB provides its own language, which incorporates many
features from C. In some regards, it is a higher level language than most common
programming languages, such as Pascal, Forton and C.

4.5 FILE TYPES

MATLAB has three types of files for storing information:

M-files are standard ASCII text files, with an .m extension to the file name. There are
two types of these files: script file and function files. Most programs we write in
MATLAB are saved as M-files. All built in functions in MATLAB are M-files, most of
which reside on our computer in precompiled format. Some built-in functions are
provided with source code in readable M-files so that they can be copied and modified.

Mat-files are binary data files, with a .mat extension to the file name. Mat-files are
created by MATLAB when we save data with the save command. The data is written in a
special format that only MATLAB can read. Mat-files can be loaded in to MATLAB with
the load command.

TLAB callable FORTRAN and C Programs, with .mex extension to the file name.

M-files:
In MATLAB we write our programs in M-file. M-files are ordinary ASCII text
files written in MATLAB’s language. They are called M-files because they must have a
‘.m’ at the end of their name. M-files can be created using any editor or word processing
applications. There are two types of M-files –script files and function files.
A script file is an M-file with a set of valid MATLAB commands in it. A
script file is executed by typing the name of the file and the command line. It is
equivalent to typing all the commands stored in the script file, one by one, at the
MATLAB prompt. Naturally, script files work on global variables, i.e. variables currently
present in the workspace. Results obtained from executing script files are left in the
workspace. A script file may contain any number of commands including those that call
built-in functions or function written by us. Script files are useful when we have to repeat
the set of commands several times.
A function file is also an M-file like a script file, except that the variables
in the function file are all local. Function files are like programs or subroutines in
Fortran, procedures in Pascal, and functions in C. A function file begins with a function
definition line, which has a well defined list of inputs and outputs. Without this line, the
file becomes a script file.

4.6 MATLAB WINDOWS

MATLAB works through three basic windows they are

1. Command Window: This is the main window. It is characterized by the MATLAB


command prompt ‘>>’. When we launch the application program, MATLAB puts us in
this window. All command including those for running user-written programs, are typed
in this window at the MATLAB prompt. In MATLAB 6, this window is a part of the
MATLAB window that contains three other smaller windows.

Workspace: The sub window lists all variables that we have generated so far and shows
their type and size. We can do various things with these variables, such as plotting, by
clicking on a variable and then using the right button on the mouse to select our option.
Command History: All commands typed on the MATLAB prompt in the command
window get recorded, even across multiple sessions, in this window. We can select a
command from this window with the mouse and execute it in the command window by
double clicking on it. We can also select a set of commands from this window and create
an M-file with the right click on the mouse.

Current Directory: This is where all our files from the current directory are listed. We
can do file navigation here. We also have several options of what we can do with a file
once we select it. To see the option, click the right button of the mouse after selecting a
file. We can run M-files, rename them, delete them, etc.

2. Graphical Window: The output of all graphics commands typed in the command
window are flushed to the graphics or Figure window, a separate gray window with white
background color. The user can create as many figure windows as the system memory
will allow.

3. Edit Window: This is where we write, edit, create, and save our own programs in files
called ‘M-files’. We can use any text editor to carry out these tasks. On most systems,
MATLAB provides its own built-in editor. However, we can use our own editor by typing
the standard file-editing command that we normally use on our system
CHAPTER 5

MICROCONTROLLER

5.1 MICRO-CONTROLLER
Micro-controller unit is constructed with ATMEL 89C51 Micro-controller chip. The
ATMEL AT89C51 is a low power, higher performance CMOS 8-bit microcomputer with 4K bytes
of flash programmable and erasable read only memory (PEROM). Its high-density non-volatile
memory compatible with standard MCS-51 instruction set makes it a powerful controller that
provides highly flexible and cost effective solution to control applications.

Micro-controller works according to the program written in it. The program is written in
such a way, so that the output from the ADC will be converted into its equivalent voltage and
based on the magnitude of the voltage, it calculates the parameter value. Now this magnitude is
again digitalized and fed to LCD display unit through the latch.

Micro-controllers are "embedded" inside some other device so that they can control the
features or actions of the product. Another name for a micro-controller, therefore, is "embedded
controller". Micro-controllers are dedicated to one task and run one specific program. The
program is stored in ROM (read-only memory) and generally does not change. Micro-controllers
are often low-power devices. A battery-operated Microcontroller might consume 50 milli watts.
A micro-controller has a dedicated input device and often (but not always) has a small LED or
LCD display for output. A micro-controller also takes input from the device it is controlling and
controls the device by sending signals to different components in the device

5.2 Necessity of Microcontroller


Microprocessors brought the concept of programmable devices and made many
applications of intelligent equipment. Most applications, which do not need large amount
of data and program memory, tended to be:

Costly: The microprocessor system had to satisfy the data and program
requirements so, sufficient RAM and ROM are used to satisfy most applications .The
peripheral control equipment also had to be satisfied. Therefore, almost all-peripheral
chips were used in the design. Because of these additional peripherals cost will be
comparatively high.

An example:

8085 chip needs: An Address latch for separating address from multiplex address
and data.32-KB RAM and 32-KB ROM to be able to satisfy most applications. As also
Timer / Counter, Parallel programmable port, Serial port and Interrupt controller are
needed for its efficient applications.
In comparison a typical Micro controller 8051 chip has all that the 8051 board has
except a reduced memory as follows.
4K bytes of ROM as compared to 32-KB, 128 Bytes of RAM as compared to 32-KB.

Bulky: On comparing a board full of chips (Microprocessors) with one chip with
all components in it (Micro controller).

Debugging: Lots of Microprocessor circuitry and program to debug. In Micro


controller there is no Microprocessor circuitry to debug Slower Development time: As we
have observed Microprocessors need a lot of debugging at board level and at program
level, where as, Micro controller do not have the excessive circuitry and the built-in
peripheral chips are easier to program for operation.
So peripheral devices like Timer/Counter, Parallel programmable port, Serial
Communication Port, Interrupt controller and so on, which were most often used were
integrated with the Microprocessor to present the Micro controller .RAM and ROM also
were integrated in the same chip. The ROM size was anything from 256 bytes to 32Kb or
more. RAM was optimized to minimum of 64 bytes to 256 bytes or more.

5.3 Typical Micro controller has all the following features:

• 8/16/32 CPU
• Instruction set rich in I/O & bit operations.
• One or more I/O ports.
• One or more timer/counters.
• One or more interrupt inputs and an interrupt controller
• One or more serial communication ports.
• Analog to Digital /Digital to Analog converter
• One or more PWM output
• Network controlled interface

5.4 Why AT 89C51?

The system requirements and control specifications clearly rule out the use of 16, 32
or 64 bit micro controllers or microprocessors. Systems using these may be earlier to
implement due to large number of internal features. They are also faster and more
reliable but, the above application is satisfactorily served by 8-bit micro controller.
Using an inexpensive 8-bit Microcontroller will doom the 32-bit product failure in
any competitive market place.
Coming to the question of why to use AT89C51 among all the 8-bit
Microcontrollers available in the market the main answer would be because it has
4 Kb on chip flash memory which is just sufficient for our application. The on-chip
Flash ROM allows the program memory to be reprogrammed in system or by
Conventional non-volatile memory Programmer. Moreover ATMEL is the leader in
Flash technology in today’s market place and hence using AT 89C51 is the optimal
solution.

5.5 8051 Microcontroller architecture


The 8051 architecture consists of these specific features:

 Eight –bit CPU with registers A (the accumulator) and B


 Sixteen-bit program counter (PC) and data pointer (DPTR)
 Eight- bit stack pointer (PSW)
 Eight-bit stack pointer (Sp)
 Internal ROM or EPROM (8751) of 0(8031) to 4K (8051)
 Internal RAM of 128 bytes:
1. Four register banks, each containing eight registers
2. Sixteen bytes, which maybe addressed at the bit level
3. Eighty bytes of general- purpose data memory
 Thirty –two input/output pins arranged as four 8-bit ports:p0-p3
 Two 16-bit timer/counters: T0 and T1
 Full duplex serial data receiver/transmitter: SBUF
 Control registers: TCON, TMOD, SCON, PCON, IP, and IE
 Two external and three internal interrupts sources.
 Oscillator and clock circuits.
Functional block diagram of micro controller

5.5.1 The 8051 oscillator and clock:

The heart of the 8051 circuitry that generates the clock pulses by which all the
internal all internal operations are synchronized. Pins XTAL1 and XTAL2 is provided for
connecting a resonant network to form an oscillator. Typically a quartz crystal and
capacitors are employed. The crystal frequency is the basic internal clock frequency of
the microcontroller. The manufacturers make 8051 designs that run at specific minimum
and maximum frequencies typically 1 to 16 MHz.
5.5.2 Types of memory:

The 8051 have three general types of memory. They are on-chip memory, external
Code memory and external Ram. On-Chip memory refers to physically existing memory
on the micro controller itself. External code memory is the code memory that resides off
chip. This is often in the form of an external EPROM. External RAM is the Ram that
resides off chip. This often is in the form of standard static RAM or flash RAM.
a) Code memory
Code memory is the memory that holds the actual 8051 programs that is to be run.
This memory is limited to 64K. Code memory may be found on-chip or off-chip. It is
possible to have 4K of code memory on-chip and 60K off chip memory simultaneously.
If only off-chip memory is available then there can be 64K of off chip ROM. This is
controlled by pin provided as EA
b) Internal RAM
The 8051 have a bank of 128 of internal RAM. The internal RAM is found on-
chip. So it is the fastest Ram available. And also it is most flexible in terms of reading
and writing. Internal Ram is volatile, so when 8051 is reset, this memory is cleared. 128
bytes of internal memory are subdivided. The first 32 bytes are divided into 4 register
banks. Each bank contains 8 registers. Internal RAM also contains 128 bits, which are
addressed from 20h to 2Fh. These bits are bit addressed i.e. each individual bit of a byte
can be addressed by the user. They are numbered 00h to 7Fh. The user may make use of
these variables with commands such as SETB and CLR.

PIN OUT DIAGRAM OF 89C51 IC


.

5.5.3 Special Function registered memory:


Special function registers are the areas of memory that control specific
functionality of the 8051 micro controller.

a) Accumulator (0E0h)
As its name suggests, it is used to accumulate the results of large no of
instructions. It can hold 8 bit values.

B) B registers (0F0h)
The B register is very similar to accumulator. It may hold 8-bit value. The b
register is only used by MUL AB and DIV AB instructions. In MUL AB the higher byte
of the product gets stored in B register. In div AB the quotient gets stored in B with the
remainder in A.

c) Stack pointer (81h)


The stack pointer holds 8-bit value. This is used to indicate where the next value
to be removed from the stack should be taken from. When a value is to be pushed onto
the stack, the 8051 first store the value of SP and then store the value at the resulting
memory location. When a value is to be popped from the stack, the 8051 returns the
value from the memory location indicated by SP and then decrements the value of SP.

d) Data pointer
The SFRs DPL and DPH work together work together to represent a 16-bit value
called the data pointer. The data pointer is used in operations regarding external RAM
and some instructions code memory. It is a 16-bit SFR and also an addressable SFR.

e) Program counter
The program counter is a 16 bit register, which contains the 2 byte address, which
tells the 8051 where the next instruction to execute to be found in memory. When the
8051 is initialized PC starts at 0000h. And is incremented each time an instruction is
executes. It is not addressable SFR.

f) PCON (power control, 87h)


The power control SFR is used to control the 8051’s power control modes.
Certain operation modes of the 8051 allow the 8051 to go into a type of “sleep mode”
which consumes much lee power.

g) TCON (timer control, 88h)


The timer control SFR is used to configure and modify the way in which the
8051’s two timers operate. This SFR controls whether each of the two timers is running
or stopped and contains a flag to indicate that each timer has overflowed. Additionally,
some non-timer related bits are located in TCON SFR. These bits are used to configure
the way in which the external interrupt flags are activated, which are set when an
external interrupt occurs.

h) TMOD (Timer Mode, 89h)


The timer mode SFR is used to configure the mode of operation of each of the
two timers. Using this SFR your program may configure each timer to be a 16-bit timer,
or 13 bit timer, 8-bit auto reload timer, or two separate timers. Additionally you may
configure the timers to only count when an external pin is activated or to count “events ”
that are indicated on an external pin.
i) TO (Timer 0 low/high, address 8A/8C h)
These two SFRs taken together represent timer 0. Their exact behavior depends
on how the timer is configured in the TMOD SFR; however, these timers always count
up. What is configurable is how and when they increment in value.

j) T1 (Timer 1 Low/High, address 8B/ 8D h)


These two SFRs, taken together, represent timer 1. Their exact behavior depends
on how the timer is configured in the TMOD SFR; however, these timers always count
up. What is
Configurable is how and when they increment in value.

k) P0 (Port 0, address 90h, bit addressable)


This is port 0 latch. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0
of port 0 is pin P0.0, bit 7 is pin p0.7. Writing a value of 1 to a bit of this SFR will send a
high level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

l) P1 (port 1, address 90h, bit addressable)


This is port latch1. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0
of port 0 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a
high level on the corresponding I/O pin whereas a value of 0 will bring it to low level
m) P2 (port 2, address 0A0h, bit addressable)
This is a port latch2. Each bit of this SFR corresponds to one of the pins on a
micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g.,
bit 0 of port 0 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will
send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low
level.

n) P3(port 3,address B0h, bit addressable)


This is a port latch3. Each bit of this SFR corresponds to one of the pins on a
micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g.,
bit 0 of port 0 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will
send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low
level

o) IE (interrupt enable, 0A8h)


The Interrupt Enable SFR is used to enable and disable specific interrupts. The
low 7 bits of the SFR are used to enable/disable the specific interrupts, where the MSB
bit is used to enable or disable all the interrupts. Thus, if the high bit of IE is 0 all
interrupts are disabled regardless of whether an individual interrupt is enabled by setting
a lower bit.

p) IP (Interrupt Priority, 0B8h)


The interrupt priority SFR is used to specify the relative priority of each interrupt.
On 8051, an interrupt maybe either low or high priority. An interrupt may interrupt
interrupts. For e.g., if we configure all interrupts as low priority other than serial
interrupt. The serial interrupt always interrupts the system, even if another interrupt is
currently executing. However, if a serial interrupt is executing no other interrupt will be
able to interrupt the serial interrupt routine since the serial interrupt routine has the
highest priority.
q) PSW (Program Status Word, 0D0h)
The program Status Word is used to store a number of important bits that are set
and cleared by 8051 instructions. The PSW SFR contains the carry flag, the auxiliary
carry flag, the parity flag and the overflow flag. Additionally, it also contains the register
bank select flags, which are used to select, which of the “R” register banks currently in
use.

r) SBUF (Serial Buffer, 99h)


SBUF is used to hold data in serial communication. It is physically two registers.
One is writing only and is used to hold data to be transmitted out of 8051 via TXD. The
other is read only and holds received data from external sources via RXD. Both mutually
exclusive registers use address 99h.

5.5.4 I/O ports:


One major feature of a microcontroller is the versatility built into the input/output
(I/O) circuits that connect the 8051 to the outside world. The main constraint that limits
numerous functions is the number of pins available in the 8051 circuit. The DIP had 40
pins and the success of the design depends on the flexibility incorporated into use of
these pins. For this reason, 24 of the pins may each used for one of the two entirely
different functions which depend, first, on what is physically connected to it and, then, on
what software programs are used to “program” the pins.

PORT 0
Port 0 pins may serve as inputs, outputs, or, when used together, as a bi directional
low-order address and data bus for external memory. To configure a pin as input, 1 must
be written into the corresponding port 0 latch by the program. When used for interfacing
with the external memory, the lower byte of address is first sent via PORT0, latched using
Address latch enable (ALE) pulse and then the bus is turned around to become the data
bus for external memory.

PORT 1
Port 1 is exclusively used for input/output operations. PORT 1 pins have no dual
function. When a pin is to be configured as input, 1 is to be written into the
corresponding Port 1 latch.

PORT 2
Port 2 maybe used as an input/output port. It may also be used to supply a high –
order address byte in conjunction with Port 0 low-order byte to address external memory.
Port 2 pins are momentarily changed by the address control signals when supplying the
high byte a 16-bit address. Port 2 latches remain stable when external memory is
addressed, as they do not have to be turned around (set to 1) for data input as in the case
for Port 0.

PORT 3
Port 3 may be used to input /output port. The input and output functions can be
programmed under the control of the P3 latches or under the control of various special
function registers. Unlike Port 0 and Port 2, which can have external addressing functions
and change all eight-port bits when in alternate use, each pin of port 3 maybe individually
programmed to be used as I/O or as one of the alternate functions? The Port 3 alternate
uses are:

Pin Alternate Use SFR

P3.0 - RXD Serial data input SBUF


P3.1 - TXD Serial data output SBUF
P3.2 - INTO 0 External interrupt 0 TCON.1
P3.3 - INTO 1 External interrupt 1 TCON.3
P3.4 - T0 External Timer 0 input TMOD
P3.5 – T1 External timer 1 input TMOD
P3.6 - WR External memory write pulse -
P3.7 - RD External memory read pulse -

5.5.5 INTERRUPTS

Interrupts are hardware signals that are used to determine conditions that exist in
external and internal circuits. Any interrupt can cause the 8051 to perform a hardware call
to an interrupt –handling subroutine that is located at a predetermined absolute address in
the program memory.
Five interrupts are provided in the 8051. Three of these are generated
automatically by the internal operations: Timer flag 0, Timer Flag 1, and the serial port
interrupt (RI or TI) Two interrupts are triggered by external signals provided by the
circuitry that is connected to the pins INTO 0 and INTO1. The interrupts maybe enable or
disabled, given priority or otherwise controlled by altering the bits in the Interrupt
Enabled (IE) register, Interrupt Priority (IP) register, and the Timer Control (TCON)
register. . These interrupts are mask able i.e. they can be disabled. Reset is a non
maskable interrupt which has the highest priority. It is generated when a high is applied to
the reset pin. Upon reset, the registers are loaded with the default values.
Each interrupt source causes the program to do store the address in PC onto the
stack and causes a hardware call to one of the dedicated addresses in the program
memory. The appropriate memory locations for each for each interrupt are as follows:
Interrupt Address
RESET 0000
IE0 (External interrupt 0) 0003
TF0 (Timer 0 interrupt) 000B
IE1 (External interrupt 1) 0013
TF1 (Timer 1 interrupt) 001B
SERIAL 0023
CHAPTER 6

SERIAL COMMUNICATION

6.1. SERIAL COMMUNICATION

The information from micro controller is sent to system through serial

communication by using MAX-232 IC in between micro controller and RS232 DB9


connector. This MAX-232 acts as voltage level translator i.e., the TTL logic voltage

level is to be transformed to RS232 DB9 connector voltage level of the system. In

short a MAX –232 is nothing but a clamper circuit, which consists of diodes and

capacitors i.e., the voltage level translator. is done through clamping circuit here

diodes are inbuilt, whereas the capacitors are to be connected externally .

In order to connect micro controller to a modem or a pc to modem a


serial port is used. Serial is a very common protocol for device communication that is
standard on almost every PC. Most computers include two RS-232 based serial ports.
Serial is also a common communication protocol that is used by many devices for
instrumentation; numerous GPIB-compatible devices also come with an RS-232 port.
Furthermore, serial communication can be used for data acquisition in conjunction with a
remote sampling device.
The concept of serial communication is simple. The serial port sends
and receives bytes of information one bit at a time. Although this is slower than parallel
communication, which allows the transmission of an entire byte at once, it is simpler and
can be used over longer distances. For example, the IEEE 488 specifications for parallel
communication state that the cabling between equipment can be no more than 20 meters
total, with no more than 2 meters between any two devices. serial, however, can extend as
much as 1200 meters. Typically, serial is used to transmit ASCII data. Communication is
completed using 3 transmission lines: (1) Ground, (2) Transmit, and (3) Receive. Since
serial is asynchronous, the port is able to transmit data on one line while receiving data
on another. Other lines are available for handshaking, but are not required. The important
serial characteristics are baud rate, data bits, stop bits, and parity. For two ports to
communicate, these parameters must match.

Baud rate: It is a speed measurement for communication. It indicates the number of


bit transfers per second. For example, 300 baud is 300 bits per second. When a clock
cycle is referred it means the baud rate. For example, if the protocol calls for a 4800 baud
rate, then the clock is running at 4800Hz. This means that the serial port is sampling the
data line at 4800Hz. Common baud rates for telephone lines are 14400, 28800, and
33600. Baud rates greater than these are possible, but these rates reduce the distance by
which devices can be separated. These high baud rates are used for device
communication where the devices are located together, as is typically the case with GPIB
devices.

Data bits: a measurement of the actual data bits in a transmission. When the
computer sends a packet of information, the amount of actual data may not be a full 8
bits. Standard values for the data packets are 5, 7, and 8 bits. Which setting chosen
depends on what information transferred? For example, standard ASCII has values from
0 to 127 (7 bits). Extended ASCII uses 0 to 255 (8 bits). If the data being transferred is
simple text (standard ASCII), then sending 7 bits of data per packet is sufficient for
communication. A packet refers to a single byte transfer, including start/stop bits, data
bits, and parity. Since the number of actual bits depends on the protocol selected, the term
packet is used to cover all instances.

Stop bits: used to signal the end of communication for a single packet. Typical
values are 1, 1.5, and 2 bits. Since the data is clocked across the lines and each device has
its own clock, it is possible for the two devices to become slightly out of sync. Therefore,
the stop bits not only indicate the end of transmission but also give the computers some
room for error in the clock speeds. The more bits that are used for stop bits, the greater
the lenience in synchronizing the different clocks, but the slower the data transmission
rate.

Parity: A simple form of error checking that is used in serial communication. There are
four types of parity: even, odd, marked, and spaced. The option of using no parity is also
available. For even and odd parity, the serial port sets the parity bit (the last bit after the
data bits) to a value to ensure that the transmission has an even or odd number of logic
high bits. For example, if the data is 011, then for even parity, the parity bit is 0 to keep
the number of logic-high bits even. If the parity is odd, then the parity bit is 1, resulting in
3 logic-high bits. Marked and spaced parity does not actually check the data bits, but
simply sets the parity bit high for marked parity or low for spaced parity. This allows the
receiving device to know the state of a bit to enable the device to determine if noise is
corrupting the data or if the transmitting and receiving device clocks are out of sync.

6.2 WHAT IS RS –232C?

RS-232 (ANSI/EIA-232 Standard) is the serial connection found on IBM-


compatible PCs. It is used for many purposes, such as connecting a mouse, printer, or
modem, as well as industrial instrumentation. Because of improvements in line drivers
and cables, applications often increase the performance of RS-232 beyond the distance
and speed listed in the standard. RS-232 is limited to point-to-point connections between
PC serial ports and devices. RS-232 hardware can be used for serial communication up to
distances of 50 feet.

DB-9 pin connector

12345
6789

(Out of computer and exposed end of cable)

Pin Functions:
Data: TxD on pin 3, RxD on pin 2
Handshake: RTS on pin 7, CTS on pin 8, DSR on pin 6,
CD on pin 1, DTR on pin 4
Common: Common pin 5(ground)
Other: RI on pin 9
The method used by RS-232 for communication allows for a simple connection of three
lines: TX, Rx, and Ground. The three essential signals for 2 way RS-232
Communications are these:
TXD: carries data from DTE to the DCE.
RXD: carries data from DCE to the DTE
SG: signal ground
Here in our project DTE is the micro controller at the remote station and PC at the
base station, DCE is the modem at both the stations. However the data to be transmitted,
both sides have to be clocking the data at the same baud rate. Even though this method is
sufficient for most applications, it is limited in being able to respond to problems such as
the receiver getting overloaded. This is where serial handshaking can help. This method
uses actual hardware lines. There are two pairs of hand shaking signals DTR/DSR and
RTS/CTS, each pair has uses defined by the standard. There are several ways to describe
the state of RS-232 and other control signals. A signal with a valid positive voltage may
be described as true to indicate that it is in the active state for example when DTR is true
the data terminal is ready. To bring the signal true the controlling device raises the line. A
signal with a valid negative voltage may be described as false or ff to indicate that its
inactive state .for example when DTR is false, the data terminal is not ready. To bring the
signal false the controlling device lowers the line. The DTR/DSR handshake is intended
for providing information about the status of the phone line or other communications
channel connected to the modem. The terminal raises DTR to request the modem to
connect to the communication channel. In response the modem raises DSR to indicate
that it is connected .DSR is false when the modem is not connected to the communication
channel or on detecting a fault. The terminal may also raise DTR in response to RI (ring
indicator) to tell the modem to answer a call.

The RTS/CTS handshake provides additional information about whether a device


is ready to receive data. This signal pair provides a full handshake. When the terminal has
data to send, it raises RTS (request to send). In response the modem raises CTS (clear to
send) to indicate that it is ready to receive. When the transmission is finished the terminal
may lower RTS. The modem should then be continue processing whatever data it has
received and lower CTS when it’s ready to respond to the next RTS. When RTS is false,
the terminal should wait for CTS to be false before raising RTS to request a new
transmission.

RI is true when a ringing signal is present on the communications channel. The


signal is true when the audible ring is present and false in the pauses between the rings.
The final control signal is the CD (carrier detect). The modem raises CD when it detects a
signal of expected frequency on the phone lines, indicating that a connection has been
established to a remote modem.

6.2.1 We have two types of connection between DTE AND DCE

1. Without handshaking: In this situation, only the data lines and signal ground are
directly connected in the modem communication cable. All other pins have no
connection. The three-wire modem cable is often simple but can we use it in all
circumstances? There is a problem, if either of the two devices checks the DSR or CD
inputs. These signals normally define the ability of the other side to communicate. As
they are not connected, their signal level will never go high. This might cause a problem.
The same holds for the RTS/CTS handshaking sequence. If the software on both sides is
well structured, the RTS output is set high and then a waiting cycle is started until a ready
signal is received on the CTS line. This causes the software to hang because no physical
connection is present to either CTS line to make this possible. The only type of
communication, which is allowed on such a modem line is data-only traffic on the
directly connected RX/TX lines.

2. Loop back handshaking: The simple modem cable without handshaking shows
incompatibilities with common software. The main problem with this cable is that there is
a possibility for the software to hang if it checks the modem signal lines in a proper way.
I.e. with this modem cable, good written programs will perform worse than badly written
programs. To overcome this problem and still be able to use a modem communication
cable with only three lines in it, a fake modem cable layout has been defined. The modem
cable with loop back handshaking resulted from this. The main purpose of this modem
cable is to let well-defined software think there is handshaking available, with a modem
cable, which has no provisions for it.

Consider first the DSR signal (pin 6). This input indicates that the other side is
ready to start communicating. In the layout, the line is linked back to the DTR output (pin
4). This means, that the software doesn't see the ready signal of the other device, but its
own. The same holds for the CD input (pin 1). The assumption is, that if software has
been written to check the DSR line to test communication availability, it will probably
also set the DTR output to indicate its own state. This is true for at least 99% of all serial
communication software. This implies that at least 99% of all serial communication
software is capable of faking its own DSR check with this modem cable. The same trick
is used with the CTS input. In the original use, RTS is set, and then CTS is checked
before starting the communication. By setting the RTS output (pin 7) the CTS input on
the same connector (pin 8) is receiving clearance immediately. There is no possibility of a
software hang-up because of dangling RTS requests.

The modem cable with loop back handshaking is often advised as the best low
cost available modem cable. The simple modem cable without handshaking has the
disadvantage that it does not permit proper written software to communicate with it.
Software, which is aware of the lack of handshaking signals, can however use it without
problems.

The connection that is implemented in the project is the modem cable with loop
back connections since the project main focus is on transmitting, receiving and not on the
acknowledgements.

6.3 POWER SUPPLY

A variable regulated power supply, also called a variable bench power


supply, is one where you can continuously adjust the output voltage to your requirements.
Varying the output of the power supply is the recommended way to test a project after
having double checked parts placement against circuit drawings and the parts placement
guide.
This type of regulation is ideal for having a simple variable bench power
supply. Actually this is quite important because one of the first projects a hobbyist should
undertake is the construction of a variable regulated power supply. While a dedicated
supply is quite handy e.g. 5V or 12V, it's much handier to have a variable supply on hand,
especially for testing. Most digital logic circuits and processors need a 5 volt power
supply. To use these parts we need to build a regulated 5 volt source. Usually you start
with an unregulated power supply ranging from 9 volts to 24 volts DC To make a 5 volt
power supply, we use a LM7805 voltage regulator IC (Integrated Circuit). The IC is
shown below.
The LM7805 is simple to use. You simply connect the positive lead of your unregulated
DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the
negative lead to the common pin and then when you turn on the power, you get a 5 volt
supply from the Output pin.

Block Diagram:

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 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.

Fig.5.2.3: - Schematic of Power Supply

BUZZER: If the system enters into an un wanted state then the buzzer will be on.
FAN: The load will be increase means crossing the average values in our project at
that time the FAN will be ON(for the cooling purpose).
RELAY: any load reaching the over current or over temp or over voltage or any thing
we want to shut down the system at that time the relay will be on.
CHAPTER 7

LIQUID CRISTAL DISPLAY

7. 1 LCD MODULE

THEORY:
A liquid crystal is a material (normally organic for LCDs) that will flow like a
liquid but whose molecular structure has some properties normally associated with solids.
The Liquid Crystal Display (LCD) is a low power device. The power requirement is
typically in the order of microwatts for the LCD. However, an LCD requires an external
or internal light source. It is limited to a temperature range of about 0C to 60C and
lifetime is an area of concern, because LCDs can chemically degrade.

There are two major types of LCDs which are:


1. Dynamic-scattering LCDs and
2. Field-effect LCDs

Field-effect LCDs are normally used in such applications where source of energy is a
prime factor (e.g., watches, portable instrumentation etc.).They absorb considerably less
power than the light-scattering type. However, the cost for field-effect units is typically
higher, and their height is limited to 2 inches. On the other hand, light-scattering units are
available up to 8 inches in height. Field-effect LCD is used in the project for displaying
the appropriate information.

The turn-on and turn-off time is an important consideration in all displays. The response
time of LCDs is in the range of 100 to 300ms.The lifetime of LCDs is steadily increasing
beyond 10,000+hours limit. Since the color generated by LCD units is dependent on the
source of illumination, there is a wide range of color choice.

HARDWARE DIAGRAM:
16 x 2 Char LCD

D0 EN RW RS Vf GND
A K D7

ACK
Vcc
D0 – D7

R1

R2

RS (Command / Data):

This bit is to specify weather received byte is command or data. So that LCD can
recognize the operation to be performed based on the bit status.

RS = 0 => Command
RS = 1 => Data

RW (Read / Write):-

RW bit is to specify weather controller wants READ from LCD or WRITE to


LCD. The READ operation here is just ACK bit to know weather LCD is free or not.

RW = 0 => Write
RW = 1 => Read

EN (Enable LCD):-
EN bit is to ENABLE or DISABLE the LCD. When ever controller wants to write
some thing into LCD or READ acknowledgment from LCD it needs to enable the LCD.

EN = 0 => High Impedance


EN = 1 => Low Impedance

ACK (LCD Ready):-

ACK bit is to acknowledge the MCU that LCD is free so that it can send new
command or data to be stored in its internal Ram locations

ACK = 1 => Not ACK


ACK = 0 => ACK

7.2 FLOWCHART:
START

Configure port pins for all hardware


connections

Copy command in to Accumulator

Wait
Yes
Is LCD Free
No

Clear RS Bit

Enable LCD

Send Command

Disable LCD

Is Command
Count Zero
No

1
1

Copy Data in to Accumulator

Wait
Yes
Is LCD Free
No

Set RS Bit

Enable LCD

Send Data

Disable LCD

Is Data
Count Zero
No

STOP
7.3 KEIL SOFTWARE:

This software is used for execution of microcontroller programs.


Keil development tools for the MC architecture support every level of software
developer from the professional applications engineer to the student just learning
about embedded software development.

The industry-standard keil C compilers, macro assemblers, debuggers,


real, time Kernels, Single-board computers and emulators support all avr derivatives
and help you to get more projects completed on schedule.

The keil software development tools are designed to solve the complex
problems facing embedded software developers.

• When starting a new project, simply select the microcontroller you

the device database and the µvision IDE sets all compiler,

assembler, linker, and memory options for you.

• Numerous example programs are included to help you get started with the

most popular embedded avr devices.

• The keil µ Vision debugger accurately simulates on-chip peripherals(PC,

CAN, UART, SPI, Interrupts, I/O ports, A/D converter, D/A converter and

PWM modules) of your avr device. Simulation helps you understand h/w

Configurations and avoids time wasted on setup problems. Additionally,

with simulation, you can write and test applications before target h/w is

available.

• When you are ready to begin testing your s/w application with target h/w,

use the MON51, MON390, MONADI, or flash MON51 target monitors,

the ISD51 In-System Debugger, or the ULINK USB-JTAG adapter to

download and test program code on your target system.


CHAPTER 8

METHODOLOGY OF WORK
8.1 FLOWCHART

STAR
T

Initialize Counter, Trained set, Threshold and Serial Communication

Create Video Object and take its Preview

Acquire Image

Convert RGB image into Gray image

Convert Gray image into Binary image

Perform Morphological Operation

Split the Acquired image into no of characters

Dilate and resize the splitted image to the required level

B
B

Take the trained image

Perform EX-OR operation between input and trained image

Divide the EX-ORed image into some no of segments

Compare each segment threshold value with the prefixed threshold

Is sum of all NO NO
Is the
trained B
Threshold < set = =0?

YES
YES
NO
Take the count value and store the Is the A
corresponding character into an array splitted
image = =0?

YES
Transmit the stored character to the LCD
Display the stored array

Close the serial communication and video object


8.2 PROGRAM

close all;
clear all;
clear name;

sc = serial ('COM3');
sc = serial ('COM3','BaudRate', 9600);
fopen (sc);

%vid = videoinput('winvideo');
%preview (vid);

pause (3);
keyim = getsnapshot(vid);

keyim = imrotate(keyim, 180,'bilinear');

subplot(331), imshow(keyim), title('Original');


gray = rgb2gray(keyim);
subplot(332), imshow(gray), title('Grey Image');
bin = im2bw(gray,0.48);
subplot(333), imshow(bin), title('binary Image');
X = ~bin;

figure,
subplot(2,2,1);
imshow(X)

BW_filled = imfill(X,'holes');
boundaries = bwboundaries(BW_filled);
sz = length(boundaries);

trainset = imread('ALPNUM1.bmp');
trset = rgb2gray(trainset);
BW_filled1 = imfill(trset,'holes');
boundaries1 = bwboundaries(BW_filled1);
sz1 = length(boundaries1);

charSet = ['0' 'A' 'M' 'W' '1' 'B' 'N' 'X' '2' 'C' 'O' 'Y' '3' 'D' 'P' 'Z' '4' 'E' 'Q' 'a' '5' 'F' 'R' 'b' '6'
'G' 'S' 'c' '7' 'H' 'T' 'd' '8' 'I' 'U' 'J' '9' 'V' 'K' 'L'];

for m=1: sz,


me = boundaries {m};
l = min (me (: 1));
t = max (me (: 2));
r = max (me (: 1));
b = min (me (: 2));
spImg = X (l: r, b:t);
%imwrite (spImg, strcat ('split', int2str (i),'.bmp'))

for n=1:sz1,
me1 = boundaries1 {n};
l1 = min (me1 (: 1));
t1 = max (me1 (: 2));
r1 = max (me1 (: 1));
b1 = min (me1 (: 2));
trImg = trset (l1:r1, b1:t1);

splitImg = imresize (spImg, [30 30]);

SE = strel ('square', 3);


splitImg = imdilate (splitImg, SE);
figure (m),
subplot (3, 3,1);
imshow (splitImg)

trainImg = imresize (trImg, [30 30]);

xrImg = xor (splitImg, trainImg );

figure (m+1),
subplot (4, 4,1);
imshow (splitImg);
subplot (4, 4, 2);
imshow (trainImg);
subplot (4, 4, 3);
imshow (xrImg);

s= [0 0 0 0 0 0 0 0 0];
j=1;
k=1;
l=0;
for i=1:9
c1=xrImg (j:j+9,k:k+9);
k=k+10;
l=l+1;
subplot (4, 4, 4+i);
imshow (c1);
if (l==3)
j=j+10;
k=1;
l=0;
end
for u=1:10,
for v=1:10,
s(i) =s(i) +c1 (u, v);
end
end
end

for sloop = 1:9,


if s (sloop) < 35,
cFlag = 1;
else
cFlag = 0;
break;
end
end

s
if cFlag==1,
n;
rChar = charSet (n);
%disp (rChar);
fwrite (sc,rChar,'char');
name (m) = rChar;
break;
else

name (m) = ' ';


end
end
end

name

fclose (sc)
delete (sc)
clear sc
#include <AT89X51.H>
#include <stdio.H>
#include"driver.h"

void main (void)


{
int i;
unsigned char byte;

lcdInit ();

putStrL ("Welcome to Demonstration of", 0x01);


delay (2000);
putStrL ("Virtual Scribbling Pad", 0x01);
delay (2000);
putStrL ("Text>", 0x01);
delay (2000);

i = 5;
serInit ();

while (1)
{
byte = getCharS ();
putCharL (byte);
i++;
if (i == 16)
putComL (0xc0);

if (i == 32)
{
i = 0;
putComL (0x01);
}
}
}

#include <AT89X51.H>
#include<stdio.h>
#include"driver.h"

void lcdInit (void)


{
unsigned char i;

unsigned char comptr[6] = {0x01, 0x06, 0x0c, 0x38, 0x80};

for (i=0; comptr[i]! =0; i++)


putComL (comptr[i]);

void putComL (unsigned char addr)


{
lcdChk ();
LCDPORT = addr;
RS = 0;
RW = 0;
EN = 1;
EN = 0;
}

void putCharL (unsigned char dat)


{
LcdChk ();
LCDPORT = dat;
RS = 1;
RW = 0;
EN = 1;
EN = 0;
}

void lcdChk(void)
{
LCDPORT = 0xFF;
RS = 0;
RW = 1;
EN = 1;
while (ACK==1);
EN = 0;
}

/*
void putCharLA(unsigned char dat, unsigned char addr)
{
putComL (addr);
putCharL (dat);
}*/

void putStrL (unsigned char *dataptr, unsigned char addr)


{
unsigned int i;
putComL (addr);

for (i=0; dataptr[i]!=NULL;i++)


{
putCharL (dataptr[i]);
if (i==15)
putComL (0xc0);

/*void putStrLA (unsigned char *dataptr, unsigned char addr)


{
unsigned char i;
putComL(addr);

if (addr==0x01)
addr=0x80;

for (i=0; dataptr[i]! =NULL; i++)


{
putCharL (dataptr[i]);
if (addr==0x8F)
{
putComL (0xc0);
addr=0xc0;
}

if (addr==0xCF)
{
putComL (0x01);
addr=0x80;
}

addr++;
}
}*/
void delay (unsigned int del)
{
unsigned int i, j;
for (i=0; i<=del; i++)
for (j=0; j<=109; j++);
}
CHAPTER 9

CONCLUSION
The concept has been implemented successfully. The module is working perfectly.
Different concepts in the digital image processing and the basic programming of the
MATLAB have been studied. The alpha-numeric data which is written on the paper is
successfully displayed on the computer screen in standard text format.
Since many threshold mismatching occur causing more delay, only a
few lower case letters have been included. But as the concept is same, we can extend it to
the rest of letters and special symbols. As MATLAB is the interfacing software the
output is not as fast as expected. A delay has been maintained to avoid any
misconceptions.

FUTURE SCOPE

As we have successfully worked out our concept on alpha-numeric data, there is a scope
for extending it to the other special symbols.

On further research, our project can be presented in its more advanced version where
there is no need for writing manually. We just need to virtually scribble with our fingertip
without using any pen and paper. As we move our fingertip the path is traced and the
scribbled data is displayed on the GUI of the computer.

Potrebbero piacerti anche