You are on page 1of 60

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 controllers 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 2 IMPLEMENTATION 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.

POWER SUPPLY

OSCILLATOR
9

DISPLAY

IR SENSORS
1

RESET

Figure 2.1: Block diagram of digital object counter using Microcontroller

DEPT OF E.C.E

Page 2

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
DEPT OF E.C.E Page 3

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

obtained from the rectifier is a pulsating d.c voltage. So in order to get a pure d.c voltage, the 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.

DEPT OF E.C.E

Page 4

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Filter:
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

DEPT OF E.C.E

Page 5

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

ranging from 9 volts to 24 volts DC (A 12 volt power supply is included with the Beginner Kit 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:

DEPT OF E.C.E

Page 6

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.4: Circuit Diagram of Power Supply 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 diodebridge 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):

DEPT OF E.C.E

Page 7

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Features:
Output Current up to 1A

Thermal Overload Protection Short Circuit Protection Output Transistor Safe Operating Area Protection

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


DEPT OF E.C.E Page 8

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 spectrum than of

desktop computing applications. No single characterization applies to the diverse

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 lifecycle 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 nondigital hardware may be used to increase the performance or safety.
DEPT OF E.C.E Page 9

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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


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.

DEPT OF E.C.E

Page 10

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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). 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:

DEPT OF E.C.E

Page 11

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.7 : Pin Configuration of 8051 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 microcontrollers 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.

DEPT OF E.C.E

Page 12

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.8 : Crystal connection 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:
DEPT OF E.C.E Page 13

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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. 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 P1.0 P1.1 P1.5 P1.6 P1.7
DEPT OF E.C.E

Alternate Functions T2(external count to Timer/Counter 2), clock-out T2EX(Timer/Counter 2 capture/reload trigger and direction control) MOSI (used for In-System Programming) MISO(used for In-System Programming) SCK(used for In-System Programming)
Page 14

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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.

Port Pin Alternate Functions: Port Pin P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 Alternate Functions RXD (serial Input port) TXD (serial output port) INT0 bar (external Interrupt 0) INT1 bar (external Interrupt 1) T0 (timer 0 external Input) T1 (timer 1 external input) WR bar (external data memory write strobe) RD bar (external data memory read strobe)

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.
DEPT OF E.C.E Page 15

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 frequency of oscillations depends up on the constants of the device. Oscillators are extensively used in electronic equipments. Oscillator CircuitsThe 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

DEPT OF E.C.E

Page 16

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

. 2.4.5 Architecture of 8051:

Figure 2.9 : Internal architecture of 8051 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
DEPT OF E.C.E Page 17

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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

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.

DEPT OF E.C.E

Page 18

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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

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.

DEPT OF E.C.E

Page 19

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 20

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 21

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 22

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 o

1 - Timer 1 operates only if the INT1 bit is set. 0 - Timer 1 operates regardless of the logic state of the INT1 bit. 1 - Timer counts pulses brought to the T1 pin (P3.5). 0 - Timer counts pulses from internal oscillator. 1 - Timer 0 operates only if the INT0 bit is set. 0 - Timer 0 operates regardless of the logic state of the INT0 bit. 1 - Timer counts pulses brought to the T0 pin (P3.4). 0 - Timer counts pulses from internal oscillator.

C/T1 selects pulses to be counted up by the timer/counter 1:


o o

GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
o o

C/T0 selects pulses to be counted up by the timer/counter 0:


o o

T0M1,T0M0 These two bits select the operational mode of the Timer 0.
Page 23

DEPT OF E.C.E

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

T1M1 0 0 1 1

T1M1,T1M0 These two bits select the operational mode of the Timer 0.
T1M0 0 1 0 1 MODE 0 1 2 3 DESCRIPTION 13-bit timer 16-bit timer 8-bit auto-reload 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 o

1 - Timer 1 is enabled. 0 - Timer 1 is disabled.

TF0 bit is automatically set on the Timer 0 overflow. TR0 bit enables the timer 0.
o o

1 - Timer 0 is enabled. 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 simultaneously and at different baud rates. Without it, serial data send and receive would be an
DEPT OF E.C.E Page 24

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 25

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:
SM0 0 0 1 1 SM1 0 1 0 1 MODE 0 1 2 3 DESCRIPTION 8-bit Shift Register 8-bit UART 9-bit UART 9-bit UART BAUD RATE 1/12 the quartz frequency Determined by the timer 1 1/32 the quartz frequency (1/64 the quartz frequency) Determined by the timer 1

Table 2.4 : SCON Register

