Sie sind auf Seite 1von 17

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 1 of 17

1. Introduction
The objective of this project is to design an Energy Saving Visitor Counter by using the
microcontroller 68hc11/8051 and to integrate hardware and software in order to simulate the
circuit in such a way that when somebody enters into the room then the counter is incremented
by one and the light in the room will be switched ON and when any one leaves the room then the
counter is decremented by one. The light will be only switched OFF until all the persons in the
room go out. The total number of persons inside the room may also be displayed on the seven
segment displays/LEDs.
The circuit designed here can count numbers from 0 to 9 as only one seven segment display is
used. The counter can be used to know the number of visitors present in a room at any given
time. It is useful for places such as movie halls, buildings and offices. It can also be implemented
at gates of parking areas and other public places. The circuit is divided in three parts- sensor
microcontroller and counter display. The sensor would observe an interruption and provide an
input to the controller which would run the counter in up/down mode depending upon the
selector setting. The same count is displayed on 7-Segment display through microcontroller. To
keep the cost low, it uses a simple calculator instead of a counter and display circuit. All the
components are easily available in the market and the circuit is easy to build.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 2 of 17

2.1 Block diagram

Figure 1: Block diagram of circuit

2.2 Block diagram description


The block diagram of bidirectional visitor counter with energy saving setup mainly comprise of a
microcontroller AT89C51, IR transmitter and receiver, seven segment display and a relay. It is
clear from block diagram that the transmitter and receiver pairs should be placed face to face so
that IR radiations from transmitter can be received by receiver. If an obstacle comes between the
transmitter receiver pairs, it blocks the IR radiation and puts receiver goes in cut off mode.
2.2.1 AT89C51 (MICROCONTROLLER)
This module comprises 8051 microcontroller (AT89C51). The microcontroller used in this block
diagram is AT89C51. It belongs to Atmel family. Atmel 89C51 have flash programmable and
erasable read only memory (PEROM). Flash memory is a non volatile memory, which can be
electrically erased read for lines and blocks. The mechanism for erasing the memory is easier and
faster than that needed for EEPROM. Typically, 1000 write/erase cycles are possible, which are
more than sufficient for any application development. The operating frequency of 89C51 could
be from 0Hz to 24Hz.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 3 of 17

Architectural overview of ATMEL89C51


Atmel AT89C51 is a powerful microcontroller which provides a highly flexible and cost
effective solution to many embedded control applications. Since AT89C51 architecture provides
32 bidirectional port pins along with two timers and 4Kbytes of flash memory, it makes the
choice ideal for the system is an RTC chip DS1307 from Dallas semiconductors, which
continuously updates the time and calendar information in its scratch pad RAM, considering leap
year compensation. Stability and accuracy of the clock is dependent on the accuracy of the clock
as well as matching of the capacitance between crystal oscillator and clock pins. There are two
16-bit timer/counters, one full duplex serial port, 128 bytes of on chip RAM, 32I/O lines, on chip
oscillator and clock circuitry. It support six interrupt sources. It consists of precision analog
comparator. It must be noted that pin P3.6 is not available externally; however it can be read in
software. P3.6 is the output of precision analog comparator
Atmel series AT89C51 is based on Harvard architecture. This processor includes internal
separated data memory (internal RAM) and program memory (internal Flash). It is possible to
connect external data memory and external program memory as well through I/O ports P0 and
P2 and control signals (detailed connection will be discussed later). Internal data memory and
program memory are separated into two different areas and are accessed at the same time via
data transfer instruction (like MOV A, 20H). External data and program memory shares the same
address and data bus, thus advantage of Harvard Design of Electronic Instruments Embedded
systems for industrial control 23 architecture is not utilized. But external data access instruction
(like MOVX A, @DPTR) and external program access instruction (MOVC A, @DPTR) still
differs.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 4 of 17

Pin Description of 8051


The 8051 is packaged in a 40-pin DIP (Dual Inline Package). Many pins of 8051 are used for
more than one function.

Figure 2: Pin out of 8051

Port 0 (Pins 32-39)


