Download - Automatic car speed +rf control (1)
"AUTOMATIC SPEED CONTROLER OF CAR SPECIFIC REGION WITH RF SIGNAL”
MINOR PROJECT REPORT
Submitted in partial fulfillment for award of degree of
Bachelor of Technology
In
Electronics and Communication
By
Vikrant Verma (0576807312)Deepak (0676807312)Atul Rana (0876807312)Anish Kumar (06776802810)
To
Project Coordinators
Mr. Pawan Kumar Ms. Chanpreet Kaur Mr. Jaijit Singh
Department of Electronics and Communication EngineeringGuru Tegh Bahadur Institute of Technology, Delhi
Batch: 2011-2015
DECLARATION
This is to certify that the project report entitled “AUTOMATIC SPEED CONTROLER OF CAR WITH SPECIFIC REGION WITH RF SIGNAL”, which is submitted by us in partial fulfillment of the requirement for the award of B.Tech degree, in Electronics and Communication to Guru Tegh Bahadur Institute of Technology, Delhi comprises only our original work and due acknowledgement has been made in the test to all other material used.
Date:
GROUP MEMBER NAME:-
Vikrant Verma (0576807312)Deepak (0676807312)
Atul Rana (0876807312)Anish Kumar (06776802810)
CERTIFICATE
This is to certify that report entitled AUTOMATIC SPEED CONTROLER OF WITHSPECIFIC REGION WITH RF SIGNAL”, which is submitted by Vikrant Verma (0576807312), Deepak (0676807312),Atul Rana (0876807312),Anish Kumar (06776802810) in partial fulfillment of the required for the award of B.Tech in Electronics And Communication Engineering to Guru Tegh Bahadur Institute of Technology, New Delhi is a record of the candidates own work carried out by them under my supervision. The matter embodied in this report is original and has not been submitted for the award of any other degree.
Place: New Delhi
Date:
"Mr Gagan " "Shivani duggal"
(Project Mentor) (Project Mentor)
Mr. Pawan Kumar Ms. Chanpreet Kaur Bhasin Mr. Jaijit Singh
(Project Co-ordinator) (Project Co-ordinator) (Project Co-ordinator)
Prof. Amrik Singh Mr. Vaneet Singh
(Overall Project Co-ordinator) (HOD, ECE)
5
ACKNOWLEDGEMENT
Setting an endeavor may not always be an easy task; obstacles are bound to come in its way and when this happens, help is welcome and needless to say without help of those people whom we are mentioning here, this endeavor would not have been successful. We are very much thankful for the precious contribution of our guides Mr/Ms: Shivani Duggal & Mr. Gagan (both mentors) and our coordinators Mr/Ms : Mr. Pawan Kumar, Ms. Chanpreet Kaur Bhasin, Mr. Jaijit Singh, Prof. Amrik Singh, (all coordinators and overall coordinator) who provided all their possible help. We would also like to thank our H.O.D. Mr. Vaneet Singh for his constant support and encouragement. The successful completion of this project has been possible due to sincere co-operation, guidance and timely advice from all the fore mentioned, who devoted their utmost co-operation in this project work.
(Name of the students…)
Vikrant Verma
Deepak
Atul Rana
Anish Kumar
6
Table of contents
1. Introduction
2. Circuit description
3. Working
4. Hardware description
5. Analog to digital converter
6. Liquid crystal display
7. Power supply
8. Cristal oscillator
9. Working of Transmitter
10.Encoder and decoder
11.RF transmitter and receiver
12. Microcontroller(80S52)
13.The features of Microcontroller
14. Pin function of IC 89s52.
15.Software description
16. Program of the project
7
Chapter descriptions :
Chapter 1:-
1. Introduction
2. circuit diagram
3. working
Chapter 2:-
Hardware description:-
1. Analog to digital converter
2. Liquid crystal display
3. Power supply
4. Cristal oscillator
Chapter 3:-
1. Working of Transmitter
2. Encoder and decoder
3. RF transmitter and receiver
4. Microcontroller(80S52)
5. The features of Microcontroller
6. Pin function of IC 89s52.
Chapter 4:-
Software description
1. Program of the project
8
List of Figures
Fig 1: Car Receiver CircuitFig 2: Transmitter Circuit Fig 3: ADC (Analog to Digital Circuit)
Fig 4: Interfacing of LCD with micro Controller
Fig 5: LCD Display Fig 6: 7805 Voltage regulated IC.
Fig 7: Voltage regulated Circuit
Fig 8: Crystal Oscillator
Fig 9: Transmitter Circuit
Fig 10: Encoder IC
Fig 11: Decoder IC
Fig 12: TWS-434A
Fig 13: TWS-434 Pin
Fig 14: Sample Transmitter Application CircuitFig 15: RWS-434 ReceiverFig 16: RWS-434 Pin DiagramFig 17: Sample Receiver Application CircuitFig 18: The 8051 doesn’t have any special feature than other microcontroller.
Fig 19: Electric Circuit
Fig 20: Interface Microcontroller with motor driver IC
9
ABSTRACT
In this project we show that how we control the speed of any car up to set value. Once the
upper limit is set then it’s not possible to increase the speed of vehicle. THIS SET
VALUE IS PROVIDED BY RF TRANSMITTER.
RF transmitter sends a set value of code to car, as the car receives a code then car
maximum speed limit is set. Now car driver cannot exceed the speed limit. As the car is
out of range then car speed can be change.
In this project we use two circuits. One is transmitter and second is receiver circuit. In
both circuit we use 89s52 controller. In receiver circuit we use 89s52 with ADC and LCD
display. LCD displays the set value of speed and speed of accelerometer. In receiver
circuit we use Ht12D as a decoder to receive the Rf frequency signal. In receiver circuit
we use 433 MHz receiver and at the transmitter circuit we use 433 MHz transmitter
circuit. In transmitter circuit we use HT12e as a encoder components.
With the help of two up down switch we set the limit for 3 values. 20, 30, 40 and 60. is
maximum set value. Third switch is entering switch. When we press the enter switch then
circuit starts the motor. Vehicle starts moving forward direction.
10
Chapter 1:-
Introduction In this project we show that how we control the speed of any car up to set value. Once the
upper limit is set then its not possible to increase the speed of vehicle. THIS SET VALUE
IS PROVIDED BY RF TRANSMITTER.
Rf transmitter send a set value of code to car, as the car receive a code then car maximum
speed limit is set. Now car driver can not exceed the speed limit. As the car is out of
range then car speed can be change.
In this project we use two circuits. One is transmitter and second is receiver circuit. In
both circuit we use 89s52 controller. In receiver circuit we use 89s52 with ADC and LCD
display. LCD displays the set value of speed and speed of accelerometer. In receiver
circuit we use Ht12D as a decoder to receive the Rf frequency signal. In receiver circuit
we use 433 MHz receiver and at the transmitter circuit we use 433 MHz transmitter
circuit. In transmitter circuit we use HT12e as a encoder components.
With the help of two up down switch we set the limit for 3 values. 20,30,40 and 60. is
maximum set value. Third switch is enter switch. When we press the enter switch then
circuit starts the motor.
For vehicle we use small DC gear motor. When we on the circuit then default value of the
motor speed is 20, not we change the setting of maximum speed limit.
Now we use variable resistor to change the value of accelerometer. This variable resistor
is connected to the input of ADC circuit. When we vary the variable resistor value then
speed of motor is also change.
11
Circuit diagram
12
Fig 1: Car Receiver Circuit
13
Fig 2: Transmitter Circuit
14
Chapter 2:-
WORKING
In the project there are two part transmitter and receiver in the transistor when press the
micro switches key given some input of microcontroller , the microcontroller check the
key input whose key press and what is the data or information sending after this process
the microcontroller1 encoded the input by the RE module the receiver the data by RE
module and collected by receiver microcontroller and the microcontroller decoding the
information signal and display on the seven segment and microcontroller sending the data
in dc Motor, and motors start the receiver part send feedback which data is
receives ,sending by the RF module again the transmitter RF module receive feedback
information and decoding by microcontroller and display on LCD (liquid crystal display).
It’s whole process based on the frequency modulation.
15
Hardware discription
ADC converts
In this project we use 0804 ADC to check the value of input resistor. This ADC is 8 bit
ADC. Output of the ADC is connected to the microcontroller port p1. ADC converts the
input voltage and deliver to the microcontroller. Input variable resistor actually varies the
5 volt DC. When we vary the input voltage then ADC converts the input voltage to the
Digital voltage. . Output of ADC is hex code, microcontroller coverts the hex data in
ASCII code and display into the LCD module. Microcontroller gets the value and save
the same in the ram content of the microcontroller. Controller continues vary the output
of the DC motor via varying the duty cycle. Controller compares the change with the set
value. When input value is become equal to the set value then microcontroller stop to
increasing the speed of the DC motor.
BASIC NOTES ON THE ADC.
Analogue to digital converters are among the most widely used devices for data
acquisition. Digital computers use binary values, but in the physical world everything is
analog. Temperature, pressure ( wind or Liquid), humidity, and velocity are a few
examples of physical quantities that we deal with every day. A physical quantity is
converted to electrical ( voltage, current) signals using a device called a transducer.
Transducers are also referred to as sensors. Although there are sensors for temperature,
velocity, pressure, light, and many other natural quantities, they produce an output that is
voltage ( or current) . Therefore, we need an analog to digital converter to translate the
analog signals to digital numbers so that the microcontroller can read them, A widely
used ADC chip is the ADC0804.
16
Fig 3: ADC (Analog to Digital Circuit)
ADC0804 CHIP.
The ADC0804 IC is an analog to digital converter in the family of the ADC800 series
from National Semiconductor. It is also available from many other manufactures. It works
with +5 volts and has a resolution of 8 bits. In addition to resolution, conversion time is
another major factor in judging and ADC. Conversion time is defined as the time it takes
the ADC to convert the anlog input to a digital number. In the ADC0804, the conversion
time varies depending on the clocking signals applied to the CLK R and CLK IN pins, but
it cannot be faster then 110 microsecond.
17
The ADC804 pin description follow.
Chapter 1 CS
Chip select is an active low input used to activate the ADC804 chip. To access the
ADC804, this pin must be low.
RD ( read)
This is an input signal and is active low. The ADC converts the analog input to its binary
equivalent and holds it in an internal register. RD is used to get the converted data out of
the ADC 0804 chip. When CS = 0, if a high to low pulse is applied to the RD pin, the 8
bit digital output shows up at the D0-D7 data pins. The RD pin is also referred to as
output enable.
WR( Start conversion)
This is an active low input used to inform the ADC 804 to start the conversion process. If
the CS = 0 when WR makes a low to high transition, ADC 804 starts converting the
analogue input value of Vin to an 8 bit digital number. The amount of time it takes to
convert varies depending on the CLK IN and CLK R values explained below. When the
data conversion is complete, the INTR pin is forced low by the ADC804.
CLK IN AND CLK R
CLK IN is an input pin connected to an external clock source when an external clock is
used for timing. However, the 804 has an internal clock generator. To use the internal
clock generator ( also called self clocking) of the ADC804 the CLK IN and CLKR pins
are connected to a capacitor and a resistor, as shown in the fig. In that case the clock
frequency is determined by the equation.
F = 1
1.1RC
18
Typical values are R = 10 k ohms and C = 150pf, Substituting in the above equation, we
get f = 606 khz. In that case, the conversion time is 110 microsecond.
INTR ( Interrupt, end of conversion)
This is an output pin and is active low, It is normal high pin and when the conversion is
finished, it goes low to signal the CPU that the converted data is ready to be picked up.
After INTR goes low, we make CS = 0 and send a high to low pulse to the RD pin to get
the data out of the ADC804 chip.
VIN ( + ) AND V in ( -)
These are the differential analog inputs where Vin = Vin(+) – Vin (-) Often the Vin ( -)
pin is connected to ground and the Vin ( +) pin is used as the anlogue to be converted to
digital.
Vcc
This is the +5 volt power supply. It is also used as a reference voltage when the Vref/2
input ( pin 9) is open ( not connected0.
Vref/2
Pin 9 is an input voltage used for the reference voltage. If the pin is open ( not
connected ), the analog input voltage for the ADC804 is in the range of 0 to 5 volts 9 the
same as the Vcc pin ). However, there are many applications where the analog input
applied to vin needs to be other than the 0 to +5v range. Vref/2 is used to implement
analog input voltages other than 0-5volt, For example, if the analog input range needs to
be 0 to 4 volts, vref/2 is connected to 2 volts.
D0-D7
D0-DT ( where D7 is the MSB, D0 the LSB ) are the digital data output pins. These are
tri-state buffered and the converted data is accessed only when CS = 0 and RD is forced
low. To calculate the output voltage, use the following formula
Dout = Vin
step size
19
Where Dout = digital data output ( in decimal ), Vin = analog input voltage, and step size
( resolution ) is the smallest change, which is ( 2 x Vref/2) / 256 for an 8 bit ADC.
ANALOG GROUND AND DIGITAL GROUND.
These are the input pins providing the ground for both the analog signal and the digital
signal. Analog ground is connected to the ground of the analog Vin while digital ground
is connected to the ground of the Vcc pin. The reason that we have two ground pins is to
isolate the analog Vin signal from transient voltages caused by digital switching of the
output D0-d7, such isolation contributes to the accuracy of the digital data output. In our
discussion, both are connected to the same ground; however, in the real world of data
acquisition the analog and digital grounds and handled separately.
20
Fig 4: Interfacing of LCD with micro Controller
21
PIN NO 1 VSS GROUND
PIN NO 2 VCC +5 V SUPPY.
PIN NO 3 VEE POWER SUPPLY TO CONTRAST CONTROL
PIN NO 4 RS RS = 0 TO SELECT
Fig 5: LCD Display
22
We use 5 volt regulated supply for the LCD display and max 232 ic. For this purpose
we use 7805 regulator with filter capacitor to provide a ripple free regulated voltage
to controller and lcd display.
We use MAX232 driver ic to provide a interface between GSM modem and
controller. MAX 232 IC convert the rs232 logic to TTL logic. Output of the max 232
is directly connected to the RX pin of the controller.
Pin no 18 and 19 of the microcontroller is connected to external crystal oscillator to
provide a external clock to microcontroller by which we set the machine cycle of the
controller
POWER SUPPLY
in this project we use one 5 volt regulated power supply to convert the 220 volt ac in to
5 volt dc with the help of the 5 volt regulator circuit. First OF all we step down the 220
volt ac into 6 volt ac with the help of step down transformer. Step down transformer step
down the voltage from 220 volt ac to 9 volt ac. This ac is further converted into the dc
voltage with the help of the full wave rectifier circuit
Fig 6: 7805 Voltage regulated IC.
23
Fig 7: Voltage regulated Circuit
Output of the diode is pulsating dc . so to convert the pulsating dc into smooth dc we use
electrolytic capacitor. Electrolytic capacitor convert the pulsating dc into smooth dc. This
Dc is further regulated by the ic 7805 regulator. IC 7805 regulator provide a regulated 5
volt dc to the microcontroller circuit and lcd circuit.
Pin no 40 of the controller is connected to the positive supply. Pin no 20 is connected to
the ground. Pin no 9 is connected to external resistor capacitor to provide a automatic
reset option when power is on.
Reset Circuitry:
Pin no 9 of the controller is connected to the reset circuit. On the circuit we connect one
resistor and capacitor circuit to provide a reset option when power is on
As soon as you give the power supply the 8051 doesn’t start. You need to restart for the
microcontroller to start. Restarting the microcontroller is nothing but giving a Logic 1 to
the reset pin at least for the 2 clock pulses. So it is good to go for a small circuit which
can provide the 2 clock pulses as soon as the microcontroller is powered.
This is not a big circuit we are just using a capacitor to charge the microcontroller and
again discharging via resistor.
24
Fig 8: Crystal Oscillator
Crystals
Pin no 18 and 19 is connected to external crystal oscillator to provide a clock to the
circuit.
Crystals provide the synchronization of the internal function and to the peripherals.
Whenever ever we are using crystals we need to put the capacitor behind it to make it free
from noises. It is good to go for a 33pf capacitor.
We can also resonators instead of costly crystal which are low cost and external capacitor
can be avoided.
But the frequency of the resonators varies a lot. And it is strictly not advised when used
for communications projects.
How is this time then calculated?
The speed with which a microcontroller executes instructions is determined by what is
known as the crystal speed. A crystal is a component connected externally to the
microcontroller. The crystal has different values, and some of the used values are 6MHZ,
10MHZ, and 11.059 MHz etc. Thus a 10MHZ crystal would pulse at the rate of
10,000,000 times per second.
25
Chapter 3:-
working of Transmitter.
In the transmitter circuit we use one RF module to send the data serially via radio
frequency. Here in this project we use 433 MHz radio frequency module o send the data
serially. Modulating frequency of the project is 433Mhtz and modulation type is ASK.
Fig 9: Transmitter Circuit
Encoder and decoder
Whenever we want to send a data we use encoder ic to convert the parallel data into
serial. This serial data is transmitting by the radio frequency module in air. For selecting a
data base we use DIP switches. In actual practice we use internal data base. But in this
project we use external data base to selection. Here we use four bit data with the help of
26
DIP switches. Data is to be converted into serial with the help of the encoder IC. Here we
use HT 12E encoder IC. HT12E encoder IC converts the parallel data into serial data.
Fig 10: Encoder IC
Pin no 1to 8 is address pin. Pin no 9 is ground pin. Pin no 10,11,12,13 is data insertion
pin. We provide a 0 bit on the entire address pin. But it is not necessary. We select the
address line pins as our requirement. For providing a data to data pins either we provide a
4 bit data from microcontroller or any other digital circuit or we connect DIP switches
Dip switches are connected with the pin no 10,11,12,13 . Pin no 14 is transmit control
pin. We control the pin no 14 by connecting a pin no 14 to ground pin. When this pin is
ground then only, data is to be transmit from the IC . Pin no 15 and 16 is the oscillator pin
of the encoder IC . On this pin we connect a 1 M ohm resistor. Pin no 17 is data output
pin. Data from this pin is connected to the input of transmitter module.
Data receive by the radio frequency receiver module. This receiver module is same as the
frequency of transmitter module. Output from radio frequency module is further decoded
by the decoder IC. Output of the decoder IC is further converted into parallel
27
Fig 11: Decoder IC
RF-Transmitter Module
The TWS-434 and RWS-434 are extremely small, and are excellent for applications
requiring short-range RF remote controls. The transmitter module is only 1/3 the size of a
standard postage stamp, and can easily be placed inside a small plastic enclosure.
TWS-434: The transmitter output is up to 8mW at 433.92MHz with arange of
approximately 400 foot (open area) outdoors. Indoors, the range is approximately 200
foot, and will go through most walls.....
Fig 12: TWS-434A
The TWS-434 transmitter accepts both linear and digital inputs, can operate from 1.5 to
12 Volts-DC, and makes building a miniature hand-held RF transmitter very easy. The
TWS-434 is approximately the size of a standard postage stamp.
28
Fig 13: TWS-434 Pin
Fig 14: Sample Transmitter Application Circuit
Receiver
RWS-434: The receiver also operates at 433.92MHz, and has a sensitivity of 3uV. The
RWS-434 receiver operates from 4.5 to 5.5 volts-DC, and has both linear and digital
outputs.
29
Click on picture for larger image
Fig 15 : RWS-434 Receiver
30
Fig 16: RWS-434 Pin Diagram
Fig 17: Sample Receiver Application Circuit
31
The example above shows the receiver section using the HT-12D decoder IC for a 4-bit
RF remote control system. The transmitter and receiver can also use the Holtek 8-bit HT-
640/HT-648L remote control encoder/decoder combination for an 8-bit RF remote control
system. Here are the schematics for an 8-bit RF remote control system:
Microcontroller
Architecture is must to learn because before learning new machine it is necessary to learn
the capabilities of the machine. This is some thing like before learning about the car you
cannot become a good driver. The architecture of the 8051 is given below.
Fig 18: Architecture of Intel 8051 Microcontroller.
Fig 18 :The 8051 doesn’t have any special feature than other microcontroller.
The only feature is that it is easy to learn. Architecture makes us to know about the
hardware features of the microcontroller. The features of the 8051 are
4K Bytes of Flash Memory
128 x 8-Bit Internal RAM
Fully Static Operation: 1 MHz to 24 MHz
32
32 Programmable I/O Lines
Two 16-Bit Timer/Counters
Six Interrupt Sources (5 Vectored)
Programmable Serial Channel
Low Power Idle and Power Down Modes
The 8051 has a 8-Bit CPU that means it is able to process 8 bit of data at a time. 8051 has
235 instructions. Some of the important registers and their functions are
Let’s now move on to a practical example. We shall work on a simple practical
application and using the example as a base, shall explore the various features of the 8051
microcontroller.
Consider an electric circuit as follows,
Fig 19: Electric Circuit
The positive side (+ve) of the battery is connected to one side of a switch. The other side
of the switch is connected to a bulb or LED (Light Emitting Diode). The bulb is then
connected to a resistor, and the other end of the resistor is connected to the negative (-ve)
side of the battery.
When the switch is closed or ‘switched on’ the bulb glows. When the switch is open or
‘switched off’ the bulb goes off
If you are instructed to put the switch on and off every 30 seconds, how would you do it?
Obviously you would keep looking at your watch and every time the second hand crosses
30 seconds you would keep turning the switch on and off.
33
Imagine if you had to do this action consistently for a full day. Do you think you would
be able to do it? Now if you had to do this for a month, a year??
No way, you would say!
The next step would be, then to make it automatic. This is where we use the
Microcontroller.
But if the action has to take place every 30 seconds, how will the microcontroller keep
track of time?
Execution time
Look at the following instruction,
clr p1.0
This is an assembly language instruction. It means we are instructing the microcontroller
to put a value of ‘zero’ in bit zero of port one. This instruction is equivalent to telling the
microcontroller to switch on the bulb. The instruction then to instruct the microcontroller
to switch off the bulb is,
Set p1.0
This instructs the microcontroller to put a value of ‘one’ in bit zero of port one.
Don’t worry about what bit zero and port one means. We shall learn it in more detail as
we proceed.
There are a set of well defined instructions, which are used while communicating with the
microcontroller. Each of these instructions requires a standard number of cycles to
execute. The cycle could be one or more in number.
How is this time then calculated?
34
The speed with which a microcontroller executes instructions is determined by what is
known as the crystal speed. A crystal is a component connected externally to the
microcontroller. The crystal has different values, and some of the used values are 6MHZ,
10MHZ, and 11.059 MHz etc.
Thus a 10MHZ crystal would pulse at the rate of 10,000,000 times per second.
The time is calculated using the formula
No of cycles per second = Crystal frequency in HZ / 12.
For a 10MHZ crystal the number of cycles would be,
10,000,000/12=833333.33333 cycles.
This means that in one second, the microcontroller would execute 833333.33333 cycles.
Therefore for one cycle, what would be the time? Try it out.
The instruction clr p1.0 would use one cycle to execute. Similarly, the instruction setb
p1.0 also uses one cycle.
So go ahead and calculate what would be the number of cycles required to be executed to
get a time of 30 seconds!
Getting back to our bulb example, all we would need to do is to instruct the
microcontroller to carry out some instructions equivalent to a period of 30 seconds, like
counting from zero upwards, then switch on the bulb, carry out instructions equivalent to
30 seconds and switch off the bulb.
Just put the whole thing in a loop, and you have a never ending on-off sequence.
Let us now have a look at the features of the 8051 core, keeping the above example as a
reference,
35
1. 8-bit CPU.( Consisting of the ‘A’ and ‘B’ registers)
Most of the transactions within the microcontroller are carried out through the ‘A’
register, also known as the Accumulator. In addition all arithmetic functions are carried
out generally in the ‘A’ register. There is another register known as the ‘B’ register,
which is used exclusively for multiplication and division.
Thus an 8-bit notation would indicate that the maximum value that can be input into these
registers is ‘11111111’. Puzzled?
The value is not decimal 111, 11,111! It represents a binary number, having an equivalent
value of ‘FF’ in Hexadecimal and a value of 255 in decimal.
We shall read in more detail on the different numbering systems namely the Binary
2. 4K on-chip ROM
Once you have written out the instructions for the microcontroller, where do you put
these instructions?
Obviously you would like these instructions to be safe, and not get deleted or changed
during execution. Hence you would load it into the ‘ROM’
The size of the program you write is bound to vary depending on the application, and the
number of lines. The 8051 microcontroller gives you space to load up to 4K of program
size into the internal ROM.
4K, that’s all? Well just wait. You would be surprised at the amount of stuff you can load
in this 4K of space.
Of course you could always extend the space by connecting to 64K of external ROM if
required.
3. 128 bytes on-chip RAM
36
This is the space provided for executing the program in terms of moving data, storing data
etc.
4. 32 I/O lines. (Four- 8 bit ports, labeled P0, P1, P2, P3)
In our bulb example, we used the notation p1.0. This means bit zero of port one. One bit
controls one bulb.
Thus port one would have 8 bits. There are a total of four ports named p0, p1, p2, p3,
giving a total of 32 lines. These lines can be used both as input or output.
5. Two 16 bit timers / counters.
A microcontroller normally executes one instruction at a time. However certain
applications would require that some event has to be tracked independent of the main
program.
The manufacturers have provided a solution, by providing two timers. These timers
execute in the background independent of the main program. Once the required time has
been reached, (remember the time calculations described above?), they can trigger a
branch in the main program.
These timers can also be used as counters, so that they can count the number of events,
and on reaching the required count, can cause a branch in the main program.
6. Full Duplex serial data receiver / transmitter.
The 8051 microcontroller is capable of communicating with external devices like the PC
etc. Here data is sent in the form of bytes, at predefined speeds, also known as baud rates.
The transmission is serial, in the sense, one bit at a time
7. 5- interrupt sources with two priority levels (Two external and three internal)
37
During the discussion on the timers, we had indicated that the timers can trigger a branch
in the main program. However, what would we do in case we would like the
microcontroller to take the branch, and then return back to the main program, without
having to constantly check whether the required time / count has been reached?
This is where the interrupts come into play. These can be set to either the timers, or to
some external events. Whenever the background program has reached the required
criteria in terms of time or count or an external event, the branch is taken, and on
completion of the branch, the control returns to the main program. Priority levels indicate
which interrupt is more important, and needs to be executed first in case two
8. On-chip clock oscillator.
This represents the oscillator circuits within the microcontroller. Thus the hardware is
reduced to just simply connecting an external crystal, to achieve the required pulsing rate.
PIN FUNCTION OF IC 89C51.
1 Supply pin of this ic is pin no 40. Normally we apply a 5 volt regulated dc
power supply to this pin. For this purpose either we use step down transformer
power supply or we use 9 volt battery with 7805 regulator.
2 Ground pin of this ic is pin no 20. Pin no 20 is normally connected to the
ground pin ( normally negative point of the power supply.
3 XTAL is connected to the pin no 18 and pin no 19 of this ic. The quartz
crystal oscillator connected to XTAL1 and XTAL2 PIN. These pins also needs
two capacitors of 30 pf value. One side of each capacitor is connected to
crystal and other pis is connected to the ground point. Normally we connect a
12 MHz or 11.0592 MHz crystal with this ic.. But we use crystal upto 20 MHz
to this pins
38
4 RESET PIN.. Pin no 9 is the reset pin of this ic.. It is an active high pin. On
applying a high pulse to this pin, the micro controller will reset and terminate
all activities. This is often referred to as a power on reset. The high pulse must
be high for a minimum of 2 machine cycles before it is allowed to go low.
5. PORT0 Port 0 occupies a total of 8 pins. Pin no 32 to pin no 39. It can be
used for input or output. We connect all the pins of the port 0 with the pullup
resistor (10 k ohm) externally. This is due to fact that port 0 is an open drain
mode. It is just like a open collector transistor.
6. PORT1. ALL the ports in micrcontroller is 8 bit wide pin no 1 to pin no 8
because it is a 8 bit controller. All the main register and sfr all is mainly 8 bit
wide. Port 1 is also occupies a 8 pins. But there is no need of pull up resistor
in this port. Upon reset port 1 act as a input port. Upon reset all the ports act
as a input port
7. PORT2. port 2 also have a 8 pins. It can be used as a input or output. There
is no need of any pull up resistor to this pin.
PORT 3. Port3 occupies a totoal 8 pins from pin no 10 to pin no 17. It can be
used as input or output. Port 3 does not require any pull up resistor. The same
as port 1 and port2. Port 3 is configured as an output port on reset. Port 3 has
the additional function of providing some important signals such as interrupts.
Port 3 also use for serial communication.
ALE ALE is an output pin and is active high. When connecting an 8031 to external
memory, port 0 provides both address and data. In other words, the 8031 multiplexes
address and data through port 0 to save pins. The ALE pin is used for demultiplexing the
address and data by connecting to the ic 74ls373 chip.
PSEN. PSEN stands for program store eneable. In an 8031 based system in which an
external rom holds the program code, this pin is connected to the OE pin of the rom.
39
EA. EA. In 89c51 8751 or any other family member of the ateml 89c51 series all come
with on-chip rom to store programs, in such cases the EA pin is connected to the Vcc.
For family member 8031 and 8032 is which there is no on chip rom, code is stored in
external memory and this is fetched by 8031. In that case EA pin must be connected to
GND pin to indicate that the code is stored externally.
SPECIAL FUNCTION REGISTER ( SFR) ADDRESSES.
ACC ACCUMULATOR 0E0H
B B REGISTER 0F0H
PSW PROGRAM STATUS WORD 0D0H
SP STACK POINTER 81H
DPTR DATA POINTER 2 BYTES
DPL LOW BYTE OF DPTR 82H
DPH HIGH BYTE OF DPTR 83H
P0 PORT0 80H
P1 PORT1 90H
P2 PORT2 0A0H
P3 PORT3 0B0H
40
TMOD TIMER/COUNTER MODE CONTROL 89H
TCON TIMER COUNTER CONTROL 88H
TH0 TIMER 0 HIGH BYTE 8CH
TLO TIMER 0 LOW BYTE 8AH
TH1 TIMER 1 HIGH BYTE 8DH
TL1 TIMER 1 LOW BYTE 8BH
SCON SERIAL CONTROL 98H
SBUF SERIAL DATA BUFFER 99H
PCON POWER CONTROL 87H
INSTRUCTIONS
SINGLE BIT INSTRUCTIONS.
SETB BIT SET THE BIT =1
CLR BIT CLEAR THE BIT =0
CPL BIT COMPLIMENT THE BIT 0 =1, 1=0
JB BIT,TARGET JUMP TO TARGET IF BIT =1
41
JNB BIT, TARGET JUMP TO TARGET IF BIT =0
JBC BIT,TARGET JUMP TO TARGET IF BIT =1 &THEN CLEAR THE BIT
MOV INSTRUCTIONS
MOV instruction simply copy the data from one location to another location
MOV D,S
Copy the data from(S) source to D(destination)
MOV R0,A ; Copy contents of A into Register R0
MOV R1,A ; Copy contents of A into register R1
MOV A,R3 ; copy contents of Register R3 into Accnmulator.
DIRECT LOADING THROUGH MOV
MOV A,#23H ; Direct load the value of 23h in A
MOV R0,#12h ; direct load the value of 12h in R0
MOV R5,#0F9H ; Load the F9 value in the Register R5
ADD INSTRUCTIONS.
42
ADD instructions adds the source byte to the accumulator ( A) and place the result in the
Accumulator.
MOV A, #25H
ADD A,#42H ; BY this instructions we add the value 42h in Accumulator ( 42H+
25H)
ADDA,R3 ;By this instructions we move the data from register r3 to
accumulator and then add the contents of the register into
accumulator .
SUBROUTINE CALL FUNCTION.
ACALL,TARGET ADDRESS
By this instructions we call subroutines with a target address within 2k bytes from the
current program counter.
LCALL, TARGET ADDRESS.
ACALL is a limit for the 2 k byte program counter, but for upto 64k byte we use LCALL
instructions.. Note that LCALL is a 3 byte instructions. ACALL is
a two byte instructions.
AJMP TARGET ADDRESS.
43
This is for absolute jump
AJMP stand for absolute jump. It transfers program execution to the target address
unconditionally. The target address for this instruction must be
withib 2 k byte of program memory.
LJMP is also for absoltute jump. It tranfer program execution to the target addres
unconditionally. This is a 3 byte instructions LJMP jump to any
address within 64 k byte location.
INSTRUCTIONS RELATED TO THE CARRY
JC TARGET
JUMP TO THE TARGET IF CY FLAG =1
JNC TARGET
JUMP TO THE TARGET ADDRESS IF CY FLAG IS = 0
Chapter 2 INSTRUCTIONS RELASTED TO JUMP WITH ACCUMULATOR
44
JZ TARGET
JUMP TO TARGET IF A = 0
JNZ TARGET
JUMP IF ACCUMULATOR IS NOT ZERO
This instructions jumps if registe A has a value other than zero
INSTRUCTIONS RELATED TO THE ROTATE
RL A
ROTATE LEFT THE ACCUMULATOR
BY this instructions we rotate the bits of A left. The bits rotated out of A are rotated back
into A at the opposite end
RR A
By this instruction we rotate the contents of the accumulator from right to left from LSB
to MSB
45
RRC A
This is same as RR A but difference is that the bit rotated out of register first enter in to
carry and then enter into MSB
RLC A
ROTATE A LEFT THROUGH CARRY
Same as above but but shift the data from MSB to carry and carry to LSB
RET
This is return from subroutine. This instructions is used to return from a subroutine
previously entered by instructions LCALL and ACALL.
RET1
THIS is used at the end of an interrupt service routine. We use this instructions after
intruupt routine,
PUSH.
46
This copies the indicated byte onto the stack and increments SP by . This instructions
supports only direct addressing mode.
POP.
POP FROM STACK.
This copies the byte pointed to be SP to the location whose direct address is indicated,
and decrements SP by 1. Notice that this instructions supports only direct addressing
mode.
DPTR INSTRUCTIONS.
MOV DPTR,#16 BIT VALUE
LOAD DATA POINTER
This instructions load the 16 bit dptr register with a 16 bit immediate value
MOV C A,@A+DPTR
This instructions moves a byte of data located in program ROM into register A. This
allows us to put strings of data, such as look up table elements.
MOVC A,@A+PC
47
This instructions moves a byte of data located in the program area to A. the address of the
desired byte of data is formed by adding the program counter ( PC) register to the original
value of the accumulator.
INC BYTE
This instructions add 1 to the register or memory location specified by the operand.
INC A
INC Rn
INC DIRECT
DEC BYTE
This instructions subtracts 1 from the byte operand. Note that CY is unchanged
DEC A
DEC Rn
DEC DIRECT
ARITHMATIC INSTRUCTIONS.
ANL dest-byte, source-byte
This perform a logical AND operation
48
This performs a logical AND on the operands, bit by bit, storing the result in the
destination. Notice that both the source and destination values are byte –size only
`
DIV AB
This instructions divides a byte accumulator by the byte in register B. It is assumed that
both register A and B contain an unsigned byte. After the division the quotient will be in
register A and the remainder in register B.
TMOD ( TIMER MODE ) REGISTER
Both timer is the 89c51 share the one register TMOD. 4 LSB bit for the timer 0 and 4
MSB for the timer 1.
In each case lower 2 bits set the mode of the timer
Upper two bits set the operations.
49
GATE: Gating control when set. Timer/counter is enabled only while the INTX
pin is high and the TRx control pin is set. When cleared, the timer is enabled whenever
the TRx control bit is set
C/T : Timer or counter selected cleared for timer operation ( input from internal
system clock)
M1 Mode bit 1
M0 Mode bit 0
M1 M0 MODE OPERATING MODE
0 0 0 13 BIT TIMER/MODE
0 1 1 16 BIT TIMER MODE
1 0 2 8 BIT AUTO RELOAD
1 1 3 SPLIT TIMER MODE
PSW ( PROGRAM STATUS WORD)
CY PSW.7 CARRY FLAG
AC PSW.6 AUXILIARY CARRY
50
F0 PSW.5 AVAILABLE FOR THE USER FRO GENERAL PURPOSE
RS1 PSW.4 REGISTER BANK SELECTOR BIT 1
RS0 PSW.3 REGISTER BANK SELECTOR BIT 0
0V PSW.2 OVERFLOW FLAG
-- PSW.1 USER DEFINABLE BIT
PCON REGISATER ( NON BIT ADDRESSABLE)
If the SMOD = 0 ( DEFAULT ON RESET)
TH1 = CRYSTAL FREQUENCY
256---- ____________________
384 X BAUD RATE
If the SMOD IS = 1
CRYSTAL FREQUENCY
TH1 = 256--------------------------------------
192 X BAUD RATE
There are two ways to increase the baud rate of data transfer in the 8051
1. To use a higher frequency crystal
2. To change a bit in the PCON register
51
PCON register is an 8 bit register . Of the 8 bits, some are unused, and some are used for
the power control capability of the 8051. the bit which is used for the serial
communication is D7, the SMOD bit. When the 8051 is powered up, D7 ( SMOD BIT)
OF PCON register is zero. We can set it to high by software and thereby double the baud
rate
BAUD RATE COMPARISION FOR SMOD = 0 AND SMOD =1
TH1 ( DECIMAL) HEX SMOD =0 SMOD =1
-3 FD 9600 19200
-6 FA 4800 9600
-12 F4 2400 4800
-24 E8 1200 2400
XTAL = 11.0592 MHZ
IE ( INTERRUPT ENABLE REGISTOR)
EA IE.7 Disable all interrupts if EA = 0, no interrupts is acknowledged
If EA is 1, each interrupt source is individually enabled or disbaled
By sending or clearing its enable bit.
IE.6 NOT implemented
ET2 IE.5 enables or disables timer 2 overflag in 89c52 only
ES IE.4 Enables or disables all serial interrupt
52
ET1 IE.3 Enables or Disables timer 1 overflow interrupt
EX1 IE.2 Enables or disables external interrupt
ET0 IE.1 Enables or Disbales timer 0 interrupt.
EX0 IE.0 Enables or Disables external interrupt 0
INTERRUPT PRIORITY REGISTER
If the bit is 0, the corresponding interrupt has a lower priority and if the bit is 1 the
corresponding interrupt has a higher priority
IP.7 NOT IMPLEMENTED, RESERVED FOR FUTURE USE.
IP.6 NOT IMPLEMENTED, RESERVED FOR FUTURE USE
PT2 IP.5 DEFINE THE TIMER 2 INTERRUPT PRIORITY LELVEL
PS IP.4 DEFINES THE SERIAL PORT INTERRUPT PRIORITY LEVEL
PT1 IP.3 DEFINES THE TIMER 1 INTERRUPT PRIORITY LEVEL
PX1 IP.2 DEFINES EXTERNAL INTERRUPT 1 PRIORITY LEVEL
PT0 IP.1 DEFINES THE TIMER 0 INTERRUPT PRIORITY LEVEL
53
PX0 IP.0 DEFINES THE EXTERNAL INTERRUPT 0 PRIORITY LEVEL
SCON: SERIAL PORT CONTROL REGISTER , BIT ADDRESSABLE
SCON
SM0 : SCON.7 Serial Port mode specifier
SM1 : SCON.6 Serial Port mode specifier
SM2 : SCON.5
REN : SCON.4 Set/cleared by the software to Enable/disable reception
TB8 : SCON.3 The 9th bit that will be transmitted in modes 2 and 3, Set/cleared
By software
RB8 : SCON.2 In modes 2 &3, is the 9th data bit that was received. In mode 1,
If SM2 = 0, RB8 is the stop bit that was received. In mode 0
RB8 is not used
T1 : SCON.1 Transmit interrupt flag. Set by hardware at the end of the 8th bit
Time in mode 0, or at the beginning of the stop bit in the other
Modes. Must be cleared by software
54
R1 SCON.0 Receive interrupt flag. Set by hardware at the end of the 8th bit
Time in mode 0, or halfway through the stop bit time in the
Modes. Must be cleared by the software.
TCON TIMER COUNTER CONTROL REGISTER
This is a bit addressable
TF1 TCON.7 Timer 1 overflow flag. Set by hardware when the Timer/Counter 1
Overflows. Cleared by hardware as processor
TR1 TCON.6 Timer 1 run control bit. Set/cleared by software to turn Timer
Counter 1 On/off
TF0 TCON.5 Timer 0 overflow flag. Set by hardware when the timer/counter 0
Overflows. Cleared by hardware as processor
TR0 TCON.4 Timer 0 run control bit. Set/cleared by software to turn timer
Counter 0 on/off.
IE1 TCON.3 External interrupt 1 edge flag
ITI TCON.2 Interrupt 1 type control bit
IE0 TCON.1 External interrupt 0 edge
IT0 TCON.0 Interrupt 0 type control bit.
- 8051 Instruction Set
55
Arithmetic Operations
Mnemonic Description Size Cycles
ADD A,Rn Add register to Accumulator (ACC). 1 1
ADD A,direct Add direct byte to ACC. 2 1
ADD A,@Ri Add indirect RAM to ACC . 1 1
ADD A,#data Add immediate data to ACC . 2 1
ADDC A,Rn Add register to ACC with carry . 1 1
ADDC A,direct Add direct byte to ACC with carry. 2 1
ADDC A,@Ri Add indirect RAM to ACC with carry. 1 1
ADDC A,#data Add immediate data to ACC with carry. 2 1
SUBB A,Rn Subtract register from ACC with borrow. 1 1
SUBB A,direct Subtract direct byte from ACC with borrow 2 1
SUBB A,@Ri Subtract indirect RAM from ACC with borrow. 1 1
SUBB A,#data Subtract immediate data from ACC with borrow. 2 1
INC A Increment ACC. 1 1
INC Rn Increment register. 1 1
INC direct Increment direct byte. 2 1
56
INC @Ri Increment indirect RAM. 1 1
DEC A Decrement ACC. 1 1
DEC Rn Decrement register. 1 1
DEC direct Decrement direct byte. 2 1
DEC @Ri Decrement indirect RAM. 1 1
INC DPTR Increment data pointer. 1 2
MUL AB Multiply A and B Result: A <- low byte, B <- high byte. 1 4
DIV AB Divide A by B Result: A <- whole part, B <- remainder. 1 4
DA A Decimal adjust ACC. 1 1
Logical Operations
Mnemonic Description Size Cycles
ANL A,Rn AND Register to ACC. 1 1
ANL A,direct AND direct byte to ACC. 2 1
ANL A,@Ri AND indirect RAM to ACC. 1 1
ANL A,#data AND immediate data to ACC. 2 1
ANL direct,A AND ACC to direct byte. 2 1
57
ANL direct,#data AND immediate data to direct byte. 3 2
ORL A,Rn OR Register to ACC. 1 1
ORL A,direct OR direct byte to ACC. 2 1
ORL A,@Ri OR indirect RAM to ACC. 1 1
ORL A,#data OR immediate data to ACC. 2 1
ORL direct,A OR ACC to direct byte. 2 1
ORL direct,#data OR immediate data to direct byte. 3
2
XRL A,Rn Exclusive OR Register to ACC. 1 1
XRL A,direct Exclusive OR direct byte to ACC. 2 1
XRL A,@Ri Exclusive OR indirect RAM to ACC. 1 1
XRL A,#data Exclusive OR immediate data to ACC. 2 1
XRL direct,A Exclusive OR ACC to direct byte. 2 1
XRL direct,#data XOR immediate data to direct byte. 3 2
CLR A Clear ACC (set all bits to zero). 1 1
CPL A Compliment ACC. 1 1
RL A Rotate ACC left. 1 1
58
RLC A Rotate ACC left through carry. 1 1
RR A Rotate ACC right. 1 1
RRC A Rotate ACC right through carry. 1 1
SWAP A Swap nibbles within ACC. 1 1
Data Transfer
Mnemonic Description Size Cycles
MOV A,Rn Move register to ACC. 1 1
MOV A,direct Move direct byte to ACC.
2 1
MOV A,@Ri Move indirect RAM to ACC. 1 1
MOV A,#data Move immediate data to ACC. 2 1
MOV Rn,A Move ACC to register. 1 1
MOV Rn,direct Move direct byte to register. 2 2
MOV Rn,#data Move immediate data to register. 2 1
MOV direct,A Move ACC to direct byte. 2 1
MOV direct,Rn Move register to direct byte. 2 2
MOV direct,direct Move direct byte to direct byte. 3 2
59
MOV direct,@Ri Move indirect RAM to direct byte. 2 2
MOV direct,#data Move immediate data to direct byte. 3 2
MOV @Ri,A Move ACC to indirect RAM. 1 1
MOV @Ri,direct Move direct byte to indirect RAM. 2 2
MOV @Ri,#data Move immediate data to indirect RAM. 2 1
MOV DPTR,#data16 Move immediate 16 bit data to data pointer register. 3 2
MOVC A,@A+DPTR Move code byte relative to DPTR to ACC (16 bit address).
1 2
MOVC A,@A+PC Move code byte relative to PC to ACC (16 bit address).1 2
MOVX A,@Ri Move external RAM to ACC (8 bit address). 1 2
MOVX A,@DPTR Move external RAM to ACC (16 bit address). 1 2
MOVX @Ri,A Move ACC to external RAM (8 bit address). 1 2
MOVX @DPTR,A Move ACC to external RAM (16 bit address). 1 2
PUSH direct Push direct byte onto stack. 2 2
POP direct Pop direct byte from stack. 2 2
XCH A,Rn Exchange register with ACC. 1 1
XCH A,direct Exchange direct byte with ACC. 2 1
60
XCH A,@Ri Exchange indirect RAM with ACC. 1 1
XCHD A,@Ri Exchange low order nibble of indirect
RAM with low order nibble of ACC 1 1
Boolean Variable Manipulation
Mnemonic Description Size Cycles
CLR C Clear carry flag. 1 1
CLR bit Clear direct bit. 2 1
SETB C Set carry flag. 1 1
SETB bitSet direct bit 2 1
CPL C Compliment carry flag. 1 1
CPL bit Compliment direct bit. 2 1
ANL C,bit AND direct bit to carry flag. 2 2
ANL C,/bit AND compliment of direct bit to carry. 2 2
ORL C,bit OR direct bit to carry flag. 2 2
ORL C,/bit OR compliment of direct bit to carry. 2 2
MOV C,bit Move direct bit to carry flag. 2 1
MOV bit,C Move carry to direct bit. 2 2
JC rel Jump if carry is set. 2 2
61
JNC rel Jump if carry is not set. 2 2
JB bit,rel Jump if direct bit is set. 3 2
JNB bit,rel Jump if direct bit is not set. 3 2
JBC bit,rel Jump if direct bit is set & clear bit. 3 2
Chapter 3 Program Branching
Mnemonic Description Size Cycles
ACALL addr11 Absolute subroutine call. 2 2
LCALL addr16 Long subroutine call. 3 2
RET Return from subroutine. 1 2
RETI Return from interrupt. 1 2
AJMP addr11 Absolute jump. 2 2
LJMP addr16 Long jump. 3 2
SJMP rel Short jump (relative address). 2 2
JMP @A+DPTR Jump indirect relative to the DPTR. 1 2
JZ rel Jump relative if ACC is zero. 2 2
JNZ rel Jump relative if ACC is not zero. 2 2
62
CJNE A,direct,rel Compare direct byte to ACC and jump if not equal. 3 2
CJNE A,#data,rel Compare immediate byte to ACC and jump if not equal.3 2
CJNE Rn,#data,rel Compare immediate byte to register and jump if not equal.32
CJNE @Ri,#data,rel Compare immediate byte to indirect and jump if not equal.32
DJNZ Rn,rel Decrement register and jump if not zero. 2 2
DJNZ direct,rel Decrement direct byte and jump if not zero. 3 2
LCD display
Frequently, an 8051 program must interact with the outside world using input and output
devices that communicate directly with a human being. One of the most common devices
attached to an 8051 is an LCD display. Some of the most common LCDs connected to the
8051 are 16x2 and 20x2 displays. This means 16 characters per line by 2 lines and 20
characters per line by 2 lines, respectively.
a
Fig 20: Interface Microcontroller with motor driver IC
HANDLING THE EN CONTROL LINE sabove, the EN line is used to t
63
Programming Tip: The LCD interprets and executes our command at the instant the EN
line is brought low. If you never bring EN low, your instruction will never be executed.
Additionally, when you bring EN low and the LCD executes your instruction, it requires
a certain amount of time to execute the command. The time it requires to execute an
instruction depends on the instruction and the speed of the crystal which is attached to the
44780's oscillator input.
CHECKING THE BUSY STATUS OF THE
WAIT_LCD:
SETB EN ;Start LCD command
CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET
Thus, our standard practice will be to send an instruction to the LCD and then call our
WAIT_LCD routine to wait until the instruction is completely executed by the LCD.
This will assure that our program gives the LCD the time it needs to execute instructions
and also makes our program compatible with any LCD, regardless of how fast or slow it
is.
Programming Tip: The above routine does the job of waiting for the LCD, but
were it to be used in a real application a very definite improvement would need to
be made: as written, if the LCD never becomes "not busy" the program will
effectively "hang," waiting for DB7 to go low. If this never happens, the program
64
will freeze. Of course, this should never happen and won't happen when the
hardware is working properly. But in a real application it would be wise to put
some kind of time limit on the delay--for example, a maximum of 256 attempts to
wait for the busy signal to go low. This would guarantee that even if the LCD
hardware fails, the program would not lock up.
INITIALIZING THE LCD
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
Programming Tip: The LCD command 38h is really the sum of a number of
option bits. The instruction itself is the instruction 20h ("Function set"). However,
to this we add the values 10h to indicate an 8-bit data bus plus 08h to indicate that
the display is a two-line display.
We've now sent the first byte of the initialization sequence. The second byte of the
initialization sequence is the instruction 0Eh. Thus we must repeat the initialization code
from above, but now with the instruction. Thus the next code segment is:
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 0Eh is really the instruction 08h plus 04h to
turn the LCD on. To that an additional 02h is added in order to turn the cursor on.
65
The last byte we need to send is used to configure additional operational parameters of
the LCD. We must send the value 06h.
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 06h is really the instruction 04h plus 02h to
configure the LCD such that every time we send it a character, the cursor position
automatically moves to the right.
So, in all, our initialization code is as follows:
INIT_LCD:
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
RET
Having executed this code the LCD will be fully initialized and ready for us to send
display data to it.
CLEARING THE DISPLAY When the LCD is first initialized, the screen should
automatically be cleared by the 447e, it's a good idea to make it a subroutine:
66
CLEAR_LCD:
SETB EN
CLR RS
MOV DATA,#01h
CLR EN
LCALL WAIT_LCD
RET
How that we've written a "Clear Screen" routine, we may clear the LCD at any time by
simply executing an LCALL CLEAR_LCD.
Programming Tip: Executing the "Clear Screen" instruction on the LCD also
positions the cursor in the upper left-hand corner as we would expect.
WRITING TEXT TO THE LCD
Now we get to the real meat of what we're trying
SETB EN
SETB RS
MOV DATA,A
CLR EN
LCALL WAIT_LCD
RET
67
Chapter 4:-
Software description:
Program of the project
sbit rs=P2^0;
sbit en=P2^1;
sbit ad_wr=P2^3;
sbit intr=P2^2;
sbit motor=P2^4;
sbit enter=P2^5;
sbit inc=P2^6;
sbit dec=P2^7;
sbit buzzer=P3^1;
//void timer0() interrupt 1 // Function to generate clock of frequency.
//{
//clk=~clk;
//}
//void timer1() interrupt 2 // Function to generate clock of frequency 500KHZ using
Timer 0 interrupt.
//{
//clk1=~clk1;
//}
void delay(unsigned int count) // Function to provide time delay in msec.
{
68
int i;
for(i=0;i<count;i++);
}
void lcd_data(char date)
{
lcd=date;
rs=1;
en=1;
delay(50);
en=0;
delay(100);
}
void lcd_cmd(char cmdd)
{
lcd=cmdd;
rs=0;
en=1;
delay(5);
en=0;
delay(10);
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0e);
lcd_cmd(0x80);
}
void lcd_print(char p)
{
unsigned char h=0;
while(ph!='\0')
69
{
lcd_data(ph);
h++;
}
}
void main()
{
unsigned int value,value1,speed=20,flag;
//TMOD=0x22; //timer0 setting for generating clock of 500KHz using interrupt enable
mode.
//TH0=0xfe;
//IE=0x82;
motor=1;
buzzer=1;
dec=1;
inc=1;
enter=1;
//TR0=1;
P1=0xff;
motor=0;
buzzer=1;
lcd_print("ENTR SPEED LIMIT");
motor=1;
buzzer=1;
while(enter==1)
{
motor=1;
70
buzzer=1;
lcd_cmd(0xc0);
if(inc==0)
{
speed=speed+10;
if(speed>60)
speed=60;
delay(10);
}
else if(dec==0)
{
speed=speed-10;
if(speed<20||speed>60)
speed=20;
delay(100);
}
lcd_data((speed/100)+0x30);
lcd_data(((speed%100)/10)+0x30);
lcd_data((speed%10)+0x30);
}
lcd_cmd(0x01);
lcd_print("SPEED LIMIT=");
lcd_data((speed/100)+0x30);
lcd_data(((speed%100)/10)+0x30);
lcd_data((speed%10)+0x30);
delay(1000);
while(enter==0);
lcd_cmd(0xc0);
delay(100);
71
intr=1;
lcd_print("ACCLERATOR =");
P1=0xff;
ad_wr=1;
delay(700);
ad_wr=0;
delay(10);
while(1)
{
P1=0xff;
ad_wr=1;
while(flag<12)
{
if(value>0)
{
motor=0;
delay(value1*10);
}
motor=1;
delay((100-value1));
}
ad_wr=0;
delay(10);
//while(intr==0);
lcd_cmd(0xcc);
value=P1;
72
if(value>=speed)
{
value1=speed;
buzzer=0;
}
else
{
value1=value;
buzzer=1;}
lcd_data((value1/100)+0x30);lcd_data(((value1%100)/10)+0x30);lcd_data((value1%10)+0x30);
if(value>0){motor=0;delay(value1*10);}
motor=1;delay((100-value1));}
73
Results and discussions
The proposed result for this topic is to prepare a model which will show the experimental view of this project covering the theoretical as well as practical areas related to this project this model will also show the practical implementation of the device which could be fitted in to the automobiles for safety purposes. We are trying to work with the all-pros and cons related to this project. Hopefully we reduce the speed vehicle’s SDC unit automatically reduce the speed.
74
CONCLUSION
Here by we conclude that this project is very easy to implement on current system, low cost and durable, ensures maximum safety to passengers and public, the driver gets allInformation about the road without distracting him from driving, driver gets all information even in bad weather conditions, low power consumption. This project is further enhanced by automatic speed control when the vehicles get any hazard signal from outside environment.
75
Reference:- Telaprolu, m.k,sarma,V.V.;.;ratankanth,E.K.;Rao,S.N.;Banda,v.,vehicular
Electronics and safety(ICVES), IEEE international conference pune(2010).
Gangadhar, S.; R N shetty Inst. Of Technol, Anintelligent road traffic control system, IEEEconference publication kahargpur (20103).
Berndt, Don, Real-Time Embedded Technology andApplications Symposium (RTAS), IEEE Education &Learning (2011).
Kassem, N. Microsoft Corp., Redmond, WA, USAKosba, A.E.; Youssef, M.;VRF-Based Vehicle Detectionand Speed Estimation vehicular Technology Conference(VTC Spring), IEEE (2012).
Murthy, C.; Manimaran, G.; Resource Management in Real-Time Systems and Networks2011. Electronics for you magazine www.Electronicshub.org www.ingenstech.com www.ijarcce.com 3. Ioannou P.A., Chien C.C. Autonomous Intelligent Cruise
Control. IEEE Trans. Veh. Technol.1993;42:657–672. Milanés V., Onieva E., Pérez J., de Pedro T., González C. Control de Velocidad
Adaptativo para Entornos Urbanos Congestionados. Rev. Iberoam. Automát. Informát. Ind. 2009;6:66–73.
Lusetti B., Nouveliere L., Glaser S., Mammar S. Experimental Strategy for A System Based Curve Warning System for A Safe Governed Speed of A Vehicle. Proceedings of IEEE Intelligent Vehicles Symposium; Eindhoven, The Netherlands. June 2008; pp. 660–665.
Zhang Y.L. A Design of bi-verification vehicle access intelligent control system based on RFID. Proceedings of the Ninth International Conference on Electronic Measurement & Instruments (ICEMI’2009); Beijing, China. August 16–19, 2009.
Hsieh W.H., Ho C.J., Jong G.J. Vehicle Information Communication Safety Combined with Mobile RFID. Proceedings of International Conference on Intelligent Information Hiding and Multimedia Signal Processing; Harbin, China. August 15–17, 2008.
Chon H.D., Jun S.B., Jung H.J., An S.W. Using RFID for Accurate Positioning. J. Global Positioning Syst. 2004;3:32–39.
11. Seo G.D., Yazici A., Ozguner U., Cho J.H. An Approach for Data Collection and Traffic Signal Control in the Futuristic City. Proceedings of the 10th International Conference on Advanced Communication Technology; Phoenix Park, Gangwon-Do, Korea. February 17–20, 2008; pp. 667–672.
12. K. Development and Evaluation of In-Vechicle Signing System Utilizing RFID Tags as Digital Traffic Signals. Int. J. ITS Res. 2006;4:53–58.
13. Rappaport T. Wireless Communications: Principles and Practice. 2nd ed. Prentice Hall; New York, NY, USA: 2003.
14. Naranjo J.E., González C., Reviejo J., Garcia R., de Pedro T. Adaptive Fuzzy Control for Inter-Vehicle Gap Keeping. IEEE