Unmanned Petrol Bunk Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 87

1

UNMANNED PETRO L BUNK SYSTEM USING SMART CARD


TECHNOLOGY
A mini project report submitted in partial fulfillment of the requirements for the
award of the degree of
BACHEULOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION ENGINEERING
Under the esteemed guidance of
J.Nehru
BE, M.Tech ,
Asst.Prof

Presented By
A.GANESH KUMAR REDDY - 11J21A0408
G.SATHWIK REDDY - 11J21A0437




DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
JOGINPALLY B.R. ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to JNT University, Hyderabad)
2014-2015

2

COLLEGE CERTIFICATE

Date:

This is to certify that the mini project report entitled unmanned petrol bunk
system using smart card technology being submitted by A.GANESH KUMAR
REDDY(11J21A0408),G.SATHWIK REDDY(11J21A0437), during 2014-2015 in partial
fulfillment of the requirements for the award of the degree of BACHEULOR OF OF
TECHNOLOGY in ELECTRONICS & COMMUNICATION ENGINEERING is a
bonafide work carried out by her/him.

The results enclosed in this report have been verified and found correct. The results
embodied in this project report have not been submitted to any other University or Institute
for the award of any degree or diploma.






Internal Guide Head of the Department
J.Nehru M. SRINIVASA RAO
B.E.,M.Tech ,Asst.Prof B.E., M.Tech,
Department of ECE Head & Professor
Department of ECE





External Examiner



3

ORGANISATION CERTIFICATE


4

ACKNOWLEDGMENTS
I take this opportunity to remember and acknowledge the cooperation, good will and
support both moral and technical extended by several individuals out of which my project has
evolved. I shall always cherish my association with them.
I am greatly thankful to Dr. D. N. Rao, B.Tech., M.E., MBA., Ph.D, Principal of our college,
for extending his valuable help. I shall forever cherish my association with him for his
constant encouragement, perennial approachability, absolute freedom of thought and action.
I express my profound gratitude to Prof. M. Srinivasa Rao, B.E.,M.Tech.,(Ph.D), Head of
the Department of Electronics and Communication Engineering, for his constant support and
encouragement in completing my project.
I express our sincere thanks and gratitude to our project coordinators Prof.V.Sriram,
B.E.,M.Tech.,Prof A.Rajaiah B.E.,M.Tech.,(Ph.D),Sri R.Durga Gopal,B.Tech.,M.Tech.,(Ph.D) Associate
Professor Sri M.Govind B.Tech., M.Tech.,(Ph.D), Associate Professor, Department of ECE,
Joginapally B.R.Engineering college for their valuable help and encouragement throughout
the project work.
I would also like to thank Sri J.Nehru, B.Tech.,M.Tech. Assistant Professor, my internal
guide, without whose suggestions and encouragement, this project would not have been
possible.
I am also greatly thankful to all the faculty members of the department who provided
their feedback and valuable suggestions at different stages of the project and helped in the
success of the project.
With immense gratitude and pleasure I take this opportunity to thank my parents and
friends who have been a catalyst in the realization of my project.

A.GANESH KUMAR REDDY(11J21A0408)
G.SATHWIK REDDY(11J21A0437)


5

ABSTARCT
Today almost all petrol pumps have a microcontroller to control the electrical pump,
drive the display, measure the quantity and accordingly turn OFF the electrical pump. But
still a person is required to collect the money. Our project is designed to eliminate this human
interaction so that there is no need of workers to fill the petrol. In general, a smart card is an
integrated circuit card with memory capable of making decisions. A smart card, chip card or
integrated circuit card (ICC), is defined as any pocket-sized card with embedded integrated
circuits which can process information. This implies that it can receive input which is
processed by way of the ICC applications and delivered as an output. In this project, we are
using a contact smart card where the information inside the card is communicated with the
card reader by inserting card into the card reader. The card reader in this project used is an
SR-90 SDK of 1KB memory size.
The smart card reader contains a PIC 16F73 microcontroller, a voltage regulator,
serial cable connections and an LED which glows whenever a card is inserted into the reader
and also it glows whenever it issues any command or receives any command. The Smart Card
Reader is interfaced with the microcontroller through serial interface.
In this system, all drivers have a smart card called just like a petrocard. This card
can be recharged by some recharge points. The petrol pump is equipped with a smart card
reader. At the Petrol pump, the driver swaps the card and the smart card reader reads the
amount in the card and will display it on the LCD. The driver then enters the quantity of
petrol that has to be filled using a keypad. The corresponding amount is calculated and
deducted from his petrocard. The electrical pump is then turned ON according to the entered
amount, fills the tank and automatically turns OFF.


6

CONTENTS
Chapter 1 Introduction
1.1 Introduction
1.2 Literature Survey
Chapter 2 General Theory
2.1 Microcontroller
Chapter 3 Hardware
3.1 Main Block Diagram
3.2 Over view of Block Diagram
3.3 Individual Block Description
3.4 Schematic Diagram
Chapter 4 Software Description
4.1 About Software
4.2 Code/Program
Chapter 5 Result Analysis
5.1 Specifications
5.2 Screen Shots










7

LIST OF FIGURES
Fig 1.1.1 Layered Architecture of an Embedded System
Fig 1.1.2 Building Blocks of an Embedded System
Fig 2.1.1 Block Diagram of AT89C51
Fig 2.1.2 Lower part of Program Memory
Fig 2.1.3 Pin Configuration
Fig 2.1.4 Oscillator connection
Fig 2.1.5 TMOD Register
Fig 2.1.6 TCON Register
Fig 2.1.7 SBUF Register
Fig 2.1.8 SCON Register
Fig 3.1 Main Block Diagram
Fig 3.3.1 Components of Regulated Power Supply
Fig 3.3.2 Smart Card Content Chip
Fig 3.3.3 Smart Card Reader
Fig 3.3.4 Types of Chip Cards
Fig 3.3.5 8 Pin Smart Card Bus Point
Fig 3.3.6 Circuit For Motor Driver
Fig 3.3.7 Interfacing motor with 8051
Fig 3.3.8 Buzzer Circuit
Fig 3.3.9 Interfacing Buzzer to 8051
Fig 3.3.10 Types of Keypads
Fig 3.3.11 Matrix Keypad Connection to Ports
Fig 3.3.12 Lcd Display
8

Fig 3.3.13 Lcd screen
Fig 3.3.14 Procedure on 8-Bit Initialization
Fig 3.3.15 Variable resistor
Fig 3.3.16 Potentiometer symbol
Fig 3.3.17 Perset Symbol
Fig 3.3.18 Lcd Interfacing With 8051
Fig 3.4 Schematic Diagram
Fig 4.1 Keil Development Tools

9

LIST OF TABLES
Table 2.1.1 8051 Interrupt Priority Table
Table 2.1.2 Baud Rate in 8051
Table 2.1.3 SCON Register Functionality
Table 2.1.4 Serial Mode Type
Table 3.3.1 Smart Card Types
Table 3.3.2 Pin Functions
Table 3.3.3
Table 3.3.4 List of Commands
Table 4.1 Data Types

10

CHAPTER 1
INTRODUCTION
1.1 INTRODUCTION:
An embedded system can be defined as a computing device that does a specific
focused job. Appliances such as the air-conditioner, VCD player, DVD player, printer, fax
machine, mobile phone etc. are examples of embedded systems. Each of these appliances will
have a processor and special hardware to meet the specific requirement of the application
along with the embedded software that is executed by the processor for meeting that specific
requirement. The embedded software is also called firm ware. The desktop/laptop
computer is a general purpose computer. You can use it for a variety of applications such as
playing games,word processing, accounting, software development and so on. In contrast,
the software in the embedded systems is always fixed listed below:
Embedded systems do a very specific task that they cannot be programmed to do
different things. Embedded systems have very limited resources, particularly the memory.
Generally, they do not have secondary storage devices such as the CDROM or the floppy
disk. Embedded systems have to work against some deadlines. A specific job has to be
completed within a specific time. In some embedded systems, called real-time systems, the
deadlines are stringent. Missing a deadline may cause a catastrophe-loss of life or damage to
property. Embedded systems are constrained for power. As many embedded systems operate
through a battery, the power consumption has to be very low.
Some embedded systems have to operate in extreme environmental conditions such as
very high temperatures and humidity.
Application Areas
Nearly 99 per cent of the processors manufactured end up in embedded systems. The
embedded system market is one of the highest growth areas as these systems are used in very
market segment- consumer electronics, office automation, industrial automation, biomedical
engineering, wireless communication, data communication, telecommunications,
transportation, military and so on.
Consumer appliances: At home we use a number of embedded systems which include
digital camera, digital diary, DVD player, electronic toys, microwave oven, remote controls
11

for TV andair-conditioner, VCO player, video game consoles, video recorders etc. Todays
high-tech car has about 20 embedded systems for transmission control, engine spark control,
air-conditioning, navigation etc. Even wristwatches are nowbecoming embedded systems.
The palmtops are powerful embedded systems using which we can carry out many general-
purpose tasks such as playing games and word processing.
Office automation: The office automation products using embedded systems are copying
machine, fax machine, key telephone, modem, printer, scanner etc.
Industrial automation: Today a lot of industries use embedded systems for process control.
These include pharmaceutical, cement, sugar, oil exploration, nuclear energy, electricity
generation and transmission. The embedded systems for industrial use are designed to carry
out specific tasks such as monitoring the temperature, pressure, humidity, voltage, current
etc., and then take appropriate action based on the monitored levels to control other devices
or to send information to a centralized monitoring station. In hazardous industrial
environment, where human presence has to be avoided, robots are used, which are
programmed to do specific jobs. The robots are now becoming very powerful and carry out
many interesting and complicated tasks such as hardware assembly.
Medical electronics: Almost all medical equipments in the hospital are embedded systems.
These equipments include diagnostic aids such as ECG, EEG, blood pressure measuring
devices, X-ray scanners, equipment used in blood analysis, radiation, colonoscopy,
endoscopy etc. Developments in medical electronics have paved way for more accurate
diagnosis of diseases.
Computer networking: Computer networking products such as bridges, routers, Integrated
Services Digital Networks (ISDN), Asynchronous Transfer Mode (ATM), X.25 and frame
relay switches are embedded systems which implement the necessary data communication
protocols. For example, a router interconnects two networks. The two networks may be
running different protocol stacks. The routers function is to obtain the data packets from
incoming pores, analyze the packets and send them towards the destination after doing
necessary protocol conversion. Most networking equipments, other than the end systems
(desktop computers) we use to access the networks, are embedded systems.
Telecommunications: In the field of telecommunications, the embedded systems can be
categorized as subscriber terminals and network equipment. The subscriber terminals such as
12