Port 0 pins can be used as I/O pins. The output drives and input buffers of port 0 are used to
access external memory. Port 0 outputs the low order byte of external memory address, time
multiplexed with the data being written or read. Thus, port 0 can be used as a multiplexed
address/data bus.
Port 1 (Pins 1-8)
Port 1 pins can be used only as I/O pins

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 5 of 17

Port 2 (Pins 21-28)


The output drives of port 2 are used to access external memory. Port 2 outputs the high order
byte of the external memory address when the address is a6=bits wide. Otherwise, port 2 is used
as an I/O port.
Port 3 (Pins 10-17)
All port pins of port 3 are multifunctional. They have special functions as shown below including
two external interrupts, two counter inputs, two special data lines and two timing control strobes.
Table 1: Pin description

Symbol Position

P3.5
P3.4

Name and significance


Read data control output. Active low pulse generated by hardware when
external data memory is read.
Write data control output. Active low pulse generated by hardware when
external data memory is written.
Timer/counter 1 external input or test pin.
Timer/counter 0 external input or test pin.

INT1

P3.3

Interrupt 1 input pin. Low level or falling edge triggered.

INT0

P3.2

Interrupt 0 input pin. Low level or falling edge triggered.

RD

P3.7

WR

P3.7

T1
T0

TXD

P3.1

RXD

P3.0

Transmit data pin for serial port in UART mode. Clock output in shift
register mode.
Receive data pin for serial port in UART mode. Data I/O pin in shift
register mode.

Power supply pins VCC (Pin 40) and VSS (Pin 20)
8051 operates on d.c. power supply of +5V with respect to ground. The +5V is to be connected
to pins VCC and ground to pin VCC with rated power supply current of 125mA.
Oscillator pins XTAL (Pins 18 and 19)
For generating an internal clock signal, the external oscillator is connected at these two pins.
ALE (Address Latch Enable, Pin 30)
AD0 to AD7 lines are multiplexed. To demultiplex these lines and for obtaining lower half of an
address, an external latch and ALE signal of 8051 is used.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 6 of 17

RESET (Pin 9)
This pin is used to reset 8051. For proper reset operation, reset signal must be held high at least
for two machine cycles, while oscillator is running/
PSEN (Program Store Enable, Pin 29)
It is the active low output control signal used to activate the enable signal of the external
ROM/EPROM. It is activated every six oscillator periods while reading the external memory.
Thus, this signal acts as the read strobe to external program memory.
EA (External Access, Pin 31)
When the EA pin is high (connected to VCC), program fetches to address 0000H through 0FFFh
are directed to the internal ROM and program fetches to address 1000H through FFFFH are
directed to external ROM/EPROM. When EA is low (grounded), all addresses (0000H to
FFFFH) fetched by program are directed to the external ROM/EPROM.
2.2.2 TRANSMITTER AND RECEIVER
Transmitter section consists of an IR transmitter and a resistor (470ohm) connected to positive
terminal of battery.
Receiver section consists of an Infrared detector module, a transistor (BC547) and a resistor
(10K) connected to P1.6 and P1.7 pins of Microcontroller. The transmitter and receiver consists
of Infrared module which are commonly used in sending and sensing IR signals in color
television.
2.2.3 RELAY
This Block comprises of a SPDT (Single Pole Double Throw) Relay and a transistor. Here
transistor is used as switch. Relay is an electromagnetic device which is used to isolate two
circuits electrically and connect them magnetically. In embedded application, the relay coil made
up of insulated wire on a metal core and a metal armature with one or more contacts. Relay
works on electromagnetic principle. When a voltage is applied to the relay coil, current flows

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 7 of 17

through the coil, which in turn generates a magnetic field. The magnetic field aatracts the
armature core and moves the contact point. The movement of the contact point changes the
power/ signal flow path. Relays are available in different configurations (SPDT, DPDT, DPST,
SPST). As relay consists of a coil, it can produce back emf and damage microcontroller. To
prevent microcontroller from damage, transistor is connected to microcontroller and relay.
2.2.4 SEVEN SEGMENT DISPLAY
The section consists of a 7-Segment display with 8 resistors (220ohm) connected to
microcontroller. The common anode of 7-segment is connected to Vcc. it basically comprises of
arrangements of the LEDs in Eight (8) fashion, and a Dot (.) with a common electrode, lead
(Anode or Cathode). The first one is common anode in which all the anodes of the LED are
connected together, leaving the cathodes open for connection. The second one is common
cathode in which all the cathodes of the LEDs are connected together, leaving the anodes open
for connection.
In this application common anode seven segment display is interfaced to AT89C51
microcontroller.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

