0% found this document useful (0 votes)
24 views93 pages

GSM Documentation

The document outlines the design and implementation of an Intelligent Public Transportation System, focusing on a Bus Electronic Control Unit (ECU) that integrates various technologies such as GSM, IR sensors, and LCD displays to enhance public transport efficiency in Indian metropolitan cities. It details the project's aim, motivation, and the necessary hardware and software specifications, including microcontroller selection and interfacing techniques. Additionally, it discusses the background of intelligent transportation systems and the importance of technologies like Automatic Passenger Counters and Automatic Vehicle Location for improving transit operations.

Uploaded by

smmcrgm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views93 pages

GSM Documentation

The document outlines the design and implementation of an Intelligent Public Transportation System, focusing on a Bus Electronic Control Unit (ECU) that integrates various technologies such as GSM, IR sensors, and LCD displays to enhance public transport efficiency in Indian metropolitan cities. It details the project's aim, motivation, and the necessary hardware and software specifications, including microcontroller selection and interfacing techniques. Additionally, it discusses the background of intelligent transportation systems and the importance of technologies like Automatic Passenger Counters and Automatic Vehicle Location for improving transit operations.

Uploaded by

smmcrgm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

CHAPTER 1

1.1 INTRODUCTION
Transportation System forms the lifeline of any development to take place in a
city. Especially in metropolitan cities like Hyderabad, Mumbai and Chennai. Though adequate
transportation facilities are present to connect almost all the parts of the city, most of the people
have their eye closed about the most efficient mode of public transport to reach their destination.
A passenger waiting for a bus hours together is a common sight. Rather he or she can select
some other break routes and catch a train or another bus from there to reach the destination
without any hassle. All these are possible if and only if a meticulous planning is done and all the
information, regarding the travel including the time of travel, cost of travel and other constraints.

1.2 Aim of the Project

Design steps

 Design and implementation of Electronic Control Unit that will go into the bus for…
o Driver (User) Interface to…
 Authenticate the bus driver with a unique Driver ID and 4-digit password.
 Display the total number of persons inside the bus along with the stop
number.
 Configuration menu driven software design for profile settings
o Automatically count the total number of empty-seats
o Interfacing the GSM modem for current nearest base-station identification.
o Uploading the information into dynamic database at server
o Proposing the embedded software algorithm that can integrate all these sub-
modules in tight memory and timing deadlines (cost-effective design)

The circuit should have the following specifications


 The microcontroller should be able to Interfacing with KEY BOARD, LCD,GSM
MODULE and IR SENSOR
 The microcontroller should have a hardware built RS-232( UART) communication
 The microcontroller should be able to communicate with Interrupts (INT0,INT1)
 A library of functions for accessing the GPIO, Serial communication using UART should
be created.

1
1.3 Motivation

1.4 Scope of the Project

The Project titled Intelligent Public Transportation System for Indian Metro Cities contains
Bus ECU unit, Central Hub ECU unit and Bus stop ECU unit. In this project mostly concentrated
on Bus ECU unit which includes Key board interface, IR sensors, GSM module and LCD
display with the Microcontroller. The Central Hub ECU and BUS stop ECU unit, GSM module
needs to be develop to provide service of Intelligent Public Transportation System.

Central Hub ECU Unit is main unit which operates with many bus units and bus stop units
for intelligent transport. The status of bus from Bus ECU Unit is transmitted to the Central Hub
through GSM module. The Central Hub contains the microcontroller, which is programmed in
such a way that, the bus stop number is incremented inside it and the count is sent to that bus
stop

Bus stop ECU unit is used to get the data from Central Hub and displays the information
such as the bus route number, passenger count and its position are displayed on LCD module at
the bus stop.

1.5 Organization of Thesis

Chapter1gives the introduction about the intelligent public transportation system and automotive
electronics growth in india. Chapter2 gives the Background of the project and the market scope
and the opportunities present in automotive electronics. Chapter 3 gives the brief discussion
about LCD interfacing and keypad interfacing and its software functionalities. Chapter 4 gives
the Object detection technique which includes the IR transmitter and IR receiver functionalities
along with 555 timer 38Khz frequency generation methods. In chapter 5 the serial
communication using UART is discussed. The chapter6 contains ECU design and its application
level flowchart and its hardware testing. Chapter 7 contains the design verification tools such as

2
Keil microvision 4 and its features.chapter 8 includes the Result analysis,simulation result
snapshots and conclusion

3
Chapter 2

2.1 Back ground on intelligent transportation systems

For years solutions have been sought to handle transportation problems such as traffic
congestion, pollution, and inefficiency. In response, Congress passed the Intermodal Surface
Transportation Efficiency Act of 1991 (ISTEA) to address these concerns. ISTEA was later
reinforced in 1998 by The Transportation Equity Act for the 21 st Century (TEA 21). An
outgrowth of ISTEA was the Federal Intelligent Transportation Systems (ITS) program. ITS is a
collection of various technologies which include information processing, communications,
control, and electronics. The purpose of ITS is to use these diverse technologies to increase
mobility and to enhance transit operations by making travel safer, more efficient,
environmentally sound, cost-effective, and convenient and comfortable. To fully understand the
potential uses of ITS in public transportation, ITS technologies have been organized into three
separate categories. The function of each technology in a category will be explored along with its
benefits to transit agencies and customers, particularly, welfare recipients. The discussion will
begin with Fleet Operation and Management, followed with Fare Collection, and conclude with
Customer Information, otherwise known as Traveler Information Systems.

Fleet Management and Operations


Fleet Management and Operation includes five different technologies, as follows: automatic
passenger counters (APC), automatic vehicle location (AVL), geographic information systems
(GIS), scheduling and dispatching (S&D), and signal priority (SP). These separate technologies
often are combined in various software packages, which allow for the integration of many
different transit functions. The computer applications allow better resource utilization to meet
service demands, which help make public transportation more appealing to customers. Since
most welfare recipients must rely on public transportation, the benefits of these technologies are
especially important for them. One of the technologies that had the most obvious impact on the
Welfare to Work program is the use of geographic information system. GIS allows transit
agencies to accurately track where demand is located in their service area.

The Automatic Passenger Counter (APC) automatically records the number of passengers, time
and location of each stop as passengers get on and off the bus. The APC can collect data,
previously recorded manually or with a hand-held device, with a reduction in time, cost, and
effort. By means of infrared beams at the doors or pressure sensitive mats on the steps, the APC
accurately records the time, location, and the number of passengers as they enter or exit the bus.
With the information provided by the APCs, transit planners can make changes to routes and

4
schedules that better serve the transportation needs of their community. For example, the city of
Calgary, which first implemented an APC system in 1990, found the count data obtained by the
APCs to be “extremely accurate” and the point-to-point travel times valuable for future planning.
The potential benefits of this information for the Welfare to Work program include making
transit agencies more aware of the particular transportation needs of the welfare recipients in
their local communities. That way changes can be made to existing routes, or additional routes
can be planned to enhance welfare recipients’ chances of attaining gainful employment.

Automatic Vehicle Location


Satellite geo-positioning technology tracking vehicles is one of the most common AVL systems,
which is another ITS technology that involves daily operations and management. With AVL,
dispatchers can pinpoint at any given time, the location of buses in their fleet that are equipped
with the technology. Access to this type of information, can be especially significant in an
emergency situation, when either passenger or driver safety may be threatened. In addition, bus
location information can be given to customers to assist them in planning an itinerary based on
the most up-to-the-minute information. Finally, this information can be used to determine
whether buses are running on schedule and, if necessary, to reroute buses around problem areas.
Many transit agencies have found that automatic vehicle location has been increasing their on-
time performance while at the same time it has been decreasing the number of buses necessary
for a route. For example, through the use of AVL in Kansas City Mo., the transit system was able
reduced the number of buses needed for its routes by 9 percent. The potential benefits for the
Welfare to Work participant are a safer more efficient and reliable way to get to work on time.

2.2 PROBLEM DEFINITION

A passenger, assume new to the city, enquires the regular bus and train goers about the best
route. It is a troublesome process as the travel time is not even half the time spent for catching a
bus or train. Time once lost can’t be regained back. This type of system leads to better
organizing, when it comes to heavily populated cities like Hyderabad, this system would help in
reducing the crowding at the bus stops and railway stations.

5
2.3 INTRODUCTION ABOUT BUS ECU UNIT

On power up, the system will initialize all the peripherals on it The bus ECU kit is a
embedded unit with a microcontroller interfaced with Keyboard, LCD, IR sensors,
RS232 ,MAX232 and GSM module. The key pads are most widely used input devices of the
microcontroller and it is used for Authentication of Bus driver. The 4x4 matrix keyboard rows
and columns are connect to microcontroller parallel port. LCD has 16 lines used for interfacing
with the microcontroller Character 16x2 Line LCD Module to the Parallel Port. The lines 7 to
14 of the LCD are connected to GPIOs of the P89C51RDXX for the data transfer. The control
pins are RS,RW and EN connect to the GPIOs port of the P89C51RD2XX. RS-232 is the
component which is used to connect system (pc) to micro controller. The MAX232 is an
integrated circuit that converts signals from an RS-232 serial port to signals suitable for use in
TTL compatible digital logic circuits. The MAX232 is a dual driver/receiver and typically
converts the RX, TX, CTS and RTS signals.

The main component used in the bus ECU unit is the IR sensors. The
IR sensors are used to count the no. of passengers in bus and GSM module is used to send the
information to central station as an SMS.

2.4 COMPUTING ELEMENT SELECTION

 It should meet the task at hand efficiently and cost efficiently. We must first see
whether a 8 bit, 16 bit or 32 bit can handle our project task. For this we have to
consider it’s speed , packaging i.e., if it is a DIP( dual in-line) or QFP( quad flat
package) or some other , power consumption, amount of on chip ROM & RAM, no
of input pins & timer on chip , cost per unit(i.e., total kit cost).
 Availability software development tools such as assembler, debugger, compiler,
emulator & technical support to the microcontroller both on inside and outside
expertise.
 Wide availability of microcontroller which fulfill needed quantities or sources of both
now & in future.

6
 TheP89C51RA2/RB2/RC2/RDxx contains non-volatile KB/16KB/32KB/64KB Flash
program memory that is both parallel programmable and serial In-System and In-
Application Programmable.
 In-System Programming (ISP) allows the user to download new code while the
microcontroller sits in the application.
 In-Application Programming (IAP) means that the microcontroller fetches new program
