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 DEPT OF E.C.E Page 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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.
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
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