74
CAR PLATE RECOGNITION SYSTEM MOHAMAD ASYRAF BIN CHE LAH UNIVERSITI TEKNOLOGI MALAYSIA

741_MOHAMADASYRAFBINCHELAH2010

Embed Size (px)

Citation preview

Page 1: 741_MOHAMADASYRAFBINCHELAH2010

CAR PLATE RECOGNITION SYSTEM

MOHAMAD ASYRAF BIN CHE LAH

UNIVERSITI TEKNOLOGI MALAYSIA

Page 2: 741_MOHAMADASYRAFBINCHELAH2010
Page 3: 741_MOHAMADASYRAFBINCHELAH2010

“I hereby declare that I have read this report and inmy opinion this report is sufficient in terms of scope and

quality for the award of the degree of Bachelor of Engineering (Computer)”

Signature :Name : Dr Izzeldin Ibrahim Mohamed AbdelazizDate : April 28, 2010

Page 4: 741_MOHAMADASYRAFBINCHELAH2010

CAR PLATE RECOGNITION SYSTEM

MOHAMAD ASYRAF BIN CHE LAH

A report submitted in partial fulfilment of therequirements for the award of the degree of

Bachelor of Engineering (Computer)

Faculty of Electrical EngineeringUniversiti Teknologi Malaysia

APRIL 2010

Page 5: 741_MOHAMADASYRAFBINCHELAH2010
Page 6: 741_MOHAMADASYRAFBINCHELAH2010

iii

To my late father, mother and all family members for encouragement, support and

advise.

Page 7: 741_MOHAMADASYRAFBINCHELAH2010

iv

ACKNOWLEDGEMENT

I am heartily thankful to my supervisor, Dr Izzeldin Ibrahim MohamedAbdelaziz, whose encouragement, guidance and support from the initial to the finallevel enabled me to develop an understanding of the subject.

Appreciate and thanks to my mother, sister and brother who has been so tolerantand supports me all these years. Thanks for their encouragement, love and emotionalsupports that they had given to me.

Lastly, I offer my regards and blessings to all of those who supported me in anyrespect and lending a hand during the completion of the project.

Asyraf

Page 8: 741_MOHAMADASYRAFBINCHELAH2010

v

ABSTRACT

Car plate recognition system has become more important nowadays, especiallyfor security purpose and law enforcement in automobiles sector. Drivers or users areidentified using their car plate. There are many applications that are use car platerecognition. For instance, car plate recognition system can be applied to the bordersystem, toll system, parking system and most common use in entrance system. Imageprocessing is the engine of this system. Characters on the car plate include alphabetsand numbers are identified and recognized. PC camera or webcam is used to captureimage in image acquisition stage. The image processing is done by MATLAB, one ofthe common image processing analyze tool. A simple graphical user interface or GUIis made by MATLAB also. Basically this system is purpose to identify the characterson the car plate, recognize all the characters and also making simple GUI. Differentwith Radio Frequency Identification or RFID, this system does not need any additionaltransmitter and receiver. This system is focused only the Malaysian single type of carplate only. Since, this is only the available sources. For future recommendation, tomake this system more secure, the system can be integrate with face detection. Itsmean that users or drivers are identified by identify his or her face. The system alsorecommended to be fully automated that can be implementing to the real time system.

Page 9: 741_MOHAMADASYRAFBINCHELAH2010

vi

ABSTRAK

Sistem pengenalan berdasarkan plat kereta telah menjadi sangat pentingzaman ini.Pengguna dikenalpasti hanye berdasarkan plat kereta mereka.Terdapatbanyak aplikasi yang menggunakan sistem ini.Sebagai contoh, sistem pengenalan platkereta boleh diterapkan ke sistem sempadan,sistem to, sistem meletakkan kenderaandan paling biasa digunakan dalam sistem pintu masuk.Pemprosesan gambar adalahenjin bagi sistem ini.Perkataan pada plat kereta termasuk huruf dan nombor akandikenalpasti.PC kamera atau webcam digunakan untuk menangkap gambar dalamproses pengambilan gambar . Pemprosesan gambar dilakukan dengan MATLAB, salahsatu perisian yang biasa digunakan untuk proses analisis .Antara muka yang mudahatau GUI telah dibagunkan juga dalam perisian MATLAB.Pada dasarnya, sistem inidibuat bertujuan untuk mengenalpasti perkataan pada plat kereta, mengenalpasti semuaaksara dan membina satu antaramuka yang mudah difahami. Berbeza dengan RadioFrequency Identification atau RFID, sistem ini tidak memerlukan pemancar tambahandan penerima .Sistem ini hanya memfokuskan pada plat Malaysia, hanya plat jenisbaris tunggal sahaja.Ini kerana plat ini hanya sumber-sumber yang telah tersedia.Untuk cadangan masa depan, untuk membuat sistem ini lebih selamat, sistem ini bolehdigabung dengan pengenalan wajah.Ini bermakna bahawa pengguna atau pemacu akandikenalpasti dengan mengenalpasti wajah mereka.Sistem ini juga disarankan untukmenjadi sistem yang automatik sepenuhnya sepertimana yang ada pada sistem nyata.

Page 10: 741_MOHAMADASYRAFBINCHELAH2010

vii

TABLE OF CONTENTS

CHAPTER TITLE PAGE

DECLARATION iiDEDICATION iiiACKNOWLEDGEMENT ivABSTRACT vABSTRAK viTABLE OF CONTENTS viiLIST OF TABLES ixLIST OF FIGURES xLIST OF ABBREVIATIONS xiiLIST OF SYMBOLS xiiiLIST OF APPENDICES xiv

1 INTRODUCTION 11.1 Background of study 11.2 Problem Statement 11.3 Objectives of project 21.4 Scope of project 21.5 Thesis outline 21.6 Summary of works 3

2 LITERATURE REVIEW AND THEORY 42.1 System overview 42.2 Image acquisition 52.3 Plate Extraction 5

2.3.1 Edge detection 62.3.2 Histogram equalization 72.3.3 Image Thresholding 7

2.4 Character Segmentation 82.5 Character Recognition 8

Page 11: 741_MOHAMADASYRAFBINCHELAH2010

viii

2.5.1 Neural Network based method 82.5.2 Template Matching 9

2.6 Real life application 102.7 MATLAB 112.8 Microcontroller 122.9 RS232 Serial Port 13

3 METHODOLOGY 153.1 Introduction 153.2 Hardware Implementation 15

3.2.1 USB PC Camera 163.2.2 Constraints 173.2.3 Microcontroller PIC16F877A 173.2.4 Power supply +5V 183.2.5 RS232 Serial Communication 19

3.3 Software Implementation 213.3.1 Programming in MATLAB 21

3.3.1.1 MATLAB for graphical user inter-face(GUI) 21

3.3.1.2 Image capturing mode 233.3.1.3 Plate Segmentation 253.3.1.4 Character Recognition 25

4 RESULT AND DISCUSSION 274.1 Introduction 274.2 Result 274.3 Discussion 28

5 CONCLUSION AND RECOMMENDATION 315.1 Introduction 315.2 Conclusion 315.3 Recommendation 31

REFERENCES 33

Appendices A – C 35 – 57

Page 12: 741_MOHAMADASYRAFBINCHELAH2010

ix

LIST OF TABLES

TABLE NO. TITLE PAGE

2.1 DB9 serial pin 13

3.1 Pin connection of PIC16F877A 17

Page 13: 741_MOHAMADASYRAFBINCHELAH2010

x

LIST OF FIGURES

FIGURE NO. TITLE PAGE

1.1 Summary of works 3

2.1 Sobel mask 72.2 Template matching 92.3 Example of templates 102.4 Applications of LPR system 112.5 DB9-connector 14

3.1 System Flow Chart 163.2 Sample Picture 163.3 Sample Picture 183.4 IC LM7805 183.5 IC LM7805 with capacitor 193.6 Connection between D9 Female serial port, MAX232 and

PIC16F877A 203.7 Example when a signal is generate on RS232 203.8 Signal after gone through MAX232 203.9 General step to design GUI using GUIDE 223.10 General step to design GUI using GUIDE 223.11 GUIDE layout 233.12 GUI for the system 233.13 Load image from file 243.14 Capture from GUI 243.15 Car plate extraction 253.16 Car plate segmentation 263.17 Samples of reference templates 26

4.1 Successful result 284.2 Failed result 284.3 Image successfully recognize 29

Page 14: 741_MOHAMADASYRAFBINCHELAH2010

xi

4.4 Image failed to recognize by the system 30

C.1 System Display 57

Page 15: 741_MOHAMADASYRAFBINCHELAH2010

xii

LIST OF ABBREVIATIONS

LPR – License Plate Recognition

GUI – Graphical User Interface

PC – Personal Computer

Page 16: 741_MOHAMADASYRAFBINCHELAH2010

xiii

LIST OF SYMBOLS

λ – Wavelength

α – Second symbol description

β – Third symbol description

γ – Fourth symbol description

You can insert a symbol listed here, e.g. α into normal text.

Page 17: 741_MOHAMADASYRAFBINCHELAH2010

xiv

LIST OF APPENDICES

APPENDIX TITLE PAGE

A SOURCE CODE 35B HARDWARE DATASHEET 47C SYSTEM DISPLAY 57

Page 18: 741_MOHAMADASYRAFBINCHELAH2010

CHAPTER 1

INTRODUCTION

This chapter will discuss the introduction of this project, objectives and scopeof works. Besides, the thesis outline also discussed as well.

1.1 Background of study