code and reprograms itself while in the system. This allows for remote programming
over a modem link. A default serial loader (boot loader) program in ROM allows serial
In-System programming of the Flash memory via the UART without the need for a
loader in the Flash code. For In-Application Programming, the user program erases and
reprograms the Flash memory by use of standard routines contained in ROM.
2.5 SELECTION OF HARDWARE
1. Tightly-constrained
 Low cost, low power, small, fast, etc.
2. Reactive and real-time
 Continually reacts to changes in the system’s environment
 Must compute certain results in real-time without delay
3. Low manufacturing cost.
4. Low power. (Microcontroller running in MHz Clock)
5. Hard memory constraints.
6. Quick time-to-prototype.
7. Maintainability/Interoperability.
8. Bug-free/Correctness, safety, many more

2.6 HARADWARE AND SOFTWARE SPECIFICATIONS

HARDWARE
1. P89C51RD2BN Microcontroller
2. IR Transmitter and Receiver
3. 3.NE555 timer
4. LIQUID CRYSTAL DISPLAY (2x16 Display)

7
5. 4 x 4 Keypad
6. SIM 300 GSM module
SOFTWARE
1. FLASH MAGIC Philips Serial ISP programming utility.
2. KEIL µVision 4IDE C51 Embedded Cross Compiler

2.7 BLOCK DIAGRAM OF BUS ECU UNIT

Fig 2.1 Block diagram of BUS ECU

8
CHAPTER 3

This chapter explores some real world applications of the P89C51RD2xx, and also
includes how to interface the P89C51RD2xx to devices such as an LCD and a
keyboard and its software functionality using embedded C language.

3.1 ELECTRONIC CONTROL UNIT (ECU) INTERFACE WITH LCD

3.1.1 HARDWARE DESIGN

Description
Fig: 3.1 LCD is used in this project for the purpose of displaying message at the Bus
stops. LCD interfacing consists of several parts like P89C51RD2XX microcontroller, 2 × 16
line LCD are main components needed. P89C51RD2XX is a 40 pin DIP microcontroller. LCD
is a 2 line 16 pin device, 2 lines means it contains 2 rows to display. To develop a protocol to
interface this LCD with 89C51 first we have to understand how they functions. These displays
contain two internal byte-wide registers, one for command and second for characters to be
displayed. There are three control signals called R/W, RS and En. Select By making RS signal
0 you can send different commands to display. These commands are used to initialize LCD, to
display pattern, to shift cursor or screen etc.

9
3.1.2 LCD interface with P89C51RD2XX microcontroller

P89C51RD2XX can be divided in to 4 ports, and each port consists of 8 pins. All the
data lines of LCD are connected with port P0. i.e., data lines D0-D7 are connected to port P0.
The ‘EN’ pin is connected with P2.7, RS is connected with P2.5 and R/W pin is connected with
P2.6. i.e., the three pins are connected to the port two. The operation of LCD depends upon
these three pin only.

Fig 3.1 LCD interface with P89C51RD2XX

The three control lines are referred to as EN, RS and RW

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1),
the data being sent is text data which should be displayed on the screen. For example, to display
the letter "S" on the screen you would set RS high

The RW line is the "Read/Write" control line. When RW is low (0), the information on the
data bus is being written to the LCD. When RW is high (1), the program is effectively reading
the LCD. Only one instruction ("Get LCD status") is a read command. All others are write
commands so RW will almost always be low.

10
3.1.3 TIMING DIAGRAMS

The Read Timing Diagram

To read the data or the current command to the LCD the controller should put a series of
signals a shown in the figure

To read the Command or data the signals RS should be set to the logic 0 or 1 according to
the requirement. To read the data from the LCD the R/W write signal to be set to read mode that
is it should be pulled up. Then enable signal is given then the LCD will respond accordingly then
it will put the data in data bus, finally the data can be accessed in to the code and manipulate or
take the decisions accordingly.

Figure: 3.2 LCD read timing diagram

11
The Write timing diagram

For writing data or command to the LCD the instruction sequence must follow like as shown
in the figure

Figure: 3.3 LCD read timing diagram

To write a command or data it must be specified with RS signal. Since the code is attempting
to read the data/ command the R/W signal must be set to write mode with RS signal as logic 0.
Now set the data to be written to the LCD in data bus and apply a logic low-high-low pulse at the
enable signal which command the controller to receive the applied signal data.

Handling the EN control line

As mentioned above, The EN line is used to tell the LCD that data is available in command
and data bus and can access the same data. Note that the EN line must be raised /lowered
before/after each instruction sent to the LCD regardless of whether that instruction is read or
write text or instruction. In short, it is must always manipulate EN when communicating with the
LCD. EN is the LCD's way of knowing that data can be received from the bus. If it is doesn't
raise/lower EN, the LCD doesn't know that the data is available for receiving.

12
3.1.4 Checking the busy status of the LCD

Busy Flag (BF):


When the busy flag is high or “1” the module is performing an internal operation and the
next instruction will not be accepted. The RS=0 is used to check the Busy flag bit too see if the
LCD is ready to receive information. The Busy flag is D7 and can be read when R/W = 1 and RS
= 0, as fallows: if R/W = 1, RS= 0.When D7=1 (busy flag), the LCD is busy taking care of
internal operations and will not accept any new information. When D7=0, the LCD is ready to
receive new information.

Busy flag flowchart

Fig 3.4 Busy flag flowchart

Software Design
Pseudo code listing 1
void lcdready(void)
{
busy=1;
rs=0; //Register select command
rw=1;
while(busy==1) // if Bit(D7) high, LCD still busy
{

13
en=0; // Finish the command
MSDelay(1);
en=1; // Start LCD command
}}

3.1.5 Writing command to the Display

To give a command to perform some special functions like move to position, clear
LCD ,blink the curser etc. the instruction sequence must follow like first instruction must be set
in the data bus set RS signal to logic 0 and enabling the LCD will receive the data . After
finishing the instruction sequence the application must wait till the LCD completes the
instruction by checking the LCD Busy status .The same sequence can be given as the sub
routine.

Writing command display flow chart


1. Check the Busy flag bit
2. Set the instruction in data lines (if it is writing)
3. Set RS bit to logic 1 to 0
4. Set R/W bit is to low
6. Set En line to high
7. Set line to low

14
Fig 3.5 Writing command display flow chart

Software Design
Pseudo code listing 2
void lcdcmd (unsigned char value) // LCD command initiation routine
{
lcdready(); // wait till the LCD executes the instruction
ldata=value; // Set the value(instruction) in Data bus
rs=0; // register select as command
rw=0;
en=1; // set the enable command
MSDelay(1);
en=0; // Reset the enable command
}

15
3.1.6 Writing Data to Display

Writing the data to the LCD is same as writing the command to it except instead of
RS=0; it should be RS=1; the remaining instructions will remain same. The routine for writing
the data is given below.

Writing data to display flow chart


1. Check the Busy flag bit
2. Set the data in data lines (if it is writing)
3. Set RS bit to logic 0 to 1
4. Set R/W bit is to low
5. Set En line to high
6. Set line to low

Fig: 3.6 writing data to display flowchart

16
Software Design
Pseudo code listing 3
void lcddata (unsigned char value) // LCD data placing routine
{
lcdready(); // wait till the LCD executes the instruction
ldata = value; // Set the value(Data) in Data bus
rs=1; //register select as data
rw=0; //read command
en=1; // Send Enable Signal to LCD
MSDelay(1); // This Function Gives Approximate Delay required For LCD Initialization

en=0; //Reset the Enable Command


}

3.1.7 Displaying the data in to the LCD

Writing the string in the LCD ,to get the result first the address at which the string has to
display on the screen is given as command followed by displaying the individual characters as
LCD data .That finishes the data to be display in the LCD .The code to display the data can be
given as fallows

Pseudo code listing 4

Displaying the data in to the LCD

void WriteString(unsigned char count,unsigned char *MSG)


{
unsigned char i;
for(i=0;i<count;i++)
{
lcddata(MSG[i]); // Display Character on LCD at Proper Location

}}

3.1.8 Initializing the LCD


Before you using the LCD, the program must initialize and configure it. This is
accomplished by sending a number of initialization instructions to the LCD.
The first instruction to send is the no of data for the LCD i.e with an 8-bit or 4-bit data
bus. The other thing need to specify is display matrix; in the selected LCD it is a 5x8 dot
character font. These two options are selected by sending the command 38h to the LCD as a
17
command. The command can give to the LCD by invoking the pre defined function call lcd cmd
with passing parameters value of 38H ,the syntax for the same can be given like lcdcmd(0x38)

Software Design
Pseudo code listing 5
Initializing the LCD

The initialization sequence code can be given as follows:

lcdcmd(0x38); // 2 lines and 5x7 matrix


lcdcmd(0xC0); // force cursor to begging of 2nd line
lcdcmd(0x0E); // display on, cursor blinking
lcdcmd(0x01); //clear display screen
lcdcmd(0x06); // increment cursor(shift cusor right)
lcdcmd(0x80); // force cursor to begging of 1st lin

18
3.2 ELECTRONIC CONTROL UNIT (ECU) INTERFACE WITH KEY PAD

3.2.1 HARDWARE DEIGN


Fig: 3.5 Keypad is used in this project for the purpose of Authentication of Bus driver
Such as user id, password etc.
There are vast varieties of keyboards available in the market; among them the one is
selected as 4x4 matrix keyboard. The selected keyboard is of low in the cost and the
resource occupation by the micro controller is also minimal in count (I/O port occupation).
3.2.2 Keypad interfacing with P89C51RD2XX microcontroller

The microcontroller (P89C51RD2XX) Port 1 is used to interface the keypad. In this Port1
the pins P1.0, P1.1, P1.2 and P1.3 are used for detection of rows, and pins P1.4, P1.5, P1.6
and P1.7 are used to detect columns.

Fig 3.5 key Board schematic

19
3.2.3 Keyboard Operating Sequence

The schematic shown above represents 4x4 matrix keyboard with four rows connected to
output port and four columns connected to input port. If no key is pressed, reading the input
port will yield 1s for all columns since they are all connected to high (Vcc). If all rows are
grounded and a key is pressed one of the microcontroller to scan the keyboard continuously to
detect and identify the key pressed.

Grounding all rows and reading all columns:

To detect a pressed key, the Microcontroller grounds all rows by providing 0 to the
output latch, and then it reads the columns. If the data read from the columns isD3- D0=1111
no key has been pressed and the process is continued until a key is detected. However if one of
the columns bits is zero this means that a key press has occur. For example if D2-D0=1101
this means that a key in D1 column has been pressed after a key press is detected, the
Microcontroller will go through the process of identifying the key. Starting with the top row,
the Microcontroller grounds it by providing a low to row D0 only then it reads the columns. If
the data read is all once, no key in that row is achieved and the process is moved to the next
row. It ground the next row reads the column and checks for any zero. This process continues
until the row is identified. After identification of the row in which the key has been press the
next task is to find out which column the pressed key belongs to. This should be easy since
the micro control knows at any time which the row and column are being accessed.
From Fig , identify the row and column of the pressed key for D3-D0= 1110 for the
row, D3-D0=1011 for the column. Here the row belongs to D0 and the column belongs to D2;
therefore, key number 7 was pressed.

3.2.4 Keyboard Scanning Algorithm

The operation goes through the following stages:


1. To make sure that the preceding key has been release,0’s are output to all rows at once,
and the columns are read and checked repeatedly until all the columns are

20
high. When columns are found to be high, programmed weights for a short amount of time before
it goes to the next stage of wafting for a key be presser.
2. To see of any key is pressed, the columns are scanned over in an infinite loop until one of
them has a 0 on it. Remember that the output latches connected to rows still have there initial;
zeros (provided 1 stage one), making them grounded. After the key press detection, it waits
20ms for the bounce and the scans columns again. This serves two functions: (a) it ensures that
the first key press detection was not an erroneous one due to a spike noise and (b) the 20ms
delay prevents the same key press from being interpreted as a multiple key press. If after the20
ms delay the key still pressed, it goes to the next stage to detect which row it belongs to;
otherwise it goes back in to the loop detect a real key press.
3. To detect which row the key press belongs to, it grounds one row at a time, reading the
column each time. If it finds that all columns are high, this means that the key press cannot
belong to that row; therefore, it ground the next row and continues until it finds the row and
the key press belongs to. Upon finding the row that the key press belongs to, it sets up the
starting address for the look-up table holding the scan codes for that rows and goes to the next
stage to identify the key.
4. To identify the key press, it rotates the column bits, one bit at a time, into the carry flag
and checks to see if it is low. Upon finding the zero, it pulls out the ASCII code for that key
from the look-up table; otherwise, it increments the pointer to point to the next element of the
look-up table.
While the key press detection is standard for all keyboards, the process for determining
which key is pressed varies form the technique. The flow chart for key detection is given next.

21
3.2.5 SOFTWARE DESIGN

The declaration for accessing the signals in keil syntax is given below
Rows and Column values declaration in register (8 bit)

// key Board variables

sbit r0=P1^0; // keypad rows


sbit r1=P1^1;
sbit r2=P1^2;
sbit r3=P1^3;

sbit c0=P1^4; //keypad columns


sbit c1=P1^5;
sbit c2=P1^6;
sbit c3=P1^7;

unsigned char KeyTest(void) // key pad function declaration