3.1

Page 8 of 17

Circuit diagram

Figure 3: Circuit diagram of Proteus

3.2

Circuit explanation

In the circuit two infrared sensor modules are used to sense entry and exit of persons. Initially
Whenever a person enters, an interrupt is generated and it increments the counter. Similarly
when someone gets out of the room, again an interrupt is generated and it decrements the
counter. Meanwhile the count value is displayed in the 7-Segment display.
Programming is done in such a manner that Pins 1.6 and 1.7 are configured as input and having
logic 1 or high. When an obstacle comes between first transmitter and receiver it blocks the IR
radiation and thus an interrupt is generated. Similarly if radiation of second transmitter and
receiver is blocked a second interrupt is generated. The counter of controller increments or
decrements depending upon whether a person enters or exits from the room. The coding feed in
microcontroller is in such a manner that when interrupts are generated, the program counter
automatically shifts to interrupt subroutine. In the interrupt subroutine desired output is fed. In
this application seven segment display is connected to the controller. Common anode 7-Segment
is interfaced with microcontroller, and count variable is displayed.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 9 of 17

A push to ON switch is connected to Pin 9 as a reset switch. When this pin is brought high for
two instruction cycles, the microcontroller will be reset. SFRs including the I/O ports, are
restored to their default conditions and the program counter will be reset to 0000h. Keep in mind
that internal RAM is not affected by a reset. The microcontroller will begin executing code at
0000h when this pin returns to a low state.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

4.1

Page 10 of 17

Hardware platform

Microcontroller is the main component of this circuit. It acts as a bridge between sensors and
display unit. Controllers are used in automatically controlled devices, such as automobile engine
control system, implantable, medical devices, remote controls, office machines, appliances,
power tools, toys and other embedded systems. It is used because it is economical to digitally
control even more devices and processes. In this application (Energy saving visitor counter)
AT89C51 is used as microcontroller. AT89C51 is used because of its enormous features. Some
are listed below:
Features of 89C51
1. 4096 bytes on chip program memory
2. 128 bytes on chip data memory
3. Four register banks
4. 128 user defined software flags
5. 64 Kilobytes each program and external RAM addressability
6. One microsecond instruction cycle with 12 MHz crystal
7. 32 bidirectional I/O lines organized as four 8-bit ports (16 lines 8031)
8. Multiple mode, high speed programmable serial port
9. Two multiple mode, 16-bit Timers/Counters
10. Two level prioritized interrupt structure
11. Full depth stack for subroutine return linkage and data storage
12. Direct bytes and bit addressability
13. Binary or decimal arithmetic
14. Signed overflow detection and parity computation
15. Hardware multiple and divide in 4 sec
4.2 Software platform
The program for the visitor counter is written in C language. Proteus and Keil are used in this
application. Circuit is designed and simulated in Proteus whereas coding is compiled and
converted in hex file using Keil. These softwares are described below:

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 11 of 17

4.2.1 Proteus
Proteus software offers the ability to co-simulate both high and low level microcontroller code in
the context of a mixed-mode SPICE circuit simulation. It combines mixed mode SPICE circuit
simulation, animated components and microprocessor models to facilitate co-simulation of
complete micro controller based designs. With VSM, it is possible to develop and test such
designs using on screen indicators such as LED and LCD displays and actuators such as switches
and buttons. The simulation takes place in real time, e.g., a 1GMHz Pentium III can simulate a
basic 8051 system clocking at over 12 MHz. Proteus VSSM also provides extensive debugging
facilities including breakpoints, single stepping and variable display for both assembly code and
high level language source.
Proteus uses ISIS schematic capture software to provide the environment for design entry and
development. The ISIS software combines ease of use with powerful editing tools. It is capable
of supporting schematic capture for both simulation and PCB design. Designs entered in to
Proteus for testing can be net listed for PCB layout either with Proteus PCB design products or
with third party PCB layout tools. ISIS also provides a very high degree of control over the
drawing appearance, in terms of line widths, fill styles, fonts, etc. these capabilities are used to
provide the graphics necessary for circuit animation.
The most important feature of Proteus is its ability to simulate the interaction between software
running on a microcontroller and any analog or digital electronics connected to it.
The microcontroller model sits on the schematic analog with the other elements of product
design. It simulates the execution of designer object code (machine code), just like a real chip. Is
the program code writes to a port, the logic levels in circuit change accordingly, and if the circuit
changes the state of the processors pins, this will be seen by the program code, just as in a real
systems.
The CPU models fully simulate I/O ports, interrupts, timers, USARTs and all other peripherals
present on each supported processor. The interaction of all thee peripherals with the external
circuit is full modeled down to waveform level and the entire system is therefore simulated.