Nowadays Car plate recognition system becomes an important applicationespecially for transportation. Instead of using law enforcement to monitor theincreasing numbers of auto-mobiles in Malaysia, CPR is a more suitable in terms ofsecurity purpose for vehicles. CPR or well known as License Plate Recognition System(LPR) is an image processing technology that uses to identify vehicle by their licenseplate [1]. It can be used in many applications such as entrance admission, security,parking control, road traffic control and also border control. One of the advantagesof this system is that all cars already have their own identification by just referring totheir registration plate. This means that there is no need to add transmitter or specialsign to the vehicles. On other word, this system is low cost and more economic. Inorder to make this system more secure, image of the driver can also be captured andstored if there are any case involved police for crime investigation. Optical characterrecognition is the heart of LPR system [2, 3], whereas image of the car plate will gothrough the process of image processing before the car plate can be recognize.

1.2 Problem Statement

Due to the increasing numbers of automobiles on the road today, it is difficultto monitor the law enforcement and security for vehicles [4]. For example in border

Page 19: 741_MOHAMADASYRAFBINCHELAH2010

2

control system, it is time consuming for an officer to physically check the car plateevery day. In addition, it is not feasible to hire full-time officer just to check on the carplate. As a solution, a simple system to identify the car plate was developed.

1.3 Objectives of project

The followings are the objectives of the project:

i. To develop a system that can determine the location if character on thecar plate

ii. To develop a system with a graphical user interface

iii. To develop a system that can recognize all characters on the car plate

1.4 Scope of project

The followings are the scopes of the project:

i. . Car plate number is specified to standard car plate in Malaysia,except for Sabah and Sarawak type of car plate. In addition, thissystem only involved single line type of car plate.

ii. The systems also target to recognize all characters on the car plateinclude numbers and alphabets.

iii. The graphical user interface (GUI) is simple that compatible inWindows operating system only

1.5 Thesis outline

This thesis consists of five chapters. In the first chapter, it discuss about theintroduction, objectives and scope of the project as long as summary of work. WhileChapter 2will discuss more on theory and literature reviews that has been done. Itwell discuss about the techniques use to detect the characters on the car plate from

Page 20: 741_MOHAMADASYRAFBINCHELAH2010

3

image acquisition till the process end. In Chapter 3, the discussion will be on themethodology software and hardware that be implemented on this project. The resultand discussion will be discussed in Chapter 4. Finally, in Chapter 5, conclusions andrecommendations for future work are presented.

1.6 Summary of works

The implementation of work is summarized into the flow chart as shown inFigure 1.1

Literature Review

Software Design

Hardware Design

Graphical User Interface Design(GUI)

Figure 1.1: Summary of works

Page 21: 741_MOHAMADASYRAFBINCHELAH2010

CHAPTER 2

LITERATURE REVIEW AND THEORY

This chapter will discuss about the theory behind the project, the techniquesused include the algorithm as well as the literature reviews when doing research forthis project.

2.1 System overview

Basically, LPR system consists of three phrases.

(a) Image acquisition.

(b) Plate extraction.

(c) Character segmentation (OCR).

Process of LPR begins with the image acquisition. Image acquisition involved thetechnique of capturing an image from hardware like camera or video. Then, theprocess continues to plate extraction and character segmentation [5]. The systemuses the sequence of image processing techniques such as edge detection, histogramequalization and also image threshold. Last but not least, each character on the carplate will be segmented, and the process of identifying the characters on the car plateis known as the optical recognition system.

Page 22: 741_MOHAMADASYRAFBINCHELAH2010

5

2.2 Image acquisition

The first stage of the system is the image acquisition. Image acquisition isthe process of obtaining or capturing image before image will be process to anotherstage.There are several ways to obtain image. The followings are the ways to acquireimage of car

(a.) Using a conventional analogue camera and scanner.

(b.) Using the digital camera.

(c.) Using a video camera and frame grabber (capture card to select).

The first method is clearly not appropriate for LPR system. It is due to the procedureto follow need a lot of time or on other words, its time consuming. The first method isalso tedious and impractical. The second method is suitable to use in this project sincethis method is more practical and cost effective one. In addition, in this method, theequipment was readily available.

For the third method, is the one that has been applied in the real life systemas everything can be automated through the computer and it suitable for the realtime processing. There are some important things that need to put in considerationwhile obtaining image in this stage such as the behavior of light and the illuminationcharacteristics.

2.3 Plate Extraction

Process of plate extraction involved the following process.

(a.) Edge Detection

(b.) Histogram equalization

(c.) Image Threshold

Page 23: 741_MOHAMADASYRAFBINCHELAH2010

6

2.3.1 Edge detection

Edge detection is an image processing technique that used to detect the edgesof the picture [6]. There is several types of edge detection algorithms. Edges are thesignificant local changes of intensity in an image and edges typically occur on theboundary between two different regions in an image. The goal of edge detection is toidentify the important feature that will be useful for plate extraction phrases. Actuallyin edge detection, there are four step involved. The followings are the step of edgedetection.

(a.) Smoothing: the edge detection process of eliminating as much noise aspossible.

(b.) Enhancement: the edge detection process of applying a filter to enhance thequality of the edges in the image (sharpening).

(c.) Detection: the edge detection process of determining which edge pixelsshould be discarded as noise and which should be retained (usually,thresholding provides the criterion used for detection).

(d.) Localization: the edge detection process determining the exact location of anedge (sub-pixel resolution might be required for some applications, that is,estimate the location of an edge to better than the spacing between pixels).Edge thinning and linking are usually required in this step.

Some of the common ones are the Sobel, Kirsch, Stochastic, Laplacian ,Marr(zero crossing), Roberts, Prewitt [7] and Canny operators. In LPR system, thetwo most popular methods for edge detection are Sobel [2, 4, 8] and Canny operator.For Malaysia standard type of license plate, the most suitable algorithm should be usedis Sobel. It is due to Malaysian license plate consist of a row of white characters ona black background, so we can say that the license plate region is characterized bya row of transitions from black to white and vice versa, such transitions are called”edges” [8].

The ideal case of Malaysian car plates where the characters are white drawnon the black background., hence they produce high intensity edge values which canbe used to find the approximate plate region. Sobel edge detector use the masks asshown in Figure 2.1 below show template as references template during the templatematching process.

Page 24: 741_MOHAMADASYRAFBINCHELAH2010

7

(a) (b)

Figure 2.1: Sobel maskes for detection

2.3.2 Histogram equalization

Histogram equalization is an image processing technique that used to contrastthe image using it histogram [6]. It is also an image transformation that computes ahistogram of every intensity level in a given image and stretches it to obtain a moresparse range of intensities [2]. This manipulation yields an image with higher contrastthan the original. The candidate selection process utilizes the guaranteed contrastbetween the characters and the license plate. Therefore, it is crucial for us to contrastthe image at preprocessing stage. In order to increase the contrast of the gray scaleimage from the PC, histogram equalization is used.

2.3.3 Image Thresholding

Pixels are classified into two categories when process of image thresholdingoccurs. Actually the result of image threshold is binarization. Image will convert toblack and white pixels. There are two types of thresholding: global thresholding andlocal thresholding [6]. Gobal thresholding also known as fixed thresholding. In fixedthresholding, the threshold value is held constant throughout the image.

g(x, y) =

0 f(x, y) < T