IE Register (Interrupt Enable):

Figure 2.22 : IE Register

EA - global interrupt enable/disable:


o o

0 - disables all interrupt requests. 1 - enables all individual interrupt requests. 0 - UART system cannot generate an interrupt. 1 - UART system enables an interrupt. 0 - Timer 1 cannot generate an interrupt. 1 - Timer 1 enables an interrupt.

ES - enables or disables serial interrupt:


o o

ET1 - bit enables or disables Timer 1 interrupt:


o o

EX1 - bit enables or disables external 1 interrupt:


o o

0 - change of the pin INT0 logic state cannot generate an interrupt. 1 - enables an external interrupt on the pin INT0 state change.

DEPT OF E.C.E

Page 26

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

ET0 - bit enables or disables timer 0 interrupt:


o o

0 - Timer 0 cannot generate an interrupt. 1 - enables timer 0 interrupt. 0 - change of the INT1 pin logic state cannot generate an interrupt. 1 - enables an external interrupt on the pin INT1 state change.

EX0 - bit enables or disables external 0 interrupt:


o o

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 27

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 28

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):

DEPT OF E.C.E

Page 29

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 LCDs internal registers. To display letters and numbers, we send ASCII codes for the 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.

DEPT OF E.C.E

Page 30

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

PIN 1 2 3 4

SYMBOL VSS VCC VEE RS

I/O ---I

DESCRIPTION Ground +5V power supply Power supply to control contrast RS=0 to select command register RS=1 to select data register

R/W

R/W=0 for write R/W=1 for read

6 7 8 9 10 11 12 13 14

EN DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7

I/O I/O I/O I/O I/O I/O I/O I/O I/O

Enable The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data bus

DEPT OF E.C.E

Page 31

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Table 3.5 : LCD Pin Description Table 3.5 : LCD Pin Description Table 2.5 : LCD Pin Description 2.5.2 LCD Command Codes :

CODE (HEX) 1 2 4 6 5 7 8

COMMAND TO LCD INSTRUCTION REGISTER CLEAR DISPLAY SCREEN RETURN HOME DECREMENT CURSOR(SHIFT CURSOR TO LEFT) INCREMENT CURSOR(SHIFT CURSOR TO RIGHT) SHIFT DISPLAY RIGHT SHIFT DISPLAY LEFT DISPLAY OFF,CURSOR OFF

DEPT OF E.C.E

Page 32

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

A C E F 10 14 18 1C 80 C0 38

DISPLAY OFF,CURSOR ON DISPLAY ON,CURSOR OFF DISPLAY ON CURSOR BLINKING DISPLAY ON CURSOR BLINKING SHIFT CURSOR POSITION TO LEFT SHIFT CURSOR POSITION TO RIGHT SHIFT THE ENTIRE DISPLAY TO THE LEFT SHIFT THE ENTIRE DISPLAY TO THE RIGHT FORCE CURSOR TO BEGINNING OF 1ST LINE FORCE CURSOR TO BEGINNING OF 2ND LINE 2 LINES AND 5x7 MATRIX

Table 2.6: LCD Command Codes

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:
DEPT OF E.C.E Page 33

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 LEDs (seven segment LEDs or other multi segment LEDs). This is due to following reasons:

The declining prices of LCDs. The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters.

2.6 INFRARED SENSORS


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.75m to 1000 m is the infrared region. Infrared waves are invisible to human eyes. The wavelength region of 0.75m 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
DEPT OF E.C.E Page 34

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 earths 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. Nonmilitary 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. 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.
DEPT OF E.C.E Page 35

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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. 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)


Page 36

DEPT OF E.C.E

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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.

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 basecollector 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
DEPT OF E.C.E Page 37

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 (emitterbase) and a reverse based photodiode (basecollector) 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.

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.

DEPT OF E.C.E

Page 38

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.29: 555 Timer IC

2.7.1 Pin Diagram of 555 Timer IC:

Figure 2.30 : pin TIMER IC

diagram of 555

2.7.2. Pin Description of 555 timer:


Pin No 1 2 3 4 5 6 7 8 Function Ground (0V) Voltage below 1/3 Vcc to trigger the pulse Pulsating output Active low; interrupts the timing interval at Output Provides access to the internal voltage divider; default 2/3 Vcc The pulse ends when the voltage is greater than Control Open collector output; to discharge the capacitor Supply voltage; 5V (4.5V - 16 V) Name Ground Trigger Output Reset Control Voltage Threshold Discharge Vcc