{
P1=0xF0;
while (1)
{
while(P1!=0xF0)
{
r0=0; r1=1;r2=1;r3=1; // r0-r3=0111
if(c0==0) //c0-c3=0111
return '1'; // return value is ‘1’

22
3.2.6 FLOW CHART OF KEY BOARD SCANING ALGORITHM

23
Fig 3.6 FLOW CHART OF KEY BOARD SCANING ALGORITHM

This chapter showed how to interface real-world devices such as LCDs and keypads to the
P89C51RD2xx. First part described the operation modes of LCDs, then described how to
program the LCD by sending data or commands to it via its interface to the P89C51RD2xx. This
chapter also described the operation of keyboards, including key press and detection
mechanisms. The P89C51RD2xx programs were written to return the ASCII code for the pressed
key.

24
CHAPTER 4

This chapter explains some real world applications of the P89C51RD2xx, and
also includes how to interface the P89C51RD2xx to devices such as an IR transmitter
and receiver and its software functionality using embedded C language. The IR
transmitter transmits 38Khz signal which is generated using 555 timer in Astable
mode is also explained in this chapter. The concept of the interrupt and interrupt
programming is also explained.

4.1 IR OBJECT DETECTION TECHNIQUE (Passenger Counting Logic)

4.1.1 Explanation of Components

The IR LED or Infra Red Light Emitting Diode is an electronic device which gives off
or emits light when current is passed through it. Like general diode, this IR LED passes current
only in one direction and requires forward operation voltage of about 2V and forward operation
current in 10 to 20 mA range. Maximum reverse voltage that the IR LED can withstand is
typically 3 to 5V, more than this could damage the component. It does not have any current
control function, so, when the IR LED is used in a circuit, a resistor must be used in series to
limit the current flow through it. If greater range is required, this resistor may be reduced to a
minimum value with a consequent adverse effect on current consumption. Do not reduce the
value of resistor unless you do require the greater range, otherwise the relay may not trip reliably
close in due to reflections caused by the high light output.

An IR Receiver is a module, which is encapsulated with Photo Transistor whose semiconductor


junction is mounted beneath an optical lens. It is normally used in its open base configuration
and act as a light-to-voltage converter. The base is open; the value of the reverse current across
collector and emitter will depend on the amount of illumination on the base face. In dark
conditions it is near zero and under bright light it is tens or hundreds of mA.

25
4.1.2 OBJECT DETECTION TECHNIQUE DESCRIPTION OF INFRA
RED TRANS-RECEIVER

The IR object detection technique (Passenger Counting Logic ) circuit is very simple in
design. Basically it consists of a pair of IR transmitter and receiver. The transmitter and the
receiver must be positioned facing each other. Whenever the IR transmitter is activated, it
generates a invisible Infra-red light beam signal and transmits an it towards the IR receiver.

The IR sensors continuously pass the power among themselves. That means, a continuous
transfer of current is present between transmitter and receiver.

Fig 4.1 IR Sensor Pair

The IR sensor has a voltage divider circuit which is at a constant voltage for the
continuous current transmission. Whenever there is an obstruction of current between transmitter
and receiver, the current passed to receiver decreases and hence the voltage across voltage
divider decreases. The TCRT5000(Detector) sensor reacts to this change in infrared energy and
provides a low- frequency , small amplitude signal .this signal can be amplified and decoded

26
using a P89C51RD2XX microcontroller. Thus whenever a passenger enters or exits the bus, it is
noted.

To get accurate value, we will use 2 pairs of IR sensors (IR1 & IR2) placed on successive
steps in bus i.e IR1 at first step & IR2 at second step. The figure can be shown as

When there is an obstruction between the IR1 sensor and IR2 sensor conditions

1. If IR1 is first detected then IR2 is detected, then it will notice that a passenger enters into
the bus and hence count in the bus is incremented.

2. if IR2 is first obstructed, then IR1 is obstructed, the count is decremented.

3. if IR1 is detected and IR2 is not detected then no operation

4. if IR2 is detected and IR1 is not detected then no operation

After the count value is finalized, it is sent along with location of bus to central hub using GSM
module. To locate the bus, we need little help of driver. All bus stops in route are numbered
from 0 for first stop, and so on….

The driver must enter the bus stop number on arriving the stop, which is noted in
microcontroller’s memory. The count value finalized is sent along with the bus stop number.

4.1.3 Assumptions

1. There must be entry for only 1 passenger at a time to avoid miscount.


2. There must be no passengers standing on steps i.e. at entrance which otherwise leads to
continuous blocking of current in IR sensors

27
4.2 555 TIMER TO MODULATE INFRARED (IR) LIGHT

IC NE555 TIMER Description:


IC 555 TIMER used in this project for the purpose of IR sensor circuits. Its internal
circuit and description is as explained below:

Fig 4.2 Astable 555 Timer

Fig 4.2 shows an Astable 555 timer circuit. The Astable 555 timer circuit outputs a series
of pulses.

When the circuit is first turned on, the discharge pin is disconnected from ground and
output pin is set high because the trigger pin is below 33% Vcc Voltage. The capacitor, C, starts
to charge through resistors R1 and R2. The threshold pin is used to detect when the voltage
across the capacitor reaches 66.6% Vcc voltage. When the voltage across the capacitor reaches
66.6% Vcc voltage, the output pin is set low and the discharge pin is connected back to ground.
When the discharge pin is connected back to ground, the capacitor starts discharging though
resistor R2. When the voltage across the capacitor reaches 33.3% Vcc voltage, the cycle repeats
and creates a series of output pulses. An Astable circuit triggers from previous output pulse
whereas a monostable circuit requires an externally applied trigger.

28
The output pin oscillates from high to low creating a series of output pulses. The duration
the output pin stays high , , is given below.

(1)

The duration the output pin stays low, is given below:

(2)

The frequency, f, of the series of pulses is:

(3)

Design parameter values


 Capacitor 0.01µf
 Resistor R1=150Ω R2=1.2kΩ

Practical Frequency calculation of 555 Timer

The Astable 555 timer circuit can be used in the following applications:

 Astable –free running mode: the 555 can operate as an oscillator. Uses include LED and
lamp flashers, pulse generation, logic clocks, tone generation, security alarms, pulse
position modulation, etc.
 Modulate transmitters such as ultrasonic and IR transmitters
 Create an accurate clock signal

29
 Turn on and off an actuator at set time intervals for a fixed duration.

Features of NE555 Timer:

 Timing is from microseconds through hours


 O/p is compatible with CMOS , DTL and TTL
 High Temperature Stability
 Duty cycle is Adjustable
 Monostable and Astable operations

Specifications of NE555Timer:

 Supply voltage Vcc 4.5 to 15V


 Supply current (Vcc=+5V) 3 to 6 mA
 Maximum O/P Current 200mA
 Power Dissipation 600mA
 Power consumption(minimum operating) 30mW@ 5V,225mW@15V
 Operating temperature 0 to 70 C

30
4.3 REFLECTIVE OPTICAL SENSOR WITH TRANSISTOR OUTPUT

Description
The TCRT5000 is reflective sensors which include an infrared emitter and
phototransistor in a leaded package which blocks visible light. The package includes two
mounting clips.

Fig 4.3 TCRT5000

Features:
 Package type: Leaded
 Detector type: Phototransistor
 Dimensions:
L 10.2 mm x W 5.8 mm x H 7.0 mm
 Peak operating distance: 2.5 mm
 Operating range: 0.2 mm to 15 mm
 Typical output current under test: IC = 1 mA

 Daylight blocking filter


 Emitter wavelength 950 nm
 Lead (Pb)-free soldering released

Applications:
 Position sensor for shaft encoder
 Detection of reflective material such as paper, IBM cards, magnetic tapes etc.
 Limit switch for mechanical motions in VCR

31
 General purpose wherever the space is limited

32
4.4 INFRARED SENSORS
This infrared sensor also called as IR sensors, consists of two parts: 1. IR transmitter circuit 2.
IR receiver unit. The transmitter unit consists of an infrared LED and its associated circuitry.

4.4.1 CONNECTIONS OF IR TRANSMITTER

The IR transmitter circuit is shown in the figure 4.3. The transmitter circuit consists of
the following components: 1. IC 555 2. TCRT5000 (infrared emitter) 3.Resistors 4.Capacitors
The IR LED emitting infrared light is put on in the transmitting unit. To generate IR
signal, 555 IC based Astable multivibrator is used. Infrared LED is driven through transistor BC
109. IC 555 is used to construct an Astable multivibrator which has two quasi-stable states. It
generates a square wave of frequency 38kHz and amplitude 5Volts. It is required to switch ON
the IR LED

In this project, the IR transmitter using IR LED (TCRT5000) this IR LED has 2 pins one
pin is connected to Vcc through Resistor (220 Ohm) another pin is connected transistor (BC109)
collector pin and the emitter is connected to ground and base of BC109 is connected to the
NE555TIMER 3rd pin through 100Ohms of resistor

Fig 4.3 IR transmitter

33
Design parameters

1. BJT(BC109)
2. 100ohms , 220ohms resistor
3. TCRT5000 IR transmitter

4.4.2 CONNECTIONS OF IR RECEIVER:

The IR receiver circuit is shown in the figure 4.4.The receiver circuit consists of the
following components: 1.TCRT5000 (photo transistor) 2. Resistors 3.interuprt pin (INT0, INT1).

IR receiver TCRT5000 it has 2 pins first pin(Anode) is ground and second


pin(Cathode) is to Vcc and the microcontroller pin INT0(interrupts pins) is connected to a
across the resistor. It is reverse bias connection.

Fig 4.4 IR receiver

The receiver unit consists of a sensor (photo transistor) and its associated circuitry. In
receiver section, the first part is a sensor, which detects IR pulses transmitted by IR-LED.
Whenever obstruction present, the output of IR sensor momentarily transmits through a low
state. As a result a short pulse is applied to the port pin of the 8051 microcontroller. On receiving
a pulse from the sensor circuit, the controller activates the circuitry required for counting the
number of passengers.

Design parameter

1. TCRT5000 ir receiver

34
2. 22ohms,4.7ohms resister

35
4.5 P89C51RD2XX integrate with 555 timer of IR transmitter and Receiver

Fig 4.5 IR sensor schematic diagram

As shown figure 4.2, it contain NE555 Timer, two IR Sensor pairs and
microcontroller pins(INT0,INT1)

In transmitter section, the IR transmitter1 and transmiter2 (infrared emitter) are


connected to the single NE555TIMER 3rd pin (node A) through 100 Ohms of resistor

In receiver section, the IR receiver1 (photo transistor) and IR receiver2 are


connected to the microcontroller pins INT0,INT1 (interrupts pins) respectively. If there is
obstruction between transmitter and receiver, the receiver output gives 3V to 5V. Whenever
there is an obstruction of current between transmitter and receiver, the current passed to receiver
decreases and hence the voltage across voltage divider decreases. As a result a short pulse is
applied to the port pin of the 8051 microcontroller. On receiving a pulse from the sensor circuit,
the controller activates the circuitry required for counting the number of passengers.

36
The modulated IR transmitter and receivers circuits are should be connected on separate
breadboards. modulated IR receiver Verify with the multimeter that everything is conected
correctly. Then apply power to the transmitter circuit. Use an oscilloscope to observe the signal
at node A. Adjust the 10kohm variable resistor until the signal at node A is a 38 kHz series of
pulses. Apply power to the receiver circuit Point the IR light emitting diode (LED) on the
transmitter to the detector on the receiver.if the visible led is blinking randomly, put exposed
35mm camera film around the IR detector.

37
4.6 Software design

4.6.1 Embedded Software Algorithms


They are
1.Round-Robin (no interrupts)
2.Round-Robin (with interrupts)
3.Function-Queue Scheduling
4.Real-Time OS
 Problem with Round-Robin (no interrupts)
 Response time slow
 Problem with Function-Queue Scheduling
 Quite complex
 Large memory space is required for execution
 Higher priority tasks may be waiting on results produced by lower priority
tasks…
 Problem with Real-Time OS
 it needs kernel
4.6.2 Round-Robin (with interrupts)
 In this architecture the interrupt service routines (ISR) deal with the very urgent needs of
the hardware and then set flags
 This architecture gives us a little bit more control over priorities. The interrupt service
routines can get good response, because the hardware interrupt signal causes the
microcontroller to stop whatever it is doing in the main function and execute the interrupt
routine instead.
 Effectively, all of the processing that we put into the interrupt routines has a higher
priority than the task code in the main routine.

 Further, since we can usually assign priorities to the various interrupts in the system,
we can control the priorities in the interrupt routines as well.

 Much better response time (low interrupt latency).


 Main still slow (i.e., lower priority then ISRs).
 Interrupts have higher priority than task code (by the interrupt mechanism..).

The Microcontroller can serve several devices. The Interrupt is the method to indicate
the microcontroller by sending it an interrupt signal. After receiving an interrupt, the
microcontroller interrupts whatever it is doing and serves the device. The program associated
with the interrupt is called the interrupt service and routine (ISR).
There must be interrupt service routine (ISR), or interrupt Handler. When an

38
interrupt is invoked, the microcontroller runs the interrupt service routine. For every interrupt,
there is a fixed location set aside to hold the addresses of ISRs is called interrupt vector table

Interrupt Vector Table


In 8051, all interrupts are vectored interrupts and have vector locations as
Listed in Table when interrupt is activated 8051 reads the address of interrupt service routine
from the vector location.
Interrupts Vector location

External hardware interrupt 0 (INTO) 0003H

Timer 0 internet (TFO Overflow) 00OBH

External hardware Interrupt 1 (INT1) 0013H

Timer 1 interrupt (TF1 Overflow) 001BH

Serial communication interrupt (Rl and Tl) 0023H


(Reception/Transmission of Serial Character)

Table 4.1(a) Interrupt vector table for 8051

4.6.3 Steps in Executing an Interrupt


 µC finishes the instruction it is executing and saves the address of the next instruction
(PC) on the stack
 it saves the current status of all the interrupts internally
 it jumps to a fixed location in memory called the interrupt vector table
 the microcontroller gets the address of the ISR from the interrupt vector table and jumps
to it and starts to execute the ISR until it reaches the last instruction RETI
 the microcontroller returns to the place where it was interrupted, it gets the PC address
from the stack by popping the top two bytes of the stack into the PC and then it starts to
execute from that address

39
Interrupt Enable Register (IE)

Fig 4.6 Interrupt Enable Register (IE)

Enabling and Disabling an Interrupt


When 8051 is reset, all interrupts are disabling. These are enabled by software. All of the
bits that generate interrupts can be set or cleared by software, with the same result as though it
had been set or cleared by hardware. That is, interrupts can be generated or pending interrupts
can be cancelled in software.
Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit
in Special Function Register IE . IE contains also a global disable bit, EA, which disables all,
interrupts at once.

40
Fig 4.7 Activation of INTO and INT1

Type of interrupt
1. level triggered interrupt
2. Edge triggered interrupt
In this project, the edge triggered interrupt is used.
Level triggered interrupt
In this mode, INT0 and INT1 are normally high and if the low level signal is applied to
them ,It triggers the Interrupt. Then the microcontroller stops and jumps to the interrupt vector
table to service that interrupt .This is all the Level Triggered or Level
Activated interrupt and is the default mode /reset of 8051

Edge triggered interrupt


Upon reset 8051 makes INT0 and INT1 low l Level-Triggered Interrupt. To make them
Edge -Triggered Interrupt, we must program the bits of the TCON Register. The TCON register
holds among other bits and IT0 and IT1 flags bit the determine level- or edge triggered mode. Of
the hardware interrupt IT0 and IT1 and bits D0 and D2 of the TCON Register Respectively. In
this Section, we have discuss only INT0 and
INT1 external Hardware Interrupts

41
4.6.4 Programming External hardware interrupt for INT0 and INT1
The 8051 has two external hardware interrupts PIN 12 (P3.2) and Pin 13 (P3.3) of
the 8051, designated as INT0 and INT1 are used as external hardware interrupts. Upon activation
of these pins, the 8051 gets interrupts in whatever it is doing and jumps to the vector table to
perform the interrupt service routine
 IR sensor1 is connected to INT0 pin(P3.2) and IR sensor2 is connected to INT1pin(P3.3)
 In this project, the external interrupts ex0 and ex1 used in the edge level triggered mode
i.e IT0=1,IT=1
 STEPS IN ENABLING AN INTERRUPT

Figure 4.6 IE (interrupt enable) register


 Bit D7 of the IE register (EA) must be set to high to allow the rest of register to
take effect.
 If EA=1, interrupts are enabled and will be respond to if their corresponding bits
in IE are high. If EA=0, no interrupt will be respond to, even if the associated bit
in the IE register is high.
 EA=1 is to enable all interrupts
 EX1=1 is to enable external interrupt 1
 and EX0=1 is to enable external interrupt 0
IE=0x85; //Enable INT0 and INT1 (1000 0101)

4.6.5 Foreground ISRs and background application of Bus-ECU embedded


software design
FORE GROUND ISR PROGRAM:

/* shared variables – Global Resources*/


Unsigned char count ; // Used for maintaining the count.
Unsigned char flag; // used for passenger increment/ decrement
void _Up() interrupt 0 // INT0
{
if(Flag==0) Flag=1;

42
if(Flag==2)
{
Count--; // passenger decrementing
Flag=0;
}
}

void _Down() interrupt 2 //INT1


{
if(Flag==1)
{
Count++; // passenger incrementing
Flag=0;
}
if(Flag==0) Flag=2;
}

BACK GROUND APPLICATION TASK:

void UpdateService(void)
{
Unsigned char Temp;
Temp=0;
while(1)
{
//To counting information
} }
void MainMenu(void)
{
switch(key)
{
case '1': //This is IR passenger counting logic.
UpdateService();
case '2':// GSM configuration
} }
void Start(void)
{
This function gives a authentication of driver.
MainMenu();
}

Listing-1: Foreground ISRs and background application of Bus-ECU


embedded software design
For the design of the embedded software by Round robin with interrupt driven architecture, the
passenger counting hardware logic with the microcontroller is done by interfacing and
programming the external interrupt pins. The foreground ISRs will now run irrespective of the
background application created as indicated in Listing – 1. The programmed interrupts were

43
working properly when we use any standard embedded software debugger like Keil µVision4
IDE. But, later when the application is ported onto the embedded target, the shared resources
(shared variables ‘Count’ and ‘Flag’, in this case) of ISRs and Application were malfunctioning.
In order to debug this problem in real-time, repetitive efforts were taken in order to understand
and identify the bugs. Care should be therefore taken with respect to the usage of shared
variables/resources between Interrupts and Application designed.

This chapter showed how to interface real-world devices such as sensor


to the P89C51RD2xx and 555 timer and also how to program it in embedded C. An interrupt is
an external or internal event that interrupts the microcontroller to inform it that a device needs its
service. Every interrupt has a program associated with it called the ISR, or interrupt service
routine. The P89C51RD2xx has 6 interrupts. The interrupts are for Reset, two for timers, two for
external hardware interrupts, and a serial communication interrupts. The P89C51RD2xx can be
programmed to enable or disable an interrupt. This chapter showed how to program interrupts in
embedded C.

44
5.1 GSM modem
Introduction
Sim300 GSM Smart Modem is a multi-functional, ready to use, rugged unit that can be
embedded or plugged into any application. The Smart Modem can be controlled and customized
to various levels by using the standard AT commands. The modem is fully type-approved, it can
speed up the operational time with full range of Voice, Data, Fax and Short Messages (Point to
Point and Cell Broadcast).

Description of the interfaces


The modem comprises several interfaces:

- LED Function including operating Status


- External antenna
- Serial and control link
- Power Supply
- SIM card holder

LED Status Indicator


The LED will indicate different status of the modem:

- OFF Modem Switched off


- ON Modem is connecting to the network
- Flashing Slowly Modem is in idle mode
- Flashing rapidly Modem is in transmission/communication (GSM only)
GSM is one of the latest mobile technologies using smart MODEM, which can easily
interfaced to embedded microcontrollers. Now everything is going to be automated using this
technology, using this technology we can access the devices remotely. Using GSM and GPS now
we can identify the people, vehicles etc in anywhere of the world.

MODEM is communicating with the microcontroller using AT commands, for example if we


want to send an SMS to number 98xxxxxxxxx,the commands we have to send is
AT+CMGS=”<98xxxxxxxxxx>”, <enter>, <message>, <ctrl-Z>.

45
In this project it is used to send SMS to the mobile

In this project MODEM is communication with the microcontroller through serial port, the
microcontroller will send the commands to the modem through RS 232.and the data is read
through serial port therefore to make compatible computer serial port with microcontroller serial
port we are using the RS 232 converter.

The GSM module has GSM modem, DB9 connector, MAX 232 line driver for its
communication with the microcontroller. Since the operating voltage different for the
microcontroller and the modem, the MAX 232 is used which provides the electrical interface
between an asynchronous communication controller and the serial port connector .The serial port
connector here is DB9 connecter.

46
Fig GSM module interface with P89C51RD2XX
The microcontroller has TTL logic levels for TXD, RXD pins and for RS232 different voltage
levels logics. So for proper communications MAX232 is used to convert RS 232 voltages to TTL
logic voltage levels. The baud rate is set to 9,600 bits/s.
• GSM modems in use has baud rate of 9600 bits/sec.
• It enables us to send and receive 30 messages at a time.
• With GSM modems, you must insert a valid SIM card into the slot on the front of the
modem.
• Once the modem has been prepared for use, connect it to a serial port on your PC using
the data cable that is included with the modem.

SERIAL PORT PROGRAMING (software design)

In this section, we discuses the serial communication registers of the 8051 and show how to
program them to transfer and receive data serially.

47
The 8051 divides crystal frequency by 12 to get the machine cycle frequency.

Machine cycle frequency=XTAL freq/12

In the case of XTAL = 11.0592MHz, the machine cycle frequency is 921.6 kHz.
The 8051 serial communication UART circuitry divides the machine cycle frequency of 921.6
kHz by 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 we will use to find the Timer to set the baud rate.
The Timer 1 is used to set the baud rate it must programmed in mode 2 that is 8 bit, auto
reload.

Fig TMOD registers


Calculate TH1:
The baud rate is 9600.
Baud rate = 28,800/-TH1
TH1= -3 ( FD is Hex value)
SBUF register
SBUF is an 8-bit register used in serial communication in the 8051. for a byte of data to be
transferred via TxD line, it must placed in the SBUF register. Similarly, SBUF holds the byte of
data when it received by the 8051’s Rxd line
SCON (serial control) register.
The SCON register is an 8-bit register used to program the start bit, stop vit, and data bits of data
framing
In appendix, fig shows various bits of the SCON register.

48
 TI (transfer interrupt) is raised when the last bit of framed data, the stop bit, is
transferred, indicating that the SBUF register is ready to transfer the next byte,
 RI (received interrupt), is raised when the entire frame of data, including the stop bit, is
received.

Fig SCON registers

//SERIAL COMMUNICATION BAUDRATE-9600

void Init_UART()
{
TMOD|=0x20; // use Timer 1 , mode 2 , 8-bit auto-reload
TH|=0xFD; // 9600 baud rate
SCON|=0x50; // serial mode 1, where an 8-bit data is framed with start and stop bits
TR1=1; // Start the Timer
}
void Tx_Char(unsigned char Data)
{
SBUF=Data; // place data in buffer
while(!TI); // wait until data is transmitted
TI=0; // clear instruction
}
unsigned char Rx_Char()
{
while(!RI); // wait to receive
RI=0; // clear instruction
return SBUF;

49
CHAPTER 5

CIRCUIT DIAGRAM DESCRIPTION

5.1 Schematic diagram of BUS ECU module

Fig 6.1 Schematic diagram of BUS ECU

6.2 Circuit Description

Power supply: The Regulated power supply (RPS) is used to provide VCC to all the blocks in
this project. The range of the output power of RPS is 0V-5V.

50
Microcontroller P89C51RD2XX connections:

It includes Keypad interfacing, LCD interfacing, MAX 232 connections and RS232 connections.
IR connections.

 The 5V DC supply from the power supply circuit is given to the pins 40(VCC) & 20pin
(GND) of P89C51RD2XX for its Working.
 The Oscillatory circuit with crystal frequency 11.0592MHz is give to the 18(XTAL2) &
19(XTAL1) pins of P89C51RD2XX. The frequency 11.0592 is used particularly for
setting the proper baud rate for serial data transfer.
 The 9(RST) pin is connected to reset circuit consisting of a resistor (8.2K) & capacitor
(10µf). This circuit enables to reset the system to the original configuration.
 The Port 1 is used to interface the keypad. In this Port1 the pins P1.0, P1.1, P1.2 and P1.3
are used for detection of rows, and pins P1.4, P1.5, P1.6 and P1.7 are used to detect
columns.
 The Port0 is used to interface LCD data lines. Through this Port the P89C51RD2XX can
send the command and data bytes.
 The Port 2.5 is connected to RS pin of LCD, and Port 2.6 is connected to RW pin of
LCD, Port 2.7 is connected to EN pin of LCD. These pins enable the LCD to operate in
different modes.
 The pins P3.0 (RxD) and P3.1(TxD) are connected to the 11, 12 pins of MAX 232 which
is used as a level translator. Through these pins the data is send to microcontroller.
 The pins 2(RxD),3(TxD) of RS 232 is connected to 13(TxD) and 14(RxD) pins of MAX
232 for data transmission.
 The P3.2 (INT0), P3.3 (INT1) pins are connected to IR Receiver through resistors.

555 TIMER and IR transmitter connections:

 The pin 3 of 555 timer is a output pin which is connected to Base of the transistor through
the 100ohms resistor at the Transmission side.

51
6.2.1 WORKING:
The power supply (5V DC) is given to the IC’s on the microcontroller board for their
operation. At this point all the peripherals are initialized and checked for their proper interfacing
.after the access system reached to ideal state .if you enter the ITS , it ask for the password. This
can be seen on the LCD screen where the countdown displayed .the key pad now waits for a key
press if the User ID and password is entered, first it is stored in the temporary register of the
P89C51RD2XX. Now the microcontroller reads the password is compared with entered
password numbers. If it is matched the driver is authenticated and if the password is mismatched
the system access denied. When the Driver authentication is completed then the IR sensor are
enabled then the passenger counting started When there is an obstruction between the IR1
sensor and IR2 sensor condition. If IR1 is first detected then IR2 is detected, then it will notice
that a passenger enters into the bus and hence count in the bus is incremented. if IR2 is first
obstructed, then IR1 is obstructed, the count is decremented. After the count value is finalized, it
is sent along with location of bus to central hub using GSM module.

6.3 Application level flow chart


52
53
Fig 6.2 application level flow chart

54
Complete application level flow chart is show above. In this flow chart Port 1.0 to Port 1.3 and
Port 1.4 to Port 1.7 pins are configured as a input and output pins respectively for interfacing the
Rows and Columns of the keypad for Authentication. After password checking Menu driven
application gives below selections to the user (i) Service (ii) Configure. In Service application
selection the foreground task initializes the two interrupts (i.e INT0, INT1). First INT0 is used
for IR sensor1 and INT1 is used for sensor 2. These sensors are used to detect the passengers and
Background application is used to count the number of passengers. In configure selection
application we can reconfigure the settings such as bus route, change password, change mobile
number etc.

6 .4 Hardware Testing

6.4.1 Testing the Hardware:

Initially the schematic must be prepared according to the application requirement,


then it must be checked thoroughly for proper interconnection, the data base of the netlist and
the packaging of the individual component are doubly cross checked to ensure that the
interconnection pattern is prepared accordingly. Once the schematic is ensured that it is error free
then it can be forwarded preparation of the PCB

6.4.2 LCD testing:

Initially the contrast needs to be adjusted so that the LCD data can visible clearly. Now a new
project can be created in the Keil to test the LCD only. The code is written like the first line of
the LCD should display the text as “welcome @ vasavi” and the second line should display the
text as “Enter ITS”. The project is compiled and the .HEX file resultant of the compilation is
downloaded in to controller using the parallel port programmer. By running the code the LCD
should display the text as “welcome @ vasavi” in the first line and “ Enter ITS” in the second
line. If the output is same as expected then the device driver and the hardware corresponding to it
are working fine.

6.4.3 Keyboard testing:

55
The scanning of the designed keyboard has its own style, so the same can be written as
instructions by using a new software project with the LCD support. The project is designed to
scan the keyboard and to print the result in the LCD. If the application created gives the
appropriate key scan codes then the code can be confirmed as working fine along with its
hardware.

56
CHAPTER 6

6.1 RESULTS ACHIEVED

The system development precedes different stages and confirming that the present stage
is giving accurate results should do proceeding from one stage to other stage. The different
stages in this system are given like

• Design of Bus Electronics Unit

• Passenger counting software Logic using 89C51 interfacing with IR sensor.

• Driver interface with 4x4 Matrix Keypad, GSM module and 2x16 LCD is done.

• The software is implemented using Keil4µVision IDE.

• The testing of the software after integrating the IR logic with Keypad and LCD design is
done.

57
6.2 Simulation results of keil software

Fig 6.1 snapshot of complete debugging

The Fig is the snapshot of Keil uVision 4 IDE. It is used for coding and debugging and it
generates .hex file from the source file. This hex file can be used by device programmer.

58
6.2.1 Counter increment snapshot

6.2.2 Counter decrement snapshot

59
6.3 Flash magic simulation results

6.3.1 Flash magic Device signature setting

Fig 8.3 snapshot of Flash magic Device signature setting

The Fig is the snapshot of Flash magic Device signature setting. Philips P89C51
microcontroller has an on-chip Flash program memory with ISP (In-System Programming),
which allows the microcontroller to be programmed without removing the microcontroller
from the board and also the microcontroller, which previously programmed can be
reprogrammed without removal from the board.
The microcontroller must be powered up in a special ’ISP mode’ to perform the ISP operation.
The ISP mode allows the microcontroller to communicate with a host device such as PC
through a serial (RS-232) port. The host sends commands and data to the microcontroller. The
commands can be erase, read, and write. After the completion of the ISP operation, the
microcontroller is reconfigured and has to be reset or power cycled so the microcontroller will
operate normally.

60
6.3.2 Flash magic Loading HEX file

Fig 8.4 snapshot of Loading HEX file

The Fig is the snapshot of FLASH MAGIC Philips Serial ISP programming utility. This
software is used for programming the microcontroller (P89C51) chip. It takes the .hex file as
input and programs the microcontroller. The above figure shows the screen shot of FLASH
MAGIC software. HEX file has to be loaded into software using browse option. When start
option is selected it automatically clears the flash and writes the program into memory and
verifies the written program.

61
6.4 BUS Electronic Control Unit

Fig 8.5 Physical connectivity of complete setup

The Fig is the snapshot of Snapshots of Bus Electronic Control Unit .This is the hardware setup
after everything is connected in place and also interfacing with IR sensors, LCD,GSM and
keypad

62
Fig 8.6 snapshot of Passenger increment

Fig 8.7 snapshot of Passenger increment

63
6.5 CONCLUSION
This project is aimed at providing intelligent public transportation system using different levels
as mentioned earlier. The Bus ECU unit is the most important unit in ITS because It detects the
number of people entering or leaving the bus, it also counts the number of seats left. The Bus
ECU unit contains an algorithm which gives the information about passengers count, bus route,
and Bus number to the Central Hub.

The main advantage of Bus ECU is low cost and higher reliability, and
less power requirement. The approach in this project provides efficient way for achieving the
goals of Intelligent Transportation Systems which can also be extended to cell phones through
GPRS capabilities.

Future scope

The Project approach provides way for better achieving the goals of Intelligent
Transportation Systems and can also be extended to cell phones through GPRS capabilities.

64
REFERENCES

[1] Janci Gillispie Mazidi, Muhammad Ali Mazidi, The 8051 micro controller

And embedded systems,l PHI Prentice hall India, Easten Economy

Edition, www.phindia.com, 2005.

[2] Kenneth J. Ayala, The 8051 Microcontroller, architecture, Programming and

Applications, Penram international publishing Pvt. Ltd. 1996.

[3] Arnold S. Berger, Embedded systems design, an introduction to process, tools, and

Techniques, CMP Books, 2005. www.cmpbooks.com

[4] Yashvant Kanetkar, Let Us C, BPB Publications, 1999 www.bpbpub.com

[5] Dreamtech Software Team, Programming for Embedded systems, WILEY Publishing,

Inc, 2003.

Websites:

http://www.semiconductors.philips.com. for 8051 core architecture P89C51RD2XX

www.datasheetcatalog.com/datasheet/M/MAX232.shtml for MAX232 datasheets.

www.wikipedia.org for 555 Timer applications and description

http://www.vishay.com/docs/83760/tcrt5000.pdf for IR sensor

http://www.8051projects.net/lcd-interfacing/ for LCD interfacing details.

www.google.co

65
APENDEX A

A.1 Microcontroller(P89c51 microcontroller)

A.1.1introduction
TheP89C51RA2/RB2/RC2/RDx contain non-volatile16KB/32KB/64KB Flash program memory
that is both parallel programmable and serial In-System and In-Application Programmable. In-System
Programming (ISP) allows the user to download new code while the microcontroller sits in the
application. In-Application Programming (IAP) means that the microcontroller fetches new program
code and reprograms itself while in the system. This allows for remote programming over a modem
link.A default serial loader (boot loader) program in ROM allows serialIn-System programming of the
Flash memory via the UART without the need for a loader in the Flash code. For In-Application
Programming, the user program erases and reprograms the Flash memory by use of standard routines
contained in ROM. The device supports 6-clock/12-clock mode selection by programming a Flash bit
using parallel programming or In-System Programming. In addition, an SFR bit (X2) in the clock
control register (CKCON) also selects between 6-clock/12-clock mode. Additionally, when in 6-clock
mode, peripherals may use either 6 clocks per machine cycle or 12 clocks per machine cycle. This
choice is available individually for each peripheral and is selected by bits in the CKCON register. This
device is a Single-Chip 8-Bit Microcontroller manufactured in an advanced CMOS process and is a
derivative of the 80C51 microcontroller family. The instruction set is 100% compatible with the
80C51 instruction set. The device also has four 8-bit I/O ports, three 16-bit timer/event counters, a
multi-source, four-priority-level, nested interrupt structure, an enhanced UART and on-chip oscillator
and timing circuits.

A.1.2 Features and its advantages


 80C51 Central Processing Unit
 On chip Flash Program Memory with In-System Programming (ISP) and In-Application
Programming
 Boot ROM contains low level Flash programming routines for downloading via the

66
UART
 Can be programmed by the end-user application(IAP)
 Supports 6-clock/12 clock mode via parallel programmer(default clock mode after Chip
Erase is 12-clock
 Speed up to 20MHz with 6-clock cycles per machine cycle
(40MHz equivalent performance), up to 33MHz with 12 clocks per machine cycle
 Fully static operation
 RAM expandable externally to 64Kbytes
 Four interrupt priority levels
 Seven interrupt sources
 Four 8-bit I/O ports
 Full-duplex enhanced UART

A.1.3 PIN DESICRIPTION

Fig A.1 P89C51RD2XX pin diagram

67
PIN DESCRIPTION:
Ground: 0 V reference.

Power Supply: This is the power supply voltage for normal, idle, and power- down operation.
Port 0: Port 0 is an open-drain, bidirectional I/O port. Port 0 pins that have 1s written to them float and can
be used as high-impedance inputs. Port 0 is also the multiplexed low-order address and data bus during
accesses to external program and data memory. In this application, it uses strong internal pull-ups when
emitting 1s.

Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups on all pins. Port
1 pins that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs. As
inputs, port 1 pins that are externally pulled low will source current because of the internal pullups.

Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Port 2 pins that have 1s written to them
are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 2 pins that are externally
being pulled low will source current because of the internal pull-up.Port 2 emits the high-order address byte
during fetches from external program memory and during accesses to external data memory that use
16-bit addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when emitting 1s.

During accesses to external data memory that use 8-bit addresses (MOV @Ri), port 2 emits the contents of
the P2 special function register.

Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. Port 3 pins that have 1s written to them
are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 3 pins that are externally
being pulled low will source current because of the pull-ups. Port 3 also serves the special features of the
89C51RA2/RB2/RC2/RD2xx, as listed below:

RxD (P3.0): Serial input port

TxD (P3.1): Serial output port

INT0 (P3.2): External interrupt

INT1 (P3.3): External interrupt

T0 (P3.4): Timer 0 external input

T1 (P3.5): Timer 1 external input


68
WR (P3.6): External data memory write strobe

RD (P3.7): External data memory read strobe

Reset: A high on this pin for two machine cycles while the oscillator is running, resets the device.
An internal resistor to VSS permits a power-on reset using only an external capacitor to VCC.
Address Latch Enable: Output pulse for latching the low byte of the address during an access to
external memory. In normal operation, ALE is emitted twice every machine cycle, and can be
used for external timing or clocking. Note that one ALE pulse is skipped during each access to
external data memory. ALE can be disabled by setting SFR auxiliary.0. With this bit set, ALE
will be active only during a MOVX instruction.
Program Store Enable: The read strobe to external program memory. When executing code
from the external program memory, PSEN is activated twice each machine cycle, except that two
PSEN activations are skipped during each access to external data memory. PSEN is not activated
during fetches from internal program memory
External Access Enable/Programming Supply Voltage: EA must be externally held low to
enable the device to fetch code from external program memory locations. If EA is held high, the
device executes from internal program memory.

The value on the EA pin is latched when RST is released and any subsequent changes have no
effect. This pin also receives the programming supply voltage (VPP) during Flash programming

Crystal 1: Input to the inverting oscillator amplifier and input to the internal clock generator circuits.

Crystal 2: Output from the inverting oscillator amplifier.

Features of 8051
It Consists of
 Bit ALU , with 2 registers A & B
 11 bit program counter & data pointer
 Bit program status word
 8 bit stack pointer
 256 bytes internal RAM

69
 4registers banks, each containing 8 registers
 16bytes , which may be addressed at bit level
 80 bytes of general purpose data
 Internal ROM/EPROM / Flash memory of 64KB

 discrete I/O pins, grouped as four 8 bit ports

 Full duplex UART

 Two 16 bit timer/counter – T0 & T1

 Two external & three interrupt sources

Control registers –TCON,TMOD,SCON,PCON and IP & IE oscillator & clock circuits

A.1.4 Architecture of P89C51 microcontroller

70
Fig A.2 Architecture of P89C51 microcontroller

Registers:

71
 8051 has 34 general purpose or working registers. Two of them A & B, hold results
of many instructions, particularly mathematical and logical operations of 8051 CPU.
 The other 32 registers arranged as a part of internal RAM in 4 banks RB0-RB3.
 A (accumulator) register is used for many operations- Addition, Subtraction, integer
multiplications & division and Boolean bit manipulations.
 Register B is used with register A for multiplication & division operations and also
for data transfer.

PROGRAM STATUS WORD (PSW):

 CY: Carry out from accumulator MSB of ALU operand


 AC: Auxiliary carry for BCD operations
 FO: General purpose
 RS1 & RS0: For register banks selection ( RB0-RB3)
 OV: Overflow flag
 P: Parity of accumulator set by hardware to 1 if it contains odd no of 1’s
NOTE: the contents of (RS1-RS0) enable the working register banks as follows

RS1 RS0 BANK and REGISTER


0 0 Bank 0-(00H-07H)

0 1 Bank 1-(08H-0FH)

1 0 Bank 2-(10H-17H)

1 1 Bank 3-(18H-1FH)

 Carry flag is set whenever there is carry out from the MSB. This flag is after 8bit

72
ADD/SUB operation.

 It can also be set to 1 or 0 directly using SETB C or CLR C

 Auxiliary carry : if there is a carry from D3 to D4 position during Add/Sub


operation, this bit will set. Otherwise, it is cleared. This flag is used for BCD operations.

 Parity flag reflects the number of 1’s in A. If ‘A’ contains an odd number of 1’s , then
P=1. Therefore P=0, if A has an even number of 1’s.

Overflow flag: This flag is set whenever the result of a signed number operation is too large
to be accommodated in 7 bits , causing the higher order bit to overflow into the sign bit.

A.2 INTERRUPTS

 An Interrupt is an external or internal event that interrupts the microcontroller to inform it


that a device needs its service.
 Whenever any device needs its service, the device notifies the microcontroller by sending
it an interrupt signal.
 Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and
serves the device.
 The program which is associated with the interrupt is called the interrupt service routine
(ISR) or interrupt handler. For every interrupt ,there is a fixed location in memory that
holds the address of its ISR. The group of memory locations set aside to hold the address
of ISRs is called the interrupt vector table shown below.

A.2.1. Steps in Executing an Interrupt

 µC finishes the instruction it is executing and saves the address of the next instruction
(PC) on the stack

 it saves the current status of all the interrupts internally

 it jumps to a fixed location in memory called the interrupt vector table

 the microcontroller gets the address of the ISR from the interrupt vector table and jumps

73
to it and starts to execute the ISR until it reaches the last instruction RETI

 the microcontroller returns to the place where it was interrupted, it gets the PC address
from the stack by popping the top two bytes of the stack into the PC and then it starts to
execute from that address

The 8051 provides five interrupt sources. These are listed below.
1. Timer 0 (TFO) and timer 1 (TF1) interrupt.
2. External hardware interrupts, INT0 and INT1.
3. Serial communication interrupt TI and RI
Interrupt Vector Table
In 8051, all interrupts are vectored interrupts and have vector locations as listed in Table
when interrupt is activated 8051 reads the address of interrupt service routine from the vector
location.

Interrupt Vector location


External hardware interrupt 0 (INTO) 0003H
Timer 0 internet (TFO Overflow) 00OBH
External hardware Interrupt 1 (INT1) 0013H
Timer 1 interrupt (TF1 Overflow) 001BH
Serial communication interrupt (Rl and Tl) 0023H
(Reception/Transmission of Serial Character)

Table A.1 Interrupt Vector Table

A.2.2 Enabling and Disabling an Interrupt


When 8051 is reset, all interrupts are disabling. These are enabled by software. All of the
bits that generate interrupts can be set or cleared by software, with the same result as though it

74
had been set or cleared by hardware. That is, interrupts can be generated or pending interrupts
can be cancelled in software.
Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit
in Special Function Register IE . IE contains also a global disable bit, EA, which disables all,
interrupts at once.IE register is shown below.

Fig A.3 IE register

A.2.3 Programming External Hardware Interrupts

TCON(Timer/Conter)register:

75
Fig A.4 TCON(Timer/Conter)register

Pins, P 3.2 (pin number 12) and P 3.3 (pin number 13) in port 3 are used as external
hardware interrupts INT0 and INT1, respectively. The external Interrupts INT0 and INT1 can
each be either level-activated or transition-activated, depending on bits IT0 and IT1 in Register
TCON. The flags that actually generate these interrupts are bits IEO and IE1 in TCON. When an
external interrupt is generated, the flag that generated it is cleared by the hardware when the
service routine is vectored to only if the interrupt was transition-activated. If the interrupt was
level-activated, then the external requesting source is what controls the request flag, rather than
the on-chip hardware.

76
Fig A.5 Activation of INT0 and INT1

If ITx (IT0=IT1) = 0, external interrupt x is triggered by a detected low at the INTx pin. If
ITx = 1, external interrupt x is edge-triggered. In this mode if successive samples of the INTx pin
show a high in one cycle and a low in the next cycle, interrupt request flag IEx(IE0=IE1=1) in
TCON is set. Flag bit IEx then requests the interrupt.

Since the external interrupt pins are sampled once each machine cycle, an input high or
low should hold for at least 12 oscillator periods to ensure sampling. If the external interrupt is
transition-activated, the external source has to hold the request pin high for at least one machine
cycle, and then hold it low for at least one machine cycle to ensure that the transition is seen so
that interrupt request flag IEx will be set. IEx will be automatically cleared by the CPU when the
service routine is called.

If the external interrupt is level-activated, the external source has to hold the request
active until the requested interrupt is actually generated. Then it has to deactivate the
request before the interrupt service routine is completed, or else another
interrupt will be generated.

77
A.2.4 Timer Interrupts and Programming
The Timer 0 and Timer 1 Interrupts are generated by TFO and TF1, which are set by
a rollover in their respective Timer/Counter registers (except see Timer 0 in Mode 3). When a
timer interrupt is generated, the flag that generated it is cleared by the on-chip hardware when
the service routine is vectored.
As the timer flag (TF) is set (=1) when the timer rolls over. In polling method, the TF
is monitored with the instruction ‘JNB TF, target addresses. We have to wait until the TF is
raised. The problem with this polling method is that 8051 cannot do anything else until TF is
set to high. This problem can be solved using interrupt method. If the timer interrupt in the
IE register is enabled, TF is set whenever the timer is rolled over and the 8051 is
interrupted. Thus the 8051 can perform anything else until it is interrupted. After
interruption (timer rolling over) only the 8051 remains busy in executing interrupt service
routine.
A.2.5 Serial Communication Interrupts and Programming

The Serial port Interrupt is generated by the logical OR of RI and TI. Neither of these
flags is cleared by hardware when the service routine is vectored to. In fact, the service
routine will normally have to determine whether it was RI or TI that generated the
interrupt, and the bit will have to be cleared in software.

In this case, the 8051 can perform other tasks in addition to serial communication, i.e.
sending and receiving data from serial communication port.

We know that transmit interrupt (TI) flag is set (=1) when the last bit of the framed
data (stop bit) is transmitted. This indicates that the SBUF register is ready to transmit the
next byte. The receive interrupt (RI) flag is set (=1) when the complete frame of data (with
stop bit) is received. RI indicates that the received byte needs to be picked up before it is
lost by new incoming serial data.
All the above concepts are applied equally using polling or an interrupt. Only difference is in
serving the serial communication needs. In polling method, the flag (TI or RI) is
monitored. The 8051 cannot do anything else until this flag is set to high. This problem is
solved using interrupt method. When 8051 has received a byte or is ready to send the next
byte, the RI or TI flag respectively is set. Any other work can be performed while the serial

78
communication needs are served. There is a single interrupt set aside for serial
communication. If IE register (IE.4) is enabled, when RI or TI is set (= 1), the 8051 is
interrupted. When interrupted, the ISR written at 0023h is executed by 8051. In ISR, the TI
and RI flags must be examined to check which one caused the interrupt and according to
flag the response is given.

APENDEX B

B.1 SERIAL COMMUNICATION


79
B.1.1 Introduction

In order to connect microcontroller to a modem or a pc to modem a serial port is used.


Serial is a very common protocol for device communication that is standard on almost every PC.
Most computers include two RS-232 based serial ports. Serial is also a common communication
protocol that is used by many devices for instrumentation; numerous GPIB-compatible devices
also come with an RS232 port. Furthermore, serial communication can be used for data
acquisition in conjunction with a remote sampling device.

The concept of serial communication is simple. The serial port sends and receives bytes
of information one bit at a time. Although this is slower than parallel communication, which
allows the transmission of an entire byte at once, it is simpler and can be used over longer
distances. For example, the IEEE 488 specifications for parallel communication state that the
cabling between equipment can be no more than 20 meters total, with no more than 2 meters
between any two device. Serial, however, can extend as much as 1200 meters.

Typically, serial is used to transmit ASCII data. Communication is completed using 3


transmission lines.(1) Ground, (2) Transmit and (3) Receive. Since serial is asynchronous, the
port is able to transmit data on one line while receiving data on another. Other lines are available
for handshaking, but are not required. The important serial characteristic are baud rate, data bits,
stop bits, and parity. For two ports to communicate, these parameters much match.

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

B.2 RS 232
RS-232 is the component which is used to connect system(pc) to micro controller.

80
In telecommunications, RS-232 (Recommended Standard 232) is a standard for
serial binary data signals connecting between a DTE (Data Terminal Equipment) and a DCE
(Data Circuit-terminating Equipment). It is commonly used in computer serial ports RS-232
devices may be classified as Data Terminal Equipment (DTE) or Data Communications
Equipment (DCE); this defines at each device which wires will be sending and receiving each
signal
RS232 is limited to point-to-point connections between PC serial ports and devices.
RS 232 hardware can be used for serial communication up to distances of 50 feet.

DB9-Pin connector:

Fig B.1 DB9-Pin connector

Pin Functions:

Data: TXD on pin3, RXD on pin 2.

81
Since RS-232 standard is not compatible therefore it requires a line drivers (voltage
converters) such as MAX 232 to convert the TTL logic levels to the RS232 voltage levels, and
vice versa.

B.3 MAX 232


Since the RS 232 is not compatible with today’s microcontrollers, the design need a
line driver (voltage converter ) to convert the RS232’s signals to TTL voltage levels that will be
acceptable to the 8051’s TXD and RXD pins. One example of such a converter is max232

The MAX232 is an integrated circuit that converts signals from an RS-232 serial port to
signals suitable for use in TTL compatible digital logic circuits. The MAX232 is a dual
driver/receiver and typically converts the RX, TX, CTS and RTS signals.

Fig B.2 MAX 232

One advantage of the MAX 232 chip is that it uses a + 5V power supply which, is
the same as the source voltage for the 8051. In other words, with a single +5v power supply we
can power both the 8051 & MAX232, with no need for the dual power supplies that are common
in many older systems. MAX232 has 2 sets of line drivers for transferring & receiving data.

FEATURES:

 Operates From a Single 5-V Power Supply With 1.0-µF Charge-Pump Capacitors

82
 Operate Up To 120 kbit/s

 Two Drivers and Two Receivers

 ±30-V Input Levels.

 Low Supply Current ...8 mA Typical

MAX 232 schematic and its interface to the DB9 connecter and 8051

Fig B.3 MAX 232 schematic and its interface to the DB9 connecter and 8051

83
B.4 DESIGN VERIFICATION TOOLS

B.4.1 Flash magic and its features

Computer side software called Flash Magic is executed that accepts the Intel HEX format file
generated from compiler Keil to be sent to target microcontroller. It detects the hardware
connected to the serial port.

Software Settings

1. Install the Software Flash Magic


2. Select Serial Port - As per your Computer
3. Select the Chip ( 89C51RD2)(1)
4. Open the Hex file from Browse (3)
5. To program click Start (5) , Then Message will appear press the reset Switch as Shown
6. Press the Reset Switch

B.4.2 In-system programming (ISP)


In-system programming (abbreviated ISP) is the ability of some programmable logic
devices, microcontrollers, and other programmable electronic chips to be programmed while
installed in a complete system, rather than requiring the chip to be programmed prior to installing
it into the system.

The primary advantage of this feature is that it allows manufacturers of electronic devices
to integrate programming and testing into a single production phase, rather than requiring a
separate programming stage prior to assembling the system. This may allow manufacturers to
program the chips in their own system's production line instead of buying preprogrammed chips
from a manufacturer or distributor, making it feasible to apply code or design changes in the
middle of a production run.

Typically, chips supporting ISP have internal circuitry to generate any necessary
programming voltage from the system's normal supply voltage, and communicate with the
programmer via a serial protocol. Most programmable logic devices use a variant of
the JTAG protocol for ISP, in order to facilitate easier integration with automated testing
procedures. Other devices usually use proprietary protocols or protocols defined by older
standards. In systems complex enough to require moderately large glue logic, designers may
84
implement a JTAG-controlled programming subsystem for non-JTAG devices such as flash
memory and microcontrollers, allowing the entire programming and test procedure to be
accomplished under the control of a single protocol.

B.4.3 Software Design (debugging and testing methodology)

Keil 4 Embedded IDE features

Introduction:
An assembler is a software tool designed to simplify the task of writing computer
programs. It translates symbolic code into executable object code. This object code may then be
programmed into a microcontroller and executed. Assembly language programs translate directly
into CPU instructions which instruct the processor what operations to perform. Therefore, to
effectively write assembly programs, you should be familiar with both the microcomputer
architecture and the assembly language.

Assembly language operation codes (mnemonics) are easily remembered. You can also
symbolically express addresses and values referenced in the operand field of instructions. Since
you assign these names, you can make them as meaningful as the mnemonics for the
instructions. For example, if your program must manipulate a date as data, you can assign it the
symbolic name DATE. If your program contains a set of instructions used as a timing loop, you
can name the instruction group TIMER_LOOP.

An assembly program has three constituent parts:

1. Machine instructions
2. Assembler directives
3. Assembler controls
A machine instruction is a machine code that can be executed by the machine. Detailed
discussion of the machine instructions can be found in the hardware manuals of the 8051 or
derivative microcontroller.

Assembler directives are used to define the program structure and symbols, and generate non-
executable code (data, messages, etc.). Assembler directives instruct the assembler how to

85
process subsequent assembly language instructions. Directives also provide a way for you to
define program constants and reserve space for variables.

Assembler controls set the assembly modes and direct the assembly flow. Assembler controls
direct the operation of the assembler when generating a listing file or object file. Typically,
controls do not impact the code that is generated by the assembler. Controls can be specified on
the command line or within an assembler source file

APPENDIX C

86
C.1 Source code:

Header file:

#include <reg51f.h>

sbit r0=P1^0; //keypad rows


sbit r1=P1^1;
sbit r2=P1^2;
sbit r3=P1^3;

sbit c0=P1^4; //keypad columns


sbit c1=P1^5;
sbit c2=P1^6;
sbit c3=P1^7;

sfr ldata=0x80; // PORT0 for SFR address(LCD data pins)

sbit rs=P2^5; //RS set for Giving the Command or Data


sbit rw=P2^6; // Read/write command for the data in the LCD RAM
sbit en=P2^7; // Enable Bit of the LCD
sbit busy=P0^7; //busy pin of the controller

void lcdcmd (unsigned char);


void lcddata (unsigned char);
void lcdready(void);
void MSDelay(unsigned int);
void WriteString(unsigned char,unsigned char *);
unsigned char KeyTest(void);
void Start(void);
void LCDClear(void);
void MainMenu(void);
void UpdateService(void);

unsigned char MY_PWD[4]={'1','2','3','4'};

unsigned char Count;


/*****************************************************************
MAIN PROGRAM:

**************************************************************/
#include "MyHeader.h"
// INTERRUPT functions
void _Up() interrupt 0
{
if(Flag==0) Flag=1;
if(Flag==2)
{
Count--; // passenger get down

87
Flag=0;
}
}

void _Down() interrupt 2


{
if(Flag==1)
{
Count++; // passenger get in
Flag=0;
}
if(Flag==0) Flag=2;
}
//******************************************************************
LCD functions
******************************************************************//
void lcdcmd (unsigned char value) // LCD command initiation routine
{
lcdready(); //wait till the LCD executes the instruction
ldata=value;
rs=0; //register select command
rw=0;
en=1; //set the enable command
MSDelay(1);
en=0; //Reset the enable command
}
void lcddata (unsigned char value) // LCD data placing routine
{
lcdready(); // wait till the LCD executes the instruction
ldata = value;
rs=1; //register select data
rw=0; //read command
en=1;
MSDelay(1);
en=0;
}

void lcdready(void)
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
}

88
void MSDelay(unsigned int Iter)
{
unsigned int i, j;
for(i=0;i<Iter;i++)
{
for(j=0;j<1275;j++);
}
}
void WriteString(unsigned char count,unsigned char *MSG)
{
unsigned char i;
for(i=0;i<count;i++)
{
lcddata(MSG[i]);
}
}
//******************************************************************
keypad functions
****************************************************************//
unsigned char KeyTest(void)
{
P1=0xF0;
while (1)
{
while(P1!=0xF0)
{
r0=0; r1=1;r2=1;r3=1;
if(c0==0)
return '1';
else if(c1==0)
return '2';
else if(c2==0)
return '3';
else if(c3==0)
return '+';

r1=0; r0=1;r2=1;r3=1;
if(c0==0)
return '4';
else if(c1==0)
return '5';
else if(c2==0)
return '6';
else if(c3==0)
return 'U'; // UP Arrow

r2=0; r0=1;r1=1;r3=1;
if(c0==0)

89
return '7';
else if(c1==0)
return '8';
else if(c2==0)
return '9';
else if(c3==0)
return 'D'; // Down Arrow

r3=0; r0=1;r1=1;r2=1;
if(c0==0)
return 0x1B;
else if(c1==0)
return '0';
else if(c2==0)
return 'E'; // Enter
else if(c3==0)
return 'R';
}
}
}

// update service(menu driven)

void UpdateService(void)
{
unsigned char Temp;
Temp=0;

while(1)
{
if(Temp!=Count)
{
MSDelay(50); // Intentional Delay of 0.1mSec.
Temp=Count;
LCDClear();
lcdcmd(0x80);
//WriteString(12,"empty seats:");
WriteString(11,"Passengers:");
lcddata(Temp/1000+0x30);
Temp=Temp%1000;
lcddata(Temp/100+0x30);
Temp=Temp%100;
lcddata(Temp/10+0x30);
lcddata(Temp%10+0x30);
lcdcmd(0xC0);
WriteString(14, "Area Code:0001");
}
}
}

90
void MainMenu(void)//step(3)
{
unsigned char key;

key=0;

do
{
key=KeyTest();
}while(key!='E');
LCDClear();
lcdcmd(0x80);
WriteString(16,"1. Start Service");
lcdcmd(0xC0);
WriteString(16,"2. Configuration");
do
{
key=KeyTest();
}while(key!='1'&&key!='2');

switch(key)
{
case '1': // This is IR passenger counting logic.
Count=0; // Initial Count of the passenger Count = 0.
LCDClear();
lcdcmd(0x80);
WriteString(14, "Passengers:000");
lcdcmd(0xC0);
WriteString(14, "Area Code:0001");
UpdateService();
break;
case '2':
// will be developed in Phase-IV (After GSM). So, calling
LCDClear();
Lcdcmd(0x80);
Writestring(14,”1.Name 2.Route”);
Writestring(14,”3.ph no 4.pwd”)
Start();
break;
}

void Start(void) // step(2)


{
unsigned char key;
unsigned char uid[8],loop,pwd[4];

91
key=0x00;

// wait for enter.


do
{
key=KeyTest();
}while(key!='E');
LCDClear();
WriteString(8,"User ID:");
loop=0;
do
{
key=KeyTest();
if(key>='0' && key<='9')
{
uid[loop]=key;
lcddata(key);
loop++;
MSDelay(100);
} // wait for enter
}while(key!='E');
lcdcmd(0xC0);
WriteString(9,"Password:");
loop=0;
do
{
key=KeyTest();
if(key>='0' && key<='9')
{
pwd[loop]=key;
lcddata('*');
MSDelay(100);
loop++;
}
}while(key!='E');
LCDClear();
if((pwd[0]==MY_PWD[0])&&
(pwd[1]==MY_PWD[1])&&
(pwd[2]==MY_PWD[2])&&
(pwd[3]==MY_PWD[3]))
{
WriteString(15,"Authenticated!!");
MainMenu(); // go to step(3)
}
else
{
WriteString(16,"Access Denied!!!");
Start();// go to step(2)
}

92
}

void LCDClear(void)
{
lcdcmd(0x0E); // display on, cursor blinking
lcdcmd(0x01); //clear display screen
lcdcmd(0x06); // increment cursor(shift cusor right)
lcdcmd(0x80); // force cursor to begging of 1st line
}

void main(void) // star pgm here step(1)


{
IE=0x85;
Flag=0;
Count=0;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
WriteString(16,"welcome @ vasavi");
lcdcmd(0xC0);
WriteString(9,"Enter ITS");
Start(); //go to step(2)

93

You might also like