1 f(x, y > T(2.1)

Meanwhile, local thresholding depends on the position of the image. The image isdivided into overlapping sections which are thresholded one by one.

Page 25: 741_MOHAMADASYRAFBINCHELAH2010

8

2.4 Character Segmentation

Character segmentation is the image processing technique that used to separateor isolate each character on the car plate. The method that usually been used forcharacter segmentation is horizontal and vertical projection [2]. The function of thisoperation is to isolate each character from the plate. The main technique using here isthe amplitude projection. Same as used in the previous section, the vertical projectionis mean sum every column of an image (size is m× n ) to a matrix of size 1× n whilehorizontal projection is mean to sum every row in an image to a matrix of size m× 1.

By perform the vertical projection, each character can be separated when therow sum is 0. This is because between each character, there is always a black zonewhich has the pixel value of 0. The horizontal projection is use to remove unwantedarea at the top and bottom.

2.5 Character Recognition

There are few method that can be used for character recognition, namely :

(a.) Neural Network based method

(b.) Template Matching

2.5.1 Neural Network based method

Neural network is a mathematical model for information processing baseon connectionist approach to computation [4]. Neural network is also one of thecommon and popular approaches in application like pattern recognition, times seriesprediction, function approximation, clustering,etc. For character recognition system,two usual algorithm that are popular are the Back Propagation and constraint baseddecomposition(CBD),In both methods, training is required to increase the accuracy ofrecognition.

Page 26: 741_MOHAMADASYRAFBINCHELAH2010

9

2.5.2 Template Matching

Template matching is basically the technique that evaluates the similaritybetween the image and a set of reference image called template. On the other words,template matching is the techniques compare portions of images against one another.The template with the highest matched point will be the character appears in theimage [2].If standard deviation of the template image compared to the source imageis small enough, template matching may be used. Templates are most often used toidentify printed characters, numbers, and other small, simple objects.

The matching process is done by moving the template image to all possiblepositions in a larger source image and compute a numerical index that indicate howwell the template matches the image in that position. Furthermore , matching is doneon a pixel-by-pixel basis.

Figure 2.2: Template matching method

Template matching has two major problems to tackle. First the templatematching is sensitive to image distortion. Distortion can be occurring during imageacquisition process [2]. For example, the distortion is due to variations in viewingangle, diffused light, bent plates, screws, and lightning and also bolt that distort theview, and a limited range in view. One way to reduce distortion during templatematching is by making a lot of samples for one extracted binary character image.

Secondly, to recognize an image, it needs to be correlated with all templatesin the reference set. Correlation is a measure of the degree to which two variables

Page 27: 741_MOHAMADASYRAFBINCHELAH2010

10

agree, not necessary in actual value but in general behavior. The two variables are thecorresponding pixel values in two images, template and source.

Figure 2.3: Examples of templates taken from real-life data.

According to [9],correlation is closely to convolution, whereby convolution isa neighborhood operation in which output pixel is the weighted sum of neighboringinput pixels. Different with convolution, in correlation, the value of an output pixelis computed as a weighted sum of neighboring pixels except that the matrix ofweights, in this case called the correlation kernel, is not rotated during the computation.Correlation can be used to locate features within an image; in this context correlationis often called template matching.

2.6 Real life application

There are many applications of the car plate recognition system. This systemis applied in access control system, border control and car park system. In a car parksituation, the system compares the recognized license plate number with is a list ofauthorized users or people with a membership and allows entry if a match is found.This information will be contained in a database. Alternatively, the recognized numberis stored with the time of entry. When the user exits, the number is read again and theparking fee is calculated from both entry and exit times. Long term parking at theairport is also a good candidate for the use of an LPR system as the actual time ofentry can retrieved in the event of a lost ticket that was issued.

Page 28: 741_MOHAMADASYRAFBINCHELAH2010

11

In border control situation, the LPR system can be used to double checkthat the car is allowed to cross and shorten the time it takes to go through theborder, hence shortening the typical long queues. Each vehicle would be registeredin a central database with information about the car and the drivers . Moreover, all border crossings can be recorded automatically and used for statistics or lawenforcement.Figure 2.4 show some example of the applications of LPR system

(a) (b)

Figure 2.4: Applications of LPR system

2.7 MATLAB

MATLAB is a high-level language and interactive environment that enable youto perform computationally intensive task faster that with traditional programminglanguage such as C,C++,and Fortran. MATLAB stands for ”Matrix Laboratory”. Thissoftware is developed by The MathWorks. MATLAB allows matrix manipulations,plotting of functions and data, implementation of algorithm, creation of user interfaceand interfacing with programs written in other languages, including C, C++, andFortran.

There are many applications toolbox that included in MATLAB, for example,the Image Processing Toolbox software. This application is a collection of functionsthat extended the capability of the MATLAB numeric computing environment [9]. Forimage processing purpose , the toolbox support various operations, including

(a.) Spatial image transformations

(b.) Morphological operations

Page 29: 741_MOHAMADASYRAFBINCHELAH2010

12

(c.) Neighborhood and block operations

(d.) Linear filtering and filter design

(e.) Transforms

(f.) Image analysis and enhancement

(g.) Image registration

(h.) Deblurring

(i.) Region of interest operations

2.8 Microcontroller

A microcontroller is a true computer on a single chip. If related tomicroprocessor, a microcontroller is a specialized form of microprocessor thatis designed to be self-sufficient and cost-effective. Nowadays, there are manyapplications being implemented with microprocessor. For example, microcontrollersare widely use in our communication system like our mobile phone, toys, in auto-mobiles and appliances. Meanwhile, microprocessors is a general purpose computer.

So what is the difference between microcontrollers and microproces-sor?.The difference is that microcontroller incorporates features of microprocessor(CPU,ALU,Registers)along with the presence of added features like presence ofRAM,ROM,I/O ports, counter and etc [10]. Here microcontroller control the operationof machine using fixed programme stored in ROM that doesn’t change with lifetime.So a microcontroller combines onto the same microchip:

i. Instruction set

ii. RAM

iii. ROM,PROM or EPROM

iv. I/O ports

v. Clock generator

vi. Reset function

vii. Watchdog timer

viii. Serial port

Page 30: 741_MOHAMADASYRAFBINCHELAH2010

13

ix. Interrupts

x. Timers

xi. Analog-to-digital converters

xii. Digital-to-analog converters

2.9 RS232 Serial Port

Information being transferred between data processing equipment andperipherals is in the form of digital data. Data can be transmitted either using serial orparallel port. Serial port using RS232 protocol is the most common mode that use fordata acquisition from PC. PC can easily connected to serial port using Comms port orCOM.

Officially, RS-232 is defined as the Interface between data terminal equipmentand data communications equipment using serial binary data exchange. This definitiondefines data terminal equipment (DTE) as the computer, while data communicationsequipment (DCE) is the modem. A modem cable has pin-to-pin connections, and isdesigned to connect a DTE device to a DCE device.The DB9 serial port pin is shownas table below.

Table 2.1: RS232 pin assignment(DB9 PC signal set)

Pin 1 Input DCD Data Carrier DetectPin 2 Input RXD Received DataPin 3 Output TXD Transmitted DataPin 4 Output DTR Data Terminal ReadyPin 5 Signal GroundPin 6 Input DSR Data Set ReadyPin 7 Output RTS Request To SendPin 8 Input CTS Clear to SendPin 9 Input RI Ring Indicator

Normal PC hardware might well run with just Tx, Rx and Ground connected,most driver software will wait forever for one of the handshaking lines to go to thecorrect level. Depending on the signal state it might sometimes work, other times it

Page 31: 741_MOHAMADASYRAFBINCHELAH2010

14

might not. The reliable solution is to loop back the handshake lines if they are notused [11].Figure 2.5 shows the pin of DB9-connector.

Figure 2.5: DB9-connector

Page 32: 741_MOHAMADASYRAFBINCHELAH2010

CHAPTER 3

METHODOLOGY

In this chapter, the way to conduct this project is being discussed. In order tomake the system to functions as same as the real time system, the proper and suitablechoice of the equipment used is to be considered. The principal aim of this researchproject was to investigate and find a suitable way to read and recognize license platenumbers.

3.1 Introduction

This section will lay down the details about the project which has been done.The process begins from image acquisition to plate extraction, character segmentationand character recognition. The Figure 3.1 below show the idea of the whole system.This project is comprises of two part; software and hardware. The software part isdiscussed in software implementation, while the hardware is discussed in hardwareimplementation.

3.2 Hardware Implementation

In this section, hardware used in this project is discussed. USB PC camera wasuse to capture the image. There are some constraints which were also discussed in thissection. Moreover, in order to make the system look alike to the real time system, theresult of the car plate from MATLAB will be sent to the 2 LCD through serial port.

Page 33: 741_MOHAMADASYRAFBINCHELAH2010

16

Image acquisition Image Processing

Plate Extraction

Character Segmentation

Character Recognition

Display ID

Figure 3.1: System Flow Chart

3.2.1 USB PC Camera

PC camera or webcam is used in the first stage of this project, imageacquisition. In this stage, photo of the of the back car is used as the input of the image.640× 480 is the resolution of that is considered for the process of image acquisition.

640 pixels

480 pixels

Figure 3.2: Sample image resolution

Page 34: 741_MOHAMADASYRAFBINCHELAH2010

17

3.2.2 Constraints

There are some constraints when the process image acquisition. As mentionedbefore, image acquisition is the most important stage in this project. So the followingsare the list of constraints:

• Image of car is taken from the fixed angle parallel to horizon.

• Image of car is taken in a distance of 30 to 40 cm.

• Only type of single line plate is considered.

• Intensity of images which is too high or too low will not be dealt with

3.2.3 Microcontroller PIC16F877A

Data that send from the serial port using RS232 is captured by microcontrollerPIC16F877A. The main role of this microcontroller PIC16F877A is to get data fromserial port than send to 2 × 16 LCD to display as the result. Refer to Table ?? for thepin connection of PIC16F877A in this system. Pins not stated in the table are not usedand left hanging.

Table 3.1: Pin connection of PIC16F877APin Name Pin No. Description Application

VDD 11,32 Power supply(+5V) Power supply to chipVSS 12,31 Ground reference Ground reference

OSC1 13 For oscillator or resonator Connected oscillator 10MhzOSC2 14 For oscillator or resonator Connected oscillator 10MhzMCLR 1 Reset input Always connected to +5VRD2-7 21,22,27-30 Input/Output pin Output Display On LCDRC6 26 TX Transmit to serialRC7 25 RX Receive from serial

Page 35: 741_MOHAMADASYRAFBINCHELAH2010

18

Figure 3.3: Sample image resolution

3.2.4 Power supply +5V

Most of the digital logic and processor need a +5 volts powersupply.Usually,power supply is in range of +9 volts to +24 volts. So the power need tobe regulated to +5 volts. In this case,IC LM7805 is chosed as voltage regulator.Belowis the Figure 3.4 shows the IC LM7805 voltage regulator. In addition, to make the

Figure 3.4: IC LM7805

voltage regulator more stable the additional capacitor is necessary. Figure ?? show thevoltage regulator with capacitor.

Page 36: 741_MOHAMADASYRAFBINCHELAH2010

19

Figure 3.5: IC LM7805 with capasitor

3.2.5 RS232 Serial Communication

SCI is an abbreviation for Serial Communication Interface and, as a specialsubsystem of microcontroller PIC16F877A. It provides RS232 serial communicationwith PC easily. As with hardware communication, we use standard NRZ (Non Returnto Zero) format also known as 8 (9)-N-1, or 8 or 9 data bits, without parity bit and withone stop bit. Free line is defined as the status of logic one. Start of transmission - StartBit, has the status of logic zero. The data bits follow the start bit (the first bit is the lowsignificant bit), and after the bits we place the Stop Bit of logic one. The duration ofthe stop bit ’T’ depends on the transmission rate and is adjusted according to the needsof the transmission. For the transmission speed of 9600 baud, T is 104s.

In order to connect a microcontroller to a serial port on a computer, we needto adjust the level of the signals so communicating can take place. The signal levelon a PC is -10V for logic zero, and +10V for logic one. Since the signal level on themicrocontroller is +5V for logic one and 0V for logic zero, we need an intermediarystage that will convert the levels. One chip specially designed for this task is MAX232.This chip receives signals from -10 to +10V and converts them into 0 and 5V. Thecircuit for this interface is shown in the following Figure 3.6.

The Figure 3.7 is an example of a signal on an RS232 line, initially it sits at-12V, known as the ’STOP CONDITION’, this condition lasts until a signal is sent. Tosend a signal we first need to let the receiving device know we are starting to send data,to do this we set the line to +12V, this is called the ’START BIT’ - the receiving deviceis waiting for this to happen, once it does it then gets ready to read the next 9 bits ofdata (eight data bits and one stop bit).

Page 37: 741_MOHAMADASYRAFBINCHELAH2010

20

Figure 3.6: Connection between D9 Female serial port, MAX232 and PIC16F877A.

Figure 3.7: Signal generate on RS232

This is the identical signal as it leaves (or enters) the PIC pin, as the MAX232inverts the signal this looks to be inverted, but is actually the correct way up.RS232logic levels are inverted compared to normal levels. It is shown below on Figure 3.8.

Figure 3.8: Signal after gone through MAX232

Page 38: 741_MOHAMADASYRAFBINCHELAH2010

21

3.3 Software Implementation

For software implementation, MATLAB is used to program the imageprocessing stage and also build GUI for this hardware. In order to acquire imagefor real time system, AMCAP software will be integrated with MATLAB. Beside,MICROELECTRONIKA PIC pro is use to program PIC16F877A.

3.3.1 Programming in MATLAB

In this project, a program will be developed using MATLAB. This software isdesigned to control when the process of acquiring image, processed the car image andalso developed a GUI application window as the main panel of the system.

3.3.1.1 MATLAB for graphical user interface(GUI)

Like C language, C++ and JAVA, we also can build GUI using MATLAB. Formy experience, building GUI in MATLAB is much more easy compare to the otherprogramming languages. MATLAB has special application named GUIDE to buildGUI.GUIDE stands for Graphical User Interface Development Environment. GUIDEwill stores GUIs in two files,

i. .fig file. This type of file contains a complete description of GUI layout andGUI components like control buttons, axes to display figure, and etc.

ii. .m file. This type of file contains code to control the GUI. Code initializationand callbacks are held here.

The following Figure 3.9 is the common steps when creating a GUI.

Page 39: 741_MOHAMADASYRAFBINCHELAH2010

22

Design GUI

Laying Out GUI

GUI Programming

Saving and Running GUI

Figure 3.9: General step to design GUI using GUIDE

To begin creating a GUI using MATLAB, the word “guide” in MATLABcommand window, then a window like figure 3.10 will appear.

Figure 3.10: General step to design GUI using GUIDE

To start design and laying out the GUI, usually user will choose ”Blank GUI”.After that, a window like Figure 3.11 should appear. Same as Microsoft FoundationClasses (MFC) application in Visual C++ 2008, the process of designing the GUI inMATLAB is also pretty same. It is due to in MATLAB, we just need to drag anddrop depends on the application in GUI. The simple GUI is made using GUIDE inMATLAB for this system is shown as Figure 3.12.

Page 40: 741_MOHAMADASYRAFBINCHELAH2010

23

Component Pallete

Allign Objects Menu Editor Tab Editor Toolbar Editor

Run GUI

Object browser

Property Inspector

M-file editor

Layout Area

Resize Box

Figure 3.11: GUIDE layout

Figure 3.12: GUI for the system

3.3.1.2 Image capturing mode

To acquire the image, this system is built in two different modes. First,image can be load from file and secondly, image can be directly captured from the

Page 41: 741_MOHAMADASYRAFBINCHELAH2010

24

software. As I mentioned before, AMCAP software is integrated with button controlin MATLAB.

Figure 3.13: GUI load image from file

Figure 3.14: Gui capture image using webcam

Page 42: 741_MOHAMADASYRAFBINCHELAH2010

25

3.3.1.3 Plate Segmentation

Segmentation is the process of subdividing image into consistent region orobjects. So, plate segmentation is the process of dividing each of the characters on thecar plate. In order to make the process of character recognition easier, it is preferredto isolate each of the characters on the car plate. For the Malaysian standard licenseplate the most suitable technique for character isolation or segmentation is horizontaland vertical projection [2].The following steps are used to segment the characters:

i. Threshold the car plate image.

ii. The connected component in the image is searched.

iii. Resize the character to 42× 24 pixels.

Figure 3.15 is shown the original picture of car plate. After the process of segmentationthe result is shown as figure 3.16 .

Figure 3.15: Car plate extraction

3.3.1.4 Character Recognition

Character recognition is the last process of this system. In this process, eachof the segmented regions for the previous process will be recognize using templatematching. The template matching is the process of comparing each character to theset of template character (reference template). In template matching, two types of testpoint is being used, that is white test point and black test point. White test point meansto test the white area on the characters, mean while the black test point will be use to

Page 43: 741_MOHAMADASYRAFBINCHELAH2010

26

Figure 3.16: Car plate segmentation

test the black area. The equation of test matching is like below:

Result =∑

Match point∑Test point

× 100% (3.1)

The black points fall in the black pixels, while white points fall in white pixels, thatis defined by matched point. During the process of template matching, to test thecharacter image, references template is loaded one by one. If one of the charactersmatched with the reference template, the rest of the template will be ignored. Thisscenario is called template priority. If the template with higher priority was foundmatched, the other templates with the lower priority is abundant. Figure 3.17 belowshow template as references template during the template matching process.

(a) (b)

Figure 3.17: Samples of reference templates with size 42× 24 pixels

Page 44: 741_MOHAMADASYRAFBINCHELAH2010

CHAPTER 4

RESULT AND DISCUSSION

4.1 Introduction

This section while describe about the result from the system and the discussionthat related to the system. Besides, there are some figure that show the success andfailed result.

4.2 Result

After all methodology and procedure has been done, image from webcam canbe capture and processing. From the sample of 100 images of car plate used for testingin a computer equip with AMD Turion X2 64 bit and 2 GHz of ram, only 80 imagesshow the positive. It means that this system only contribute 80% in term of accuracy.Figure 4.1 shows that the successful cases. Then, figure 4.2 shows the failed cases.The fail cases will be discuss in the next section.

Page 45: 741_MOHAMADASYRAFBINCHELAH2010

28

Figure 4.1: Successful case

Figure 4.2: Failed case

4.3 Discussion

There are several reasons why some images of car plate could not berecognized. The followings are the possible reasons that are identify during the study:

Page 46: 741_MOHAMADASYRAFBINCHELAH2010

29

i. The black plate look too whity because of the direct light source. The difficultyappears when thresholding process.

ii. The characters on the car plate too close. This problem will cause problemduring segmentation process. Too many connecting character make theisolation of car plate characters became more difficult.

iii. The black plate color are too dark. Process of thresholding image becamedifficult.

Figure 4.3 below shows some images of cars that are successfully recognize bysystem.While, Figure refc4:f4 shows images of cars that are failed to recognize bythe system.

Figure 4.3: Some image that are successfully recognize by the system

Page 47: 741_MOHAMADASYRAFBINCHELAH2010

30

Figure 4.4: Some image that are failed to recognize by the system

Page 48: 741_MOHAMADASYRAFBINCHELAH2010

CHAPTER 5

CONCLUSION AND RECOMMENDATION

5.1 Introduction

This chapter will discuss about the conclusion of the project. Apart from that,it will also include future recommendations for further study.

5.2 Conclusion

For the conclusion, the system was able to detect the characters of the carplate. Indeed, the system was also able to recognize all the characters on the car plate.Moreover, the GUI also easily to understood and used. This system is suitable to beapplied to the access control system, car parking system and border control system.The objectives of this system were successfully achieved. However, there are stillnot enough to apply to the real time system. The next section will discuss on therecommendation for future work.

5.3 Recommendation

Nowadays people are aware of the need of vehicle security due to the fact thatthey are various cases of car robbery. Therefore it is incumbent upon us to increasethe level of securities. To make the system more secure, the system is recommendedto integrate with face detection. This is means instead of identifying driver with theirplate, it also important to identify by her or his face.

This system also recommended to be a full automatic system. It can be

Page 49: 741_MOHAMADASYRAFBINCHELAH2010

32

implement in a real time system. Beside, this system also recommended to be moreflexible which means car plate can be detect for any angle.

Last but not least, process of characters recognition using the templatematching sometimes gives the wrong result. It is recommended to use more referencestemplate with different font. Besides, the neural network algorithm should also betrying and compare to template matching.

Page 50: 741_MOHAMADASYRAFBINCHELAH2010

REFERENCES

1. Ozbay, S. and Ercelebi, E. Automatic Vehicle Identification by

PlateRecognition. Technical report. World Academy of Science, Engineeringand Technology.

2. Pierre Ponce, D. L. W., Stanley S. Wang. License Plate Recognition. Technicalreport.

3. Wisam Al Faqheri, a. S. M. A Real-Time Malaysian Automatic License

Plate Recognition (M-ALPR) using Hybrid Fuzzy. Technical Report VOL.9No.2. Faculty of Engineering Universiti Putra Malaysia 43400 UPM, Serdang,Selangor Darul Ehsan, Malaysia: Dept. of Computer and CommunicationSystems. 2009.

4. Ho C. H., L. M. H. M. M. M. R. T., Koay S. B. License Plate Recognition

(Software). Technical report. University of Malaya: Department of ElectricalEngineering.

5. Tran Duc Duan, T. V. P. N. V. H., Tran Le Hong Du. Building an

Automatic Vehicle License-Plate Recognition System. Technical report. CanTho, Vietnam: Intl. Conf. in Computer Science.

6. Rafael C.Gonzalez, S. L. E., Richard E. Woods. Digital Image Processing

Using Matlab. Upper Saddle River,NJ: Prentice Hall. 2002.

7. Abbasi, T. A. and Abbasi, M. U. A Novel Architecture for Prewitt Edge

Detector. Technical Report Vol. 8, pp. 203211. Faculty of Engineering andTechnology, Jamia Millia Islamia, New Delhi, India: University Polytechnic,Department of Electronics and Communication,. 2009.

8. Othman Khalifa, R. I., Sheroz Khan and Suleiman, A. Malaysian Vehicle

License Plate Recognition. Technical Report Vol.4,No.4. International IslamicUniversity Malaysia: Kulliyah of Engineering. 2007.

9. The MathWorks, I. Image Processing Toolbox Users Guide. Natick, MA01760-2098: The MathWorks, Inc. 19932008.

10. Technology, M. PIC16F87XA Data Sheet 28/40/44-Pin Enhanced Flash

Microcontrollers. U.S.A.: Microchip Technology Incorporated. 2003.

Page 51: 741_MOHAMADASYRAFBINCHELAH2010

34

11. Peacock, C. Interfacing the Serial / RS232 Port, 2005. URL http://www.

beyondlogic.org/serial/serial.htm.

12. Parallex, I. 2 x16 Parallel LCD (603-00006). 599 Menlo Drive, Suite 100Rocklin, California 95765, USA: Parallex,Inc.

Page 52: 741_MOHAMADASYRAFBINCHELAH2010

APPENDIX A

SOURCE CODE

Source code of the system.

A.1 LCD display

1 sbit LCD_RS at RD2_bit;

2 sbit LCD_EN at RD3_bit;

3 sbit LCD_D7 at RD7_bit;

4 sbit LCD_D6 at RD6_bit;

5 sbit LCD_D5 at RD5_bit;

6 sbit LCD_D4 at RD4_bit;

7 //sbit PSPMODE at TRISE4_bit;

89 // Pin direction

10 sbit LCD_RS_Direction at TRISD2_bit;

11 sbit LCD_EN_Direction at TRISD3_bit;

12 sbit LCD_D7_Direction at TRISD7_bit;

13 sbit LCD_D6_Direction at TRISD6_bit;

14 sbit LCD_D5_Direction at TRISD5_bit;

15 sbit LCD_D4_Direction at TRISD4_bit;

1617 char txt1[] = "Selamat Datang";

18 char txt2[] = "Please wait";

19 char txt3[] = "Identifying";

20 char txt4[] = ".";

21 char txt5[] = "Car Plate ID:" ;

2223 char i=0; // Loop variable

24 int j;

25 int k = 0;

26 unsigned short kb,kj = 0;

2728 void Move_Delay() // Function used for text moving

Page 53: 741_MOHAMADASYRAFBINCHELAH2010

36

29 Delay_ms(500); 1// You can change the moving speed here

30

3132 void main()

33 TRISD = 0;

34 PORTD = 0xFF;

35 TRISD = 0xff;

3637 TRISB = 1 ;

38 PORTB = 0xFF;

3940 Lcd_Init(); // Initialize LCD

41 UART1_Init(9600); //initialize serial

4243 Lcd_Cmd(_LCD_CLEAR); // Clear display

44 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

454647 //Lcd_Out(2,6,txt4); // Write text in second row

48 //Delay_ms(2000);

49 Lcd_Cmd(_LCD_CLEAR); // Clear display

5051 Lcd_Out(1,2,txt1); // Write text in first row

52 Lcd_Out(2,5,txt2); // Write text in second row

53 Delay_ms(2000);

5455 Lcd_Cmd(_LCD_CLEAR);

56 Lcd_Out(1,1,txt3); // Write text in first row

57 //int i;

58 for (i=12;i<=16;i++)

59

60 Lcd_Out(1,i,txt4);

61 Delay_ms(1000);

6263

64 Lcd_Cmd(_LCD_CLEAR);

65 Lcd_Out(1,1,txt5);

6667 // Lcd_Cmd(_LCD_CLEAR);

68 /*while(1)

69

7071 if (UART1_Data_Ready() == 1)

72 kb = RCREG;

73 Lcd_Chr(2, 1, kb);

7475

Page 54: 741_MOHAMADASYRAFBINCHELAH2010

37

767778 */

798081 // Lcd_Cmd(_LCD_CLEAR);

828384 while(k!=7) // Endless loop

858687 //if hv data received via uart

88 //read 1st data received

89 // kj = RCREG;

90 if(k<=7)

91

92 if (UART1_Data_Ready() == 1)

93 kb = RCREG;

94 Lcd_Chr(2, 10+k, kb);

95 kb = 0;

96 k++;

97

9899

100101102

103 Delay_ms(5000);

104 Lcd_Cmd(_LCD_CLEAR);

105

106107 /* main */

Page 55: 741_MOHAMADASYRAFBINCHELAH2010

38

A.2 GUI Programming using MATLAB

1 function varargout = PSM(varargin)

2 % PSM M-file for PSM.fig

3 % PSM, by itself, creates a new PSM or raises the existing

4 % singleton*.

5 %

6 % H = PSM returns the handle to a new PSM or the handle to

7 % the existing singleton*.

8 %

9 % PSM(’CALLBACK’,hObject,eventData,handles,...) calls the local

10 % function named CALLBACK in PSM.M with the given input

11 % arguments.

12 %

13 % PSM(’Property’,’Value’,...) creates a new PSM or raises the

14 % existing singleton*. Starting from the left, property value pairs

are applied to the GUI before PSM_OpeningFcn gets called.

15 % An unrecognized property name or invalid value makes property

16 % application stop. All inputs are passed to PSM_OpeningFcn via

17 % varargin.

18 %

19 % *See GUI Options on GUIDE’s Tools menu. Choose "GUI allows only

one

20 % instance to run (singleton)".

21 %

22 % See also: GUIDE, GUIDATA, GUIHANDLES

2324 % Edit the above text to modify the response to help PSM

25 % Last Modified by GUIDE v2.5 31-Mar-2010 16:41:23

2627 % Begin initialization code - DO NOT EDIT

28 gui_Singleton = 1;

29 gui_State = struct(’gui_Name’, mfilename, ...

30 ’gui_Singleton’, gui_Singleton, ...

31 ’gui_OpeningFcn’, @PSM_OpeningFcn, ...

32 ’gui_OutputFcn’, @PSM_OutputFcn, ...

33 ’gui_LayoutFcn’, [] , ...

34 ’gui_Callback’, []);

35 if nargin && ischar(varargin1)

36 gui_State.gui_Callback = str2func(varargin1);

37 end

3839 if nargout

40 [varargout1:nargout] = gui_mainfcn(gui_State, varargin:);

41 else

42 gui_mainfcn(gui_State, varargin:);

43 end

44 % End initialization code - DO NOT EDIT

Page 56: 741_MOHAMADASYRAFBINCHELAH2010

39

454647 % --- Executes just before PSM is made visible.

48 function PSM_OpeningFcn(hObject, eventdata, handles, varargin)

49 % This function has no output args, see OutputFcn.

50 % hObject handle to figure

51 % eventdata reserved - to be defined in a future version of MATLAB

52 % handles structure with handles and user data (see GUIDATA)

53 % varargin command line arguments to PSM (see VARARGIN)

5455 % Choose default command line output for PSM

56 handles.output = hObject;

57 set(handles.tResult,’string’,’’);

585960 % Update handles structure

61 guidata(hObject, handles);

6263 % UIWAIT makes PSM wait for user response (see UIRESUME)

64 uiwait(handles.figure1);

656667 % --- Outputs from this function are returned to the command line.

68 function varargout = PSM_OutputFcn(hObject, eventdata, handles)

69 % varargout cell array for returning output args (see VARARGOUT);

70 % hObject handle to figure

71 % eventdata reserved - to be defined in a future version of MATLAB

72 % handles structure with handles and user data (see GUIDATA)

7374 % Get default command line output from handles structure

75 handles.output = hObject;

76 varargout1 = handles.output;

777879 % --- Executes on button press in Load.

80 function Load_Callback(hObject, eventdata, handles)

81 % hObject handle to Load (see GCBO)

82 % eventdata reserved - to be defined in a future version of MATLAB

83 % handles structure with handles and user data (see GUIDATA)

84 [FileName,PathName]=uigetfile(’*.jpg;*.tif;*.png;*.gif’,’All Image

Files’;...

85 ’*.*’,’All Files’ ,’Open file’,...

86 ’C:\Users\ah cap\Desktop\PSM\Demo’)

8788 if size(PathName)== 0

89 display (’no file selected’);

90 return

Page 57: 741_MOHAMADASYRAFBINCHELAH2010

40

91 else

92 handles.file=fullfile(PathName,FileName);

9394 I=imread(handles.file);

95 handles.ImNow=I;

96 handles.INimej=handles.ImNow;

9798 set(handles.Original,’HandleVisibility’,’ON’);

99 set(handles.New,’HandleVisibility’,’OFF’);

100 axes(handles.Original);

101 %handles.load=handles.Original;

102 image(handles.INimej);

103104 %axis equal;

105 %axis tight;

106 axis off;

107 pause(2);

108 set(handles.Original,’HandleVisibility’,’OFF’);

109 end

110 %set(handles.New,’HandleVisibility’,’ON’);

111 %axes(handles.New);

112 %image(handles.INimej);

113 %axis off;

114115116 %handles.ImNow=handles.INimej;

117 s=size(handles.ImNow);

118 s

119120 Im=rgb2gray(handles.ImNow);

121 Im=imadjust(Im);

122 B = medfilt2(Im,[5 5]);

123 BW = edge(B,’sobel’);

124 handles.ImNow=Im;

125 set(handles.Original,’HandleVisibility’,’ON’);

126 axes(handles.Original);

127 imshow(BW);

128129130 %set(handles.Original,’HandleVisibility’,’OFF’);

131132133 k=waitforbuttonpress;

134 if k==0

135 pos = get(handles.Original,’CurrentPoint’)

136 %pos = get(handles.uicursor,’TooltipString’);

137 set(handles.eX,’String’,num2str(round(pos(1))));

Page 58: 741_MOHAMADASYRAFBINCHELAH2010

41

138 set(handles.eY,’String’,num2str(round(pos(3))));

139 rectangle(’Position’,[pos(1),pos(3),350,80],’EdgeColor’,[0,1,0],’

linewidth’,2);

140 end

141 set(handles.Original,’HandleVisibility’,’OFF’);

142143 guidata(hObject, handles);

144145 % --- Executes on button press in Recognition.

146 function Recognition_Callback(hObject, eventdata, handles)

147 % hObject handle to Recognition (see GCBO)

148 % eventdata reserved - to be defined in a future version of MATLAB

149 % handles structure with handles and user data (see GUIDATA)

150 handles.NewIm=handles.bprocess;

151 %handles.ImNow=imcrop(handles.NewIm,[170 280 80 473]);

152 set(handles.New,’HandleVisibility’,’ON’);

153 axes(handles.New);

154 image(handles.NewIm);

155 axis off;

156 set(handles.New,’HandleVisibility’,’OFF’);

157158 %axis off;

159160 figure,imshow(handles.NewIm);

161162 G=handles.NewIm;

163164 % Convert to gray scale

165 if size(G,3)==3 %RGB image

166 G=rgb2gray(G);

167 else

168 % Convert to BW

169 threshold = graythresh(G);

170 I =im2bw(G,threshold);

171172 % Remove all object containing fewer than 30 pixels

173 I = bwareaopen(I,30);

174175 handles.ImNow=I;

176 set(handles.New,’HandleVisibility’,’ON’);

177 axes(handles.New);

178 imshow(handles.ImNow);

179 axis off;

180 figure,imshow(handles.ImNow);

181 set(handles.New,’HandleVisibility’,’OFF’);

182 end

183

Page 59: 741_MOHAMADASYRAFBINCHELAH2010

42

184 %Storage matrix word from image

185 word=[ ];

186 re=I;

187188189 % Load templates

190 load templates

191 global templates

192193 % Compute the number of letters in template file

194 num_letters=size(templates,2);

195196 %--------------------------------------------------

197 % Label and count connected components

198 [L Ne] = bwlabel(re);

199 for n=1:Ne

200 [r,c] = find(L==n);

201 % Extract letter

202 n1=re(min(r):max(r),min(c):max(c));

203 % Resize letter (same size of template)

204 img_r=imresize(n1,[42 24]);

205 %Uncomment line below to see letters one by one

206 figure,imshow(img_r);%pause(0.5)

207 %----------------------------------------------------

208 % Call fcn to convert image to text

209 letter=read_letter(img_r,num_letters);

210 % Letter concatenation

211 word=[word letter];

212213 handles.result=word;

214215216217 end

218 %fprintf(fid,’%s\n’,lower(word));%Write ’word’ in text file (

lower)

219 word

220221222 %serail port connection

223 s=serial(’com4’);

224 fopen(s);

225 [r c]=size(word);

226227 for m=1:c

228 res = word(m);pause(0.1);

229 fwrite(s,res);

Page 60: 741_MOHAMADASYRAFBINCHELAH2010

43

230 end

231 fclose(s);

232 set(handles.tResult,’string’,handles.result);

233234 % Clear ’word’ variable

235 word=[ ];

236237 guidata(hObject, handles);

238239240 % --- Executes on button press in Exit.

241 function Exit_Callback(hObject, eventdata, handles)

242 % hObject handle to Exit (see GCBO)

243 % eventdata reserved - to be defined in a future version of MATLAB

244 % handles structure with handles and user data (see GUIDATA)

245 % Get the current position of the GUI from the handles structure

246 % to pass to the modal dialog.

247248 pos_size = get(handles.figure1,’Position’);

249 % Call modaldlg with the argument ’Position’.

250 user_response = Exit(’Title’,’Confirm Close’);

251 switch user_response

252 case ’No’

253 % take no action

254 case ’Yes’

255 % Prepare to close GUI application window

256 % .

257 % .

258 % .

259 delete(handles.figure1)

260 end

261262263264 % ------------------------------------------------

265 function File_Callback(hObject, eventdata, handles)

266 % hObject handle to File (see GCBO)

267 % eventdata reserved - to be defined in a future version of MATLAB

268 % handles structure with handles and user data (see GUIDATA)

269270271 % ------------------------------------------------

272 function Help_Callback(hObject, eventdata, handles)

273 % hObject handle to Help (see GCBO)

274 % eventdata reserved - to be defined in a future version of MATLAB

275 % handles structure with handles and user data (see GUIDATA)

276

Page 61: 741_MOHAMADASYRAFBINCHELAH2010

44

277278 % -------------------------------------------------

279 function About_Callback(hObject, eventdata, handles)

280 % hObject handle to About (see GCBO)

281 % eventdata reserved - to be defined in a future version of MATLAB

282 % handles structure with handles and user data (see GUIDATA)

283284285286 % -----------------------------------------------------

287 function uicursor_OnCallback(hObject, eventdata, handles)

288 % hObject handle to uicursor (see GCBO)

289 % eventdata reserved - to be defined in a future version of MATLAB

290 % handles structure with handles and user data (see GUIDATA)

291292293294 function eX_Callback(hObject, eventdata, handles)

295 % hObject handle to eX (see GCBO)

296 % eventdata reserved - to be defined in a future version of MATLAB

297 % handles structure with handles and user data (see GUIDATA)

298299 % Hints: get(hObject,’String’) returns contents of eX as text

300 % str2double(get(hObject,’String’)) returns contents of eX as a

double

301302303 % --- Executes during object creation, after setting all properties.

304 function eX_CreateFcn(hObject, eventdata, handles)

305 % hObject handle to eX (see GCBO)

306 % eventdata reserved - to be defined in a future version of MATLAB

307 % handles empty - handles not created until after all CreateFcns

called

308309 % Hint: edit controls usually have a white background on Windows.

310 % See ISPC and COMPUTER.

311 if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’

defaultUicontrolBackgroundColor’))