key telephones, ISDN phones, terminal adapters, web cameras are embedded systems. The
network equipment includes multiplexers, multiple access systems, Packet Assemblers
Dissemblers (PADs), sate11ite modems etc. IP phone, IP gateway, IP gatekeeper etc. are the
latest embedded systems that provide very low-cost voice communication over the Internet.
Wireless technologies: Advances in mobile communications are paving way for many
interesting applications using embedded systems. The mobile phone is one of the marvels of
the last decade of the 20th century. It is a very powerful embedded system that provides voice
communication while we are on the move. The Personal Digital Assistants and the palmtops
can now be used to access multimedia services over the Internet. Mobile communication
infrastructure such as base station controllers, mobile switching centers are also powerful
embedded systems.
Insemination: Testing and measurement are the fundamental requirements in all scientific
and engineering activities. The measuring equipment we use in laboratories to measure
parameters such as weight, temperature, pressure, humidity, voltage, current etc. are all
embedded systems. Test equipment such as oscilloscope, spectrum analyzer, logic analyzer,
protocol analyzer, radio communication test set etc. are embedded systems built around
powerful processors. Thank to miniaturization, the test and measuring equipment are now
becoming portable facilitating easy testing and measurement in the field by field-personnel.
Security: Security of persons and information has always been a major issue. We need to
protect our homes and offices; and also the information we transmit and store. Developing
embedded systems for security applications is one of the most lucrative businesses nowadays.
Security devices at homes, offices, airports etc. for authentication and verification are
embedded systems. Encryption devices are nearly 99 per cent of the processors that are
manufactured end up in~ embedded systems. Embedded systems find applications in every
industrial segment- consumer electronics, transportation, avionics, biomedical engineering,
manufacturing, process control and industrial automation, data communication,
telecommunication, defense, security etc. They are used to encrypt the data/voice being
transmitted on communication links such as telephone lines.Biometric systems using
fingerprint and face recognition are now being extensively used for user authentication in
banking applications as well as for access control in high security buildings.
Finance: Financial dealing through cash and cheques are now slowly paving way for
transactions using smart cards and ATM (Automatic Teller Machine, also expanded as Any
13

Time Money) machines. Smart card, of the size of a credit card, has a small micro-controller
and memory; and it interacts with the smart card reader! ATM machine and acts as an
electronic wallet. Smart card technology has the capability of ushering in a cashless society.
Well, the list goes on. It is no exaggeration to say that eyes wherever you go, you can see, or
at least feel, the work of an embedded system!
Overview of Embedded System Architecture
Every embedded system consists of custom-built hardware built around a Central
Processing Unit (CPU). This hardware also contains memory chips onto which the software
is loaded. The software residing on the memory chip is also called the firmware. The
embedded system architecture can be represented as a layered architecture as shown in Fig.
Fig 1.1.1 layered architecture of an Embedded system
The operating system runs above the hardware, and the application software runs
above the operating system. The same architecture is applicable to any computer including a
desktop computer. However, there are significant differences. It is not compulsory to have an
operating system in every embedded system. For small appliances such as remote control
units, airconditioners, toys etc., there is no need foran operating system and you can write
only the software specific to that application.
For applications involving complex processing, it is advisable to have an operating
system. In such a case, you need to integrate the application software with the operating
system and then transfer the entire software on to the memory chip. Once the software is
transferred to the memory chip, the software will continue to run for a long time you dont
need to reload new software.
14

Now, let us see the details of the various building blocks of the hardware of an embedded
system. As shown in Fig. the building blocks are;
Central Processing Unit (CPU)
Memory (Read-only Memory and Random Access Memory)
Input Devices
Output devices
Communication interfaces
Application-specific circuitry
Fig 1.1.2 Building Blocks of an Embedded systems
Central Processing Unit (CPU):
The Central Processing Unit (processor, in short) can be any of the following:
microcontroller, microprocessor or Digital Signal Processor (DSP). A micro-controller is a
low-cost processor. Its main attraction is that on the chip itself, there will be many other
components such as memory, serial communication interface, analog-to digital converter etc.
So, for small applications, a micro-controller is the best choice as the number of external
components required will be very less. On the other hand, microprocessors are more
powerful, but you need to use many external components with them. D5P is used mainly for
applications in which signal processing is involved such as audio and video processing.
Memory:
The memory is categorized as Random Access Memory (RAM) and Read Only
Memory (ROM). The contents of the RAM will be erased if power is switched off to the
chip, whereas ROM retains the contents even if the power is switched off. So, the firmware is
15

stored in the ROM. When power is switched on, the processor reads the ROM; the program is
program is executed.
Input devices:
Unlike the desktops, the input devices to an embedded system have very limited
capability. There will be no keyboard or a mouse, and hence interacting with the embedded
system is no easy task. Many embedded systems will have a small keypad-you press one key
to give a specific command. A keypad may be used to input only the digits. Many embedded
systems used in process control do not have any input device foruser interaction; they take
inputs from sensors or transducers and produce electrical signals that are in turn fed to other
systems.
Output devices:
The output devices of the embedded systems also have very limited capability. Some
embedded systems will have a fewLight Emitting Diodes (LEDs) to indicate the health status
of the system modules, or forvisual indication of alarms. A small Liquid Crystal Display
(LCD) may also be used to display someimportant parameters.
Communication interfaces:
The embedded systems may need to, interact with other embedded systems at they
may have to transmit data to a desktop. To facilitate this, the embedded systems are provided
with one or a few communication interfaces such as RS232, RS422, RS485, Universal Serial
Bus (USB), IEEE 1394, Ethernet etc.
Application-specific circuitry:
Sensors, transducers, special processing and control circuitry may be required fat an
embedded system, depending on its application. This circuitry interacts with the processor to
carry out the necessary work. The entire hardware has to be given power supply either
through the 230 volts main supply or through a battery. The hardware has to design in such a
way that the power consumption is minimized.


16

1.2 LITERATURE SURVEY:
Software Tools:
1. Keil compiler
2. Orcad
3. Proload
Hardware Tools:
1. Microcontroller AT89S52.
2. 24c04 as a smart card.
3. LCD
4. Buzzer and driver circuit
5. AC motor and driver circuit
6. Keypad
















17


CHAPTER 2
GENERAL THEORY
2.1 MICROCONTROLLER:
INTRODUCTION:
A Micro controller consists of a powerful CPU tightly coupled with memory RAM,
ROM or EPROM), various I / O features such as Serial ports, Parallel Ports, Timer/Counters,
Interrupt Controller, Data Acquisition interfaces-Analog to Digital Converter (ADC), Digital
to Analog Converter (ADC), everything integrated onto a single Silicon Chip.
It does not mean that any micro controller should have all the above said features on
chip, Depending on the need and area of application for which it is designed, The ON-CHIP
features present in it may or may not include all the individual section said above.
Any microcomputer system requires memory to store a sequence of instructions
making up a program, parallel port or serial port for communicating with an external system,
timer / counter for control purposes like generating time delays, Baud rate for the serial port,
apart from the controlling unit called the Central Processing Unit.
INTRODUCTION TO 8051 MICROCONTROLLER
In 1981,Intel corporation introduced an 8 bit microcontroller called the 8051.This
microcontroller had 128 bytes of RAM,4K bytes of on-chip ROM, two timers, one serial port
and 4 ports(each 8-bits wide)all on single chip. At that time it was also referred to as a
system on a chip.
INTRODUCTION TO ATMEL MICROCONTROLLER
The major Features of 8-bit Micro controller ATMEL 89C51:
8 Bit CPU optimized for control applications
Extensive Boolean processing (Single - bit Logic) Capabilities.
On - Chip Flash Program Memory
On - Chip Data RAM
Bi-directional and Individually Addressable I/O Lines
18

Multiple 16-Bit Timer/Counters
Full Duplex UART
Multiple Source / Vector / Priority Interrupt Structure
On - Chip Oscillator and Clock circuitry.
On - Chip EEPROM
One Serial communication port

Block Diagram:













Fig 2.1.1 Block Diagram of AT89C51
COUNTER
INPUTS

INTERRUPT
CONTROL



ON-CHIP
FLASH
ON-CHIP
RAM

RAM
ON-CHIP
RAM
TIMER 1
TIMER 0
CPU
OSCILLATOR BUS
CONTROL
4 I/O
PORTS
SERIAL
PORT
PO P2 P1 P3
TXD RXD
ON-CHIP
FLASH
EXTERNAL
INTERRUPTS
19

The P89C51 provides the following standard features: 4K bytes of Flash, 128 bytes
of RAM, 32 I/O lines, two 16-bit timer/counters, five vector two-level interrupt architecture,
a full duplex serial port, and on-chip oscillator and clock circuitry. In addition, the P89C51 is
designed with static logic for operation down to zero frequency and supports two software
selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM,
timer/counters, serial port and interrupt system to continue functioning. The Power-down
Mode saves the RAM contents but freezes the oscillator disabling all other chip functions
until the next hardware reset.
Memory Organization
Program Memory:
Below Fig shows a map of the lower part of the program memory. After reset, the
CPU begins execution from location 0000H. As shown in fig.4, each interrupt is assigned a
fixed location in program memory. The interrupt causes the CPU to jump to that location,
where it executes the service routine. External Interrupt 0, for example, is assigned to
location 0003H. If External Interrupt 0 is used, its service routine must begin at location
0003H. If the interrupt is not used, its service location is available as general purpose.

