GSM Documentation
GSM Documentation
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.
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)
1
1.3 Motivation
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.
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
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.
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.
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.
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
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
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.
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.
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
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.
11
The Write timing diagram
For writing data or command to the LCD the instruction sequence must follow like as shown
in the figure
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.
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
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
}}
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.
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.
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
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
}}
Software Design
Pseudo code listing 5
Initializing the LCD
18
3.2 ELECTRONIC CONTROL UNIT (ECU) INTERFACE WITH KEY PAD
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.
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.
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.
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)
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.
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.
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.
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.
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
27
4.2 555 TIMER TO MODULATE INFRARED (IR) LIGHT
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)
(2)
(3)
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.
Specifications of NE555Timer:
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.
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
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.
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
33
Design parameters
1. BJT(BC109)
2. 100ohms , 220ohms resistor
3. TCRT5000 IR transmitter
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).
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
As shown figure 4.2, it contain NE555 Timer, two IR Sensor pairs and
microcontroller pins(INT0,INT1)
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
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.
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
39
Interrupt Enable Register (IE)
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
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
42
if(Flag==2)
{
Count--; // passenger decrementing
Flag=0;
}
}
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();
}
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.
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).
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.
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.
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.
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.
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
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.
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.
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
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.
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
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
• Driver interface with 4x4 Matrix Keypad, GSM module and 2x16 LCD is done.
• 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
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
59
6.3 Flash magic simulation results
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
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
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
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
[3] Arnold S. Berger, Embedded systems design, an introduction to process, tools, and
[5] Dreamtech Software Team, Programming for Embedded systems, WILEY Publishing,
Inc, 2003.
Websites:
www.google.co
65
APENDEX A
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.
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
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:
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.
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
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.
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.
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
µC finishes the instruction it is executing and saves the address of the next instruction
(PC) on the stack
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.
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.
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
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.
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:
Pin Functions:
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.
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.
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
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
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
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.
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.
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>
**************************************************************/
#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 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';
}
}
}
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;
}
91
key=0x00;
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
}
93