312 set(hObject,’BackgroundColor’,’white’);

313 end

314315316317 function eY_Callback(hObject, eventdata, handles)

318 % hObject handle to eY (see GCBO)

319 % eventdata reserved - to be defined in a future version of MATLAB

320 % handles structure with handles and user data (see GUIDATA)

Page 62: 741_MOHAMADASYRAFBINCHELAH2010

45

321322 % Hints: get(hObject,’String’) returns contents of eY as text

323 % str2double(get(hObject,’String’)) returns contents of eY as a

double

324325326 % --- Executes during object creation, after setting all properties.

327 function eY_CreateFcn(hObject, eventdata, handles)

328 % hObject handle to eY (see GCBO)

329 % eventdata reserved - to be defined in a future version of MATLAB

330 % handles empty - handles not created until after all CreateFcns

called

331332 % Hint: edit controls usually have a white background on Windows.

333 % See ISPC and COMPUTER.

334 if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’

defaultUicontrolBackgroundColor’))

335 set(hObject,’BackgroundColor’,’white’);

336 end

337338339 % --- Executes on button press in process.

340 function process_Callback(hObject, eventdata, handles)

341 % hObject handle to process (see GCBO)

342 % eventdata reserved - to be defined in a future version of MATLAB

343 % handles structure with handles and user data (see GUIDATA)