Fig 2.1.2 Lower Part of Program Memory
0033H
002BH
0023H
001BH
0013H
000BH
0003H
0000H

8 bytes
INTERRUPT
LOCATIONS
RESET
20

Program Memory:
Program memory addresses are always 16 bits wide, even though the actual amount o
program memory used may be less than 64Kbytes. External program execution sacrifices two
of the 8-bit ports, P0 and P2, to the function of addressing the program memory.

Data Memory:
The right half of Figure 3 shows the internal and external data memory spaces
available on Philips Flash microcontrollers. Fig.6 shows a hardware configuration for
accessing up to 2K bytes of external RAM. In this case, the CPU executes from internal flash.
Port0 serves as a multiplexed address/data bus to the RAM, and 3 lines of Port 2 are used to
page the RAM. The CPU generates RD and WR signals as needed during external RAM
accesses. You can assign up to 64K bytes of external data memory. External data memory
addresses can be either 1 or 2bytes wide.
Internal data memory addresses are always 1 byte wide, which implies an address
space of only 256bytes. However, the addressing modes for internal RAM can infact
accommodate 384 bytes. Direct addresses higher than 7FH access one memory space and
indirect addresses higher than 7FH access a different memory space. Thus, Figure.7 shows
the Upper 128 and SFR space occupying the same block of addresses, 80H through FFH,
although they are physically separate entities. The lowest 32 bytes are grouped into 4 banks
of 8 registers. Program instructions call out these registers as R0 through R7.
The next 16 bytes above the register banks form a block of bit-addressable memory
space. The microcontroller instruction set includes a wide selection of single-bit instructions,
and these instructions can directly address the 128 bits in this area. These bit addresses are
00H through 7FH. All of the bytes in the Lower 128 can be accessed by either direct or
indirect addressing.
REGISTERS:
In the CPU, registers are used to store information temporarily. That information
could be a byte of data to be processed, or an address pointing to the data to be fetched. The
vast majority of 8051 registers are 8bit registers. In the 8051 there is only one data type:
21

8bits. The 8bits of aregister are should in the diagram from the MSB (most significant bit)
D7 to the LSB (least significant bit) D0. With an 8-bit data type, any data larger than 8bits
must be broken into 8-bit chunks before it is processed.

The most widely used registers of the 8051 are A(Accumulator), B, R0, R1, R2, R3,
R4, R5, R6, R7, DPTR(Data Pointer), and PC(Program Counter). All of the above registers
are 8-bits, except DPTR and the program counter. The Accumulator, register A, is used for
all arithmetic and logic instructions.
SFRs (Special Function Registers):
Among the registers R0-R7 are part of the 128 bytes of RAM memory. Whatabout
registers A,B, PSW, and DPTR? Do they also have addresses? The answer is yes. In the
8051, registers A, B, PSW and DPTR are part of the group of registers commonly referred to
as SFR (special function registers). There are many special function registers and they are
widely used. The SFR can be accessed by the names (which is much easier) or by their
addresses. For example, register A has address E0h, and register B has been ignited the
address F0H.
PIN CONFIGURATION

fig 2.1.3 Pin configuration1
D7 D6 D5 D4 D3 D2 D1 D0

22

Pin Description:
VCC: Pin 40 provides supply voltage to the chip. The voltage source is +5v.
GND: Pin 20 is the ground.
Ports 0, 1, 2 and 3:
As shown in pin diagram, the four ports P0, P1, P2, and P3 each use of 8 pins, making
the 8-bit ports. All the ports upon Reset are configured as input, since P0-P3 have FFH on
them.
Port 0:
Port 0 occupies a total of 8 pins (pins 32-33). It can be used for input or output. Port0
is also designated as AD0-AD7, allowing it to be used for both address and data. When
connecting an 8051/31 to an external memory, port 0 provides both address and data. The
8051 multiplexes address and data through port 0 to save pins. ALE=0, it provides data D0-
D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for demultiplexing
address and data with the help of a 74LS373 latch. In the 8051-based systems where there is
no external memory connection, the pins of P0 must be connected externally to a 10k ohm
pull-up resistor.
This is due to the fact that P0 is an Open drain, Unlike P1, P2, P3. Open drain is a
term used for MOS chips in the same way that open collector is used for TTL chips. In many
systems using the 8751, 89C51, or DS89C4x0 chips, we normally connect P0 to pull-up
resistors. With external pull-up resistors connected to P0, it can be used as a simple I/O port,
just like P1 and P2. In contrast to Port 0, ports p1, p2, and p3 do not need any pull-up
resistors since they already have pull-up resistors internally. Upon reset, ports p1, p2, and p3
are configured as input ports.
Port 1:
Port 1 occupies a total of 8-pins (pins1-8). It can be used as input or output. In
contrast to port 0, this port does not need any pull-up resistors since it already has pull-up
resistors internally. Upon reset, port1 is configured as an input port.
Port 2:
23

Port 2 occupies a total 8 pins (pins 21-28). It can be used as input or output. However,
in 8031-based systems, port2 is also designated as A8-A15, indicating its dual function.
Since an 8051/31 is capable of accessing 64K bytes of external memory, it needs a path for
the 16 bits of the address. While P0 provides the lower 8 bits via A0-A7, it is the job of p2 is
used for the upper 8 bits of the 16-bit address, and it cannot be used for I/O. Just like P1, port
2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon
reset, port2 is configured as an input port.
Port 3:
Port 3 occupies a total of 8 pins (pins 10-17). It can be used as input or output. P3
does not need any pull-up resistors, just as P1 and P2 did not. Although Port 3 is configured
as an input port upon reset, this is not the way it is most commonly used. Port 3 has the
additional function of providing some extremely important signals such as interrupts. The
below table provides these alternate functions of P3. This is information applies to both 8051
and 8031 chips.
Alternate Functions of PORT3:
Port 3 also receives some control signals for Flash programming and verification.
RST:
Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device.
ALE/PROG:
Prior to each reading from external memory, the microcontroller will set the lower
address byte (A0-A7) on P0 and immediately after that activates the output ALE. Upon
receiving signal from the ALE pin, the external register (74HCT373 or 74HCT375 circuit is
usually embedded) memorizes the state of P0 and uses it as an address for memory chip. In
the second part of the microcontrollers machine cycle, a signal on this pin stops being
emitted and P0 is used now for data transmission (Data Bus). In this way, by means of only
one additional (and cheap) integrated circuit, data multiplexing from the port is performed.
This port at the same time used for data and address transmission.
PSEN:
24

Program Store Enable is the read strobe to external program memory. When the
AT89C51 is executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to external
data memory.
EA/VPP:
External Access Enable. EA must be strapped to GND in order to enable the device to
fetch code from external program memory locations starting at 0000H up to FFFFH. Note,
however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should
be strapped to VCC for internal program executions. This pin also receives the 12-volt
programming enable voltage (VPP) during Flash programming, for parts that require 12-volt
VPP.
XTAL1 and XTAL2:
The 8051 has an on-chip oscillator but requires an external clock to run it. Most often
a quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18). The
quartz crystal oscillator connected to XTAL1 and XTAL2 also needs two capacitors of 30pf
value. One side of each capacitor is connected to the ground as shown below.

Fig 2.1.4Oscillator Connection
It must be noted that there are various speeds of the 8051 family. Speed refers to the
maximum oscillator frequency connected to XTAL. For example, a 12-MHz chip must be
connected to a crystal with 12 MHz frequency of no more than 20MHz. When the 8051 is
connected to a crystal oscillator and is powered up, we can observe the frequency on the
XTAL2 pin using the oscilloscope.
25

TIMERS:
On-chip timing/counting facility has proved the capabilities of the microcontroller for
implementing the real time application. These includes pulse counting, frequency
measurement, pulse width measurement, baud rate generation, etc,. Having sufficient number
of timer/counters may be a need in a certain design application. The 8051 has two
timers/counters. They can be used either as timers to generate a time delay or as counters to
count events happening outside the microcontroller. Let discuss how these timers are used to
generate time delays and we will also discuss how they are been used as event counters.
BASIC RIGISTERS OF THE TIMER:
Both Timer 0 and Timer 1 are 16 bits wide. Since the 8051 has an 8-bit architecture,
each 16-bit timer is accessed as two separate registers of low byte and high byte.
TIMER 0 REGISTERS:
The 16-bit register of Timer 0 is accessed as low byte and high byte. the low byte
register is called TL0(Timer 0 low byte)and the high byte register is referred to as TH0(Timer
0 high byte).These register can be accessed like any other register, such as
A,B,R0,R1,R2,etc.for example, the instruction MOV TL0, #4Fmoves the value 4FH into
TL0,the low byte of Timer 0.These registers can also be read like any other register.
TIMER 1 REGISTERS:
Timer 1 is also 16-bit register is split into two bytes, referred to as TL1 (Timer 1 low
byte) and TH1(Timer 1 high byte).these registers are accessible n the same way as the
register of Timer 0.
TMOD (Timer Mode) REGISTER:
Both timers 0 and 1 use the same register, called TMOD, to set the various timer
operation modes. TMOD is an 8-bit register in which the lower 4 bits are set aside for Timer
0 and the upper 4 bits for Timer 1.in each case; the lower 2 bits are used to set the timer mode
and the upper 2 bits to specify the operation.
26


Fig 2.1.5TMOD Register
TCON Register:
TCON controls the timer/counter operations. The lower four bits of TCON cater to
interrupt functions, but the upper four bits are for timer operations. The details of the TCON
register are as shown.
Fig 2.1.6 TCON Register
INTERRUPTS:
A single microcontroller can serve several devices. There are two ways to do that:
INTERRUPTS or POLLING.

