Post on 01-Jan-2016
description
1
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
INTRODUCTION
All fans which are used now a day are controlled manually by voltage regulators
which have different stages of speed. This process is done manually which can be
done automatically by the use of this circuit. Here we are introducing an efficient
fan speed regulation circuit, by which the speed of a fan can be controlled
depending up on the room temperature. The circuit is highly efficient since energy
loss can be minimized by power saving as the circuit automatically adjusts the fans
speed.
DEPARTMENT OF EEE,VAST
2
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
PRINCIPLE OF OPERATION
This circuit uses thermistor as the temperature sensor, i.e. one having a negative
temperature coefficient. This circuit is designed in such a way that the speed of the fan
increases/decreases with respect to the room temperature with a minimum parts counting
and avoiding the use of special-purpose ICs, often difficult to obtain.
DEPARTMENT OF EEE,VAST
3
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
BLOCK DIAGRAM
Figure 1. Block Diagram
DEPARTMENT OF EEE,VAST
TRIGGERING
CIRCUIT
TEMPERATURE SENSOR
&
WHEATSTONE BRIDGE
SWITCHING CIRCUIT
LOAD
4
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
COMPONENTS USED
NAME OF COMPONENT SPECIFICATION QUANTITY
Linear Potentiometer-P1 22K 1
Thermistor-R1 15K @ 20°C n.t.c 1
SCR-D2 TYN612 1
Zener Diode-D1 BZX79C18 1
Diodes-D3,D4,D5,D6 1N4007 1000V 4
Transistors-Q1,Q2 BC327 2
Transistor-Q3 BC337 1
Polyester Capacitor-C1 10nF 63V 1
Resistor-R2 100K 1/4W 1
Resistors-R3,R6 10K 1/4W 2
Resistors-R4,R5 22K 1/4W 2
Resistor-R7 100R 1/4W 1
Resistor-R8 470R 1/4W 1
DEPARTMENT OF EEE,VAST
5
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Resistors-R9,R10 68K 2W 2
Female Mains socket -SK1 - 1
Male Mains plug-PL1 - 1
PCB - 1
Breadboard - 1
Connecting Wires
Microcontroller
lcd
- As required
Table No:1. Component List
DEPARTMENT OF EEE,VAST
6
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
8051 microcontroller
DEPARTMENT OF EEE,VAST
7
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Introduction
The term microcomputer is used to describe a system that includes at minimum a
microprocessor, program memory, data memory, and an input-output (I/O) device. Some
microcomputer systems include additional components such as timers, counters, and analog-to-
digital converters. Thus, a microcomputer system can be anything from a large computer having
hard disks, floppy disks, and printers to a single-chip embedded controller.
We are going to consider only the type of microcomputers that consist of a single silicon chip. Such
microcomputer systems are also called microcontrollers, and they are used in many household goods
such as microwave ovens, TV remote control units, cookers, hi-fi equipment, CD players, personal
computers, and refrigerators. Many different microcontrollers are available on the market. In this book
we shall be looking at programming and system design for the 8051 series of microcontrollers .
Microcontrollers versus Microprocessors
Microcontroller differs from a microprocessor in many ways. First and the most important is its
functionality. In order for a microprocessor to be used, other components such as memory, or
components for receiving and sending data must be added to it. In short that means that
microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to
be all of that in one. No other external components are needed for its application because all
necessary peripherals are already built into it. Thus, we save the time and space needed to
construct devices.
DEPARTMENT OF EEE,VAST
8
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Fig 3.7.1 microprocessor and its component block diagram.
Fig 3.7.2 Microcontroller unit
Microcontroller System:
DEPARTMENT OF EEE,VAST
9
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
In today present a lot of microcontroller manufactures appeared almost every major electronic
company produce their own microcontroller to use into their own devices each
microcontroller type may add or improve existing features but all microcontrollers share basic
features that is microprocessor (CPU), memory and an input-output (I/O) device.
Fig 3.8.1 the basic microcontroller system
The input components would consist of digital devices such as, switches, push buttons, pressure
mats, float switches, keypads, radio receivers etc. and analogue sensors such as light dependent
resistors, thermistors, gas sensors, pressure sensors, etc.
The control unit is of course the microcontroller. The microcontroller will monitor the inputs and
as a result the program would turn outputs on and off. The microcontroller stores the program in
its memory, and executes the instructions under the control of the clock circuit.
The output devices would be made up from LEDs, buzzers, motors, alpha numeric displays,
radio transmitters, 7 segment displays, heaters, fans etc.
The most obvious choice then for the microcontroller is how many digital inputs, analogue inputs
and outputs does the system require. This would then specify the minimum number of inputs and
outputs (I/O) that the microcontroller must have. If analogue inputs are used then the microcontroller
must have an Analogue to Digital (A/D) module inside.
The next consideration would be what size of program memory storage is required. This should not
be too much of a problem when starting out, as most programs would be relatively small.
The clock frequency determines the speed at which the instructions are executed. This is important if
any lengthy calculations are being undertaken. The higher the clock frequency the quicker the micro
will finish one task and start another.
DEPARTMENT OF EEE,VAST
10
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Other considerations are the number of interrupts and timer circuits required how much data
EEPROM if any is needed.
Microcontrollers have traditionally been programmed using the assembly language of the target
device. Although the assembly language is fast, it has several disadvantages. An assembly program
makes learning and maintaining a program written using the assembly language difficult. Also,
microcontrollers manufactured by different firms have different assembly languages, so the user must
learn a new language with every new microcontroller he uses.
Microcontrollers can also be programmed using a high-level language, such as BASIC, PASCAL, or
C. High-level languages are much easier to learn than assembly languages. They also facilitate the
development of large and complex programs.
A microcontroller is a very powerful tool that allows a designer to create sophisticated input-output
data manipulation under program control. Microcontrollers are classified by the number of bits they
process. 12
Microcontrollers with 8 bits are the most popular and are used in most microcontroller-based
applications. Microcontrollers with 16 and 32 bits are much more powerful, but are usually more
expensive and not required in most small- or medium-size general purpose applications that call for
microcontrollers.
Microcontroller basic architecture:
The simplest microcontroller architecture consists of a microprocessor, memory, and input-output.
The microprocessor consists of a central processing unit (CPU) and a control unit (CU). The CPU is
the brain of the microcontroller; this is where all the arithmetic and logic operations are
performed. The CU controls the internal operations of the microprocessor and sends signals to
other parts of the microcontroller to carry out the required instructions.
Central Processing Unit
As its name indicates, this is a unit which monitors and controls all processes inside the
microcontroller. It consists of several smaller units, of which the most important are:
DEPARTMENT OF EEE,VAST
11
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Instruction Decoder: is a part of electronics which recognizes program instructions and runs
other circuits on the basis of that. The ―instruction set‖ which is different for each
microcontroller family expresses the abilities of this circuit.
Arithmetical Logical Unit (ALU): performs all mathematical and logical operations upon
data.
Accumulator: is a SFR closely related to the operation of ALU. It is a kind of working desk
used for storing all data upon which some operation should be performed (addition,
shift/move etc.). It also stores results ready for use in further processing.
Status Register (PSW): One of SFRs is close to the accumulator. It shows at any moment
the ―status of a number stored in the accumulator (number is greater or less than zero etc.)..
Microcontroller central processing unit
Memory unit
Memory, an important part of a microcontroller system, can be classified into two types: program
memory and data memory. Program memory stores the program written by the programmer and
is usually nonvolatile (i.e., data is not lost after the power is turned off). Data memory stores the
temporary data used in a
program and is usually
volatile (i.e., data is lost
after the power is turned
off).
DEPARTMENT OF EEE,VAST
12
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Typical memory unit device
There are basically six types of memories, summarized as follows: RAM RAM, random access memory, is a general purpose memory that usually stores the user data in a
program. RAM memory is volatile in the sense that it cannot retain data in the absence of power (i.e.,
data is lost after the power is turned off). Most microcontrollers have some amount of internal RAM,
256 bytes being a common amount, although some microcontrollers have more, some less. The
AT89C52 microcontroller, for example, has 256 bytes of RAM. Memory can usually be extended by
adding external memory chips.
ROM
DEPARTMENT OF EEE,VAST
13
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
ROM, read only memory, usually holds program or fixed user data. ROM is nonvolatile. If power is
removed from ROM and then reapplied, the original data will still be there. ROM memory is
programmed during the manufacturing process, and the user cannot change its contents. ROM
memory is only useful if you have developed a program and wish to create several thousand copies
of it.
2.4.2.3 PROM PROM, programmable read only memory, is a type of ROM that can be programmed in the field,
often by the end user, using a device called a PROM programmer. Once a PROM has been
programmed, its contents cannot be changed. PROMs are usually used in low production applications
where only a few such memories are required.
EPROM
DEPARTMENT OF EEE,VAST
14
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
EPROM, erasable programmable read only memory, is similar to ROM, but EPROM can be
programmed using a suitable programming device. An EPROM memory has a small clear-glass
window on top of the chip where the data can be erased under strong ultraviolet light. Once the
memory is programmed, the window can be covered with dark tape to prevent accidental erasure of
the data. An EPROM memory must be erased before it can be reprogrammed. Many developmental
versions of microcontrollers are manufactured with EPROM memories where the user program can
be stored. These memories are erased and reprogrammed until the user is satisfied with the program.
Some versions of EPROMs, known as OTP (one time programmable), can be programmed using a
suitable programmer device but cannot be erased. OTP memories cost much less than EPROMs.
OTP is useful after a project has been developed completely and many copies of the program
memory must be made.
EEPROM EEPROM, electrically erasable programmable read only memory, is a nonvolatile memory that can
be erased and reprogrammed using a suitable programming device. EEPROMs are used to save
configuration information, maximum and minimum values, identification data, etc. Some
microcontrollers have built-in EEPROM memories. For instance, the PIC18F452 contains a 256-byte
EEPROM memory where each byte can be programmed and erased directly by applications software.
EEPROM memories are usually very slow. An EEPROM chip is much costlier than an EPROM chip.
Flash EEPROM Flash EEPROM, a version of EEPROM memory, has become popular in microcontroller applications
and is used to store the user program. Flash EEPROM is nonvolatile and usually very fast. The data
can be erased and then reprogrammed using a suitable programming device. Some
microcontrollers have only 1K flash EEPROM while others have 32K or more. The AT89C52
microcontroller has 1K bytes of flash memory.
DEPARTMENT OF EEE,VAST
15
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Input / Output ports In order that the microcontroller is of any use, it has to be connected to additional electronics, i. e.
peripherals. For that reason, each microcontroller has one or more registers (called "port" in this
case) connected to the microcontroller pins. Why input/output? Because you can change the pin‘s
function as you wish. simply performed by software, which means that pin‘s function can be
changed during operation. One of more important feature of I/O pins is maximal current they can
give/get. For the most microcontrollers, current obtained from one pin is sufficient to activate a LED
or other similar low-current consumer (10-20 mA). If the microcontroller has many I/O pins, then
maximal current of one pin is lower. each I/O port is under control of another SFR, which means
that each bit of that register determines state of the corresponding microcontroller pin. For
example, by writing logic one (1) to one bit of that control register SFR, the appropriate port pin is
automatically configured as input. It means that voltage brought to that pin can be read as logic 0 or
1. Otherwise, by writing zero to the SFR, the appropriate port pin is configured as output. Its voltage
(0V or 5V) corresponds to the state of the appropriate bit of the port register.
Some of Microcontroller Features:
DEPARTMENT OF EEE,VAST
16
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Supply Voltage
Most microcontrollers operate with the standard logic voltage of + 5V. Some microcontrollers can
operate at as low as + 2.7V, and some will tolerate + 6V without any problem. The manufacturer‘s
data sheet will have information about the allowed limits of the power supply voltage. At89c52
microcontrollers can operate with a power supply of + 2V to 5.5V. Usually, a voltage regulator
circuit is used to obtain the required power supply voltage when the device is operated from a
mains adapter or batteries. For example, a 5V regulator is required if the microcontroller is
operated from a 5V supply using a 9V battery.
The Clock
All microcontrollers require a clock (or an oscillator) to operate, usually provided by external
timing devices connected to the microcontroller. In most cases, these external timing devices
are a crystal plus two small capacitors. In some cases they are resonators or an external
resistor-capacitor pair. Some microcontrollers have built-in timing circuits and do not require
external timing components. If an application is not time-sensitive, external or internal (if
available) resistor-capacitor timing components are the best option for their simplicity and low
cost. An instruction is executed by fetching it from the memory and then decoding it. This
usually takes several clock cycles and is known as the instruction cycle. Thus the
microcontroller operates at a clock rate that is one-quarter of the actual oscillator frequency.
The 8051 series of microcontrollers can operate with clock frequencies up to 40MHz.
Timers
Timers are important parts of any microcontroller. A timer is basically a counter which is
driven from either an external clock pulse or the microcontroller‘s internal oscillator. A timer
can be 8 bits or 16 bits wide. Data can be loaded into a timer under program control, and the
timer can be stopped or started by program control. Most timers can be configured to
DEPARTMENT OF EEE,VAST
17
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
generate an interrupt when they reach a certain count (usually when they overflow). The user
program can use an interrupt to carry out accurate timing-related operations inside the
microcontroller. Microcontrollers in the 8051 series have at least three timers. For example,
the AT89C52 microcontroller has three built-in timers. Some microcontrollers offer capture
and compare facilities, where a timer value can be read when an external event occurs, or the
timer value can be compared to a preset value, and an interrupt is generated when this value
is reached.
Reset Input
A reset input is used to reset a microcontroller externally. Resetting puts the microcontroller
into a known state such that the program execution starts from address 0 of the program
memory. An external reset action is usually achieved by connecting a push-button switch to
the reset input. When the switch is pressed, the microcontroller is reset.
Interrupts
Interrupts are an important concept in microcontrollers. An interrupt causes the microcontroller to
respond to external and internal (e.g., a timer) events very quickly. When an interrupt occurs, the
microcontroller leaves its normal flow of program execution and jumps to a special part of the
program known as the interrupt service routine (ISR). The program code inside the ISR is executed,
and upon return from the ISR the program resumes its normal flow of execution.
The ISR starts from a fixed address of the program memory sometimes known as the interrupt
vector address. Some microcontrollers with multi-interrupt features have just one interrupt vector
address, while others have unique interrupt vector addresses, one for each interrupt source.
Interrupts can be nested such that a new interrupt can suspend the execution of another interrupt.
Another important feature of multi-interrupt capability is that different interrupt sources can be
assigned different levels of priority. The at89c52 microcontroller has 8 interrupts source.
Analog-to-Digital Converter
DEPARTMENT OF EEE,VAST
18
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
An analog-to-digital converter (A/D) is used to convert an analog signal, such as voltage, to
digital form so a microcontroller can read and process it. Some microcontrollers have built-
in A/D converters. External A/D converter can also be connected to any type of
microcontroller. A/D converters are usually 8 to 10 bits, having 256 to 1024 quantization
levels. Most 8051 microcontrollers with A/D features have multiplexed A/D converters
which provide more than one analog input channel. The A/D conversion process must be
started by the user program and may take several hundred microseconds to complete. A/D
converters usually generate interrupts when a conversion is complete so the user program
can read the converted data quickly. A/D converters are especially useful in control and
monitoring applications, since most sensors (e.g., temperature sensors, pressure sensors,
force sensors, etc.) produce analog output voltages.
Serial Input-Output
Serial communication (also called RS232 communication) enables a microcontroller to be
connected to another microcontroller or to a PC using a serial cable. Some microcontrollers have
built-in hardware called USART (universal synchronous-asynchronous receiver-transmitter) to
implement a serial communication interface. The user program can usually select the baud rate
and data format. If no serial input-output hardware is provided, it is easy to develop software to
implement serial data communication using any I/O pin of a microcontroller.
The 8051 Microcontroller
Archutecture:
DEPARTMENT OF EEE,VAST
19
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
All 8051 microcontrollers are 40 pin devices. The pin configuration of AT89C52 or AT89S52 (DIP
package) is shown in figure.
2.6.2 Block diagram:
DEPARTMENT OF EEE,VAST
20
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
2.6.3 The Reset:
The reset action put the microcontroller in the unknown state. Resetting a 8051 microcontroller
starts execution of the program from address 0000H of the program memory.
DEPARTMENT OF EEE,VAST
21
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
2.6.4 The clock source:
The 8051 microcontroller can be operated from an external crystal or ceramic resonator
connected to the microcontroller's XTAL1 and XTAL2 pins.
2.6.5 Input/Output Ports (I/O Ports):
All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as
inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to
be connected to peripheral devices are available for use.
Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends on
its logic state, in order to configure a microcontroller pin as an input, it is necessary to apply a
logic one (1) to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is
the case with any TTL input.
Port 0
The P0 port is characterized by two functions. If external memory is used then the lower address byte
(addresses A0-A7) is applied on it. Otherwise, all bits of this port are configured as inputs/outputs.
The other function is expressed when it is configured as an output. Unlike other ports consisting of pins
with built-in pull-up resistor connected by its end to 5 V power supply, pins of this port have this resistor
left out. This apparently small difference has its consequences:
DEPARTMENT OF EEE,VAST
22
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
If any pin of this port is configured as an input then it acts as if it “floats”. Such an input has unlimited
input resistance and in determined potential.
When the pin is configured as an output, it acts as an “open drain”. By applying logic 0 to a port bit, the
appropriate pin will be connected to ground (0V). By applying logic 1, the external output will keep on
“floating”. In order to apply logic 1 (5V) on this output pin, it is necessary to built in an external pull-up
resistor.
Port 1
P1 is a true I/O port, because it doesn't have any alternative functions as is the case with P0, but
can be configured as general I/O only. It has a pull-up resistor built-in and is completely
compatible with TTL circuits.
Port 2
DEPARTMENT OF EEE,VAST
23
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
P2 acts similarly to P0 when external memory is used. Pins of this port occupy addresses
intended for external memory chip. This time it is about the higher address byte with addresses
A8-A15. When no memory is added, this port can be used as a general input/output port showing
features similar to P1.
Port 3
All port pins can be used as general I/O, but they also have an alternative function. In order to
use these alternative functions, a logic one (1) must be applied to appropriate bit of the P3
register. In terms of hardware, this port is similar to P0, with the difference that its pins have a
pull-up resistor built-in.
Pin's Current limitations
When configured as outputs (logic zero (0)), single port pins can receive a current of 10mA. If
all 8 bits of a port are active, a total current must be limited to 15mA (port P0: 26mA). If all
ports (32 bits) are active, total maximum current must be limited to 71mA. When these pins are
configured as inputs (logic 1), built-in pull-up resistors provide very weak current, but strong
enough to activate up to 4 TTL inputs of LS series.
Special Function Registers (SFRs):
Special Function Registers (SFRs) are a sort of control table used for running and monitoring the
operation of the microcontroller. Each of these registers as well as each bit they include, has its
name, address in the scope of RAM and precisely defined purpose such as timer control,
interrupt control, serial communication control etc. Even though there are 128 memory locations
intended to be occupied by them, the basic core, shared by all types of 8051 microcontrollers,
has only 21 such registers. Rest of locations are intentionally left unoccupied in order to enable
the manufacturers to further develop microcontrollers keeping them compatible with the
previous versions. It also enables programs written a long time ago for microcontrollers which
are out of production now to be used today.
DEPARTMENT OF EEE,VAST
24
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
A Register (Accumulator)
A register is a general-purpose register used for storing intermediate results obtained during
operation. Prior to executing an instruction upon any number or operand it is necessary to store it
in the accumulator first. All results obtained from arithmetical operations performed by the ALU
are stored in the accumulator. Data to be moved from one register to another must go through the
accumulator. In other words, the A register is the most commonly used register and it is
impossible to imagine a microcontroller without it. More than half instructions used by the 8051
microcontroller use somehow the accumulator.
B Register
Multiplication and division can be performed only upon numbers stored in the A and B registers.
All other instructions in the program can use this register as a spare accumulator (A).
DEPARTMENT OF EEE,VAST
25
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
R Registers (R0-R7)
This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7). Even though they are
not true SFRs, they deserve to be discussed here because of their purpose. They occupy 4 banks
within RAM. Similar to the accumulator, they are used for temporary storing variables and
intermediate results during operation. Which one of these banks is to be active depends on two
bits of the PSW Register. Active bank is a bank the registers of which are currently used.
The following example best illustrates the purpose of these registers. Suppose it is necessary to
perform some arithmetical operations upon numbers previously stored in the R registers:
(R1+R2) - (R3+R4). Obviously, a register for temporary storing results of addition is needed.
This is how it looks in the program:
MOV A,R3; Means: move number from R3 into accumulator
ADD A,R4; Means: add number from R4 to accumulator (result remains in accumulator)
DEPARTMENT OF EEE,VAST
26
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
MOV R5,A; Means: temporarily move the result from accumulator into R5
MOV A,R1; Means: move number from R1 to accumulator
ADD A,R2; Means: add number from R2 to accumulator
SUBB A,R5; Means: subtract number from R5 (there are R3+R4)
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.
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.
F0 - Flag 0:
This is a general-purpose bit available for use.
AC - Auxiliary Carry Flag:
is used for BCD operations only.
CY - Carry Flag:
DEPARTMENT OF EEE,VAST
27
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
is the (ninth) auxiliary bit used for all arithmetical operations and shift instructions.
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 primarily used for external
memory addressing. Besides, the DPTR Register is usually used for storing data and
intermediate results.
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,
DEPARTMENT OF EEE,VAST
28
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
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.
P0, P1, P2, P3 - Input/Output Registers
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.
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.
DEPARTMENT OF EEE,VAST
29
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
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.
Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists of
will contain 0. If the timer contains for example number 1000 (decimal), then the TH0 register
(high byte) will contain the number 3, while the TL0 register (low byte) will contain decimal
number 232.
Formula used to calculate values in these two registers is very simple:
TH0 × 256 + TL0 = T
Matching the previous example it would be as follows:
3 × 256 + 232 = 1000
DEPARTMENT OF EEE,VAST
30
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case of
exceeding this value, the timer will be automatically cleared and counting starts from 0. This
condition is called an overflow. Two registers TMOD and TCON are closely connected to this
timer and control its operation.
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. There are 4 operational modes and each of them is described herein.
Bits of this register have the following function:
GATE1 :
enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3):
1 - Timer 1 operates only if the INT1 bit is set.
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:
1 - Timer counts pulses brought to the T1 pin (P3.5).
0 - Timer counts pulses from internal oscillator.
T1M1,T1M0:
These two bits select the operational mode of the Timer 1.
T 1 M 1 T 1 M 0 M O D E D E S C R I P T I O N
DEPARTMENT OF EEE,VAST
31
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto-reload
1 1 3 Split mode
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
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:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.
T 0 M 1 T 0 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
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, while rest of them is used for interrupt control to be
discussed later.
DEPARTMENT OF EEE,VAST
32
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
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.
How to use the Timer 0 ?
In order to use timer 0, it is first necessary to select it and configure the mode of its operation. Bits of the
TMOD register are in control of it:
Referring to figure above, the timer 0 operates in mode 1 and counts pulses generated by internal clock
the frequency of which is equal to 1/12 the quartz frequency.
Turn on the timer:
DEPARTMENT OF EEE,VAST
33
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
The TR0 bit is set and the timer starts operation. If the quartz crystal with frequency of 12MHz is
embedded then its contents will be incremented every microsecond. After 65.536 microseconds, the both
registers the timer consists of will be loaded. The microcontroller automatically clears them and the timer
keeps on repeating procedure from the beginning until the TR0 bit value is logic zero (0).
8051 Microcontroller Interrupts
There are five interrupt sources for the 8051, which means that they can recognize 5 different events that
can interrupt regular program execution. Each interrupt can be enabled or disabled by setting bits of the
IE register. Likewise, the whole interrupt system can be disabled by clearing the EA bit of the same
register. Refer to figure below.
Now, it is necessary to explain a few details referring to external interrupts- INT0 and INT1. If the IT0 and
IT1 bits of the TCON register are set, an interrupt will be generated on high to low transition, i.e. on the
falling pulse edge (only in that moment). If these bits are cleared, an interrupt will be continuously
executed as far as the pins are held low.
DEPARTMENT OF EEE,VAST
34
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
IE Register (Interrupt Enable)
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.
DEPARTMENT OF EEE,VAST
35
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
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.
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.
Interrupt Priorities
It is not possible to forseen when an interrupt request will arrive. If several interrupts are enabled, it may
happen that while one of them is in progress, another one is requested. In order that the microcontroller
knows whether to continue operation or meet a new interrupt request, there is a priority list instructing it
what to do.
The priority list offers 3 levels of interrupt priority:
1. Reset! The apsolute master. When a reset request arrives, everything is stopped and the
microcontroller restarts.
2. Interrupt priority 1 can be disabled by Reset only.
3. Interrupt priority 0 can be disabled by both Reset and interrupt priority 1.
The IP Register (Interrupt Priority Register) specifies which one of existing interrupt sources have higher
and which one has lower priority. Interrupt priority is usually specified at the beginning of the program.
According to that, there are several possibilities:
If an interrupt of higher priority arrives while an interrupt is in progress, it will be
immediately stopped and the higher priority interrupt will be executed first.
If two interrupt requests, at different priority levels, arrive at the same time then the
higher priority interrupt is serviced first.
If the both interrupt requests, at the same priority level, occur one after another, the one
which came later has to wait until routine being in progress ends.
If two interrupt requests of equal priority arrive at the same time then the interrupt to be
serviced is selected according to the following priority list:
1. External interrupt INT0
2. Timer 0 interrupt
DEPARTMENT OF EEE,VAST
36
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
3. External Interrupt INT1
4. Timer 1 interrupt
5. Serial Communication Interrupt
IP Register (Interrupt Priority)
The IP register bits specify the priority level of each interrupt (high or low priority).
PS - Serial Port Interrupt priority bit
o Priority 0
o Priority 1
PT1 - Timer 1 interrupt priority
o Priority 0
o Priority 1
PX1 - External Interrupt INT1 priority
o Priority 0
o Priority 1
PT0 - Timer 0 Interrupt Priority
o Priority 0
o Priority 1
PX0 - External Interrupt INT0 Priority
o Priority 0
o Priority 1
Handling Interrupt
When an interrupt request arrives the following occurs:
1. Instruction in progress is ended.
2. The address of the next instruction to execute is pushed on the stack.
3. Depending on which interrupt is requested, one of 5 vectors (addresses) is written to the
program counter in accordance to the table below:
4.
DEPARTMENT OF EEE,VAST
37
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
I N T E R R U P T S O U R C E V E C T O R ( A D D R E S S )
IE0 3 h
TF0 B h
TF1 1B h
RI, TI 23 h
All addresses are in hexadecimal format
5. These addresses store appropriate subroutines processing interrupts. Instead of them,
there are usually jump instructions specifying locations on which these subroutines reside.
6. When an interrupt routine is executed, the address of the next instruction to execute is
poped from the stack to the program counter and interrupted program resumes operation
from where it left off.
From the moment an interrupt is enabled, the microcontroller is on alert all the time. When an interrupt
request arrives, the program execution is stopped, electronics recognizes the source and the program
“jumps” to the appropriate address (see the table above). This address usually stores a jump instruction
specifying the start of appropriate subroutine. Upon its execution, the program resumes operation from
where it left off.
Introduction to assembly programming:
The process of writing program for the microcontroller mainly consists of giving instructions (commands)
in the specific order in which they should be executed in order to carry out a specific task. As electronics
cannot “understand” what for example an instruction “if the push button is pressed- turn the light on”
means, then a certain number of simpler and precisely defined orders that decoder can recognise must
be used. All commands are known as INSTRUCTION SET. All microcontrollers compatibile with the 8051
have in total of 255 instructions, i.e. 255 different words available for program writing.
At first sight, it is imposing number of odd signs that must be known by heart. However, It is not so
complicated as it looks like. Many instructions are considered to be “different”, even though they perform
the same operation, so there are only 111 truly different commands. For example: ADD A,R0, ADD
A,R1, ... ADD A,R7 are instructions that perform the same operation (additon of the accumulator and
DEPARTMENT OF EEE,VAST
38
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
register). Since there are 8 such registers, each instruction is counted separately. Taking into account that
all instructions perform only 53 operations (addition, subtraction, copy etc.) and most of them are rarely
used in practice, there are actually 20-30 abbreviations to be learned, which is acceptable.
Types of instructions
Depending on operation they perform, all instructions are divided in several groups:
Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions
The first part of each instruction, called MNEMONIC refers to the operation an instruction performs (copy,
addition, logic operation etc.). Mnemonics are abbreviations of the name of operation being executed. For
example:
INC R1 - Means: Increment register R1 (increment register R1);
LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as LAB5);
JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is not 0,
jump to the address marked as LOOP);
The other part of instruction, called OPERAND is separated from mnemonic by at least one whitespace
and defines data being processed by instructions. Some of the instructions have no operand, while some
of them have one, two or three. If there is more than one operand in an instruction, they are separated by
a comma. For example:
RET - return from a subroutine;
JZ TEMP - if the number in the accumulator is not 0, jump to the address marked as
TEMP;
ADD A,R3 - add R3 and accumulator;
CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump to the
address marked as LOOP;
Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand. For example:
ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.
DEPARTMENT OF EEE,VAST
39
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
A R I T H M E T I C I N S T R U C T I O N S
Mnemonic Description Byte Cycle
ADD A,Rn Adds the register to the accumulator 1 1
ADD A,direct Adds the direct byte to the accumulator 2 2
ADD A,@Ri Adds the indirect RAM to the accumulator 1 2
ADD A,#data Adds the immediate data to the accumulator 2 2
ADDC A,Rn Adds the register to the accumulator with a carry flag 1 1
ADDC A,direct Adds the direct byte to the accumulator with a carry flag 2 2
ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag 1 2
ADDC A,#data Adds the immediate data to the accumulator with a carry flag 2 2
SUBB A,Rn Subtracts the register from the accumulator with a borrow 1 1
SUBB A,direct Subtracts the direct byte from the accumulator with a borrow 2 2
SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow 1 2
SUBB A,#data Subtracts the immediate data from the accumulator with a borrow 2 2
INC A Increments the accumulator by 1 1 1
INC Rn Increments the register by 1 1 2
INC Rx Increments the direct byte by 1 2 3
INC @Ri Increments the indirect RAM by 1 1 3
DEC A Decrements the accumulator by 1 1 1
DEC Rn Decrements the register by 1 1 1
DEC Rx Decrements the direct byte by 1 1 2
DEC @Ri Decrements the indirect RAM by 1 2 3
INC DPTR Increments the Data Pointer by 1 1 3
DEPARTMENT OF EEE,VAST
40
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
MUL AB Multiplies A and B 1 5
DIV AB Divides A by B 1 5
DA A Decimal adjustment of the accumulator according to BCD code 1 1
Branch Instructions
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where the program
continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a specified condition is
met. Otherwise, the program normally proceeds with the next instruction.
B R A N C H I N S T R U C T I O N S
Mnemonic Description Byte Cycle
ACALL addr11 Absolute subroutine call 2 6
LCALL addr16 Long subroutine call 3 6
RET Returns from subroutine 1 4
RETI Returns from interrupt subroutine 1 4
AJMP addr11 Absolute jump 2 3
LJMP addr16 Long jump 3 4
SJMP rel Short jump (from –128 to +127 locations relative to the following instruction) 2 3
JC rel Jump if carry flag is set. Short jump. 2 3
JNC rel Jump if carry flag is not set. Short jump. 2 3
JB bit,rel Jump if direct bit is set. Short jump. 3 4
JBC bit,rel Jump if direct bit is set and clears bit. Short jump. 3 4
DEPARTMENT OF EEE,VAST
41
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
JMP @A+DPTR Jump indirect relative to the DPTR 1 2
JZ rel Jump if the accumulator is zero. Short jump. 2 3
JNZ rel Jump if the accumulator is not zero. Short jump. 2 3
CJNE A,direct,rel Compares direct byte to the accumulator and jumps if not equal. Short jump. 3 4
CJNE A,#data,rel Compares immediate data to the accumulator and jumps if not equal. Short jump. 3 4
CJNE Rn,#data,rel Compares immediate data to the register and jumps if not equal. Short jump. 3 4
CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps if not equal. Short jump. 3 4
DJNZ Rn,rel Decrements register and jumps if not 0. Short jump. 2 3
DJNZ Rx,rel Decrements direct byte and jump if not 0. Short jump. 3 4
NOP No operation 1 1
Data Transfer Instructions
Data transfer instructions move the content of one register to another. The register the content of which is
moved remains unchanged. If they have the suffix “X” (MOVX), the data is exchanged with external
memory.
D A T A T R A N S F E R I N S T R U C T I O N S
Mnemonic Description Byte Cycle
MOV A,Rn Moves the register to the accumulator 1 1
MOV A,direct Moves the direct byte to the accumulator 2 2
MOV A,@Ri Moves the indirect RAM to the accumulator 1 2
MOV A,#data Moves the immediate data to the accumulator 2 2
MOV Rn,A Moves the accumulator to the register 1 2
MOV Rn,direct Moves the direct byte to the register 2 4
MOV Rn,#data Moves the immediate data to the register 2 2
DEPARTMENT OF EEE,VAST
42
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
MOV direct,A Moves the accumulator to the direct byte 2 3
MOV direct,Rn Moves the register to the direct byte 2 3
MOV direct,direct Moves the direct byte to the direct byte 3 4
MOV direct,@Ri Moves the indirect RAM to the direct byte 2 4
MOV direct,#data Moves the immediate data to the direct byte 3 3
MOV @Ri,A Moves the accumulator to the indirect RAM 1 3
MOV @Ri,direct Moves the direct byte to the indirect RAM 2 5
MOV @Ri,#data Moves the immediate data to the indirect RAM 2 3
MOV DPTR,#data Moves a 16-bit data to the data pointer 3 3
MOVC A,@A+DPTR Moves the code byte relative to the DPTR to the accumulator (address=A+DPTR) 1 3
MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator (address=A+PC) 1 3
MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator 1 3-10
MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator 1 3-10
MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address) 1 4-11
MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address) 1 4-11
PUSH direct Pushes the direct byte onto the stack 2 4
POP direct Pops the direct byte from the stack/td> 2 3
XCH A,Rn Exchanges the register with the accumulator 1 2
XCH A,direct Exchanges the direct byte with the accumulator 2 3
XCH A,@Ri Exchanges the indirect RAM with the accumulator 1 3
XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the accumulator 1 3
Logic Instructions
DEPARTMENT OF EEE,VAST
43
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Logic instructions perform logic operations upon corresponding bits of two registers. After execution, the
result is stored in the first operand.
L O G I C I N S T R U C T I O N S
Mnemonic Description Byte Cycle
ANL A,Rn AND register to accumulator 1 1
ANL A,direct AND direct byte to accumulator 2 2
ANL A,@Ri AND indirect RAM to accumulator 1 2
ANL A,#data AND immediate data to accumulator 2 2
ANL direct,A AND accumulator to direct byte 2 3
ANL direct,#data AND immediae data to direct register 3 4
ORL A,Rn OR register to accumulator 1 1
ORL A,direct OR direct byte to accumulator 2 2
ORL A,@Ri OR indirect RAM to accumulator 1 2
ORL direct,A OR accumulator to direct byte 2 3
ORL direct,#data OR immediate data to direct byte 3 4
XRL A,Rn Exclusive OR register to accumulator 1 1
XRL A,direct Exclusive OR direct byte to accumulator 2 2
XRL A,@Ri Exclusive OR indirect RAM to accumulator 1 2
XRL A,#data Exclusive OR immediate data to accumulator 2 2
XRL direct,A Exclusive OR accumulator to direct byte 2 3
XORL direct,#data Exclusive OR immediate data to direct byte 3 4
CLR A Clears the accumulator 1 1
CPL A Complements the accumulator (1=0, 0=1) 1 1
DEPARTMENT OF EEE,VAST
44
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
SWAP A Swaps nibbles within the accumulator 1 1
RL A Rotates bits in the accumulator left 1 1
RLC A Rotates bits in the accumulator left through carry 1 1
RR A Rotates bits in the accumulator right 1 1
RRC A Rotates bits in the accumulator right through carry 1 1
Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that these
are performed upon single bits.
B I T - O R I E N T E D I N S T R U C T I O N S
Mnemonic Description Byte Cycle
CLR C Clears the carry flag 1 1
CLR bit Clears the direct bit 2 3
SETB C Sets the carry flag 1 1
SETB bit Sets the direct bit 2 3
CPL C Complements the carry flag 1 1
CPL bit Complements the direct bit 2 3
ANL C,bit AND direct bit to the carry flag 2 2
ANL C,/bit AND complements of direct bit to the carry flag 2 2
ORL C,bit OR direct bit to the carry flag 2 2
ORL C,/bit OR complements of direct bit to the carry flag 2 2
MOV C,bit Moves the direct bit to the carry flag 2 2
MOV bit,C Moves the carry flag to the direct bit 2 3
DEPARTMENT OF EEE,VAST
45
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Description of all 8051 instructions
Here is a list of the operands and their meanings:
A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory bank;
Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a
SFR (I/O port, control register etc.);
@Ri - is indirect internal or external RAM location addressed by register R0 or R1;
#data - is an 8-bit constant included in instruction (0-255);
#data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
addr11 - is an 11-bit address. May be within the same 2KB page of program memory as
the first byte of the following instruction;
rel - is the address of a close memory location (from -128 to +127 relative to the first
byte of the following instruction). On the basis of it, assembler computes the value to add
or subtract from the number currently stored in the program counter;
bit - is any bit-addressable I/O pin, control or status bit; and
C - is carry flag of the status register (register PSW).
LCD (LIQUID CRYSTAL DISPLAY):
It is very important to keep a track of the working of almost all the automated and semi-automated devices, be it a washing machine, an
autonomous robot or anything else. This is achieved by displaying their status on a small display module. LCD (Liquid Crystal
Display) screen is such a display module and a 16x2 LCD module is very commonly used. These modules are replacing seven segments
and other multi segment LEDs for these purposes. The reasons being: LCDs are economical, easily programmable, have no
limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced
with a microcontroller to display a message or status of a device.
DEPARTMENT OF EEE,VAST
46
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
This topic explains the basics of a 16x2 LCD and how it can be interfaced with AT89C51 to display a character.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel
matrix. This LCD has two registers.
1. Command/Instruction Register- stores the command instructions given to the LCD. A command is an instruction given to
LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc.
2. Data Register- stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
Commonly used LCD Command codes:
Hex Code Command to LCD Instruction Register
1 Clear screen display
2 Return home
4 Decrement cursor
6 Increment cursor
E Display ON, Cursor ON
80 Force the cursor to the beginning of the 1st line
C0 Force cursor to the beginning of the 2nd line
DEPARTMENT OF EEE,VAST
47
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
38 Use 2 lines and 5x7 matrix
The pin description of this module is given below.
Pin configuration:
Pin Symbol Description
1 VSS Ground 0 V
2 VCC Main power supply +5 V
3 VEE Power supply to control contrast
Contrast adjustment by providing a variable
resistor through VCC
4 RS Register Select
RS=0 to select Command Register
RS=1 to select Data Register
5 R/W Read/write
R/W=0 to write to the register
R/W=1 to read from the register
6 EN Enable A high to low pulse (minimum 450ns wide) is given when data is sent to
data pins
7 DB0 To display letters
8 DB1
DEPARTMENT OF EEE,VAST
48
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
9 DB2
10 DB3 8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Led+ Backlight VCC +5V
16 Led- Backlight Ground 0V
Programming the LCD:
1. Data pin8 (DB7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations. Therefore before passing any data to LCD, its command register should be
read and busy flag should be checked.
2. To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data
is sent. Each write operation is performed on the positive edge of the Enable signal.
3. To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write
DEPARTMENT OF EEE,VAST
49
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.
Displaying single character ‘A’ on LCD
The LCD is interfaced with microcontroller ( AT89C51 ). This microcontroller has 40 pins with four 8-bit ports (P0, P1, P2, and
P3). Here P1 is used as output port which is connected to data pins of the LCD. The control pins (pin 4-6) are controlled by pins 2-4 of P0 port. Pin 3 is connected to a preset of 10k? to adjust the contrast on LCD screen. This program uses the above concepts of interfacing
the LCD with controller by displaying the character ‘A’ on it.
CIRCUIT DIAGRAM
DEPARTMENT OF EEE,VAST
50
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
51
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Figure 2- Automatic Temperature Controlled Fan Circuit
DEPARTMENT OF EEE,VAST
52
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
WORKING
R3-R4 and P1-R1 are wired as a Wheatstone bridge in which R3-R4 generate a fixed
two-thirds-supply "reference" voltage, P1-R1 generate a temperature-sensitive "variable"
voltage, and Q1 is used as a bridge balance detector.
P1 is adjusted so that the "reference" and "variable" voltages are equal at a temperature
just below the required trigger value, and under this condition Q1 Base and Emitter are at equal
voltages and Q1 is cut off. When the R1 temperature goes above this "balance" value the P1-R1
voltage falls below the "reference" value, so Q1 becomes forward biased, pulse-charging C1.
This occurs because the whole circuit is supplied by a 100Hz half-wave voltage obtained
from mains supply by means of D3-D6 Diode Bridge without a smoothing capacitor and fixed to
18V by R9 and Zener diode D1. Therefore the 18V supply of the circuit is not true DC but has a
rather trapezoidal shape. C1 provides a variable phase-delay pulse-train related to temperature
and synchronous with the mains supply "zero voltage" point of each half cycle, thus producing
minimal switching RFI from the SCR. Q2 and Q3 form a trigger device, generating a short pulse
suitable to drive the SCR.
DEPARTMENT OF EEE,VAST
53
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
COMPONENT DESCRIPTION
. SCR
Figure 3.. Symbol of SCR
Figure 4. Pictorial Representation of SCR
A thyristor, also known as a SCR (silicon controlled rectifier), is a special type of diode
with four layers of alternating N and P-type material. They act as bistable switches, conducting
when their gate receives a current pulse, and continue to conduct for as long as they are forward
biased (that is, as long as the voltage across the device has not reversed).
The thyristor is a four-layer, three terminal semiconducting devices, with each layer
consisting of alternately N-type or P-type material, for example P-N-P-N. The main terminals,
labelled anode and cathode, are across the full four layers, and the control terminal, called the
gate, is attached to p-type material near to the cathode. (A variant called an SCS—Silicon
Controlled Switch—brings all four layers out to terminals.) The operation of a thyristor can be
understood in terms of a pair of tightly coupled bipolar junction transistors, arranged to cause the
self-latching action.
DEPARTMENT OF EEE,VAST
54
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Figure 5 Transistor Equivalent Circuit of an SCR
Thyristors have three states:
1. Reverse blocking mode — Voltage is applied in the direction that would be blocked
by a diode
2. Forward blocking mode — Voltage is applied in the direction that would cause a
diode to conduct, but the thyristor has not yet been triggered into conduction
3. Forward conducting mode — The thyristor has been triggered into conduction and
will remain conducting until the forward current drops below a threshold value
known as the "holding current"
DEPARTMENT OF EEE,VAST
55
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
The thyristor has three p-n junctions (serially named J1, J2, J3 from
the anode).When the anode is at a positive potential VAK with respect to the
cathode with no voltage applied at the gate, junctions J1 and J3 are forward
biased, while junction J2 is reverse biased. As J2 is reverse biased, no
conduction takes place (Off state). Now if VAK is increased beyond the
breakdown voltage VBO of the thyristor, avalanche breakdown of
J2 takes place and the thyristor starts conducting (On state).
If a positive potential VG is applied at the gate terminal with respect to the cathode, the
breakdown of the junction J2 occurs at a lower value of VAK. By selecting an appropriate value
of VG, the thyristor can be switched into the on state suddenly.
It should be noted that once avalanche breakdown has occurred, the thyristor continues to
conduct, irrespective of the gate voltage, until both: (a) the potential VG is removed and (b) the
current through the device (anode−cathode) is less than the holding current specified by the
manufacturer. Hence VG can be a voltage pulse, such as the voltage output from a UJT relaxation
oscillator.
These gate pulses are characterized in terms of gate trigger voltage (VGT) and gate trigger
current (IGT). Gate trigger current varies inversely with gate pulse width in such a way that it is
evident that there is a minimum gate charge required to trigger the thyristor.
DEPARTMENT OF EEE,VAST
. Fig .6 Layer diagram of thyristor
56
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Figure 7 SCR Characteristic
In a conventional thyristor, once it has been switched on by the gate terminal, the device
remains latched in the on-state (i.e. does not need a continuous supply of gate current to
conduct), providing the anode current has exceeded the latching current (IL). As long as the
anode remains positively biased, it cannot be switched off until the anode current falls below the
holding current (IH).
A thyristor can be switched off if the external circuit causes the anode to become
negatively biased. In some applications this is done by switching a second thyristor to discharge
a capacitor into the cathode of the first thyristor. This method is called forced commutation.
DEPARTMENT OF EEE,VAST
57
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
SCR Phase Control
In SCR Phase Control, the firing angle, or point during the half-cycle at which the SCR is
triggered, determines the amount of current which flows through the device. It acts as a high-
speed switch which is open for the first part of the cycle, and then closes to allow power flow
after the trigger pulse is applied.
Figure .8 Output Wave form of SCR
Figure above shows an AC waveform being applied with a gating pulse at 45 degrees.
There are 360 electrical degrees in a cycle; 180 degrees in a half-cycle. The number of degrees
from the beginning of the cycle until the SCR is gated ON is referred to as the firing angle, and
the number of degrees that the SCR remains conducting is known as the conduction angle. The
earlier in the cycle the SCR is gated ON, the greater will be the voltage applied to the load.
DEPARTMENT OF EEE,VAST
58
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Figure .9 Load voltage regulated by thyristor phase control.
For applications with frequencies higher than the domestic AC mains supply (e.g. 50 Hz
or 60 Hz), thyristors with lower values of tQ are required. Such fast thyristors are made by
diffusing into the silicon heavy metals ions such as gold or platinum which act as charge
combination centers. Alternatively, fast thyristors may be made by neutron irradiation of the
silicon.
DEPARTMENT OF EEE,VAST
59
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
THERMISTOR
Figure .10 Pictorial Representation of Thermistor
A thermistor is a type of resistor whose resistance varies with temperature. The word is
a portmanteau of thermal and resistor. Thermistors are widely used as inrush current limiters,
temperature sensors, self-resetting over current protectors, and self-regulating heating elements.
The material used in a thermistor is generally a ceramic or polymer. The temperature responses
of thermistor are typically achieve a higher precision within a limited temperature range [usually
−90 °C to 130 °C].Assuming, as a first-order approximation, that the relationship between
resistance and temperature is linear, then:
Where
ΔR = change in resistance
ΔT = change in temperature
k = first-order temperature coefficient of resistance
DEPARTMENT OF EEE,VAST
Figure .11 Symbol of Thermistor
60
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Thermistors can be classified into two types, depending on the sign of k. If k is
positive, the resistance increases with increasing temperature, and the device is called a positive
temperature coefficient (PTC) thermistor, or posistor. If k is negative, the resistance decreases
with increasing temperature, and the device is called a negative temperature coefficient (NTC)
thermistor. Here we are using a thermistor with negative temperature coefficient Resistors that
are not thermistors are designed to have a k as close to zero as possible(smallest possible k), so
that their resistance remains nearly constant over a wide temperature range.
Many NTC thermistors are made from a pressed disc or cast chip of
a semiconductor such as a sintered metal oxide. They work because raising the temperature of a
semiconductor increases the number of electrons able to move about and carry charge - it
promotes them into the conduction band. The more charge carriers that are available, the
more current a material can conduct.
Most PTC thermistors are of the "switching" type, which means that their resistance rises
suddenly at a certain critical temperature. The devices are made of doped
polycrystalline ceramic containing barium (BaTiO3) and other compounds. The dielectric
constant of this ferroelectric material varies with temperature. Below the Curie
point temperature, the high dielectric constant prevents the formation of potential barriers
between the crystal grains, leading to a low resistance. In this region the device has a small
negative temperature coefficient. At the Curie point temperature, the dielectric constant drops
sufficiently to allow the formation of potential barriers at the grain boundaries, and the resistance
increases sharply. At even higher temperatures, the material reverts to NTC behaviour.
DEPARTMENT OF EEE,VAST
61
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
Another type of PTC thermistor is the polymer PTC, which is sold under brand names
such as "Polyswitch" "Semifuse", and "Multifuse". This consists of a slice of plastic
with carbon grains embedded in it. When the plastic is cool, the carbon grains are all in contact
with each other, forming a conductive path through the device. When the plastic heats up, it
expands, forcing the carbon grains apart, and causing the resistance of the device to rise rapidly.
This type of thermistors is used for switching, not for proportional temperature measurement.
Applications of Thermistor
PTC thermistors can be used as current-limiting devices for circuit protection, as
replacements for fuses.
NTC thermistors are used as resistance thermometers in low-temperature measurements of
the order of 10 K.
NTC thermistors can be used as inrush-current limiting devices in power supply circuits.
They present a higher resistance initially which prevents large currents from flowing at turn-
on, and then heat up and become much lower resistance to allow higher current flow during
normal operation.
NTC thermistors are regularly used in automotive applications. For example, they monitor
things like coolant temperature and/or oil temperature inside the engine and provide data to
the ECU and, indirectly, to the dashboard.
Thermistors are also commonly used in modern digital thermostats and to monitor the
temperature of battery packs while charging.
DEPARTMENT OF EEE,VAST
62
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
ZENER DIODE
Figure.12 Zener Diode Symbol
A Zener diode is a type of diode that permits current not only in the forward direction
like a normal diode, but also in the reverse direction if the voltage is larger than the breakdown
voltage known as "Zener knee voltage" or "Zener voltage".
A Zener diode exhibits almost the same properties of the conventional solid-state diode,
except the device is specially designed so as to have a greatly reduced breakdown voltage, the
so-called Zener voltage. By contrast with the conventional device, a reverse-biased Zener diode
will exhibit a controlled breakdown and allow the current to keep the voltage across the Zener
diode at the Zener voltage. For example, a diode with a Zener breakdown voltage of 3.2 V will
exhibit a voltage drop of 3.2 V if reverse bias voltage applied across it is more than its Zener
voltage. The Zener diode is therefore ideal for applications such as the generation of a reference
voltage (e.g. for an amplifier stage), or as a voltage stabilizer for low-current applications.
Zener diodes are widely used as voltage references and as shunt regulators to regulate the
voltage across small circuits. When connected in parallel with a variable voltage source so that it
is reverse biased, a Zener diode conducts when the voltage reaches the diode's reverse
DEPARTMENT OF EEE,VAST
63
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
breakdown voltage. From that point on, the relatively low impedance of the diode keeps the
voltage across the diode at that value.A load may be placed across the diode in the circuit, and as
long as the Zener stays in reverse breakdown, the diode will provide a stable voltage source to
the load.
A Zener diode used in this way is known as a shunt voltage regulator (shunt, in this
context, meaning connected in parallel, and voltage regulator being a class of circuit that
produces a stable voltage across any load). In a sense, a portion of the current through the
resistor is shunted through the Zener diode, and the rest is through the load. Thus the voltage that
the load sees is controlled by causing some fraction of the current from the power source to
bypass it—hence the name, by analogy with locomotive switching points.
DEPARTMENT OF EEE,VAST
64
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DIODE
Figure .13 Symbol of Diode
A Diode is a two-terminal electronic component that conducts electric current in only one
direction. The term usually refers to a semiconductor diode, the most common type today, which
is a crystal of semiconductor connected to two electrical terminals. The most common function
of a diode is to allow an electric current to flow through it in one direction (called the diode's
forward direction) while blocking current in the opposite direction (the reverse direction). Thus,
the diode can be thought of as an electronic version of a check valve. This unidirectional
behavior is called rectification, and is used to convert alternating current to direct current, and
extract modulation from radio signals in radio receivers.
A modern semiconductor diode is made of a crystal of semiconductor like silicon that has
impurities added to it to create a region on one side that contains negative charge carriers
(electrons), called n-type semiconductor, and a region on the other side that contains positive
charge carriers (holes), called p-type semiconductor. The diode's terminals are attached to each
of these regions. The boundary within the crystal between these two regions, called a PN
junction, is where the action of the diode takes place. The crystal conducts conventional current
in a direction from the p-type side (called the anode) to the n-type side (called the cathode), but
not in the opposite direction.
DEPARTMENT OF EEE,VAST
65
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
66
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
TRANSISTOR
Figure .14 Pictorial Representation and Symbol of Transistors NPN PNP
A transistor is a semiconductor device used to amplify and switch electronic signals. It is
made of a solid piece of semiconductor material, with at least three terminals for connection to
an external circuit. A voltage or current applied to one pair of the transistor's terminals changes
the current flowing through another pair of terminals. A Bipolar transistor has terminals labelled
base, collector, and emitter. A small current at the base terminal (that is, flowing from the base to
the emitter) can control or switch a much larger current between the collector and emitter
terminals. Here we are using two types of transistors PNP and NPN.
DEPARTMENT OF EEE,VAST
67
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
NPN
NPN is one of the two types of bipolar transistors, in which the letters "N" and "P" refer
to the majority charge carriers inside the different regions of the transistor. Most bipolar
transistors used today are NPN, because electron mobility is higher than hole mobility in
semiconductors, allowing greater currents and faster operation.
NPN transistors consist of a layer of P-doped semiconductor (the "base") between two N-
doped layers. A small current entering the base in common-emitter mode is amplified in the
collector output. In other terms, an NPN transistor is "on" when its base is pulled high relative to
the emitter.
The arrow in the NPN transistor symbol is on the emitter leg and points in the direction
of the conventional current flow when the device is in forward active mode.
PNP
The other type of BJT is the PNP with the letters "P" and "N" referring to the
majority charge carriers inside the different regions of the transistor.
PNP transistors consist of a layer of N-doped semiconductor between two layers of P-
doped material. A small current leaving the base in common-emitter mode is amplified in the
collector output. In other terms, a PNP transistor is "on" when its base is pulled low relative to
the emitter.
The arrow in the PNP transistor symbol is on the emitter leg and points in the direction of
the conventional current flow when the device is in forward active mode.
DEPARTMENT OF EEE,VAST
68
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
ADVANTAGES
Circuit is simpler in design.
The use of voltage regulators in fans can be avoided.
Power saving.
Temperature variations can be easily tracked down.
Less maintenance.
Easily repairable. Since there is no complex circuitry setup involved.
Low installation cost.
DEPARTMENT OF EEE,VAST
69
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
APPLICATIONS
This circuit can be employed in places such as railway stations and such public places
where people use to gather and they don’t care about the working of these fans. In such places
these circuits can be employed so the voltage regulators need not be operated manually.
Installing these circuits in such places leads to power saving as the circuit automatically adjusts
the fans speed.
Another application of these circuit is that this can be used in houses which uses air
conditioners for power saving.
DEPARTMENT OF EEE,VAST
70
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
RESULT
Automatic temperature controlled fan circuit was setup and connected to 230V mains
supply and obtained the required output according to different temperature conditions. The
circuit was found to be working as the temperature increased, speed of the fan increased and vice
versa.
DEPARTMENT OF EEE,VAST
71
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
SCOPE FOR FUTURE WORK
The circuit can be expanded by incorporating a passive infrared sensor along with the temperature sensor. The passive infrared sensor can include a fresnel lens for sensing a 360° circumference beneath the fan so that the fan can be turned on and off based on motion of persons approaching and leaving a selected area .
DEPARTMENT OF EEE,VAST
72
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
CONCLUSION
This circuit is found to be more reliable than a regulator circuit since this seems to be
more efficient than conventional regulator circuits. Since power consumption can be minimised
to a greater extent. Even though it is simple this has a significant role to play in the development
of technology. Every small step is significant in the path of success. Our project though simple is
significant in the current status of our country facing energy crisis.
DEPARTMENT OF EEE,VAST
73
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
REFERENCES
http://www.redcircuits.com/
http://en.wikipedia.org/
http://www.allaboutcircuits.com/
http://www.pc-control.co.uk/
http://www.howstuffworks.com/
DEPARTMENT OF EEE,VAST
74
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
APPENDIX
DEPARTMENT OF EEE,VAST
75
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DATA SHEET
DEPARTMENT OF EEE,VAST
76
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
77
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
78
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
79
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
80
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
81
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
82
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST
83
AUTOMATIC TEMPERATURE CONTROLLED FAN MINI PROJECT’11
DEPARTMENT OF EEE,VAST