344 handles.width=300;

345 handles.width=80;

346 handles.bProcess=handles.ImNow;

347 %figure,imshow(handles.bProcess);

348 [r c]=size(handles.bProcess)

349350351 x=str2double(get(handles.eX,’String’));

352 y=str2double(get(handles.eY,’String’));

353 sample = handles.bProcess(y:y+85,x:x+350);

354 axes(handles.plateAxes);

355 imshow(sample);

356 axis off;

357 handles.bprocess=sample;

358359 guidata(hObject, handles);

360361362 % --- Executes on button press in camMode.

363 function camMode_Callback(hObject, eventdata, handles)

364 % hObject handle to camMode (see GCBO)

Page 63: 741_MOHAMADASYRAFBINCHELAH2010

46

365 % eventdata reserved - to be defined in a future version of MATLAB

366 % handles structure with handles and user data (see GUIDATA)

367 status = dos(’C:\Program Files\Common Files\PAP7501\amcap.exe’)

368 if size(status)==0

369 return

370 end

A.3 Serial Communication GUI to hardware

1 s=serial(’com4’);

2 fopen(s);

3 [r c]=size(word);

45 for m=1:c

6 res = word(m);pause(0.1);

7 fwrite(s,res);

8 end

9 fclose(s);

Page 64: 741_MOHAMADASYRAFBINCHELAH2010
Page 65: 741_MOHAMADASYRAFBINCHELAH2010