POLLING:
In polling the microcontroller continuously monitors the status of a given device;
when the status condition is met, it performs the service .After that, it moves on to monitor
the next device until each one is serviced. Although polling can monitor the status of several
devices and serve each of them as certain condition are met.
INTERRUPTS:
In the interrupts method, whenever any device needs its service, the device notifies
the microcontroller by sending it an interrupts signal. Upon receiving an interrupt signal, the
microcontroller interrupts whatever it is doing and serves the device. The program associated
with the interrupts is called the interrupt service routine (ISR).or interrupt handler.
27

Various Interrupts in the 8051:
In reality, only five interrupts are available to the user in the 8051, but many
manufacturers data sheets state that there are six interrupts since they include reset .the six
interrupts in the 8051 are allocated as above.
1. Reset. When the reset pin is activated, the 8051 jumps to address location 0000.this is
the power-up reset.
2. Two interrupts are set aside for the timers: one for Timer 0 and one for Timer
1.Memory location 000BH and 001BH in the interrupt vector table belong to Timer 0
and Timer 1, respectively.
3. Two interrupts are set aside for hardware external harder interrupts. Pin number
12(P3.2) and 13(P3.3) in port 3 are for the external hardware interrupts INT0 and
INT1,respectively.These external interrupts are also referred to as EX1 and
EX2.Memory location 0003H and 0013H in the interrupt vector table are assigned to
INT0 and INT1, respectively.
4. Serial communication has a single interrupt that belongs to both receive and transmit.
The interrupt vector table location 0023H belongs to this interrupt.

8051/52 Interrupt Priority upon Reset
External Interrupt 0 INT0
Timer Interrupt 0 TF0
External Interrupt 1 INT1
Timer Interrupt 1 TF1
Serial Communication RI+TI
Timer 2(8052 only) TF2
NOTE:Highest to Lowest Priority
Table 2.1.1 8051 Interrupt Priority table



28

SERIAL COMMUNICATION:
Computers can transfer data in two ways: parallel and serial. In parallel data
transfers, often 8 or more lines (wire conductors) are used to transfer data to a device that is
only a few feet away. An example of parallel transfers a printers and hard disks; each uses
cables with many wire strips. Although in such cases a lot of data can be transferred in a
short amount of time by using many wires in parallel, the distance cannot be great.
To transfer to a device located many meters away, the serial method is used. In serial
communication, the data is sent one bit at a time, in contrast to parallel communication, in
which the data is sent a byte or more at a time. Serial communication of the 8051 is the topic
of this chapter. The 8051 has serial communication capability built into it, thereby making
possible fast data transfer using only a few wires.
If data is to be transferred on the telephone line, it must be converted from 0s and 1s to
audio tones, which are sinusoidal-shaped signals. This conversion is performed by a
peripheral device called a modem, which stands for modulator/demodulator.Serial data
communication uses two methods, asynchronous and synchronous. The synchronous method
transfers a block of data at a time, while the asynchronous method transfers a single byte at a
time.
In data transmission if the data can be transmitted and received, it is a duplex
transmission. This is in contrast to simplex transmissions such as with printers, in which the
computer only sends data. Duplex transmissions can be half or full duplex, depending on
whether or not the data transfer can be simultaneous.
Asynchronous serial communication and data framing:
The data coming in at the receiving end of the data line in a serial data transfer is all 0s
and 1s; it is difficult to make sense of the data unless the sender and receiver agree on a set of
rules, a protocol, on how the data is packed, how many bits constitute a character, and when
the data begins and ends.
Start and stop bits:
Asynchronous serial data communication is widely used for character-oriented
transmissions, while block-oriented data transfers use the synchronous method. In the
asynchronous method, each character is placed between start and stop bits. This is called
29

framing. In the data framing for asynchronous communications, the data, such as ASCII
characters, are packed between a start bit and a stop bit. The start bit is always one bit, but the
stop bit can be one or two bits. The start bit is always a 0 (low) and the stop bit (s) is 1
(high).
Data transfer rate:
The rate of data transfer in serial data communication is stated in bps (bits per second).
Another widely used terminology for bps is baud rate. The data transfer rate of given
computer system depends on communication ports incorporated into that system. For
example, the early IBMPC/XT could transfer data at the rate of 100 to 9600 bps. In recent
years, however, Pentium based PCS transfer data at rates as high as 56K bps. It must be
noted that in asynchronous serial data communication, the baud rate is generally limited to
100,000bps.
Baud rate in the 8051:
The 8051 transfers and receives data serially at many different baud rates. The baud
rate in the 8051 is programmable. It is done with the help of Timer1. The 8051 divides the
crystal frequency by 12 to get the machine cycle frequency. In the case of
XTAL=11.0592MHZ, the machine cycle frequency is 921.6 KHz
(11.0592MHz/12=921.6KHz). The 8051s serial communication UART circuitry divides the
machine cycle frequency of 921.6KHZ divided by 32 once more before it is used by Timer 1
to set the Baud rate. Therefore, 921.6 KHz divided by 32 gives 28,800 Hz. This is the
number well use to find the Timer 1 value to set baud rate.
Baud Rate TH1(Decimal) TH1(Hex)
9600 -3 FD
4800 -6 FA
2400 -12 F4
1200 -24 E8
NOTE: XTAL=11.0592MHz
Table 2.1.2 Baud Rate in 8051


30

SBUF register:
SBUF is an 8-bit register used solely for serial communication in the 8051. for a byte
of data to be transferred via the TXD line, it must be placed in the SBUF register. Similarly,
SBUF holds the byte of data when it is received by the 8051s RXD line. SBUF can be
accessed like any other register in the 8051. Look at the following the examples of how this
register is accessed.
MOV SBUF, #D ; load SBUF=44h, ASCII for D
MOV SBUF, A ; copy accumulator into SBUF
MOV A, SBUF ; copy SBUF into accumulator
The moment a byte is written into SBUF, it is framed with the start and stop bits and
transferred serially via the TXD pin. Similarly, when the bits are received serially via RXD,
the 8051 defames it by eliminating the stop and start bits, making a byte out of the data
received, and then placing it in the SBUF.

Fig 2.1.7 SBUF Register
SCON (serial control) register:
The SCON register is an 8-bit register used to program the start bit, stop bit, and data
bits of data framing, among other things.The following describes various bits of the SCON
register.

Fig 2.1.8 SCON Register
BIT NAME BIT NUMBER FUNCTION
SM0 SCON.7 Serial port mode specifier
31

SM1 SCON.6 Serial port mode specifier
SM2 SCON.5 Used for multiprocessor
communication. (Make it 0.)
REN SCON.4 Set/cleared by software to
enable/disable reception
TB8 SCON.3 Not widely used
RB8 SCON.2 Not widely used
TI SCON.1 Transmit interrupt flag. Set
by hardware at the beginning
of the stop bit in mode 1.
Must be cleared by software.
RI SCON.0 Receive interrupt flag. Set by
hardware halfway through the
stop bit time mode 1. Must
be cleared by software.
Note: Make SM2, TB8, and RB8=0.
Table 2.1.3 SCON Register Functionality
SM0, SM1:
SM0 and SM1 are D7 and D6 of the SCON register, respectively. These two bits
determine the framing of data by specifying the number of bits per character and the start and
stop bits. They take the following combinations.
SMO SM1 FUNCTION
0 0 Serial Mode-0
0 1 Serial Mode-1
1 0 Serial Mode-2
1 1 Serial Mode-3
Table 2.1.4 Serial Mode Type
Of the 4 serial modes, only mode 1(8-bit data, 1-start bit, 1-stop bit) is of interest to us.
In the SCON register, when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit, and
1 start bit, which makes it compatible with the COM port of IBM/compatible PCs. More
importantly, serial mode 1 allows the baud rate to be variable and is set by Timer 1 of the
32

8051. In serial mode 1, for each character a total of 10 bits are transferred, where the first bit
is the start bit, followed by 8 bits of data, and finally 1 stop bit.





















33


CHAPTER 3
HARDWARE DESCRIPTION
3.1 MAIN BLOCK DIAGRAM:

Fig 3.1 Main Block Diagram








34

3.2 OVERVIEW OF BLOCK DIAGRAM:




























35

3.3 INDIVIDUAL BLOCK DESCRIPTION:
POWER SUPPLY
The input to the circuit is applied from the regulated power supply. The a.c. input
i.e., 230V from the mains supply is step down by the transformer to 12V and is fed to a
rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order to
get a pure d.c voltage, the output voltage from the rectifier is fed to a filter to remove
any a.c components present even after rectification. Now, this voltage is given to a
voltage regulator to obtain a pure constant dc voltage.

Fig 3.3.1 Components Of Regulated Power Supply
Transformer:
Usually, DC voltages are required to operate various electronic equipment and these
voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c
input available at the mains supply i.e., 230V is to be brought down to the required voltage
level. This is done by a transformer. Thus, a step down transformer is employed to decrease
the voltage to a required level.

Rectifier:
36

The output from the transformer is fed to the rectifier. It converts A.C. into pulsating
D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier
is used because of its merits like good stability and full wave rectification.
Filter:
Capacitive filter is used in this project. It removes the ripples from the output of
rectifier and smoothens the D.C. Output received from this filter is constant until the mains
voltage and load is maintained constant. However, if either of the two is varied, D.C. voltage
received at this point changes. Therefore a regulator is applied at the output stage.

Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage regulator is an
electrical regulator designed to automatically maintain a constant voltage level. In this
project, power supply of 5V and 12V are required. In order to obtain these voltage levels,
7805 and 7812 voltage regulators are to be used. The first number 78 represents positive
supply and the numbers 05, 12 represent the required output voltage levels.

