You are on page 1of 67

MICROCONTROLLER Based AUTOMATIC TEMPERATURE & BRIGHTNESS CONTROLLER

Abstract:In Daily life there were vast uses of Automatic Temperature & brightness controller .These things can easy the human efforts and also has a wide area of application . Microcontroller is an important phenomena by which these application could be generalised .This can be used in daily life system as temperature control application such as fan, irrigating system and brightness using different types of sensor. This will allow a wide area of application using microcontroller.

INTRODUCTION:The aim of this project is to design an ambient temperature measurement and brightness control circuit. The motivation for doing this project is the fact that temperature measurement has become an integral part of any control system operating in a temperature sensitive environment and the various learning outcomes associated during the implementation of the project. In this project the ambient temperature will be displayed on a LCD. An 89s52 Microcontroller will be used for handling all the required computations and control.

Hardware Used Microcontroller AT89S52(8052 derivative)

ICS
1. DS 1820 (Temperature Sensor) 2. LM 7805 (Regulator IC for 5 volts constant D.C supply)

3.Light DEPENDENT register (For Brightness Control)

LCD For display at remote station. Crystal Oscillator To produce 11.0592 MHz Frequency for microcontroller clock. General Purpose PCBs.

Software Used
Keil u-Vision 3.0
Keil Software is used provide you with software development tools for 8051 based microcontrollers. With the Keil tools, you can generate embedded applications for virtually every 8051 derivative. The supported microcontrollers are listed in the -vision

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.
A circuit is designed which uses a LDR(light dependent resistor) to sense the light emitted by object coming from the opposite direction. This light sensed by the LDR is used to send signals to the circuit to trigger the command to a upper or the dipper circuit depending on the amount of light emitted by the vehicle coming from opposite direction.

BLOCK DIAGRAM

COMPONENTS USED
NAME OF COMPONENT SPECIFICATION 22K QUANTITY 1

Linear Potentiometer-P1 Thermistor-R1 SCR-D2 Zener Diode-D1 Diodes-D3,D4,D5,D6 Transistors-Q1,Q2 Transistor-Q3 Polyester Capacitor-C1 Resistor-R2 Resistors-R3,R6 Resistors-R4,R5 Resistor-R7 Resistor-R8 Resistors-R9,R10 Female Mains socket -SK1 Male Mains plug-PL1
PCB Breadboard Connecting Wires Microcontroller lcd

15K @ 20C n.t.c TYN612 BZX79C18 1N4007 1000V BC327 BC337 10nF 63V 100K 1/4W 10K 1/4W 22K 1/4W 100R 1/4W 470R 1/4W
68K 2W -

1 1
1 4 2

1 1 1
2

2 1 1
2 1 1 1 1 As required

8051 microcontroller
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 analogto-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 .

Microcontroller System:
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. 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 inputoutput 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 inputoutput. 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: 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).

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

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

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 pins function as you wish. simply performed by software, which means that pins 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:


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 manufacturers 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 microcontrollers 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 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 pushbutton 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
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 receivertransmitter) 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:

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:

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.

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:

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

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

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

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

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 TH0 256 + Matching the previous example it 3 256 + 232 = 1000

two

registers is very simple: TL0 = T would be as follows:

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.
T1M1 T1M0 MODE DESCRIPTION

13-bit timer

0 1 1

1 0 1

1 2 3

16-bit timer 8-bit auto-reload 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.

T0M1

T0M0

MODE

DESCRIPTION

0 0 1 1

0 1 0 1

0 1 2 3

13-bit timer 16-bit timer 8-bit auto-reload 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.

o o o o

TF1 bit is automatically set on the Timer 1 overflow. TR1 bit enables the Timer 1.
1 - Timer 1 is enabled. 0 - Timer 1 is disabled.

TF0 bit is automatically set on the Timer 0 overflow. TR0 bit enables the timer 0.
1 - Timer 0 is enabled. 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:

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.

IE Register (Interrupt Enable)

o o o o o o o

EA - global interrupt enable/disable:


0 - disables all interrupt requests. 1 - enables all individual interrupt requests.

ES - enables or disables serial interrupt:


0 - UART system cannot generate an interrupt. 1 - UART system enables an interrupt.

ET1 - bit enables or disables Timer 1 interrupt:


0 - Timer 1 cannot generate an interrupt. 1 - Timer 1 enables an interrupt.

EX1 - bit enables or disables external 1 interrupt:


0 - change of the pin INT0 logic state cannot generate an interrupt.

o o o o o

1 - enables an external interrupt on the pin INT0 state change.

ET0 - bit enables or disables timer 0 interrupt:


0 - Timer 0 cannot generate an interrupt. 1 - enables timer 0 interrupt.

EX0 - bit enables or disables external 0 interrupt:


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

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

o o o o o o o o o o

PS - Serial Port Interrupt priority bit


Priority 0 Priority 1

PT1 - Timer 1 interrupt priority


Priority 0 Priority 1

PX1 - External Interrupt INT1 priority


Priority 0 Priority 1

PT0 - Timer 0 Interrupt Priority


Priority 0 Priority 1

PX0 - External Interrupt INT0 Priority


Priority 0 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.
INTERRUPT SOURCE VECTOR (ADDRESS)

IE0 TF0

3h Bh

TF1 RI, TI All addresses are in hexadecimal format

1B h 23 h

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

CIRCUIT DIAGRAM

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.

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

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"

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
. Fig .6 Layer diagram of

thyristor

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 (anodecathode) is less than the hol ding 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.

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.

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.

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.

THERMISTOR

Figure .10 Pictorial Representation of Thermistor

Figure .11 Symbol 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

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.

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.

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 solidstate 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 reversebiased 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 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 ithence the name, by analogy with locomotive switching points.

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.

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.

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

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.

APPLICATIONS This circuit can be employed in places such as railway stations and such public places where people use to gather and they dont 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.

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.

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 .

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.

REFERENCES

http://www.redcircuits.com/ http://en.wikipedia.org/
http://www.allaboutcircuits.com/ http://www.pc-control.co.uk/

http://www.howstuffworks.com/

APPENDIX

DATA SHEET

You might also like