48

APPENDIX B

HARDWARE DATASHEET

B.1 PIC16f877a(refer to [10])

2003 Microchip Technology Inc. DS39582B

PIC16F87XAData Sheet

28/40/44-Pin Enhanced FlashMicrocontrollers

Page 66: 741_MOHAMADASYRAFBINCHELAH2010

49

DS39582B-page ii 2003 Microchip Technology Inc.

Information contained in this publication regarding deviceapplications and the like is intended through suggestion onlyand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.No representation or warranty is given and no liability isassumed by Microchip Technology Incorporated with respectto the accuracy or use of such information, or infringement ofpatents or other intellectual property rights arising from suchuse or otherwise. Use of Microchip’s products as criticalcomponents in life support systems is not authorized exceptwith express written approval by Microchip. No licenses areconveyed, implicitly or otherwise, under any intellectualproperty rights.

Trademarks

The Microchip name and logo, the Microchip logo, Accuron,dsPIC, KEELOQ, MPLAB, PIC, PICmicro, PICSTART, PRO MATE and PowerSmart are registered trademarks ofMicrochip Technology Incorporated in the U.S.A. and othercountries.

AmpLab, FilterLab, microID, MXDEV, MXLAB, PICMASTER,SEEVAL and The Embedded Control Solutions Company areregistered trademarks of Microchip Technology Incorporatedin the U.S.A.