SMART CARD TECHNOLOGY:
A Smart Card is a plastic card the size of a credit card with an integrated circuit built
into it. This integrated circuit may consist only of EEPROM in the case of a memory card, or
it may also contain ROM, RAM and even a CPU.
A smart card, a type of chip card is a plastic card embedded with a computer chip that
stores and transacts data between users. This data is associated with either value or
information or both and is stored and processed within the card's chip, either a memory or
microprocessor. The card data is transacted via a reader that is part of a computing system.
Smart card-enhanced systems are in use today throughout several key applications, including
healthcare, banking, entertainment and transportation. To various degrees, all applications
can benefit from the added features and security that smart cards provide.
Smart cards are portable data cards that must communicate with another device to gain
access to a display device or a network. Cards can be plugged into a reader, commonly
referred to as a card terminal, or they can operate using radio frequencies (RF).
37

When the smart card and the card reader come into contact, each identifies itself to the
other by sending and receiving information. If the messages exchanged do not match, no
further processing takes place. So, unlike ordinary bank cards, smart cards can defend
themselves against unauthorized users and uses in innovative security measures.


Fig 3.3.2 Smart Card Contact Chip
The history of Smart cards
The proliferation of plastic cards started in the USA in the early 1950s. The low price
of the synthetic material PVC made it possible to produce robust, durable plastic cards that
were much more suitable for everyday use than the paper and cardboard cards previously
used, which could not adequately withstand mechanical stresses and climatic effects. The first
all-plastic payment card for general use was issued by the Diners Club in 1950. It was
intended for an exclusive class of individual, and thus also served as a status symbol,
allowing the holder to pay with his or her good name instead of cash. Initially, only the
more select restaurants and hotels accepted these cards, so this type of card came to be known
as a travel and entertainment card.

The entry of Visa and MasterCard into the field led to a very rapid proliferation of
plastic money in the form of credit cards. A cardholder is never at a loss for means of
payment, yet he or she avoids exposure to the risk of loss due to theft or other unpredictable
hazards, particularly while traveling. Using a credit card also eliminates the tedious task of
exchanging currency when traveling abroad. These unique advantages helped credit cards
become rapidly established throughout the world.

38

At first, the functions of these cards were quite simple. They served as data storage
media that were secure against forgery and tampering. General information, such as the card
issuers name, was printed on the surface, while personal data elements, such as the
cardholders name and the card number, were embossed.

Increasing handling costs for merchants and banks made a machine-readable card
necessary, while at the same time, losses suffered by card issuers as the result of customer
insolvency and fraud grew from year to year.

The first improvement consisted of a magnetic stripe on the back of the card, which
allowed digital data to be stored on the card in machine-readable form as a supplement to the
visual information. This made it possible to minimize the use of paper receipts, which were
previously essential, although the customers signature on a paper receipt was still required in
traditional credit card applications as a form of personal identification. However, magnetic-
stripe technology has a crucial weakness, which is that the data stored on the stripe can be
read, deleted and rewritten at will by anyone with access to the necessary equipment. It is
thus unsuitable for storing confidential data. Additional techniques must be used to ensure
confidentiality of the data and prevent manipulation of the data.

The development of the smart card, combined with the expansion of electronic data
processing systems, has created completely new possibilities for devising such solutions.
Enormous progress in microelectronics in the 1970s made it possible to integrate data storage
and processing logic on a single silicon chip measuring a few square millimeters.

The great breakthrough was achieved in 1984, when the French PTT (postal and
telecommunications services agency) successfully carried out a field trial with telephone
cards. In this field trial, smart cards immediately proved to meet all expectations with regard
to high reliability and protection against manipulation.

39

The smart card proved to be an ideal medium. It made a high level of security (based on
cryptography) available to everyone, since it could safely store secret keys and execute
cryptographic algorithms. In addition, smart cards are so small and easy to handle that they
can be carried and used everywhere by everybody in everyday life. It was a natural idea to
attempt to use these new security features for bank cards, in order to come to grips with the
security risks arising from the increasing use of magnetic-stripe cards.

The smart cards high degree of functional flexibility, which even allows programs for
new applications to be added to a card already in use, has opened up completely new
application areas extending beyond the boundaries of traditional card uses. Smart cards are
also being used as electronic tickets for local public transport in many cities throughout the
world.
Specifications of a smart card
Smarts cards may have up to 8 kilobytes of RAM, 346 kilobytes of ROM, 256
kilobytes of programmable ROM and a 16-bit microprocessor. The smart card uses a serial
interface and receives its power from external sources like a card reader. The processor uses a
limited instruction set for applications such as cryptography.

Characteristics of smart card:

A "SMART CARD" is also characterized as follows:
Dimensions are normally credit card size. The ID-1 of ISO/IEC 7810 standard defines
them as 85.60 53.98 mm. Another popular size is ID-000 which is 25 x 15 mm.
Both are .76 mm thick.
Contains a security system with tamper-resistant properties (e.g. a secure crypto
processor, secure file system, human-readable features) and is capable of providing
security services (e.g. confidentiality of information in the memory).
Asset managed by way of a central administration system which interchanges
information and configuration settings with the card through the security system. The
latter includes card hot listing, updates for application data.
40

Card data is transferred to the central administration system through card reading
devices, such as ticket readers, ATMs etc.
Smart card readers:

Fig 3.3.3 Smart Card Reader

Smart Card Readers are also known as card programmers (because they can write to a
card), card terminals, card acceptance device (CAD) or an interface device (IFD). There is a
slight difference between the card reader and the terminal. The term 'reader' is generally used
to describe a unit that interfaces with a PC for the majority of its processing requirements. In
contrast, a 'terminal' is a self-contained processing device.
Smart cards are portable data cards that must communicate with another device to gain
access to a display device or a network. Cards can be plugged into a reader, commonly
referred to as a card terminal, or they can operate using radio frequencies (RF).

When the smart card and the card reader come into contact, each identifies itself to the
other by sending and receiving information. If the messages exchanged do not match, no
further processing takes place. So, unlike ordinary bank cards, smart cards can defend
themselves against unauthorized users and uses in innovative security measures.

Communicating with a Smart Card Reader
The reader provides a path for the application to send and receive commands from the
card. There are many types of readers available, such as serial, PC Card, and standard
keyboard models.
41



Each manufacturer provides a different protocol for communication with the reader.
First you have to communicate with the reader.
Second, the reader communicates with the card, acting as the intermediary before
sending the data to the card.
Third, communication with a smart card is based on the APDU format. The card will
process the data and return it to the reader, which will then return the data to its
originating source.

The following classes are used for communicating with the reader:
ISO command classes for communicating with 7816 protocol
Classes for communicating with the reader
Classes for converting data to a manufacturer-specific format
An application for testing and using the cards for an intended and specific purpose.

Readers come in many forms, factors and capabilities. The easiest way to describe a reader is
by the method of its interface to a PC. Smart card readers are available that interface to
RS232 serial ports, USB ports, PCMCIA slots, floppy disk slots, parallel ports, infrared
IRDA ports and keyboards and keyboard wedge readers. Card readers are used to read data
from - and write data to - the smart card.

42

Another difference in reader types is on-board intelligence and capabilities. An
extensive price and performance difference exists between an industrial strength reader that
supports a wide variety of card protocols and the less expensive win-card reader that only
works with microprocessor cards and performs all processing of the data in the PC.

To process a smart card, the computer has to be equipped with a smart card reader
possessing the following mandatory features:
1. Smart Card Interface Standard - ISO 7816 is an international standard that describes
the interface requirements for contact-type smart cards. These standards have multiple
parts. For instance, part 1, 2 and 3 are applicable to card readers. Part 1 defines the
physical characteristics of the card. Part 2 defines dimension and location of smart
card chip contacts. Part 3 defines the electronic signals and transmission protocols of
the card. Card readers may be referred to as conforming to ISO 7816 1/2/3, or in its
simplified term, ISO 7816.
2. Driver - This refers to the software used by the operating system (OS) of a PC for
managing a smart card and applicable card reader. To read a smart ID card, the driver
of the card reader must be PC/SC compliant which is supported by most card reader
products currently available. It should be noted that different OS would require
different drivers. In acquiring card readers, the compatibility between the driver and
the OS has to be determined and ensured.

Desirable Features in a Smart Card Reader
Card Contact Types refers to how the contact between a card reader and a smart card is
physically made. There are two primary types of contact: landing contact and friction contact
(also known as sliding or wiping).
1. For card readers featuring friction contact, the contact part is fixed. The contact wipes
on the card surface and the chip when a card is inserted.
2. For card readers featuring the landing type, the contact part is movable. The contact
"lands" on the chip after a card is wholly inserted. In general, card readers of the
landing type provide better protection to the card than that of the friction type.

Smart card readers are also used as smart card programmers to configure and
personalize integrated circuit cards. These programmers not only read data, but also put data
into the card memory. This means that not only CPU based smart cards, but also simple
43

memory cards can be programmed using a smart card reader. Of course the card reader must
support the appropriate protocol such as the asynchronous T=0, T=1 or synchronous I2C
protocols.

Types of Chip Cards
Smart cards are defined according to
1) How the card data is read and written
2) The type of chip implanted within the card and its capabilities.
There is a wide range of options to choose from when designing your system.

Fig 3.3.4 Types Of Chip Cards
Contact Cards
This is the most common type of smart card. The electrical contacts, located on the
outside of the card, connect to a card reader when the card is inserted. In this project, we are
using a contact smart card where the information inside the card is communicated with the
card reader by inserting the card into the reader.
44

The below figure defines the pinout of the smart card. This comprises of gold plated contact
pads which makes contact with the reader.

Fig 3.3.5 8 Pin Smart Card Bus Point
Electrical characteristics of smart card pinout:
C1-VCC: Power supply input.
C2-RST: Either used itself (reset signal supplied from the interface device) or in combination
with an internal reset control circuit. If internal reset is implemented, the voltage supply on
Vcc is mandatory.
C3-CLK: Clocking or timing signal.
C4-GND: Ground (reference voltage).
C6-VPP: Programming voltage input.
C7-I/O: Input or Output for serial data to the integrated circuit inside the card.