4.2.2 Keil
Keil vision5 is a licensed IDE tool from Keil software, an ARM company, for 8051 family
microcontroller based embedded firmware development. To start with the IDE (after installing
the demo tool) execute the program Uv3.exe (or the shortcut Keil Vision3 from desktop or

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 12 of 17

All programs tab from start menu). Keil offers an evaluation package that will allow the
assembly and debugging of files 2K or less. This package is freely available at their website. Keil
software publishes one of the most complete development tool suites for 8051 software, which is
used throughout industry. For development of C code, their Developers Kit product includes
their C51 compiler, as well as an integrated 8051 simulator for debugging. The C programming
language was designed for computers, through, and embedded systems. It does not support direct
access to registers, nor does it allow for the reading and setting of single bits, two very important
requirements for 8051 software. In addition, most software developers are accustomed to writing
programs that will be executed by an operating system, which provides system calls in program
to access to registers, nor does it allow for the reading and setting of single bits, two very
important requirements for 8051 software. In addition, most software developers are accustomed
to writing programs that will be executed by an operating system, which provides systems calls
in program to access the hardware.

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 13 of 17

Press the simulate/ play button in Proteus. In initial condition 0 is displayed on the seven
segment as shown in figure below:

Figure 4: Circuit simulation in Proteus

Figure 5: Circuit simulation in Proteus

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 14 of 17

Figure 6: Circuit simulation in Proteus

Figure 7: Circuit if count decrements to 0

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 15 of 17

Keil Window
Compilation of program with no error and creating hex file.

Figure 4: Keil window

Figure 8: Keil Window

Figure 9: Keil Window

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 16 of 17

As program counter reads the instruction, it changes the values of ports.

Figure 10: Keil Window

Figure11: Hardware circuit

Level 2

Asia Pacific Institute of Information Technology

2014

CE00604-2 Digital and Embedded software(Real time system)-1 Individual Assignment

Page 17 of 17

The project fulfills two objectives. First one is count number of peoples getting in and out of the
room and second is if there is no one in the room, light of room automatically turns off. The
assignment is beneficial for those who are interested in embedded system and want to learn
about it. Through this project, we learnt a lot about the functioning of microcontroller, seven
segment, IR sensors and other electronics components with their application in real life. We were
able to correlate what we studied in our module with this assignment.
This application may be implemented in auditorium, malls, hostels, hotel rooms, parking areas to
count number of persons and vehicles getting in and out of the vicinity.
Advantages
1. Low cost in fabrication of circuit
2. Automatic controlling
3. Implemented in single door
Drawbacks
This is a very basic circuit and has many shortcomings. For example, this system will not be able
to differentiate between a person and any other obstacle interrupting the sensors.
This circuit wont work efficiently if more than one person entering at a time.
The system is of short range.
1. Multiple devices can be turned ON/OFF instead of just lights.
2. We can check the ambient light intensity and then decide if the light needs to be turned
On or not.
3. Metal detector can be added for security reasons
4. By using this circuit and proper supply we can implement various applications such as
fans, tube lights, etc.
5. Circuit can be modified by using two relays and a solenoid for opening and closing o
doors.
6. Cameras may be added to differentiate between a person and an obstacle.

Level 2

Asia Pacific Institute of Information Technology

2014

Das könnte Ihnen auch gefallen