Application Maestro, dsPICDEM, dsPICDEM.net, ECAN,ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, microPort,Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,PICkit, PICDEM, PICDEM.net, PowerCal, PowerInfo,PowerMate, PowerTool, rfLAB, rfPIC, Select Mode,SmartSensor, SmartShunt, SmartTel and Total Endurance aretrademarks of Microchip Technology Incorporated in theU.S.A. and other countries.

Serialized Quick Turn Programming (SQTP) is a service markof Microchip Technology Incorporated in the U.S.A.

All other trademarks mentioned herein are property of theirrespective companies.

© 2003, Microchip Technology Incorporated, Printed in theU.S.A., All Rights Reserved.

Printed on recycled paper.

Note the following details of the code protection feature on Microchip devices:

• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of ourproducts. Attempts to break microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such actsallow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Microchip received QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999 and Mountain View, California in March 2002. The Company’s quality system processes and procedures are QS-9000 compliant for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, non-volatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001 certified.

Page 67: 741_MOHAMADASYRAFBINCHELAH2010

50

2003 Microchip Technology Inc. DS39582B-page 1

PIC16F87XA

Devices Included in this Data Sheet:

High-Performance RISC CPU:

• Only 35 single-word instructions to learn• All single-cycle instructions except for program

branches, which are two-cycle• Operating speed: DC – 20 MHz clock input

DC – 200 ns instruction cycle• Up to 8K x 14 words of Flash Program Memory,

Up to 368 x 8 bytes of Data Memory (RAM), Up to 256 x 8 bytes of EEPROM Data Memory

• Pinout compatible to other 28-pin or 40/44-pin PIC16CXXX and PIC16FXXX microcontrollers

Peripheral Features:

• Timer0: 8-bit timer/counter with 8-bit prescaler

• Timer1: 16-bit timer/counter with prescaler,can be incremented during Sleep via external crystal/clock

• Timer2: 8-bit timer/counter with 8-bit periodregister, prescaler and postscaler

• Two Capture, Compare, PWM modules

- Capture is 16-bit, max. resolution is 12.5 ns- Compare is 16-bit, max. resolution is 200 ns- PWM max. resolution is 10-bit

• Synchronous Serial Port (SSP) with SPI™ (Master mode) and I2C™ (Master/Slave)

• Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection

• Parallel Slave Port (PSP) – 8 bits wide withexternal RD, WR and CS controls (40/44-pin only)

• Brown-out detection circuitry forBrown-out Reset (BOR)

Analog Features:

• 10-bit, up to 8-channel Analog-to-Digital Converter (A/D)

• Brown-out Reset (BOR)

• Analog Comparator module with:- Two analog comparators- Programmable on-chip voltage reference

(VREF) module- Programmable input multiplexing from device

inputs and internal voltage reference- Comparator outputs are externally accessible

Special Microcontroller Features:

• 100,000 erase/write cycle Enhanced Flash program memory typical

• 1,000,000 erase/write cycle Data EEPROM memory typical

• Data EEPROM Retention > 40 years

• Self-reprogrammable under software control• In-Circuit Serial Programming™ (ICSP™)

via two pins• Single-supply 5V In-Circuit Serial Programming• Watchdog Timer (WDT) with its own on-chip RC

oscillator for reliable operation• Programmable code protection

• Power saving Sleep mode• Selectable oscillator options• In-Circuit Debug (ICD) via two pins

CMOS Technology:

• Low-power, high-speed Flash/EEPROM technology

• Fully static design

• Wide operating voltage range (2.0V to 5.5V) • Commercial and Industrial temperature ranges• Low-power consumption

• PIC16F873A• PIC16F874A

• PIC16F876A• PIC16F877A

Device

Program Memory DataSRAM(Bytes)

EEPROM(Bytes)

I/O10-bit

A/D (ch)CCP

(PWM)

MSSP

USARTTimers8/16-bit

ComparatorsBytes

# Single WordInstructions

SPIMaster

I2C

PIC16F873A 7.2K 4096 192 128 22 5 2 Yes Yes Yes 2/1 2

PIC16F874A 7.2K 4096 192 128 33 8 2 Yes Yes Yes 2/1 2

PIC16F876A 14.3K 8192 368 256 22 5 2 Yes Yes Yes 2/1 2

PIC16F877A 14.3K 8192 368 256 33 8 2 Yes Yes Yes 2/1 2

28/40/44-Pin Enhanced Flash Microcontrollers

Page 68: 741_MOHAMADASYRAFBINCHELAH2010

51

2003 Microchip Technology Inc. DS39582B-page 3

PIC16F87XA

Pin Diagrams (Continued)

RB7/PGDRB6/PGCRB5RB4RB3/PGMRB2RB1RB0/INTVDD

VSS

RD7/PSP7RD6/PSP6RD5/PSP5RD4/PSP4RC7/RX/DTRC6/TX/CKRC5/SDO

RC4/SDI/SDARD3/PSP3RD2/PSP2

MCLR/VPP

RA0/AN0RA1/AN1

RA2/AN2/VREF-/CVREF

RA3/AN3/VREF+RA4/T0CKI/C1OUT

RA5/AN4/SS/C2OUTRE0/RD/AN5RE1/WR/AN6RE2/CS/AN7

VDD

VSS

OSC1/CLKIOSC2/CLKO

RC0/T1OSO/T1CKIRC1/T1OSI/CCP2

RC2/CCP1

RC3/SCK/SCLRD0/PSP0RD1/PSP1

1234567891011121314151617181920

4039383736353433323130292827262524232221

PIC

16F

874A

/877

A

40-Pin PDIP

1011121314151617

18 19 20 21 22 23 24 25 26

44

87

6 5 4 3 2 1

27 28

2930313233343536373839

40414243

9

PIC16F874A

RA4/T0CKI/C1OUTRA5/AN4/SS/C2OUT

RE0/RD/AN5

OSC1/CLKIOSC2/CLKO

RC0/T1OSO/T1CK1NC

RE1/WR/AN6RE2/CS/AN7

VDDVSS

RB3/PGMRB2RB1RB0/INTVDDVSSRD7/PSP7RD6/PSP6RD5/PSP5RD4/PSP4

RA

3/A

N3/

VR

EF+

RA

2/A

N2/

VR

EF-/C

VR

EF

RA

1/A

N1

RA

0/A

N0

MC

LR/V

PP

NC

RB

7/P

GD

RB

6/P

GC

RB

5R

B4

NC

NC

RC

6/T

X/C

KR

C5/

SD

OR

C4/

SD

I/SD

AR

D3/

PS

P3

RD

2/P

SP

2R

D1/

PS

P1

RD

0/P

SP

0R

C3/

SC

K/S

CL

RC

2/C

CP

1R

C1/

T1O

SI/C

CP

2

1011

23456

1

18 19 20 21 2212 13 14 15

38

87

44 43 42 41 40 3916 17

2930313233

232425262728

36 3435

9

PIC16F874A

37

RA

3/A

N3/

VR

EF+

RA

2/A

N2/

VR

EF-/C

VR

EF

RA

1/A

N1

RA

0/A

N0

MC

LR/V

PP

NC

RB

7/P

GD

RB

6/P

GC

RB

5R

B4

NC

RC

6/T

X/C

KR

C5/

SD

OR

C4/

SD

I/SD

AR

D3/

PS

P3

RD

2/P

SP

2R

D1/

PS

P1

RD

0/P

SP

0R

C3/

SC

K/S

CL

RC

2/C

CP

1R

C1/

T1O

SI/C

CP

2N

C

NCRC0/T1OSO/T1CKIOSC2/CLKOOSC1/CLKIVSS

VDD

RE2/CS/AN7RE1/WR/AN6RE0/RD/AN5RA5/AN4/SS/C2OUTRA4/T0CKI/C1OUT

RC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7

VSS

VDD

RB0/INTRB1RB2

RB3/PGM

44-Pin PLCC

44-Pin TQFP

PIC16F877A

PIC16F877A

RC7/RX/DT

Page 69: 741_MOHAMADASYRAFBINCHELAH2010

52

PIC16F87XA

DS39582B-page 46 2003 Microchip Technology Inc.

4.3 PORTC and the TRISC Register

PORTC is an 8-bit wide, bidirectional port. The corre-sponding data direction register is TRISC. Setting aTRISC bit (= 1) will make the corresponding PORTCpin an input (i.e., put the corresponding output driver ina High-Impedance mode). Clearing a TRISC bit (= 0)will make the corresponding PORTC pin an output (i.e.,put the contents of the output latch on the selected pin).

PORTC is multiplexed with several peripheral functions(Table 4-5). PORTC pins have Schmitt Trigger inputbuffers.