Memory Cards
Memory cards have no sophisticated processing power and cannot manage files
dynamically. All memory cards communicate to readers through synchronous protocols. In
all memory cards, the reading and writing is done to a fixed address on the card. There are
three primary types of memory cards: 1) Straight, 2) Protected and 3) Stored Value.

1. Straight Memory Cards
These cards just store data and have no data processing capabilities. These cards are the
lowest cost per bit for user memory. They should be regarded as floppy disks of varying sizes
without the lock mechanism. These cards cannot identify themselves to the reader, so the host
system has to know what type of card is being inserted into a reader. These cards are easily
duplicated and cannot be tracked by on-card identifiers.
45

2. Protected / Segmented Memory Cards
These cards have built-in logic to control the access to the memory of the card. These
devices can be set to write protect some or the entire memory array and thus sometimes
referred to as Intelligent Memory cards. Some of these cards can be configured to restrict
access to both reading and writing. This is usually done through a password or system key.
Segmented memory cards can be divided into logical sections for planned multi-functionality.
These cards are not easily duplicated but can possibly be impersonated by hackers. They
typically can be tracked by an on-card identifier.

3. Stored Value Memory Cards
These cards are designed for the specific purpose of storing value or tokens. The cards
are either disposable or rechargeable. Most cards of this type incorporate permanent security
measures at the point of manufacture. These measures can include password keys and logic
that are hard-coded into the chip by the manufacturer. The memory arrays on these devices
are set up as decrements or counters. There is little or no memory left for any other function.
For simple applications such as a telephone card, the chip has 60 or 12 memory cells, one for
each telephone unit. A memory cell is cleared each time a telephone unit is used. Once all the
memory units are used, the card becomes useless and is thrown away. This process can be
reversed in the case of rechargeable cards.

CPU/MPU Microprocessor Multifunction Cards
These cards have on-card dynamic data processing capabilities. Multifunction smart
cards allocate card memory into independent sections or files assigned to a specific function
or application. Within the card, a microprocessor or microcontroller chip is present that
manages this memory allocation and file access. This type of chip is similar to those found
inside all personal computers and when implanted in a smart card, manages data in organized
file structures, via a card operating system (COS). Unlike other operating systems, this
software controls access to the on-card user memory.
This capability permits different and multiple functions and/or different applications to
reside on the card, allowing businesses to issue and maintain a diversity of products through
the card. One example of this is a debit card that also enables building access on a college
campus.
46

Multifunction cards benefit issuers by enabling them to market their products and
services via state-of-the-art transaction and encryption technology. Specifically, the
technology enables secure identification of users and permits information updates without
replacement of the installed base of cards, simplifying program changes and reducing costs.
For the card user, multifunction means greater convenience and security, and ultimately,
consolidation of multiple cards down to a select few that serve many purposes.
There are many configurations of chips in this category including chips that support
cryptographic PKI functions with on board math co-processors or Java virtual machine
hardware blocks. As a rule of thumb, the more functions the higher the cost.
Contactless Cards
These are smart cards that employ a radio frequency (RFID) between card and reader
without physical insertion of the card. Instead the card is passed along the exterior of the
reader and read. Types include proximity cards which are implemented as a read-only
technology for building access. These cards function with a limited memory and
communicate at 125 MHz. True read & write contactless cards were first used in
transportation for quick decrementing and re-loading of fare values where their lower security
was not an issue. They communicate at 13.56 MHz, and conform to the ISO14443 standard.
These cards are often straight memory types. They are also gaining popularity in retail stored
value, since they can speed-up transactions and not lower transaction processing revenues
(i.e. VISA and MasterCard), like traditional smart cards.
Contactless card drawbacks include the limits of cryptographic functions and user
memory versus microprocessor cards and the limited distance between card and reader
required for operation.
Combination Cards
These are hybrids that employ both contact and contactless technology in one card.
Combination cards can also contain two different types of chips in contrast to a Dual
Interface card where a single chip manages both the functions.

Common smart cards include:
47


Table 3.3.1 Smart Card Types
Applications
First introduced in Europe over a decade ago, smart cards debuted as a stored value
tool for pay phones to reduce theft. As smart cards and other chip-based cards advanced,
people found new ways to use those including charge cards for credit purchases and for
record keeping in place of paper.
In U.S, consumers have been using chip cards for everything from visiting libraries to
buying groceries to attending movies, firmly integrating them into our everyday lives. Several
states have chip card programs in progress for government applications ranging from the
Department of Motor Vehicles to Electronic Benefit Transfer (EBT). Many industries have
implemented the power of smart cards into their products such as the new GSM digital
cellular phones to TV satellite decoders.


The most common smart card applications are:
Credit cards
Electronic cash
Computer security systems
Wireless communication
Loyalty systems (like frequent flyer points)
Banking
Satellite TV
48

Government identification
Uses of Smart Cards
Smart cards greatly improve the convenience and security of any transaction. They
provide tamper-proof storage of user and account identity. Smart cards also provide vital
components of system security for the exchange of data throughout virtually any type of
network. They protect against a full range of security threats, from careless storage of user
passwords to sophisticated system hacks. Multifunction cards can also serve as network
system access and store value and other data. People worldwide are now using smart cards
for a wide variety of daily tasks, these include:

Loyalty and Stored Value
A primary use of smart cards is stored value, particularly loyalty programs that track
and incentive repeat customers. Stored value is more convenient and safer than cash. For
issuers, float is realized on unspent balances and residuals on balances that are never used.

Securing Information and Physical Assets
In addition to information security, smart cards achieve greater physical security of
services and equipment, because the card restricts access to all but the authorized user(s). E-
mail and PCs are being locked-down with smart cards. Information and entertainment is
being delivered via to the home or PC. Home delivery of service is encrypted and decrypted
per subscriber access. Digital video broadcasts accept smart cards as electronic keys for
protection. Smart cards can also act as keys to machine settings for sensitive laboratory
equipment and dispensers for drugs, tools, library cards, health club equipment etc.

E-Commerce
Smart cards make it easy for consumers to securely store information and cash for
purchasing. The advantages they offer consumers are:
The card can carry personal account, credit and buying preference information that
can be accessed with a mouse click instead of filling out forms.
Cards can manage and control expenditures with automatic limits and reporting.
Internet loyalty programs can be deployed across multiple vendors with disparate
POS systems and the card acts as a secure central depository for points or rewards.
49

Micro Payments - paying nominal costs without transaction fees associated with
credit cards or for amounts too small for cash, like reprint charges.
Personal Finance
As banks enter competition in newly opened markets such as investment brokerages,
they are securing transactions via smart cards at an increased rate. This means:
Smart cards increase trust through improved security. Two-Factor Authentication
insures protection of data and value across the internet. Threats such as the "Man in
the middle" and "Trojan Horses" that replay a user name and password are eliminated
This will improve customer service. Customers can use secure smart cards for fast,
24-hour electronic funds transfers over the internet
Costs are reduced: transactions that normally would require a bank employee's time
and paperwork can be managed electronically by the customer with a smart card
Health Care
The explosion of health care data brings up new challenges to the efficiency of patient
care and privacy safeguards. Smart cards solve both challenges with secure storage and
distribution of everything from emergency data to benefits status.
Rapid identification of patients; improved treatment
A convenient way to carry data between systems or to sites without systems
Reduction of records maintenance costs
Network Security
Business to business Intranets and Virtual Private Networks VPNs are enhanced by
the use of smart cards. Users can be authenticated and authorized to have access to specific
information based on preset privileges. Additional applications range from secure email to
electronic commerce.
MOTOR DRIVER:
Digital systems and microcontroller pins lack sufficient current to drive the circuits like
relays, buzzer circuits, motors etc. While these circuits require around 10milli amps to be
operated, the microcontrollers pin can provide a maximum of 1-2milli amps current. For this
reason, a driver such as a power transistor is placed in between the microcontroller and the
motor.
50


Fig 3.3.6 Circuit for Motor Driver