Table 2.7 : Pin Description of 555 timer 2.7.3. Block Diagram

DEPT OF E.C.E

Page 39

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 40

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Operating Voltage Maximum Supply Current High Level Output Voltage Maximum Output Current

= 4.5V to 16V = 5mA @ 5V Operating Voltage = 12mA @ 15V Operating Voltage = 3.3V @ 5V Operating Voltage = 13.3V @ 15V Operating Voltage = 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 discharge Capacitor set. pin C1 This low) then releases across begins the capacitor to short C1. charge circuit At and this the (created point voltage by the holding output it of begins the high. to goes

across

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 Minimum output pulse R1 minimum resistance R1 maximum resistance = 5 minutes = 5 uS = 1K ohm = 1Mohm

DEPT OF E.C.E

Page 41

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.32 : Monostable Operation

2.7.7 Astable Operation

DEPT OF E.C.E

Page 42

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 2.33: Astable operation In astable mode the in timer continually triggers repeating itself and runs as a on multi the

vibrator. output pin.

This

results

a continually

signal being

generated

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: The 'Low' output time is given by: Therefore the total period is given by: The frequency of oscillation is given by: t1 = 0.693 (R1 + R2) x C1 t2 = 0.693 (R2) x C1 T = t1 + t2 = 0.693 (R1 + R2) x C1 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 43

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. LEDs 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-LEDs 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 44

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

2.8.1 Color Vs Potential Difference:


Color Infrared Red Potential Difference 1.6 V 1.8 V to 2.1 V 2.2 V 2.4 V 2.6 V 3.0 V to 3.5 V 3.0 V to 3.5 V 3.5V

Orange Yellow Green Blue White -

Ultraviolet

2.8.2 Advantages:
1. LEDs have many advantages over other technologies like lasers. As compared to laser diodes or IR sources 2. LEDs 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 lightproduction 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. LEDs 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. 5. LEDs offer advantages such as low cost and long service life. Moreover LEDs have very low power consumption and are easy to maintain.

DEPT OF E.C.E

Page 45

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

2.8.3

Disadvantages:
1. LEDs performance largely depends on the ambient temperature of the operating environment. 2. LEDs must be supplied with the correct current. 3. LEDs 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 LEDs 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 specific of instructions used as a timing loop (a set of instructions executed repeatedly until a

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
DEPT OF E.C.E Page 46

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 nonexecutable 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:
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
DEPT OF E.C.E Page 47

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

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 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.

G, main in the Output Window to execute to the main C function.


DEPT OF E.C.E

Page 48

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

CHAPTER 3 CIRCUIT OPERATION 3.1 Circuit Diagram

Figure 3.1: Circuit Diagram of Digital Object Counter using Microcontroller

DEPT OF E.C.E

Page 49

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

Figure 3.2 : IR TRANSMITTER CIRCUIT

Figure 3.3: IR RECEIVER CIRCUIT

DEPT OF E.C.E

Page 50

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

3.2 Electrical and Component Specification:


Microcontroller Power consumption Loads to be connected LCD (liquid crystal display) Power Supply No. of devices : 89c51 : 1W (max) : Sensor (230v) :1 : 5v/1A :1

3.3 Flow chart:

Start

Produ ct Sense d

No

Waiting for product to be sensed

YES Incrementing the Display

DEPT OF E.C.E

Page 51

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 52

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 53

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 54

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

DEPT OF E.C.E

Page 55

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

anl b,#0fh mov a,b 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
DEPT OF E.C.E Page 56

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

sbit rw = cmdport^1; // read write pin sbit e = cmdport^2; //enable pin 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);
DEPT OF E.C.E Page 57

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

e=0; } 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; unsigned char ASCII[2]; tmp = z>>4; if(tmp <= 0x09) ASCII[1] = tmp+0x30; else { ASCII[1] = tmp-0x09; ASCII[1] += 0x40; } tmp = (z & 0x0f);
DEPT OF E.C.E

// define temporary variable // define 2 digit variable // get upper nibble // if its less then 9 convert it // in ASCII by adding 30

//otherwise first deduct 9 // then convert it in ascii

// get lower nibble and perform


Page 58

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

if(tmp <= 0x09)

// same operation

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");
DEPT OF E.C.E Page 59

DIGITAL OBJECT COUNTER USING MICROCONTROLLER

delay(100); lcdcmd(0xc1); lcd_data_string("count:"); while(1) { if(op==1) { count=count+1; lcdcmd(0xC7); delay(100); display(count); } } }

DEPT OF E.C.E

Page 60