When the I2C module is enabled, the PORTC<4:3>pins can be configured with normal I2C levels, or withSMBus levels, by using the CKE bit (SSPSTAT<6>).

When enabling peripheral functions, care should betaken in defining TRIS bits for each PORTC pin. Someperipherals override the TRIS bit to make a pin anoutput, while other peripherals override the TRIS bit tomake a pin an input. Since the TRIS bit override is ineffect while the peripheral is enabled, read-modify-write instructions (BSF, BCF, XORWF) with TRISC as thedestination, should be avoided. The user should referto the corresponding peripheral section for the correctTRIS bit settings.

FIGURE 4-6: PORTC BLOCK DIAGRAM (PERIPHERAL OUTPUT OVERRIDE) RC<2:0>, RC<7:5>

FIGURE 4-7: PORTC BLOCK DIAGRAM (PERIPHERAL OUTPUT OVERRIDE) RC<4:3>

Port/Peripheral Select(2)

Data Bus

WR Port

WR TRIS

Data Latch

TRIS Latch

SchmittTrigger

QD

QCK

Q D

EN

Peripheral Data Out0

1

QD

QCK

P

N

VDD

VSS

RD Port

PeripheralOE(3)

Peripheral Input

I/Opin(1)

Note 1: I/O pins have diode protection to VDD and VSS.

2: Port/Peripheral Select signal selects between portdata and peripheral output.

3: Peripheral OE (Output Enable) is only activated ifPeripheral Select is active.

RD TRIS

Port/Peripheral Select(2)

Data Bus

WR Port

WR TRIS

Data Latch

TRIS Latch

SchmittTrigger

QD

QCK

Q D

EN

Peripheral Data Out0

1

QD

QCK

P

N

VDD

VSS

RD Port

PeripheralOE(3)

SSP Input

I/Opin(1)

Note 1: I/O pins have diode protection to VDD and VSS.2: Port/Peripheral Select signal selects between port data

and peripheral output.3: Peripheral OE (Output Enable) is only activated if

Peripheral Select is active.

0

1

CKESSPSTAT<6>

SchmittTriggerwithSMBusLevels

RD TRIS

Page 70: 741_MOHAMADASYRAFBINCHELAH2010

53

2003 Microchip Technology Inc. DS39582B-page 47

PIC16F87XA

TABLE 4-5: PORTC FUNCTIONS

TABLE 4-6: SUMMARY OF REGISTERS ASSOCIATED WITH PORTC

Name Bit# Buffer Type Function

RC0/T1OSO/T1CKI bit 0 ST Input/output port pin or Timer1 oscillator output/Timer1 clock input.

RC1/T1OSI/CCP2 bit 1 ST Input/output port pin or Timer1 oscillator input or Capture2 input/Compare2 output/PWM2 output.

RC2/CCP1 bit 2 ST Input/output port pin or Capture1 input/Compare1 output/PWM1 output.

RC3/SCK/SCL bit 3 ST RC3 can also be the synchronous serial clock for both SPI and I2C modes.

RC4/SDI/SDA bit 4 ST RC4 can also be the SPI data in (SPI mode) or data I/O (I2C mode).

RC5/SDO bit 5 ST Input/output port pin or Synchronous Serial Port data output.

RC6/TX/CK bit 6 ST Input/output port pin or USART asynchronous transmit or synchronous clock.

RC7/RX/DT bit 7 ST Input/output port pin or USART asynchronous receive or synchronous data.

Legend: ST = Schmitt Trigger input

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on: POR, BOR

Value on all other Resets

07h PORTC RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 xxxx xxxx uuuu uuuu

87h TRISC PORTC Data Direction Register 1111 1111 1111 1111

Legend: x = unknown, u = unchanged

Page 71: 741_MOHAMADASYRAFBINCHELAH2010

54

PIC16F87XA

DS39582B-page 48 2003 Microchip Technology Inc.

4.4 PORTD and TRISD Registers

PORTD is an 8-bit port with Schmitt Trigger inputbuffers. Each pin is individually configurable as an inputor output.

PORTD can be configured as an 8-bit widemicroprocessor port (Parallel Slave Port) by settingcontrol bit, PSPMODE (TRISE<4>). In this mode, theinput buffers are TTL.

FIGURE 4-8: PORTD BLOCK DIAGRAM (IN I/O PORT MODE)

TABLE 4-7: PORTD FUNCTIONS

TABLE 4-8: SUMMARY OF REGISTERS ASSOCIATED WITH PORTD

Note: PORTD and TRISD are not implementedon the 28-pin devices. Data

Bus

WRPort

WRTRIS

RD Port

Data Latch

TRIS Latch

RD

SchmittTriggerInputBuffer

I/O pin(1)

Note 1: I/O pins have protection diodes to VDD and VSS.

QD

CK

QD

CK

EN

Q D

EN

TRIS

Name Bit# Buffer Type Function

RD0/PSP0 bit 0 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 0.

RD1/PSP1 bit 1 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 1.

RD2/PSP2 bit2 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 2.

RD3/PSP3 bit 3 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 3.

RD4/PSP4 bit 4 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 4.

RD5/PSP5 bit 5 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 5.

RD6/PSP6 bit 6 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 6.

RD7/PSP7 bit 7 ST/TTL(1) Input/output port pin or Parallel Slave Port bit 7.

Legend: ST = Schmitt Trigger input, TTL = TTL input Note 1: Input buffers are Schmitt Triggers when in I/O mode and TTL buffers when in Parallel Slave Port mode.

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on:POR, BOR

Value on all other Resets

08h PORTD RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 xxxx xxxx uuuu uuuu

88h TRISD PORTD Data Direction Register 1111 1111 1111 1111

89h TRISE IBF OBF IBOV PSPMODE — PORTE Data Direction Bits 0000 -111 0000 -111

Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’. Shaded cells are not used by PORTD.

Page 72: 741_MOHAMADASYRAFBINCHELAH2010

55

B.2 LCD(refer to [12])

© Parallax, Inc. • 2X16 Parallel LCD (#603-00006) 7/2005 Version 1.3 Page 1

599 Menlo Drive, Suite 100 Rocklin, California 95765, USA Office: (916) 624-8333 Fax: (916) 624-8003

General: [email protected] Technical: [email protected] Web Site: www.parallax.com Educational: www.StampsInClass.com

2 x16 Parallel LCD (#603-00006)

General Information The 2 X16 Parallel LCD is an 8 bit or 4 bit parallel interfaced LCD. This unit allows the user to display text, numerical data and custom created characters. The LCD uses the HD44780 series LCD driver from Hitachi, or equivalent controller. The LCD is connected to a female 14-pin connector for easy interface with the BS2p24/40 Demo Board (#45187) and the Professional Development Board (#28138). Though the device has the ribbon cable and 14-pin connector it may also be hooked up manually using the diagram on the next page.

Technical Specifications Cable length: 6” (152 mm) Power requirements: 5.0 +VDC Dimensions may vary

1.4

“ (36

mm

)

3.2“ (81 mm)

2.9“ (73.5 mm)

1.0

“ (25

mm

)

1.2

2“ (3

1 m

m)

.09“ (2.3 mm)2-56 screw size

2.95“ (75 mm)

Character size .12” x .2” (3 x 5 mm)

LCD Control from a BASIC Stamp Parallax (www.parallax.com) publishes many circuits and examples to control LCDs. Most of these examples are available for download from our web site. These examples are featured in StampWorks, the Nuts and Volts of BASIC Stamps books, the free LCD Character Creator Software, and the BS2p Plus Pack. Example codes are listed below for the BASIC Stamp 1 and 2 modules.

Page 73: 741_MOHAMADASYRAFBINCHELAH2010

56

© Parallax, Inc. • 2X16 Parallel LCD (#603-00006) 7/2005 Version 1.3 Page 2

RedP2

P4

P6

P8

P10

P12

P1

P3

P5

P7

P9

P11

Red

Vss

R/W

DB0

DB2

DB4

DB6

Vdd

RS

E

DB1

DB3

DB5

DB6

Pin 1

Con.

To interface to the LCD in a 4-bit mode you will need set up the LCD in the following manner.

P2

10 kΩ pot

P0

P3

P7

P6

P5

P4

5

6

4

14

13

12

11

All10kΩ

R/W

E

RS

DB7

DB6

DB5

DB4

4.7KΩ

2 3 1 7 98 10

+5

Vss

Stamp I/O pins

BASIC Stamp 1 code ' ========================================================================= ' File...... Parallel_LCD.bs1 ' Purpose... Parallel LCD Display Demo ' Author.... Parallax, Inc. ' E-mail.... [email protected] ' $STAMP BS1 ' $PBASIC 1.0 ' -----[ Program Description ]--------------------------------------------- ' This program demonstrates using a Hitachi-compatible Parallel LCD Display ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL E = 0 ' Enable Pin. 1 = Enabled SYMBOL RS = 3 ' Register Select. 0 = Instruction SYMBOL RW = 2 ' Read / Write control. 0 = Write ' -----[ Variables ]------------------------------------------------------- SYMBOL char = B3 ' Character sent to LCD SYMBOL temp = B4 ' Temp Variable ' -----[ EEPROM Data ]----------------------------------------------------- EEPROM ("Hello, this is the LCD demo.") ' -----[ Initialization ]-------------------------------------------------- Begin: LET PINS = 0 ' Clear The Output Lines LET DIRS = %11111000 ' One Input, 7 Outputs PAUSE 200 ' Wait 200 ms For LCD To Reset

Page 74: 741_MOHAMADASYRAFBINCHELAH2010

APPENDIX C

SYSTEM DISPLAY

Figure C.1: System Display