Upload
kishan-amara
View
2.444
Download
8
Embed Size (px)
DESCRIPTION
Embedded systems
Citation preview
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
CHAPTER-1 INTRODUCTION
1.1 Introduction
The digital object counter is a cost effective and a simple system. It overcomes the
problem of manual counting of objects. Everything is digital, so the signals can be used for
further analysis and is compatible with other digital devices. If this system is implemented, then
automation in the product counting can be achieved. Also, there is no hazardous elements used in
the circuitry and hence it can be used even at hazardous atmospheres in an industrial area.
The logic is very simple, the circuit has TSOP1738 sensor which detects whether
there is a object or not in front of it. The microcontroller will take the input from the TSOP1738
sensor, process it and sends the output to the LCD display unit which will display the number of
products counted.
The TSOP1738 is a IR detecting device, it detects the IR rays transmitted at 38kHz
frequency (it is transmitting frequency not the frequency of the IR rays). Its output is not affected
by the surrounding lights; therefore it will sense the object only. To transmit IR rays at 38 kHz
the astable multivibrator mode of 555 IC is used. The output of the sensor is processed by the
microcontroller. After processing it the controller’s output signal is fed to the LCD display which
displays the output.
1.2 Aim of the Project
1. The Basic aim of the project is to count the number of objects.
2. To design an efficient model with low cost.
DEPT OF E.C.E Page 1
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
CHAPTER 2IMPLEMENTATION OF THE PROJECT
2.1 BLOCK DIAGRAM
To implement the project we require both hardware and software . The block diagram of
the project is illustrated in the figure below.
Figure 2.1: Block diagram of digital object counter using Microcontroller
DEPT OF E.C.E Page 2
POWER SUPPLY
8
9
C
5
1
OSCILLATOR
IR SENSORS RESET
DISPLAY
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Description of Blocks:
Power Supply:
The input to the system is 230v AC; the power supply section converts the input to required
DC voltage and distributes to the other parts of the circuit.
Oscillator:
The oscillator circuit is used to provide micro controller IC with a working clock
frequency.
Reset:
This part is used to reset the micro controller IC
Sensor:
The heart of the project is the sensor which senses the income of a object and sends a signal
to the microcontroller.
Controller:
It also plays a major role in checking the signal. When ever the sensor gives a signal, the
controller gets the signal and increments the counter according to the function assigned to it.
LCD display:
This is used to display the count for the number of objects.
2.2 POWER SUPPLY
2.2.1 Introduction:
The input to the circuit is applied from the regulated power supply. The a.c. input i.e., 230V
from the mains supply is step down by the transformer to 12V and is fed to a rectifier. The output
obtained from the rectifier is a pulsating d.c voltage. So in order to get a pure d.c voltage, the
DEPT OF E.C.E Page 3
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
output voltage from the rectifier is fed to a filter to remove any a.c components present even after
rectification. Now, this voltage is given to a voltage regulator to obtain a pure constant dc
voltage.
Figure 2.2 : Block Diagram of Power Supply
Transformer:
Usually, DC voltages are required to operate various electronic equipment and these voltages
are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c input available at
the mains supply i.e., 230V is to be brought down to the required voltage level. This is done by a
transformer. Thus, a step down transformer is employed to decrease the voltage to a required
level.
Rectifier:
The output from the transformer is fed to the rectifier. It converts A.C. into pulsating D.C.
The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier is used
because of its merits like good stability and full wave rectification.
Filter:
DEPT OF E.C.E Page 4
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Capacitive filter is used in this project. It removes the ripples from the output of rectifier and
smoothens the D.C. Output received from this filter is constant until the mains voltage and load
is maintained constant. However, if either of the two is varied, D.C. voltage received at this point
changes. Therefore a regulator is applied at the output stage.
Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage regulator is an
electrical regulator designed to automatically maintain a constant voltage level. In this project,
power supply of 5V and 12V are required. In order to obtain these voltage levels, 7805 and 7812
voltage regulators are to be used. The first number 78 represents positive supply and the numbers
05, 12 represent the required output voltage levels. A variable regulated power supply, also
called a variable bench power supply, is one where you can continuously adjust the output
voltage to your requirements. Varying the output of the power supply is the recommended way
to test a project after having double checked parts placement against circuit drawings and the
parts placement guide.
This type of regulation is ideal for having a simple variable bench power supply. Actually this
is quite important because one of the first projects a hobbyist should undertake is the
construction of a variable regulated power supply. While a dedicated supply is quite handy e.g.
5V or 12V, it's much handier to have a variable supply on hand, especially for testing.
Figure 2.3 : Pins of Voltage Regulator
Most digital logic circuits and processors need a 5-volt power supply. To use these parts
we need to build a regulated 5-volt source. Usually you start with an unregulated power supply
ranging from 9 volts to 24 volts DC (A 12 volt power supply is included with the Beginner Kit
DEPT OF E.C.E Page 5
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
and the Microcontroller Beginner Kit.). To make a 5 volt power supply, we use a LM7805
voltage regulator IC (Integrated Circuit). The IC is shown above.
2.2.2 Circuit Features:
Brief description of operation: Gives out well regulated +5V output, output current
capability of 100 mA
Circuit protection: Built-in overheating protection shuts down output when regulator IC
gets too hot
Circuit complexity: Very simple and easy to build
Circuit performance: Very stable +5V output voltage, reliable operation
Availability of components: Easy to get, uses only very common basic components
Design testing: Based on datasheet example circuit, I have used this circuit successfully
as part of many electronics projects
Applications: Part of electronics devices, small laboratory power supply
Power supply voltage: Unregulated DC 8-18V power supply
Power supply current: Needed output current + 5 mA
Component costs: Few dollars for the electronics components + the input transformer
cost.
2.2.3 CIRCUIT DIAGRAM:
Figure 2.4: Circuit Diagram of Power Supply
DEPT OF E.C.E Page 6
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
This 5V dc acts as Vcc to the microcontroller. The excess voltage is dissipated as heat via an
Aluminum heat sink attached to the voltage regulator.
Bridge Rectifier:
A diode bridge is an arrangement of four diodes connected in a bridge circuit as shown
below, that provides the same polarity of output voltage for any polarity of the input voltage.
When used in its most common application, for conversion of alternating current (AC) input into
direct current (DC) output, it is known as a bridge rectifier. The diagram describes a diode-
bridge design known as a full-wave rectifier. This design can be used to rectify single phase AC
when no transformer center tap is available. A bridge rectifier makes use of four diodes in a
bridge arrangement to achieve full-wave rectification. This is a widely used configuration, both
with individual diodes wired as shown and with single component bridges where the diode
bridge is wired internally.
Figure 2.5: Current Flow in The Bridge Rectifier
LM7805 (3-Terminal 1A Positive Voltage Regulator):
Features:
• Output Current up to 1A
• Thermal Overload Protection
• Short Circuit Protection
• Output Transistor Safe Operating Area Protection
DEPT OF E.C.E Page 7
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Description:
The MC7805 three terminal positive regulators are available in the TO-220/D-PAK package
and with several fixed output voltages, making them useful in a wide range of applications. Each
type employs internal current limiting, thermal shut down and safe operating area protection,
making it essentially indestructible. If adequate heat sinking is provided, they can deliver over
1A output current. Although designed primarily as fixed voltage regulators, these devices can be
used with external components to obtain adjustable voltages and currents.
Figure 2.6: Pin Diagram Of 7805
2.3 Introduction to Embedded System
An embedded system is a special purpose computing system designed to perform one or
a few dedicated functions, often with real time computing constraints. It is usually embedded as
a part of a complete device including hardware and software. In contrast, a general purpose
computer, such as a personal computer can do many different tasks depending on programming.
Embedded systems have become very important today as they control many of the common
devices we use.
Many embedded systems have substantially different design constraints than
desktop computing applications. No single characterization applies to the diverse spectrum of
DEPT OF E.C.E Page 8
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
embedded systems. However, some combination of cost pressure, long life-cycle, real time
requirements, reliability requirements and design function dis-culture can make it difficult to be
successful applying traditional computer systems methodologies and tools to embedded
applications. Embedded systems in many cases must be optimized for life-
cycle and business driven factors rather than for maximum computing
throughput. There is currently little tool support for expanding embedded computer design to the
scope of holistic embedded system design. However, knowing the strengths and weaknesses of
current approaches can set expectations appropriately, identify risk areas to tool adopters and
suggest ways in which tool builders can meet industrial needs.
Since the embedded system is dedicated to specific tasks, design engineers can optimize
it, reducing the cost of the product or increasing the reliability and performance. Some embedded
systems are mass produced and thus benefit from economies of scale.
2.3.1 Examples of Embedded Systems:
An embedded system encompasses the CPU as well as many other resources. In
addition to the CPU and memory hierarchy, there are a variety of interfaces that enable the
system to measure, manipulate and otherwise interact with the external environment. Some
differences with desktop computing may be: The human interface may be as simple as a flashing
light or as complicated as real time robotic vision. The diagnostic part may be used for
diagnosing the system that is being controlled and not just for diagnosing the computer.
Special purpose field programmable (FPGA), application specific (ASIC) or even non-
digital hardware may be used to increase the performance or safety.
Software often has a fixed function and is specific to the application. Instead of
executing spreadsheets, word processing and engineering analysis. Embedded systems typically
execute control laws, finite state machines and signal processing algorithms.
2.4 8051 Microcontroller:
2.4.1 Introduction
DEPT OF E.C.E Page 9
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
A micro-controller consists of a powerful CPU tightly coupled with memory,
various I/O interfaces such as serial port, parallel port, timer or counter, interrupt controller, data
acquisition interfaces like A/D converter, D/A converter integrated on a single silicon chip.
If a system is developed with a microprocessor, the designer has to go for external
memory such as RAM, ROM, EPROM and peripherals. But controller is provided with all these
facilities on a single chip. Development of a micro-controller reduces PCB size and cost of the
design.
One of the major differences between a micro-processor and a micro-controller is that
a controller often deals with bits not bytes as in the real world application. Intel has introduced a
family of micro-controllers called the MCS-51.
The Intel 8051 is an 8-bit microcontroller which means that most available operations
are limited to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and Extended. The
Short and Standard chips are often available in DIP (dual in-line package) form, but the
Extended 8051 models often have a different form factor, and are not "drop-in compatible". All
these things are called 8051 because they can all be programmed using 8051 assembly language,
and they all share certain features.
2.4.2. Features:
1. 128KB on chip program memory.
2. 128 bytes on chip data memory (RAM).
3. 4 reg banks.
4. 128 user defined software flags.
5. 8-bit data bus
6. 16-bit address bus
7. 32 general purpose registers each of 8 bits
8. 16 bit timers (usually 2, but may have more, or less).
DEPT OF E.C.E Page 10
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
9. 3 internal and 2 external interrupts.
10. Bit as well as byte addressable RAM area of 16 bytes.
11. Four 8-bit ports, (short models have two 8-bit ports).
12. 16-bit program counter and data pointer.
13. 1 Microsecond instruction cycle with 12 MHz Crystal.
Typical applications:
8051 chips are used in a wide variety of control systems, telecom applications, robotics
as well as in the automotive industry. By some estimation, 8051 family chips make up over 50%
of the embedded chip market.
2.4.3 Pin Configuration:
Figure 2.7 : Pin Configuration of 8051 Microcontroller
DEPT OF E.C.E Page 11
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
2.4.4. Basic Pins description:
Vcc:
Supply voltage.
Gnd:
Ground.
Pin 9:
PIN 9 is the reset pin which is used to reset the microcontroller’s internal registers and
ports upon starting up. (Pin should be held high for 2 machine cycles.)
Pin 11 – TXD:
Serial asynchronous communication output or Serial synchronous communication clock
output.
Pin 10 – RXD:
Serial asynchronous communication input or Serial synchronous communication
output.
Pin 19 - XTAL 1:
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
Pin 18 - XTAL2:
Output from the inverting oscillator amplifier.
Figure 2.8 : Crystal connection
DEPT OF E.C.E Page 12
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
which can be configured for use as an on chip oscillator. Either a quartz crystal or ceramic
resonator may be used. To drive the device from an external clock source, XTAL2 should be left
unconnected while XTAL1 is driven as shown in Figure.
Pins 40 and 20:
Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V 500mA to
function properly, although there are lower powered versions like the Atmel 2051 which is
a scaled down version of the 8051 which runs on +3V.
Pin 30- ALE/PROG:
Address Latch Enable (ALE) is an output pulse for latching the low byte of the address
during accesses to external memory. This pin is also the program pulse input (PROG) during
Flash Programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator
frequency and may be used for external timing or clocking purposes. Note, however, that one
ALE pulse is skipped during each access to external data memory.
If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the
bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly
pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external
execution mode.
Pin 29- PSEN:
Program Store Enable (PSEN) is the read strobe to external program memory.When
the AT89C51 is executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to external Data
memory.
Pin 31- EA/VPP:
External Access Enable. EA must be strapped to GND in order to enable the device to
fetch Code from external program memory locations starting at 0000H up to FFFFH. Note,
however, that if lock bit 1 is programmed, EA will be internally latched on reset.EA should be
strapped to VCC for internal program executions.
DEPT OF E.C.E Page 13
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
This pin also receives the 12-volt programming enable voltage (VPP) during Flash
programming.
PORTS:
There are 4 8-bit ports: P0, P1, P2 and P3.
Port P1 (Pins 1 to 8):
The port P1 is a general purpose input/output port which can be used for a variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or additional functions associated with them based upon the context of their usage. The port 1 output buffers can sink/source four TTL inputs. When 1s are written to portn1 pins are pulled high by the internal pull-ups and can be used as inputs.
Port Pin Alternate Functions
Port Pin Alternate Functions
P1.0 T2(external count to Timer/Counter 2), clock-out
P1.1 T2EX(Timer/Counter 2 capture/reload trigger and direction control)
P1.5 MOSI (used for In-System Programming)
P1.6 MISO(used for In-System Programming)
P1.7 SCK(used for In-System Programming)
Table 2.1 : Port1 Pin Alternate functions
Port P3 (Pins 10 to 17):
PORT P3 acts as a normal IO port, but Port P3 has additional functions such as, serial transmit and receive pins, 2 external interrupt pins, 2 external counter inputs, read and write pins for memory access.
DEPT OF E.C.E Page 14
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Port Pin Alternate Functions:
Table 2.2 : Port 3 Pin alternate Function
Port P2 (pins 21 to 28):
PORT P2 can also be used as a general purpose 8 bit port when no external memory is present,
but if external memory access is required then PORT P2 will act as an address bus in conjunction
with PORT P0 to access external memory. PORT P2 acts as A8-A15.
Port P0 (pins 32 to 39):
PORT P0 can be used as a general purpose 8 bit port when no external memory is present, but if
external memory access is required then PORT P0 acts as a multiplexed address and data bus
that can be used to access external memory in conjunction with PORT P2. P0 acts as AD0-AD7.
Oscillator:
An Electronic device, that generates oscillations (Signals), is called an oscillator. Simply says an
oscillator receives DC energy and converts it into AC energy of desired frequency. The
DEPT OF E.C.E Page 15
Port Pin Alternate Functions
P3.0 RXD (serial Input port)
P3.1 TXD (serial output port)
P3.2 INT0 bar (external Interrupt 0)
P3.3 INT1 bar (external Interrupt 1)
P3.4 T0 (timer 0 external Input)
P3.5 T1 (timer 1 external input)
P3.6 WR bar (external data memory write strobe)
P3.7 RD bar (external data memory read strobe)
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
frequency of oscillations depends up on the constants of the device. Oscillators are extensively
used in electronic equipments.
Oscillator Circuits-
The 8051 requires an external oscillator circuit. The oscillator circuit usually runs around 12MHz, although the 8051 (depending on which specific model) is capable of running at a maximum of 40MHz. Each machine cycle in the 8051 is 12 clock cycles, giving an effective cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the maximum 40MHz clock). The oscillator circuit generates the clock pulses so that all internal operations are synchronized
. 2.4.5 Architecture of 8051:
Figure 2.9 : Internal architecture of 8051
DEPT OF E.C.E Page 16
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
2.4.6 Data and Program Memory:
The 8051 Microcontroller can be programmed in PL/M, 8051 Assembly, C and a number
of other high-level languages. Many compilers even have support for compiling C++ for an
8051.Program memory in the 8051 is read-only, while the data memory is considered to be
read/write accessible. When stored on EEPROM or Flash, the program memory can be rewritten
when the micro controller is in the special programmer circuit.
Program Start Address
The 8051 starts executing program instructions from address 0000 in the program
memory. The A register is located in the SFR memory location 0xE0. The A register works in a
similar fashion to the AX register of x86 processors. The A register is called the accumulator,
and by default it receives the result of all arithmetic operations.
2.4.7 General Purpose Registers:
The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means
that there are essentially 32 available general purpose registers, although only 8 (one bank) can
be directly accessed at a time. To access the other banks, we need to change the current bank
number in the flag status register.
Figure 2.10 : General Purpose Register
DEPT OF E.C.E Page 17
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
2.4.8 Special Function Registers:
The Special Function Register (SFR) is the upper area of addressable memory, from address
0x80 to0xFF. A, B, PSW, DPTR are called SFR. This area of memory cannot be used for data or
program storage, but is instead a series of memory-mapped ports and registers. All port input and
output can therefore be performed by memory move operations on specified addresses in the
SFR. Also, different status registers are mapped into the SFR, for use in checking the status of
the 8051, and changing some operational parameters of the 8051.
A and B Registers:
The A register is located in the SFR memory location 0xE0. The A register works in
a similar fashion to the AX register of x86 processors. The A register is called
the accumulator, and by default it receives the result of all arithmetic operations. The B register
is used in a similar manner, except that it can receive the extended answers from the multiply and
divide operations. When not being used for multiplication and Division, the B register is
available as an extra general-purpose register.
Figure 2.11 : Accumulator Register
Figure 2.12 : B register
DEPT OF E.C.E Page 18
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Program Status Word (PSW) register:
PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two register
bank select bits, Overflow flag, parity bit and user-definable status flag.
Figure 2.13 : PSW Register
P - Parity bit. If a number stored in the accumulator is even then this bit will be automatically
set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.
- Bit 1. This bit is intended to be used in the future versions of microcontrollers.
OV Overflow occurs when the result of an arithmetical operation is larger than 255 and cannot
be stored in one register. Overflow condition causes the OV bit to be set (1). Otherwise, it will be
cleared (0).
RS0, RS1 - Register bank select bits. These two bits are used to select one of four register banks
of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four banks of
RAM.
Data Pointer Register (DPTR):
DPTR register is not a true one because it doesn't physically exist. It consists of two separate
registers: DPH (Data Pointer High) and (Data Pointer Low). For this reason it may be treated as a
16-bit register or as two independent 8-bit registers. Their 16 bits are primarly used for external
memory addressing. Besides, the DPTR Register is usually used for storing data and
intermediate results.
DEPT OF E.C.E Page 19
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.14 : DPTR Register
Stack Pointer (SP) Register:
A value stored in the Stack Pointer points to the first free stack address and permits stack
availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops
decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack Pointer,
which means that the space of RAM reserved for the stack starts at this location. If another value
is written to this register, the entire Stack is moved to the new memory location.
Figure 2.15 : SP Register
P0, P1, P2, P3 - Input/output Registers:
Figure 2.16 : Input/output Registers
DEPT OF E.C.E Page 20
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
If neither external memory nor serial communication system are used then 4 ports with in
total of 32 input/output pins are available for connection to peripheral environment. Each bit
within these ports affects the state and performance of appropriate pin of the microcontroller.
Thus, bit logic state is reflected on appropriate pin as a voltage (0 or 5 V) and vice versa, voltage
on a pin reflects the state of appropriate port bit.
As mentioned, port bit state affects performance of port pins, i.e. whether they will be
configured as inputs or outputs. If a bit is cleared (0), the appropriate pin will be configured as an
output, while if it is set (1), the appropriate pin will be configured as an input. Upon reset and
power-on, all port bits are set (1), which means that all appropriate pins will be configured as
inputs.
2.4.9 Counters and Timers:
As you already know, the microcontroller oscillator uses quartz crystal for its operation.
As the frequency of this oscillator is precisely defined and very stable, pulses it generates are
always of the same width, which makes them ideal for time measurement. Such crystals are also
used in quartz watches. In order to measure time between two events it is sufficient to count up
pulses coming from this oscillator. That is exactly what the timer does. If the timer is properly
programmed, the value stored in its register will be incremented (or decremented) with each
coming pulse, i.e. once per each machine cycle. A single machine-cycle instruction lasts for 12
quartz oscillator periods, which means that by embedding quartz with oscillator frequency of
12MHz, a number stored in the timer register will be changed million times per second, i.e. each
microsecond.
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their
main purpose is to measure time and count external events. Besides, they can be used for
generating clock pulses to be used in serial communication, so called Baud Rate.
Timer T0
As seen in figure below, the timer T0 consists of two registers – TH0 and TL0 representing a low
and a high byte of one 16-digit binary number.
DEPT OF E.C.E Page 21
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.17 : Timer T0
TMOD Register (Timer Mode):
The TMOD register selects the operational mode of the timers T0 and T1. As seen in figure
below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 - bit7) refer to
the timer 1.
Figure 2.18 : TMOD Register
GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3):
o 1 - Timer 1 operates only if the INT1 bit is set.
o 0 - Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1 selects pulses to be counted up by the timer/counter 1:
o 1 - Timer counts pulses brought to the T1 pin (P3.5).
o 0 - Timer counts pulses from internal oscillator.
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
o 1 - Timer 0 operates only if the INT0 bit is set.
o 0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
o 1 - Timer counts pulses brought to the T0 pin (P3.4).
o 0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.
DEPT OF E.C.E Page 22
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
T1M1,T1M0 These two bits select the operational mode of the Timer 0.
T 1 M 1 T 1 M 0 M O D E D E S C R I P T I O N
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto-reload
1 1 3 Split mode
Table 2.3: TMOD Register (TimerMode)
Timer Control (TCON) Register:
TCON register is also one of the registers whose bits are directly in control of timer operation.
Only 4 bits of this register are used for this purpose.
Figure 2.19 : TCON Register
TF1 bit is automatically set on the Timer 1 overflow.
TR1 bit enables the Timer 1.
o 1 - Timer 1 is enabled.
o 0 - Timer 1 is disabled.
TF0 bit is automatically set on the Timer 0 overflow.
TR0 bit enables the timer 0.
o 1 - Timer 0 is enabled.
o 0 - Timer 0 is disabled.
UART (Universal Asynchronous Receiver and Transmitter):
One of the microcontroller features making it so powerful is an integrated UART, better
known as a serial port. It is a full-duplex port, thus being able to transmit and receive data
DEPT OF E.C.E Page 23
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
simultaneously and at different baud rates. Without it, serial data send and receive would be an
enormously complicated part of the program in which the pin state is constantly changed and
checked at regular intervals. When using UART, all the programmer has to do is to simply select
serial port mode and baud rate. When it's done, serial data transmit is nothing but writing to the
SBUF register, while data receive represents reading the same register. The microcontroller takes
care of not making any error during data transmission.
Figure 2.20 : SBUF Register
Serial Port Control (SCON) Register:
Figure 2.21 : SCON register
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
When set, it enables multiprocessor communication in mode 2 and 3, and eventually
mode 1. It should be cleared in mode 0.
REN - Reception Enable bit enables serial reception when set. When cleared, serial
reception is disabled.
TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of
transmiting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.
RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th
bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is
sent. It's a signal to the processor that the line is available for a new byte transmite. It
must be cleared from within the software.
DEPT OF E.C.E Page 24
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte
is received and should be read quickly prior to being replaced by a new data. This bit is
also cleared from within the software.
As seen, serial port mode is selected by combining the SM0 and SM2 bits:
S M 0 S M 1 M O D E D E S C R I P T I O N B A U D R A T E
0 0 0 8-bit Shift Register 1/12 the quartz frequency
0 1 1 8-bit UART Determined by the timer 1
1 0 2 9-bit UART 1/32 the quartz frequency (1/64 the quartz frequency)
1 1 3 9-bit UART Determined by the timer 1
Table 2.4 : SCON Register
IE Register (Interrupt Enable):
Figu re 2 .22 : IE Reg i s t e r
EA - global interrupt enable/disable:
o 0 - disables all interrupt requests.
o 1 - enables all individual interrupt requests.
ES - enables or disables serial interrupt:
o 0 - UART system cannot generate an interrupt.
o 1 - UART system enables an interrupt.
ET1 - bit enables or disables Timer 1 interrupt:
o 0 - Timer 1 cannot generate an interrupt.
o 1 - Timer 1 enables an interrupt.
EX1 - bit enables or disables external 1 interrupt:
o 0 - change of the pin INT0 logic state cannot generate an interrupt.
o 1 - enables an external interrupt on the pin INT0 state change.
DEPT OF E.C.E Page 25
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
ET0 - bit enables or disables timer 0 interrupt:
o 0 - Timer 0 cannot generate an interrupt.
o 1 - enables timer 0 interrupt.
EX0 - bit enables or disables external 0 interrupt:
o 0 - change of the INT1 pin logic state cannot generate an interrupt.
o 1 - enables an external interrupt on the pin INT1 state change.
IP Register (Interrupt Priority):
The IP register bits specify the priority level of each interrupt (high or low priority).
Figure 2.23 : IP register
PS - Serial Port Interrupt priority bit
PT1 - Timer 1 interrupt priority
PX1 - External Interrupt INT1 priority
PT0 - Timer 0 Interrupt Priority
PX0 - External Interrupt INT0 Priority
PCON Register :
Figure 2.24 : PCON Register
DEPT OF E.C.E Page 26
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
The purpose of the Register PCON bits is:
SMOD Baud rate is twice as much higher by setting this bit.
GF1 General-purpose bit (available for use).
GF1 General-purpose bit (available for use).
GF0 General-purpose bit (available for use).
PD By setting this bit the microcontroller enters the Power Down mode.
IDL By setting this bit the microcontroller enters the Idle mode.
2.5 Liquid Crystal Display (LCD): A Liquid crystal display is a thin, flat panel used for electronically displaying information such as text, images, and moving pictures. Its uses include monitors for computers, televisions, instrument panels, and other devices ranging from aircraft cockpit displays, to every-day consumer devices such as video players, gaming devices, clocks, watches, calculators, and telephones. Among its major features are its light weight construction, its portability, and its ability to be produced in much larger screen sizes. Its low electrical power consumption enables it to be used in battery- powered electronic equipment.
It is an electronically-modulated optical device made up of any number of pixels filled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produce images in color or monochrome. Each pixel of an LCD typically consists of a layer of molecules aligned between two transparent electrodes and two polarizing filters. With no actual liquid crystal between the polarizing filters, light passing through the first filter would be blocked by the second polarizer. The surfaces of the electrodes that are in contact with the liquid crystal material are treated so as to align the liquid crystal molecules in a particular direction. The direction of the liquid crystal alignment is then defined by the direction of rubbing.
Electrodes are made of a transparent conductor called Indium Tin Oxide (ITO).Before applying an electric field, the orientation of the liquid crystal molecules is determined by the alignment at the surfaces of electrodes. In a twisted nematic device (still the most common liquid crystal device), the surface alignment directions at the two electrodes are perpendicular to each other, and so the molecules arrange themselves in a helical structure, or twist. This reduces the rotation of the polarization of the incident light, and the device appears grey. This light will then be mainly polarized perpendicular to the second filter, and thus be blocked and the pixel will appear black. By controlling the voltage applied across the liquid crystal layer in each pixel, light can be allowed to pass through in varying amounts thus constituting different levels of gray.
DEPT OF E.C.E Page 27
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.25 : LCD Pin Configuration
2.5.1 Pin Description:
Vcc, Vss and Vee:
While VCC and VSS provide +5V and ground respectively, VEE is used for controlling
LCD contrast.
RS (Register Select):
There are two important registers inside the LCD. 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 that is sent is a text data which should be displayed on the screen. For
example, to display the letter "T" on the screen you would set RS high
RW (Read/Write):
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
querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read command. All
others are write commands, so RW will almost be low.
EN (Enable):
The EN line is called "Enable". This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should first set this line high (1) and then
set the other two control lines and/or put data on the data bus.
D0-D7 (Data Lines):
The 8-bit data pins, D0-D7 are used to send information to the LCD or read the content
of the LCD’s internal registers. To display letters and numbers, we send ASCII codes for the
DEPT OF E.C.E Page 28
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
letters A-Z, a-z and numbers 0-9 to these pins while making RS=1. There are also instruction
command codes that can be sent to the LCD to clear the display or force the cursor to the home
position or blink the cursor.
Table 3.5 : LCD Pin Description
DEPT OF E.C.E Page 29
PIN SYMBOL I/O DESCRIPTION
1 VSS -- Ground
2 VCC -- +5V power supply
3 VEE -- Power supply to control contrast
4 RS I RS=0 to select command register
RS=1 to select data register
5 R/W I R/W=0 for write
R/W=1 for read
6 EN I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Table 3.5 : LCD Pin Description Table 2.5 : LCD Pin Description2.5.2 LCD Command Codes :
CODE (HEX) COMMAND TO LCD INSTRUCTION REGISTER
1 CLEAR DISPLAY SCREEN
2 RETURN HOME
4 DECREMENT CURSOR(SHIFT CURSOR TO LEFT)
6 INCREMENT CURSOR(SHIFT CURSOR TO RIGHT)
5 SHIFT DISPLAY RIGHT
7 SHIFT DISPLAY LEFT
8 DISPLAY OFF,CURSOR OFF
A DISPLAY OFF,CURSOR ON
C DISPLAY ON,CURSOR OFF
E DISPLAY ON CURSOR BLINKING
F DISPLAY ON CURSOR BLINKING
10 SHIFT CURSOR POSITION TO LEFT
14 SHIFT CURSOR POSITION TO RIGHT
18 SHIFT THE ENTIRE DISPLAY TO THE LEFT
1C SHIFT THE ENTIRE DISPLAY TO THE RIGHT
80 FORCE CURSOR TO BEGINNING OF 1ST LINE
C0 FORCE CURSOR TO BEGINNING OF 2ND LINE
38 2 LINES AND 5x7 MATRIX
Table 2.6: LCD Command Codes
DEPT OF E.C.E Page 30
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
2.5.3 Factors For Designing LCDs:
Resolution:
The horizontal and vertical screen size expressed in pixels (e.g., 1024x768).Unlike CRT
monitors, LCD monitors have a native supported resolution for best display effect.
Viewable size:
The size of an LCD panel measured on the diagonal (more specifically known as active
display area).
Response time:
The minimum time necessary to change a pixel's color or brightness. Response time is
also divided into rise and fall time. For LCD monitors, this is measured in btb (black to black) or
gtg (gray to gray).
Brightness:
The amount of light emitted from the display ( more specifically known as luminance).
Contrast ratio:
The ratio of the intensity of the brightest bright to the darkest dark.
Aspect ratio:
The ratio of the width to the height (for example, 4:3, 5:4, 16:9 or 16:10).
2.5.4. Advantages:
LCD interfacing with 8051 is a real-world application. In recent years the LCD is
finding widespread use replacing LED’s (seven segment LED’s or other multi segment LED’s).
This is due to following reasons:
The declining prices of LCD’s.
The ability to display numbers, characters and graphics. This is in contrast to LED’s,
which are limited to numbers and a few characters.
2.6 INFRARED SENSORS
DEPT OF E.C.E Page 31
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Infrared radiation is the portion of electromagnetic spectrum having wavelengths longer
than visible light wavelengths, but smaller than microwaves, i.e., the region roughly from
0.75µm to 1000 µm is the infrared region. Infrared waves are invisible to human eyes. The
wavelength region of 0.75µm to 3 µm is called near infrared, the region from 3 µm to 6 µm is
called mid infrared and the region higher than 6 µm is called far infrared. (The demarcations are
not rigid; regions are defined differently by many).
2.6.1 Features:
• Nine standard packages in hermetic and low-cost epoxy
• End- and side-radiating packages
• Graded Output
• High efficiency Ga, AI, As, 880 nm LPE process delivers twice the power of Conventional
GaAs 940 nm emitters.
Infrared (IR) radiation is electromagnetic radiation whose wavelength is longer than that
of visible light (400-700 nm), but shorter than that of terahertz radiation (100 µm - 1 mm) and
microwaves (~30,000 µm). Infrared radiation spans roughly three orders of magnitude (750 nm
and 100 nm).
Direct sunlight has a luminous efficacy of about 93 lumens per watt of radiant flux,
which includes infrared (47% share of the spectrum), visible (46%), and ultra-violet (only 6%)
light. Bright sunlight provides luminance of approximately 100,000 candelas per square meter at
the earth’s surface.
2.6.2 Overview:
Infrared imaging is used extensively for both military and civilian purposes. Military
applications include target acquisition, surveillance, night vision, homing and tracking. Non-
military uses include thermal efficiency analysis, remote temperature sensing, short-ranged
wireless communication, spectroscopy, and weather forecasting.. Infrared astronomy uses
sensor-equipped telescopes to penetrate dusty regions of space, such as molecular clouds; detect
cool objects such as planets, and to view highly red-shifted objects from the early days of the
universe.
DEPT OF E.C.E Page 32
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
At the atomic level, infrared energy elicits vibration modes in a molecule through a change
in the dipole moment, making it a useful frequency range for study of these energy states
for molecules of the proper symmetry. Infrared spectroscopy examines absorption and
transmission of photons in the infrared energy range, based on their frequency and
intensity.
Origins of the term
The name means below red (from the Latin infra, "below"), red being the color of
the longest wavelengths of visible light. IR light has a longer wavelength (a lower
frequency) than that of red light, hence below.
Different regions in the infrared
Objects generally emit infrared radiation across a spectrum of wavelengths, but only a
specific region of the spectrum is of interest because sensors are usually designed only to collect
radiation within a specific bandwidth. As a result, the infrared band is often subdivided into
smaller sections.
Figure 2.26 : Infrared Sensors
2.6.3 TSOP 1738 (IR Sensor)
This is the sensor which has been used in this Digital Object Counter. The TSOP 1738 is
a member of IR remote control receiver series. This IR sensor module consists of a PIN diode
and a pre amplifier which are embedded into a single package. The output of TSOP is active low
and it gives +5V in off state. When IR waves, from a source, with a centre frequency of 38 kHz
incident on it, its output goes low.
DEPT OF E.C.E Page 33
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Lights coming from sunlight, fluorescent lamps etc. may cause disturbance to it and
result in undesirable output even when the source is not transmitting IR signals. A bandpass
filter, an integrator stage and an automatic gain control are used to suppress such disturbances.
TSOP module has an inbuilt control circuit for amplifying the coded pulses from the IR
transmitter. A signal is generated when PIN photodiode receives the signals. This input signal is
received by an automatic gain control (AGC). For a range of inputs, the output is fed back to
AGC in order to adjust the gain to a suitable level. The signal from AGC is passed to a band pass
filter to filter undesired frequencies. After this, the signal goes to a demodulator and this
demodulated output drives an npn transistor. The collector output of the transistor is obtained at
pin 3 of TSOP module.
Members of TSOP17xx series are sensitive to different centre frequencies of the IR
spectrum. For example TSOP1738 is sensitive to 38 kHz whereas TSOP1740 to 40 kHz centre
frequency.
Specifications of TSOP 1738:
Continuous data transmission possible (up to 2400 bps)
High immunity against ambient light
Photo detector and preamplifier in one package
Improved shielding against electrical field disturbance
TTL and CMOS compatibility
Active low output
Low power consumption
Internal filter for PCM frequency.
DEPT OF E.C.E Page 34
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.27 : TSOP 1738
2.6.4 IR Receiver:
Features
Tight production distribution.
Steel lead frames for improved reliability in solder mounting.
Good optical-to-mechanical alignment.
Plastic package is infrared transparent black to attenuate visible light.
Can be used with QECXXX LED, Black plastic body allows easy recognition from LED.
Phototransistors also consist of a photodiode with internal gain. A phototransistor is in
essence nothing more than a bipolar transistor that is encased in a transparent case so that light
can reach the base-collector junction. The electrons that are generated by photons in the base-
collector junction are injected into the base, and this photodiode current is amplified by the
transistor's current gain. Note that while phototransistors have a higher responsively for light
they are not able to detect low levels of light any better than photodiodes. Phototransistors also
have slower response times. A simple model of a phototransistor, would be a forward based LED
(emitter–base) and a reverse based photodiode (base–collector) sharing an anode (base) in a
single package such that 99% (αF%) of the light emitted by the led is absorbed by the
photodiode. Each electron-hole recombination in the LED produces one photon and each photon
absorbed by the photodiode produces one electron-hole pair.
DEPT OF E.C.E Page 35
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.28 : IR Receiver
IR Receiver needs to be in line of sight with the transmitter to efficiently transform light
impulses into digital values. The light emitted from the IR LED is modulated with a lens into a
compact beam and then turned an and of concerning the message.
2.7 - 555 Timer IC:
555 is a very commonly used IC for generating accurate timing pulses. It is an 8pin timer
IC and has mainly two modes of operation: monostable and astable. In monostable mode time
delay of the pulses can be precisely controlled by an external resistor and a capacitor whereas in
astable mode the frequency & duty cycle are controlled by two external resistors and a capacitor.
555 is very commonly used for generating time delays and pulses.
Figure 2.29: 555 Timer IC
2.7.1 Pin Diagram of 555 Timer IC:
DEPT OF E.C.E Page 36
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.30 : pin diagram of 555 TIMER IC
2.7.2. Pin Description of 555 timer:
Pin No Function Name
1 Ground (0V) Ground2 Voltage below 1/3 Vcc to trigger the pulse Trigger
3 Pulsating output Output4 Active low; interrupts the timing interval at Output Reset
5 Provides access to the internal voltage divider; default 2/3 Vcc Control Voltage6 The pulse ends when the voltage is greater than Control Threshold7 Open collector output; to discharge the capacitor Discharge8 Supply voltage; 5V (4.5V - 16 V) Vcc
Table 2.7 : Pin Description of 555 timer
2.7.3. Block Diagram
DEPT OF E.C.E Page 37
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.31 : Block Diagram of 555 timer
2.7.4. Operating Overview
The 555 timer is a simple circuit. By taking the trigger signal from high to low
the flip-flop is set. This causes the output to go high and the discharge pin to
be released from Gnd (0V). The releasing of the discharge pin from End
causes an external capacitor to begin charging.
When the capacitor is charges the voltage across it increases. This results in the voltage on the
threshold pin increasing. When this is high enough it will result in the threshold pin to causing
the flip-flop to reset.
This causes the output to go low and the discharge pin is also taken back to
Gnd. This discharges the external capacitor ready for the next time the device
is triggered.
2.7.5 Electrical Characteristics
DEPT OF E.C.E Page 38
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Operating Voltage = 4.5V to 16V
Maximum Supply Current = 5mA @ 5V Operating Voltage
= 12mA @ 15V Operating Voltage
High Level Output Voltage = 3.3V @ 5V Operating Voltage
= 13.3V @ 15V Operating Voltage
Maximum Output Current = 200mA @ 15V Operating Voltage
= 100mA @ 5V Operating Voltage
2.7.6. Monostable Operation
In monostable mode the device produces a 'one shot' pulsed output. The
pulse is started by a taking the trigger input from a high (V+) to a low voltage.
Once triggered the circuit remains in this state even if triggered again during
the pulse interval.
The pulse high time is given by:
t = 1.1 x R1 x C1
The high to low voltage transition on the trigger input causes the Flip-Flop to
become set. This releases the short circuit (created by holding of the
discharge pin low) across capacitor C1. At this point the output goes high.
Capacitor C1 then begins to charge and the voltage across it begins to
increase. When it reaches 2/3 V+ the Flip-Flop is reset. This causes capacitor
C1 to discharge very quickly and the output goes low.
Maximum output pulse = 5 minutes
Minimum output pulse = 5 uS
R1 minimum resistance = 1K ohm
R1 maximum resistance = 1Mohm
DEPT OF E.C.E Page 39
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.32 : Monostable Operation
2.7.7 Astable Operation
DEPT OF E.C.E Page 40
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 2.33: Astable operation
In astable mode the timer continually triggers itself and runs as a multi
vibrator. This results in a continually repeating signal being generated on the
output pin.
The external capacitor C1 charges through both R1 and R2 but discharges only through R2.
Therefore the duty cycle is determined by the ratio of these resistor. If the value of the two
resistors is the same the duty cycle will be 50%and a square wave will be output.
The 'High' output time is given by: t1 = 0.693 (R1 + R2) x C1
The 'Low' output time is given by: t2 = 0.693 (R2) x C1
Therefore the total period is given by: T = t1 + t2 = 0.693 (R1 + R2) x C1
The frequency of oscillation is given by: f = 1 / T= 1.44 / ((R1 + R2) x C1
2.8 Light Emitting Diode (LED) :
A light-emitting diode (LED) is a semiconductor diode that emits incoherent narrow
spectrum light when electrically biased in the forward direction of the PN-junction, as in the
common LED circuit. This effect is a form of electroluminescence.
DEPT OF E.C.E Page 41
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
While sending a message in the form of bits such as 1,the data is sent to the receiver side
correspondingly the LED glows representing the data is being received simultaneously when we
send 8 as a data the LED gets off .
Figure 2.34: Light Emitting Diode
As in the simple LED circuit, the effect is a form of electroluminescence where incoherent
and narrow-spectrum light is emitted from the p-n junction.
LED’s are widely used as indicator lights on electronic devices and increasingly in higher power
applications such as flashlights and area lighting. An LED is usually a small area (less than 1
mm2) light source, often with optics added to the chip to shape its radiation pattern and assist in
reflection. The color of the emitted light depends on the composition and condition of the semi
conducting material used, and can be infrared, visible, or ultraviolet.
Besides lighting, interesting applications include using UV-LED’s for sterilization of water and
disinfection of devices, and as a grow light to enhance photosynthesis in plants
Figure 2.35: Different types of LED
DEPT OF E.C.E Page 42
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
2.8.1 Color Vs Potential Difference:
Color Potential Difference
Infrared - 1.6 V
Red - 1.8 V to 2.1 V
Orange - 2.2 V
Yellow - 2.4 V
Green - 2.6 V
Blue - 3.0 V to 3.5 V
White - 3.0 V to 3.5 V
Ultraviolet - 3.5V
2.8.2 Advantages:
1. LED’s have many advantages over other technologies like lasers. As compared to laser
diodes or IR sources
2. LED’s are conventional incandescent lamps. For one thing, they don't have a filament
that will burn out, so they last much longer. Additionally, their small plastic bulb makes
them a lot more durable. They also fit more easily into modern electronic circuits.
3. The main advantage is efficiency. In conventional incandescent bulbs, the light-
production process involves generating a lot of heat (the filament must be warmed).
Unless you're using the lamp as a heater, because a huge portion of the available
electricity isn't going toward producing visible light.
4. LED’s generate very little heat. A much higher percentage of the electrical power is
going directly for generating light, which cuts down the electricity demands considerably.
DEPT OF E.C.E Page 43
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
5. LED’s offer advantages such as low cost and long service life. Moreover LED’s have
very low power consumption and are easy to maintain.
2.8.3 Disadvantages:
1. LED’s performance largely depends on the ambient temperature of the operating
environment.
2. LED’s must be supplied with the correct current.
3. LED’s do not approximate a "point source" of light, so cannot be used in applications
needing a highly collimated beam.
But the disadvantages are quite negligible as the negative properties of LED’s do not
apply and the advantages far exceed the limitations
2.9 SOFTWARE DESCRIPTION
2.9.1 KEIL Software
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 that instruct the processor what operations to perform. Therefore, to effectively write
assembly language programs, you should be familiar with both, the microprocessor 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 to
the symbolic name DATE. If your program contains a set
of instructions used as a timing loop (a set of instructions executed repeatedly until a specific
DEPT OF E.C.E Page 44
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
amount of time has passed), you can name the instruction group TIMER_LOOP.An assembly
language program has three constituent parts:
1. Machine instructions
2. Assembler directives
3. Assembler controls
A Machine instruction is a machine code that can be executed by the machine. Detailed
discussion of the machine instructions can be found in the hardware manuals of the 8052.
An Assembler directive is used to define the program structure and symbols and generate non-
executable code (data, messages etc…). Assembler directives instruct the assembler how to
process subsequent assembly language instructions. Directives also provide a way for you to
define program constants and reserve space for variables.
An Assembler control sets the assembly mode and directs 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.
2.9.2 Overview of KEIL Cross C Compiler
It is possible to create the source files in a text editor such as notepad, run the compiler
on each C source file, specifying a list of controls, run the Assembler on each assembler source
file, specifying another list of controls, run either the library manager or linker (again specifying
a list of controls) and finally running the Object-HEX converter to convert the linker output file
to an Intel Hex file. Once that has been completed the Hex file can be used to create source files;
automatically compile, link and convert using options set with an easy to use user interface and
finally simulate or perform debugging on the hardware with access to C variables and memory.
Unless you have to use the tolls on the command line, the choice is clear. KEIL Greatly
simplifies the process of creating and testing an embedded application.
2.9.3 Simulation/debugger:
DEPT OF E.C.E Page 45
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
The simulation/debugger in KEIL can perform a very detailed simulation of a micro
controller along with external signals. It is possible to view the precise execution time of a single
assembly instruction, or a single line of C code, all the way up to the entire application, simply
by entering the crystal frequency. A window can be opened for each peripheral on the device,
showing the state of the peripheral. This enables quick trouble shooting of miss-configured
peripherals. Breakpoints may be set on either assembly instructions or lines of C code, and
execution may be stepped through one instruction or Cline at a time. The contents of all the
memory areas may be viewed allowing a detailed view of what the microcontroller is doing at
any point in time.
2.9.4 Creating your own application in Uvision:
To create a new project in uVision2, you must:
1. Select Project - New Project.
2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device.
4. Database
5. Create source files to add to the project.
6. Select Project - Targets, Groups, and Files. Add/Files, select Source
Group1, and add the source files to the project.
7. Select Project - Options and set the tool options. Note when you select the target
device from the Device Database all-special options are set automatically. You only need to
configure the memory map of your target hardware. Default memory model settings are optimal
for most.
2.9.5 Debugging An Application in Uvision2 :
To debug an application created using uVision2, you must:
Select Debug - Start/Stop Debug Session.
Use the Step toolbar buttons to single-step through your program. You may enter
G, main in the Output Window to execute to the main C function.
DEPT OF E.C.E Page 46
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step, Go, Break, and so on.
CHAPTER 3
CIRCUIT OPERATION
3.1 Circuit Diagram
DEPT OF E.C.E Page 47
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 3.1: Circuit Diagram of Digital Object Counter using Microcontroller
DEPT OF E.C.E Page 48
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
Figure 3.2 : IR TRANSMITTER CIRCUIT
Figure 3.3: IR RECEIVER CIRCUIT
DEPT OF E.C.E Page 49
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
3.2 Electrical and Component Specification:
Microcontroller : 89c51
Power consumption : 1W (max)
Loads to be connected : Sensor (230v)
LCD (liquid crystal display) : 1
Power Supply : 5v/1A
No. of devices : 1
3.3 Flow chart:
No
YES
DEPT OF E.C.E Page 50
Product Sensed
Waiting for product to be
sensed
Incrementing the Display
Start
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
CHAPTER 4
APPLICATIONS AND FUTURE SCOPE
4.1 Applications:
Digital Object Counter can be used in counting the objects efficiently. This is a low
cost efficient device and consumes low power. It can be even used in
1 . Industries where the number of products or objects can be counted.
2. In the parking areas to know the number of vehicles have entered.
4.2 Future Scope:
In real time, by using advanced sensors the distance between receiver and transmitter can
be increased and can be useful to count heavy objects.
Using different sensors and technologies, we not only can increment the count of objects
but can also decrement of no of objects going out.
DEPT OF E.C.E Page 51
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
CHAPTER-5
CONCLUSION
Chapter 2 gives an overview of the implementation of the project and the components
used in the project.
The main components in the project are described along with working which is useful to
understand the project better and helps us in analyzing the scope and working. We have seen the
working and output of the project and discussed in detail.
It gives us an overview of the implementation of the project and the hardware and software
tools used in the project.
By doing this project, it was very helpful to us to gain a better insight on the vast field of
embedded system.
This project does not consume much power and the components used in the project are
familiar to many people.
DEPT OF E.C.E Page 52
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
CHAPTER-6
REFERENCES
Books Referred:
[1] Muhammad Ali Mazidi and Janice Gillispi Mazidi, “The 8051 Microcontroller and Embedded Systems”.
[2] A.K.Ray, “The 8051 Microprocessor and Microcontroller”.
[3]MICROCONTROLLER (8051) – A.P.GODSE
Web Reference:
[1] Datasheets of Microcontroller AT89C51
[2] www.electronicsforu.com
[3] www.alldatasheets.com
[4] www.datasheet4u.com
[5] www.keil.com
[6] www.engineersgarage.com
DEPT OF E.C.E Page 53
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
APPENDIX- I
SOURCE CODE
Org 00h
mov r0,#00h
mov r1,#00h
mov p2,#0ffh;polling
mov p1,#00h;ssd
mov p2,#00h
clr a
mov a,r0
mov p1,a
here: jb p2.0,increm
jb p2.1,decrem
sjmp here
increm: inc r0
mov a,r0
add a,#00h
da a
mov r0,a
mov p1, a
sjmp here
decrem: mov b,r0
anl b,#0fh
mov a,b
DEPT OF E.C.E Page 54
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
cjne a,#00h,skip
mov a,r0
cjne a,#00h,next
mov p1,#00h
sjmp here
next: subb a,#07h
mov a,r0
mov p1,a
sjmp here
skip: dec r0
mov a,r0
mov p1,a
sjmp here
end
//LCD CODE//
#include<reg51.h>
#define cmdport P3
#define dataport P1
#define port P2
#define q 100
sbit rs = cmdport^0; //register select pin
sbit rw = cmdport^1; // read write pin
sbit e = cmdport^2; //enable pin
DEPT OF E.C.E Page 55
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
sbit op=P2^0;
void delay(unsigned int msec) // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
}
void lcddata(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
}
DEPT OF E.C.E Page 56
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
lcddata(str[i]);
i++;
delay(10);
}
}
void display(unsigned char z)
{
unsigned char tmp; // define temporary variable
unsigned char ASCII[2]; // define 2 digit variable
tmp = z>>4; // get upper nibble
if(tmp <= 0x09) // if its less then 9 convert it
ASCII[1] = tmp+0x30; // in ASCII by adding 30
else
{
ASCII[1] = tmp-0x09; //otherwise first deduct 9
ASCII[1] += 0x40; // then convert it in ascii
}
tmp = (z & 0x0f); // get lower nibble and perform
if(tmp <= 0x09) // same operation
DEPT OF E.C.E Page 57
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
ASCII[0] = tmp+0x30;
else
{
ASCII[0] = tmp-0x09;
ASCII[0] += 0x40;
}
lcddata(ASCII[1]);
lcddata(ASCII[0]);
}
void main()
{
char count=0;
P2= 0xff;
op=0;
lcdcmd(0x38); // for using 8-bit 2 row mode of LCD
delay(100);
lcdcmd(0x0E); // turn display ON for cursor blinking
delay(100);
lcdcmd(0x01); //clear screen
delay(100);
lcdcmd(0x06); //display ON
delay(100);
lcd_data_string("Product Counter");
delay(100);
lcdcmd(0xc1);
DEPT OF E.C.E Page 58
DIGITAL OBJECT COUNTER USING MICROCONTROLLER
lcd_data_string("count:");
while(1)
{
if(op==1)
{
count=count+1;
lcdcmd(0xC7);
delay(100);
display(count);
}
}
}
DEPT OF E.C.E Page 59