OPERATION:
The input to the base of the transistor is applied from the microcontroller port pin
P1.0. The transistor will be switched on when the base to emitter voltage is greater than 0.7V
(cut-in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1 (>0.7V),
the transistor will be switched on and thus the motor will be switched ON.

When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in
off state and the motor will be switched OFF. Thus the transistor acts like a current driver to
operate the motor accordingly.
Motor Interfacing with the Microcontroller:

Fig 3.3.7 Interfacing Motor with 8051


51

Buzzer:
Audio Indication:
Digital systems and microcontroller pins lack sufficient current to drive the circuits
like relays, buzzer circuits etc. While these circuits require around 10milliamps to be
operated, the microcontrollers pin can provide a maximum of 1-2milli amps current. For this
reason, a driver such as a power transistor is placed in between the microcontroller and the
buzzer circuit.


Fig 3.3.8 Buzzer circuit

Operation:
The input to the base of the transistor is applied from the microcontroller port pin P1.0.
The transistor will be switched on when the base to emitter voltage is greater than 0.7V (cut-
in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1 (>0.7V), the
transistor will be switched on and thus the buzzer will be ON.
52

When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in
off state and the buzzer will be OFF. Thus the transistor acts like a current driver to operate
the buzzer accordingly.


Buzzerinterfacing with the Microcontroller:

Fig 3.3.9 Interfacing Buzzer with 8051

KEYPAD:
Keypads and LCDs are the most widely used input/output devices of the 8051 and a
basic understanding of them is essential. The keypads are mainly three types:
1. 4*3 keypad
2. 4*4 keypad
3. 4*8 keypad.

53

The keypad used in this project is 4*3 keypad.


Fig 3.3.10 Types Of Keypads

Interfacing the keypad to 8051
At the lowest level, keyboards are organized in a matrix of rows and columns. The
CPU accesses both rows and columns through ports. Therefore, with two 8-bit ports, an 8*8
matrix of keys can be connected to a microprocessor. When a key is pressed, a row and a
column make a contact, otherwise there is no connection between rows and columns. A
single microcontroller (consisting of a microprocessor, RAM, EPROM and several ports all
on a single chip) takes care of hardware and software interfacing of the keypad. In such
systems, it is the function of programs stored in EPROM of the microcontroller to scan the
keys continuously, identify which one has been activated and present it to the motherboard.
54


Fig 3.3.11 Matrix Keypad Connections To Ports
Scanning and identifying the key:
The rows are connected to an output port and the columns are connected to an input
port. If no key has been pressed, reading the input port will yield 1s for all columns since they
are all connected to high (Vcc). If all the rows are grounded and a key is pressed, one of the
columns will have 0 since the key pressed provides the path to ground. It is the function of
the microcontroller to scan the keypad continuously to detect and identify the key pressed.

Grounding rows and reading the columns:
To detect a pressed key, the microcontroller grounds all rows by providing 0 (zero)
to the output latch, then it reads the columns. If the data read from the columns is D2-D0
=111, no key has been pressed and the process continues until a key press is detected.
However, if one of the column bits has a zero, this means that a key press has occurred i.e.,
for example, if D2-D0=110, this means that a key in the D0 column has been pressed. After a
key press is detected, the microcontroller will go through a process of identifying the key.
Starting with the top row, the microcontroller grounds it by providing a low to row D0 only
55

and then it reads the columns. If the data read is all 1s, no key in that row is activated and the
process is moved to the next row. It grounds the next row, reads the columns and checks for
any zero. This process continues until the row is identified. After identification of the row in
which the key has been pressed, the next task is to find out which column the pressed key
belongs to. Now this will be easy since the microcontroller knows at any time which row and
column are being accessed.

LIQUID CRYSTAL DISPLAY:
LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing
LEDs (seven segment LEDs or other multi segment LEDs) because of the following reasons:
1. The declining prices of LCDs.
2. The ability to display numbers, characters and graphics. This is in contrast to LEDs,
which are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of
the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to
keep displaying the data.
4. Ease of programming for characters and graphics.
These components are specialized for being used with the microcontrollers, which
means that they cannot be activated by standard IC circuits. They are used for writing
different messages on a miniature LCD.

Fig 3.3.12 Lcd Display
A model described here is for its low price and great possibilities most frequently
used in practice. It is based on the HD44780 microcontroller (Hitachi) and can display
messages in two lines with 16 characters each. It displays all the alphabets, Greek letters,
56

punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols
that user makes up on its own.
Automatic shifting message on display (shift left and right), appearance of the pointer,
backlight etc. are considered as useful characteristics.

Pins Functions
There are pins along one side of the small printed board used for connection to the
microcontroller. There are total of 14 pins marked with numbers (16 in case the background
light is built in). Their function is described in the table below:

Function
Pin
Number
Name
Logic
State
Description
Ground 1 Vss - 0V
Power supply 2 Vdd - +5V
Contrast 3 Vee - 0 Vdd
Control of
operating
4 RS
0
1
D0 D7 are interpreted as
commands
D0 D7 are interpreted as data
5 R/W
0
1
Write data (from controller to
LCD)
Read data (from LCD to
controller)
6 E
0
1
From 1 to
0
Access to LCD disabled
Normal operating
Data/commands are transferred to
LCD
Data / commands
7 D0 0/1 Bit 0 LSB
8 D1 0/1 Bit 1
9 D2 0/1 Bit 2
10 D3 0/1 Bit 3
11 D4 0/1 Bit 4
12 D5 0/1 Bit 5
57

13 D6 0/1 Bit 6
14 D7 0/1 Bit 7 MSB
Table:3.3.2 Pin Functions
LCD screen:
LCD screen consists of two lines with 16 characters each. Each character consists of
5x7 dot matrix. Contrast on display depends on the power supply voltage and whether
messages are displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied
on pin marked as Vee. Trimmer potentiometer is usually used for that purpose. Some
versions of displays have built in backlight (blue or green diodes). When used during
operating, a resistor for current limitation should be used (like with any LE diode).


Fig 3.3.13 Lcd Screen
LCD Basic Commands
All data transferred to LCD through outputs D0-D7 will be interpreted as commands
or as data, which depends on logic state on pin RS:
RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in
processor addresses built in map of characters and displays corresponding symbols.
Displaying position is determined by DDRAM address. This address is either previously
defined or the address of previously transferred character is automatically incremented.
58

RS = 0 - Bits D0 - D7 are commands which determine display mode. List of commands
which LCD recognizes are given in the table below:
Command RS RW D7 D6 D5 D4 D3 D2 D1 D0
Execution
Time
Clear display 0 0 0 0 0 0 0 0 0 1 1.64Ms
Cursor home 0 0 0 0 0 0 0 0 1 x 1.64mS
Entry mode set 0 0 0 0 0 0 0 1 I/D S 40uS
Display on/off control 0 0 0 0 0 0 1 D U B 40uS
Cursor/Display Shift 0 0 0 0 0 1 D/C R/L x x 40uS
Function set 0 0 0 0 1 DL N F x x 40uS
Set CGRAM address 0 0 0 1 CGRAM address 40uS
Set DDRAM address 0 0 1 DDRAM address 40uS
Read BUSY flag (BF) 0 1 BF DDRAM address -
Write to CGRAM or
DDRAM
1 0 D7 D6 D5 D4 D3 D2 D1 D0 40uS
Read from CGRAM or
DDRAM
1 1 D7 D6 D5 D4 D3 D2 D1 D0 40uS

59


Table 3.3.3 List Of Commands
LCD Connection
Depending on how many lines are used for connection to the microcontroller, there
are 8-bit and 4-bit LCD modes. The appropriate mode is determined at the beginning of the
process in a phase called initialization. In the first case, the data are transferred through
outputs D0-D7 as it has been already explained. In case of 4-bit mode, for the sake of saving
valuable I/O pins of the microcontroller, there are only 4 higher bits (D4-D7) used for
communication, while other may be left unconnected.

60

Consequently, each data is sent to LCD in two steps: four higher bits are sent first
(that normally would be sent through lines D4-D7), four lower bits are sent afterwards. With
the help of initialization, LCD will correctly connect and interpret each data received.
Besides, with regards to the fact that data are rarely read from LCD (data mainly are
transferred from microcontroller to LCD) one more I/O pin may be saved by simple
connecting R/W pin to the Ground. Such saving has its price.

Even though message displaying will be normally performed, it will not be possible
to read from busy flag since it is not possible to read from display.

LCD Initialization
Once the power supply is turned on, LCD is automatically cleared. This process lasts
for approximately 15mS. After that, display is ready to operate. The mode of operating is set
by default. This means that:
1. Display is cleared
2. Mode
DL = 1 Communication through 8-bit interface
N = 0 Messages are displayed in one line
F = 0 Character font 5 x 8 dots
3. Display/Cursor on/off
D = 0 Display off
U = 0 Cursor off
B = 0 Cursor blink off
4. Character entry
ID = 1 Addresses on display are automatically incremented by 1
S = 0 Display shift off

Automatic reset is mainly performed without any problems. If for any reason power
supply voltage does not reach full value in the course of 10mS, display will start to perform
completely unpredictably.
If voltage supply unit cannot meet this condition or if it is needed to provide
completely safe operating, the process of initialization by which a new reset enabling display
to operate normally must be applied.
61

Algorithm, according to the initialization, is being performed depends on whether
connection to the microcontroller is through 4- or 8-bit interface. All left over to be done after
that is to give basic commands and of course- to display messages.

Fig 3.3.14 Procedure On 8-bit Initialization
Contrast control:
To have a clear view of the characters on the LCD, contrast should be adjusted. To
adjust the contrast, the voltage should be varied. For this, a preset is used which can behave
like a variable voltage device. As the voltage of this preset is varied, the contrast of the LCD
can be adjusted.
62


Fig 3.3.15 Variable Resistor
Potentiometer
Variable resistors used as potentiometers have all three terminals connected. This
arrangement is normally used to vary voltage, for example to set the switching point of a
circuit with a sensor, or control the volume (loudness) in an amplifier circuit. If the terminals
at the ends of the track are connected across the power supply, then the wiper terminal will
provide a voltage which can be varied from zero up to the maximum of the supply.

Fig 3.3.16 Potentiometer Symbol
Presets
These are miniature versions of the standard variable resistor. They are designed to be
mounted directly onto the circuit board and adjusted only when the circuit is built. For
example, to set the frequency of an alarm tone or the sensitivity of a light-sensitive circuit, a
small screwdriver or similar tool is required to adjust presets.
Presets are much cheaper than standard variable resistors so they are sometimes used
in projects where a standard variable resistor would normally be used.
Multiturn presets are used where very precise adjustments must be made. The screw must
be turned many times (10+) to move the slider from one end of the track to the other, giving
very fine control.
63


Fig 3.3.17 Preset Symbol
LCD Interfacing with 8051:

Fig 3.3.18 Lcd Interfacing With 8051






64

3.4 SCHEMATIC DIAGRAM:


Fig 3.4 Schematic Diagram














65

CHAPTER 4
SOFTWARE DESCRIPTION
4.1 ABOUT SOFTWARE:
Keil development tools for the 8051 Microcontroller Architecture support every
level of software developer from the professional applications engineer to the student just
learning about embedded software development.
The Keil products from ARM include C/C++ compilers, debuggers, integrated
development and simulation environments, RTOS and middleware libraries, and
evaluation boards for ARM, Cortex-M, Cortex-R4, 8051, C166, and 251 processor
families.
Keil was founded in 1985 to market add-on products for the development tools
provided by many of the silicon vendors. It soon became evident that there was a void in
the marketplace that must be filled by quality software development tools. It was then that
Keil implemented the first C compiler designed from the ground-up specifically for the
8051 microcontroller.
In October 2005, Keil (Keil Electronic GmbH in Munich, Germany, and Keil
Software, Inc. in Plano, Texas) was acquired by ARM.
Since the acquisition, ARM has continued the development and support of Keil
products for existing 8051, 251, and C166 markets. In addition, we have driven
innovation to support and significantly improve software development around ARM
processor-based devices.
Today, the Keil development tools are used by a wide range of developers
building software applications for end products targeting diverse vertical markets such as
Aerospace, Banking, Healthcare, Automotive, Transportation, Manufacturing, Consumer,
Military and Telecommunications.
The following chart shows the Keil development tools and how they interface to
each other.
66



Fig 4.1Keil Development Tools

The Keil 8051 Development Tools are designed to solve the complex problems
facingembedded software developers.
When starting a new project, simply select the microcontroller you use from the Device
Database and the Vision IDE sets all compiler, assembler, linker, and memory options
for you.
The Keil Vision Debugger accurately simulates on-chip peripherals (IC, CAN, UART,
SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM Modules) of your
8051 device. Simulation helps you understand hardware configurations and avoids time
wasted on setup problems. Additionally, with simulation, you can write and test
applications before target hardware is available.
When you are ready to begin testing your software application with target hardware, use
the MON51, MON390, MONADI, or FlashMON51 Target Monitors, the ISD51 In-
System Debugger, or the ULINK USB-JTAG Adapter to download and test program
code on your target system.

Third-Party
Utilities extend
the functions and
capabilities of
Vision.
Keil PK51 is a complete software
development environment for
classic and extended 8051
microcontrollers. Like all Keil
tools, it is easy to learn and use.
RTX Real-Time
Kernels enables
the development
of real-time
software.
67

Steps to operate on keil software (Assembler project):

1. Click on the Keil u Vision Icon on Desktop
2. Click on the Project menu from the title bar
3. Then Click on New Project
4. Save the Project by typing suitable project name with no extension in u r own
folder sited in either C:\ or D:\
5. Then Click on Save button above.
6. Select the component for u r project. i.e. Atmel
7. Click on the + Symbol beside of Atmel
8. Select AT89C51
9. Then Click on OK
10. Then Click either YES or NOmostly NO
11. Now your project is ready to USE
12. Now double click on the Target1, you would get another option Source group 1
13. Click on the file option from menu bar and select new
14. The next screen will be as shown in next page, and just maximize it by double
clicking on its blue boarder.
15. Now start writing program in either in C or ASM
16. For a program written in Assembly, then save it with extension . asm and for
C based program save it with extension .C
17. Now right click on Source group 1 and click on Add files to Group Source
18. Now you will get another window, on which by default C files will appear.
19. Now select as per your file extension given while saving the file
20. Click only one time on option ADD
21. Now Press function key F7 to compile. Any error will appear if so happen.If the
file contains no error, then press Control+F5 simultaneously.
22. The new window is as follows
23. Then Click OK
24. Now Click on the Peripherals from menu bar, and check your required port
25. Drag the port a side and click in the program file.
68

26. Now keep Pressing function key F11 slowly and observe.
27. You are running your program successfully

Embedded C:
Data Types:
We have already come across the word Data types in C- Language. Here also the
functionality and the meaning of the word is same except a small change in the prefix of their
labels. Now we will discuss some of the widely used data types for embedded C-
programming.
Data Type Size in Bits Data Range/Usage
Unsigned Char 8-bit 0-255
Signed Char 8-bit -128 to +127
Unsigned Int 16-bit 0 to 65535
Signed Int 16-bit -32,768 to +32,767
Sbit 1-bit SFR bit addressable only
Bit 1-bit RAM bit addressable only
Sfr 8-bit RAM addresses 80-FFH only
Table 4.1 Data Types
Sbit (single bit):
The sbit data type is widely used and designed specifically to access single bit
addressable registers. It allows access to the single bits of the SFR registers.
CODE/PROGRAM:
#include<reg51.h>
#include"lcddisplay.h"
#include"eeprom.h"
#include"string.h"
#include<math.h>

unsigned char v1,v2,v3;
69

unsigned char temp,count=0,fares=0,a[5],i1;
unsigned int amount=0;
unsigned int i,y;

sbit row0=P2^0;
sbit row1=P2^1;
sbit row2=P2^2;
sbit row3=P2^3;
sbit col0=P2^4;
sbit col1=P2^5;
sbit col2=P2^6;

sbit buz=P2^7;
sbit motor=P3^7;


unsigned char r,c,uc_key_val;

unsigned char key[4][3] = {'1','2','3', // KEYPAD MATRIX INITILIZATION
'4','5','6',
'7','8','9',
'*','0','#'};

unsigned char keypad();
void convert(unsigned int temp1_value)
{
unsigned int d1,d2,d3;

d3=temp1_value%10;
70

temp1_value=temp1_value/10;
d2=temp1_value%10;
d1=temp1_value/10;
lcddata(d1+48);
lcddata(d2+48);
lcddata(d3+48);
}
void main()
{
buz=1;
motor=0;
lcd_init();
delay(100);
lcd_init();
delay(200);
msgdisplay("WELCOME");
//amount = 9999;

write_eeprom(0,0x01);
delay(500);
write_eeprom(1,0xF4);
delay(500);
lcdcmd(0x01);
y = read_eeprom(0);
y = y<<8;
y = y|(read_eeprom(1));



71


if(y!=0xffff)
{
delay(500);
lcdcmd(1);
msgdisplay("recharged with");
lcdcmd(0xc5);
convert(y);
}




st: //led=1;
delay(500);
lcdcmd(1);
msgdisplay("UNMANNED PETROL");
lcdcmd(0XC0);
msgdisplay(" BUNK ");
delay(500);


while(1)
{
c=read_eeprom(0);



if(c!=0xff)
72

{
lcdcmd(1);
buz=0;
msgdisplay("card detected.");
//led=0;
delay(500);
buz=1;
lcdcmd(1);
msgdisplay("enter the pswd");
i=0;
lcdcmd(0xc0);
while(1)
{
a[i]=keypad();
lcddata(a[i]);
delay(200);
if(a[i]=='#')
goto xx1;
i++;
}


xx1: a[i]='\0';

if(strcmp(a,"123"))
{
buz=0;
lcdcmd(1);
msgdisplay("unauthorized");
73

delay(500);
buz=1;
goto st;
}

lcdcmd(1);
msgdisplay("Enter the amount");
delay(500);
lcdcmd(0xc0);
i=1;
temp=amount=0;
while(1)
{
temp=keypad();
if(temp=='#')
goto xx;
else
{
lcddata(temp);
amount=amount*10+temp-48;
}
delay(200);
}



xx:
lcdcmd(0x01);

msgdisplay("amount enterd");
74

lcdcmd(0xc0);

convert(amount);
delay(500);

y = read_eeprom(0);
y = y<<8;
y = y|(read_eeprom(1));




if(y==0xffff)
{
lcdcmd(0x01);
msgdisplay("invalid card");
goto st;
}

if(y<amount)
{
buz=0;
lcdcmd(0x01);
msgdisplay("insufficient");
lcdcmd(0xc0);
msgdisplay("balance !!");
delay(500);
lcdcmd(0x01);
msgdisplay("please recharge");
75

lcdcmd(0xc0);
msgdisplay("your card !!");
buz=1;
while(1);
}

y=y-amount;
lcdcmd(0x01);
msgdisplay("Amount Deducted");
lcdcmd(0xc0);
msgdisplay("Avl Bal: ");
convert(y);


write_eeprom(0,(y&0xff00)>>8);
delay(300);
write_eeprom(1,(y&0x00ff));
delay(1000);
lcdcmd(0x01);
msgdisplay("Now take the");
lcdcmd(0xc0);
msgdisplay("petrol");
delay(500);
for(i=0;i<amount;i++)
{
motor=1;
delay(50);

}
76

motor=0;
lcdcmd(0x01);
msgdisplay("take your card");

while(read_eeprom(0)!=0xff)
delay(200);

lcdcmd(0xc0);
msgdisplay("thank you");

goto st;
delay(500);
}

delay(500);


}


}

unsigned char keypad()
{
unsigned char K,c0,c1,c2;

while(1)
{
row0=0x00;
77

row1=0x00;
row2=0x00;
row3=0x00;
col0=0x01;
col1=0x01;
col2=0x01;


do
{
c0=col0;
c1=col1;
c2=col2;
}while((c0!=0x01)||(c1!=0x01)||(c2!=0x01)); // To check all keys are relesead or not

do
{
c0=col0;
c1=col1;
c2=col2;
}while((c0==0x01)&&(c1==0x1)&&(c2==0x01)); // To check any key is pressed or not





while(1)
{

row0=0x00; // If row0 is pressed
78

row1=0x01;
row2=0x01;
row3=0x01;
c0=col0;
c1=col1;
c2=col2;

if((c0!=1)||(c1!=1)||(c2!=1))
{
r=0;
break;
}

row0=1; // If row1 is pressed
row1=0;
row2=1;
row3=1;
c0=col0;
c1=col1;
c2=col2;

if((c0!=1)||(c1!=1)||(c2!=1))
{
r=1;
break;
}

row0=1; // If row2 is pressed
row1=1;
79

row2=0;
row3=1;
c0=col0;
c1=col1;
c2=col2;

if((c0!=0x01)||(c1!=0x01)||(c2!=0x01))
{
r=2;
break;
}

row0=1; // If row3 is pressed
row1=1;
row2=1;
row3=0;
c0=col0;
c1=col1;
c2=col2;

if((c0!=1)||(c1!=1)||(c2!=1))
{
r=3;
break;
}
}

if((c0==0)&&(c1==1)&&(c2==1))
{
80

K=key[r][0];
return K;
}
else
if((c0==1)&&(c1==0)&&(c2==1))
{
K=key[r][1];
return K;
}

else
{
K=key[r][2];
delay(100);
return K;
}
}
}








81

CHAPTER 5
RESULT ANALYSIS
5.1 SPECIFICATIONS:

















82

ADVANTAGES:



















83

DISADVANTAGES:



















84

APPLICATIONS:



















85

CONCLUSION:



















86

FUTURE SCOPE:



















87

REFERENCES:

You might also like