Sei sulla pagina 1di 56

Contents

ABSTRACT

1. INTRODUCTION

2. LITERATURE SURVEY

2.1 Aim of the Project

2.2 Requirement Analysis:

2.2.1 Hardware requirements

2.2.2 Software requirements

2.3 Scope of the Project

2.4 Organization of Report

3. DESIGN METHODOLOGY

10

3.1 Power supply

10

3.2 Block level design of temperature controlled fan

13

3.3 Selection of hardware

13

3.4 Description of microcontroller

14

3.4.1 Pin Diagram of Micro Controller

14

3.4.2 Input Output (I/O) Ports

18

3.4.3 Interrupts controls

22

3.4.4 BUS CONTROLS

22

3.4.5 Memory organization

23

3.4.6 Registers in 8051

24

3.4.7 Oscillator

27

3.5 HARDWARE DESIGN OF LCD

28

3.5.1 LCD screen

29

3.5.2 PIN DESCRIPTION OF LCD

30

3.5.3 SPECIFICATIONS:

32

3.5.4 Functionality of LCD in this project:

33

3.6 HARDWARE DESIGN OF ADC

33

3.6.1 PRINCIPLES OF OPERATION

33

3.6.2 PIN DESCRIPTION OF ADC

34

3.6.3 FUNCTIONALITY OF ADC IN THIS PROJECT

34

3.7 TEMPERATURE SENSOR

35

3.7.1 Features

35

3.7.2 Pin Description of LM35

36

3.7.3 FUNCTIONALITY OF LM35 IN THIS PROJECT

36

3.8 Resistors

36

3.9 Capacitors

37

3.10 Crystal oscillator

38

4. HARDWARE IMPLEMENTATION

40

4.1 Complete Schematic of temperature controlled fan

40

4.2 Connections of AT89S52

40

4.3 Pin connections of LCD

41

4.4 Pin connections of ADC

42

4.5 Pin connections of LM35

43

5.SOFTWARE IMPLEMENTATION

45

5.1 JHD162A LCD INTERFACING


5.1.1 Initializing the LCD

45
45

5.1.2 The initialization sequence code

46

5.1.3 Checking the busy status of the LCD

46

5.1.4 Writing command to the Display

46

5.1.5 Writing Data to Display

47

5.1.6 Displaying the data in to the LCD

47

5.2 FLOWCHARTS

47

5.2.1 Checking the busy status of the LCD

47

5.2.2 Writing command to the Display

48

5.2.3 Displaying the data in to the LCD

50

5.2.4 Complete Flow Chart Of Smart Energy Meter

51

6.DEBUGGING TECHNIQUES

52

6.1 Keiluvision Debugger

52

6.1.1 Introduction to Keil IDE

52

6.1.2 Features

52

6.1.3 Steps to follow while writing a program in keil:

53

6.2 LABTOOL-48UXP

54

6.2.1 Features

54

6.2.2 The steps for while using lab tool

55

RESULTS

55

FUTURE SCOPE

56

BIBILOGRAPHY

57

APPENDIX

58

ACKNOWLEDGEMENT

Our sincere thanks to our director prof. Sri VIJAY KUMAR, who has given support to make
our project at IETE.
We thank our principal Sri BELLUBI sir for his kind support.
Our sincere thanks to our HOD, Sri GIRI RAJU sir who as guided us to the IETE (Institute of
Electronics and Telecommunication Engineering) where we successfully accomplished the
project.
Our sincere thanks to the external guide, Sri N.Abid Ali khan sir and Shankar sir, who has
guided us at IETE. He has taken all the care to complete the project in time.

ABSTRACT

This project is a standalone automatic fan controller that controls an electric fan according
to our requirement. Use of embedded technology makes this closed loop feedback control
system efficient and reliable. Micro controller allows dynamic and faster control. Liquid
crystal display (LCD) makes the system user-friendly. The sensed temperature values are
simultaneously displayed on the LCD panel. Micro controller is the heart of the circuit as it
controls all the functions.
The temperature sensor LM35 senses the temperature and converts it into an electrical
(analog) signal, which is applied to the micro controller through ADC. The analog signal is
converted into digital format by the analog-to-digital converter (ADC). The sensed and set
values of the temperature are displayed on the LCD. The micro controller drives control
relays to control the fan speed with the help of high wattage tagged wire wound resistor.
The relays are used to operate the electrical fan or for operating any other electrical device.
Normally the relay remain off. As soon as pin of the micro controller goes high, the relays
operate The system uses a compact circuitry built around 8051 microcontroller Programs are
developed in Embedded C. Flash magic is used for loading programs into Microcontroller
Keywords: Temperature sensor, ADC, LCDdisplay, relay, embedded systems

CHAPTER - I

INTRODUCTION

Now-a-days electricity has become a basic need to humans. The consumption of electricity
has increased a lot compared to the past years. In this project we present you the Automatic
temperature controlled fan which is used to cooling the electronic devices and machines in
industries .As we know every electronic device is consuming some power and dissipate some
heat.

The generated heat may increase the temperature of the surroundings of the device. Due to
increase in temperature of the device the parameters of the components are varying this will
effect the functionality of the device. If the heat dissipation is more then there may be a
chance of destroying of device. So it is necessary to cooling of device ,this can be done by
providing a coolers nearby the devices .The cooler is always running whenever the device
is ON, due to this power consumption will be more .By using electronic technology we can
reduce the power consumption by switching the motor whenever the device is hot and the
motor will switched off when the device is in normal condition .
We are explaining how to implement the above mentioned system throughout this document.

CHAPTER- II

LITERATURE SURVEY

2.1 Aim of the Project

The aim of the project is to Design and implementation of temperature controlled fan.

Customer (User) Interface to

Display the current temperature.

Indicating the off to on state of motor

The circuit should have the following specifications

The microcontroller should be able to Interfacing with LCD

The microcontroller should be able to Interfacing with the temperature sensor through

the analog to digital converter


2.2 Requirement Analysis:
2.2.1 Hardware requirements
The components those are required for temperature controlled fan project is given below.
1.

Micro Controller (AT89S52).

2.

ADC 0804

3.

Power supply.

4.

LCD display.

5.

Temperature sensors

6.

System fan

7.

Resistors

8.

Capacitors

2.2.2 Software requirements


1.

Lab tool universal programmer-48uxp.

2.

KEIL Vision 4IDE C51 Embedded Cross Compiler.

2.3 Scope of the Project

The scope of this project is to make use of new modern technologies and implement them
into more practical fields. Our project can be implement in industries to cool the devices and
it can be implemented in house hold purpose also .It is act like a air conditioner whenever
the temperature is high the fan will be automatically ON and it will be off when the
temperature is normal .This can reduce the human involvement and the power consumption
.Our project extremely helped in computer s to work properly .
2.4 Organization of Report

Chapter1gives the introduction,. Chapter2 gives the aim and scope of the project and
selection of Hardware and software. Chapter 3 gives the brief discussion about DESIGN
METHODOLOGY .Chapter 4 gives the hardware implementation .The chapter 5 contains the
software implementation. Chapter 6 Includes the debugging techniques.

CHAPTER - III

DESIGN METHODOLOGY

3.1 Power supply

In this power supply, a step down transformer is used to step down the current
from 230V to 5V AC, next step is to convert this AC to DC which is done by using a full
wave Rectifier and additional Filter Circuits are used where the ripples or noised in the DC
voltage are removed and at last a 7805 Regulatfror is used to makeup regulated a 5V DC,
from the output of the 7805 IC we connect a 2 pin connector to make a connection with the
corresponding Vcc(40) and Ground(20) pins of the AT89C51 microcontroller. Now the
microcontroller is powered up to do the specified controlling action given by the user.

REGULATED POWER SUPPLY


A variable regulated power supply, also called a variable bench power supply, is one where
you can continuously adjust the output voltage to your requirements. Varying the output of
the power supply is the recommended way to test a project after having double checked parts
placement against circuit drawings and the parts placement guide.
This type of regulation is ideal for having a simple variable bench power supply. Actually this
is quite important because one of the first projects a hobbyist should undertake is the
construction of a variable regulated power supply. While a dedicated supply is quite handy
e.g. 5V or 12V, it's much handier to have a variable supply on hand, especially for testing.
Most digital logic circuits and processors need a 5 volt power supply. To use these parts we
need to build a regulated 5 volt source. Usually you start with an unregulated power supply
ranging from 9 volts to 24 volts DC (A 12 volt power supply is included with the Beginner
Kit and the Microcontroller beginner Kit.). To make a 5 volt power supply, we use a
LM7805 voltage

Regulator IC .The IC is shown below

IC LM-35 TEMPERATURE SENSOR


The LM7805 is simple to use. You simply connect the positive lead of your unregulated DC
power supply (anything from 9VDC to 24VDC) to the Input pin, connect the negative lead to
the Common pin and then when you turn on the power, you get a 5 volt supply from the
Output pin.

BLOCK DIAGRAM OF LM 7805:

3.2 Block level design of temperature controlled fan

Fig 3.2 a: Functional block diagram of temperature controlled fan


3.3 Selection of hardware

The hardware selected must be such a way that

Low cost

Low power consumption, small, fast

Continually reacts to changes in the systems environment

Must compute certain results in real-time without delay

Simple design

Easy maintainability and interoperability

Bug-free/Correctness, safety, many more

3.4 Description of microcontroller

WHY ATMEGA 16?

The ATMEGA 16 is a low-power, high-performance CMOS 8-bit microcomputer with


8Kbytes of Flash programmable and erasable read only memory (PEROM). The device is
manufactured using Atmels high-density nonvolatile memory technology and is compatible
with the industry-standard 80C51 and 80C52 instruction set and pin out. The on-chip Flash
allows the program memory to be reprogrammed in-system or by a conventional nonvolatile
memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip.
The Atmel ATMEGA 16 is a powerful microcomputer which provides a highly-flexible and
cost-effective solution to many embedded control applications. The main advantages of
89s52 over 8051 are

Software Compatibility

Program Compatibility

Re-writability

The ATMEGA 16 microcontroller has an excellent software compatibility, i.e. the software
used can be applicable to any other microcontroller. The program written on this
microcontroller can be carried to any base. Program compatibility is the major advantage in
89s52. The program can be used in any other advanced microcontroller. The program can be
reloaded and changed for nearly 1000 times.

3.4.1 Pin Diagram of Micro Controller


The micro controller has 40 pins, of which 32 ports, VCC, GND, EA, ALE, PSEN, XTAL1
and XTAL2. The figure 4.3 shows the pin diagram of ATMEGA 16.

Fig3.4 a: Pin Diagram of ATMEL89S52 Micro Controller

Pin Description:

Pin 18: Port 1: Each of these pins can be used as either input or output according to

your needs. Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer;
these can be seen in the figure 4.3 shown above.

Pin 9: Reset Signal: High logical state on this input halts the MCU and clears all the

registers. Bringing this pin back to logical state zero starts the program a new as if the power
had just been turned on. In another words, positive voltage impulse on this pin resets the
MCU. Depending on the device's purpose and environs, this pin is usually connected to the
push-button, reset-upon-start circuit or a brown out reset circuit.The image shows one simple
circuit for safe reset upon starting the controller. It is utilized in situations when power fails to
reach its optimal voltage.

Figure 3.4 b: Reset Pin Circuit

Pin 10-17: Port 3 as with Port 1, each of these pins can be used as universal input or

output. However, each pin of Port 3 has an alternative function.

Pin 10: RXD - Serial input for asynchronous communication or serial output for

synchronous communication.

Pin 11: TXD - Serial output for asynchronous communication or clock output for

synchronous communication

Pin 12: INT0 - Input for interrupt 0

Pin 13: INT1 - Input for interrupt 1

Pin 14: T0

- Clock input of counter 0

Pin 15: T1

- Clock input of counter 1

Pin 16: WR

- Signal for writing to external (add-on) RAM memory

Pin 17: RD

- Signal for reading from external RAM memory.

Pin 18-19: X2 and X1; Input and output of internal oscillator. Quartz crystal

controlling the frequency commonly connects to these pins. Capacitances within the
oscillator mechanism are not critical and are normally about 30pF. Instead of a quartz crystal,

miniature ceramic resonators can be used for dictating the pace. In that case, manufacturers
recommend using somewhat higher capacitances. New Mucus works at frequencies from 0Hz
to 50MHz+.

Pin 20: GND: Ground

Pin 21- 28: Port 2 if external memory is not present, pins of Port 2 act as universal

input/output. If external memory is present, this is the location of the higher address byte, i.e.
addresses A8 A15. It is important to note that in cases when not all the 8 bits are used for
addressing the memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not
available as input/output.

Pin 29: PSEN: MCU activates this bit (brings to low state) upon each reading of byte

(instruction) from program memory. If external ROM is used for storing the program, PSEN
is directly connected to its control pins.

Of the external memory, MCU sends the lower byte of the address register (addresses

A0 A7) to port P0 and activates the output ALE. External register (74HCT373 or
74HCT375 circuits are common), memorizes the state of port P0 upon receiving a signal
from ALE pin, and uses it as part of the address for memory chip.

Pin 30:ALE: During the second part of the mechanical MCU cycle, signal on ALE is

off, and port P0 is used as Data Bus. In this way, by adding only one cheap integrated circuit,
data from port can be multiplexed and the port simultaneously used for transferring both
addresses and data.

Pin 31: EA: Bringing this pin to the logical state zero (mass) designates the ports P2

and P3 for transferring addresses regardless of the presence of the internal memory. This
means that even if there is a program loaded in the MCU it will not be executed, but the one
from the external ROM will be used instead. Conversely, bringing the pin to the high logical
state causes the controller to use both memories, first the internal, and then the external (if
present).

Pin 32-39: Port 0 Similar to Port 2, pins of Port 0 can be used as universal

input/output, if external memory is not used. If external memory is used, P0 behaves as


address output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus)
when ALE pin is at low logical level.

Pin 40: VCC: Power +5V.

3.4.2 Input Output (I/O) Ports

Every MCU from 8051 families has 4 I/O ports of 8 bits each. This provides the user with 32
I/O lines for connecting MCU to the environs. Unlike the case with other controllers, there is
no specific SFR register for designating pins as input or output. Instead, the port itself is in
charge: 0=output, 1=input. If particular pin on the case is needed as output, the appropriate bit
of I/O port should be cleared. This will generate 0V on the specified controller pin. Similarly,
if particular pin on the case is needed as input, the appropriate bit of I/O port should be set.
This will designate the pin as input, generating +5V as a side effect (as with every TTL
input).

Port 0:
Port 0 has two-fold role: if external memory is used, it contains the lower address byte
(addresses A0-A7); otherwise all bits of the port are either input or output. Another feature of
this port comes to play when it has been designated as output. Unlike other ports, Port 0 lacks
the "pull up" resistor (resistor with +5V on one end). This seemingly insignificant change has
the following consequences: When designated as input, pin of Port 0 acts as high impedance
offering the infinite input resistance with no "inner" voltage.
When designated as output, pin acts as "open drain". Clearing a port bit grounds the
appropriate pin on the case (0V). Setting a port bit makes the pin act as high impedance.
Therefore, to get positive logic (5V) at output, external "pull up" resistor needs to be added
for connecting the pin to the positive pole.
Therefore, to get one (5V) on the output, external "pull up" resistor needs to be added
for connecting the pin to the positive pole.
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight
TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance
inputs.

Port 0 can also be configured to be the multiplexed low order address/data bus during
accesses to external program and data memory. In this mode, P0 has internal pull ups.
Port 0 also receives the code bytes during Flash programming and outputs the code bytes
during program verification. External pull ups are required during program verification.

Port 1:This is "true" I/O port, devoid of dual function characteristic for Port 0. Having the
"pull up" resistor, Port 1 is fully compatible with TTL circuits
Port 1 is an 8-bit bidirectional I/O port with internal pull ups. The Port 1 output buffers can
sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the
internal pull ups and can be used as inputs. As inputs, Port 1 pins that are externally being
pulled low will source current (IIL) because of the internal pull ups.
In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input
(P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the
following table.
Port 1 also receives the low-order address bytes during Flash programming and verification.

Table 3.1 Port1 specifications

Port 2:When external memory is used, this port contains the higher address byte (addresses
A8A15), similar to Port 0. Otherwise, it can be used as universal I/O port.
Port 2 is an 8-bit bidirectional I/O port with internal pull ups. The Port 2 output
buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled
high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are
externally being pulled low will source current (IIL) because of the internal pull-ups.

Port 2 emits the high-order address byte during fetches from external program memory and
during accesses to external data memory that uses 16-bit addresses (MOVX @ DPTR). In
this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to
external data memory that uses 8-bit addresses (MOVX @ RI), Port 2 emits the contents of
the P2 Special Function Register.
Port 2 also receives the high-order address bits and some control signals during Flash
programming and verification.

Port 3:Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can
sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being
pulled low will source current (IIL) because of the pull-ups.
Port 3 also serves the functions of various special features of the ATMEGA 16, as shown in
the following table.
Port 3 also receives some control signals for Flash programming and verification.

Table 3.2 Port3 specifications

Beside its role as universal I/O port, each pin of Port 3 has an alternate function. In
order to use one of these functions, the pin in question has to be designated as input, i.e., the
appropriate bit of register P3 needs to be set. From a hardware standpoint, Port 3 is similar to
Port 0.
As can be seen from the individual descriptions of the ports, they all share highly similar
structure. However, you need to consider which task should be assigned to which port. For
example: if utilizing port as output with high level (5V), avoid using Port 0, as its pins cannot
produce high logical level without an additional resistor connected to +5V. If using other port

to a same end, bear in mind that built-in resistors have relatively high values, producing the
currents limited to few hundreds of amperes as pin output.
3.4.3 Interrupts controls
There are 7 kinds of interrupt controllers that 8051 handles. They are as follows.
1.

INT0 external interrupt.

2.

INT1 external interrupt.

3.

Timer 0

4.

Timer 1

5.

Reset.

6.

Transmitted interrupt (TXD).

7.

Received interrupt (RXD).

There are two types of external hardware interrupts. Pin 12 (P3.2) and pin 13 (P3.3) of the
8051, designated as INT0 and INT1, are used as external hardware interrupts. Upon the
activation of these pins, the 8051 gets interrupted in whatever it is doing and jumps to the
vector table to perform the interrupt service routines (ISR).
Timer 0 and timer 1 interrupts can be used in pooling method. In this method, we have to
wait until the TF is raised. The problem with this method is that the microcontroller is tied
down the controller. If the timer interrupt in the IE register is enabled, whenever the timer
rolls over, TF is raised, and the microcontroller is interrupted in whatever it is doing, and
jumps to the interrupts vector table to service the ISR.
Reset pin is an input pin and is active high (normally low). Upon applying a high pulse to this
pin, the microcontroller will reset and terminate all activities. This is often referred to as
power-on reset. In order for RESET input to be effective, it must have a minimum duration of
two machine cycles. In other words, the high pulse must be high for a minimum of two
machine cycles before it is allowed to go low. TXD and RXD are serial communication
interrupts.

3.4.4 BUS CONTROLS


The main bus controllers available in 8051 are ALE, EA, RST and PSEN.
ALE (Address Latch Enable):
Output pulse for latching the low byte of the address during an access to external memory. In
normal operation, ALE is emitted twice every machine cycle, and can be used for external
timing or clocking. Note that one ALE pulse is skipped during each access to external data
memory. ALE can be disabled by setting SFR auxiliary.0. With this bit set, ALE will be active
only during a MOVX instruction.
EA (External Access Enable/Programming Supply Voltage):
EA must be externally held low to enable the device to fetch code from external program
memory locations. If EA is held high, the device executes from internal program memory.
The value on the EA pin is latched when RST is released and any subsequent changes have
no effect. This pin also receives the programming supply voltage (VPP) during Flash
programming.

RST (Reset):
A high on this pin for two machine cycles while the oscillator is running resets the device. An
internal resistor to VSS permits a power-on reset using only an external capacitor to VCC.
PSEN (Program Store Enable):
The read strobe to external program memory. When executing code from the external
program memory, PSEN is activated twice each machine cycle, except that two PSEN
activations are skipped during each access to external data memory. PSEN is not activated
during fetches from internal program memory.

3.4.5 Memory organization

The 8051 has two types of memory and these are Program Memory and Data
Memory. Program Memory (ROM) is used to permanently save the program being executed,

while Data Memory (RAM) is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller. Depending on the model in use
(we are still talking about the 8051 microcontroller family in general) at most a few Kb of
ROM and 128 or 256 bytes of RAM is used. All 8051 microcontrollers have a 16-bit
addressing bus and are capable of addressing 64 kb memory. It is neither a mistake nor a big
ambition of engineers who were working on basic core development. It is a matter of smart
memory organization which makes these microcontrollers a real programmers goody.

Program memory
The first models of the 8051 microcontroller family did not have internal program
memory. It was added as an external separate chip. These models are recognizable by their
label beginning with 803 (for example 8031 or 8032). All later models have a few Kbyte
ROM embedded. Even though such an amount of memory is sufficient for writing most of
the programs, there are situations when it is necessary to use additional memory as well. A
typical example is so called lookup tables. They are used in cases when equations describing
some processes are too complicated or when there is no time for solving them. In such cases
all necessary estimates and approximates are executed in advance and the final results are put
in the tables (similar to logarithmic tables).
Data memory
Data Memory is used for temporarily storing data and intermediate results created and
used during the operation of the microcontroller. Besides, RAM memory built in the 8051
family includes many registers such as hardware counters and timers, input/output ports,
serial data buffers etc. The previous models had 256 RAM locations, while for the later
models this number was incremented by additional 128 registers. However, the first 256
memory locations (addresses 0-FFh) are the heart of memory common to all the models
belonging to the 8051 family.
3.4.6 Registers in 8051

In the CPU, registers are used to store information temporarily. That information
could be a byte of data to be processed, or an address pointing to the data to be fetched. The

vast majority of 8051 registers are 8- bit registers. In the 8051 there is only one data type: 8
bits. With an 8-bit data type, any data larger than 8 bits must be broken into 8- bit chunks
before it is processed. The most widely used registers of the 8051 are A (Accumulator), B,
and SPF (special function registers) and PSW (Program Status Word).
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
.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.
SFR (Special Function Registers)
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.
PROGRAM STATUS WORD(PSW):

CY: Carryout from accumulator MSB of ALU operand

AC: Auxiliary carry for BCD operations

FO: General purpose

RS1 & RS0: For register banks selection (RB0-RB3)

OV: Overflow flag

P: Parity of accumulator set by hardware to1 if it contains odd no of1s

Table 3.3.The contents of (RS1-RS0) enable the working register banks


RS 1

RS 0

BANKS AND REGISTERS

BANK 0 (00H-07H)

BANK 1 (08H0FH)

BANK 2 (10H-17H)

BANK 3 (18H-1FH)

Carry flag:
CarryflagissetwheneverthereiscarryoutfromtheMSB.Thisflagisafter8bitADD/SUB
operation .It can also be set to 1or 0 directly using SETB C or CLR C

Auxiliary carry:

If there is a carry from D3 to D4 position during Add/Sub operation, this bit will set.
Otherwise, it is cleared .This flag is used for BCD operations.
Parityflagreflectsthenumberof1sinA.IfAcontainsanoddnumberof1s, then P=1. Therefore
P=0, if A has an even number of1s.

Overflow flag:
This flag is set whenever there of assigned number operation is too large to be accommodated
in7 bits, causing the higher order bit to overflow into the sign bit.

3.4.7 Oscillator

The microcontroller used in this project, ATMEGA 16 requires a baud rate of 9600.
To acquire this baud rate, an 11.0592 MHz crystal must be connected between 19th and 20th
pins of controller. The determination of machine cycle frequency and Baud rate is as follows.
MCF = (XTLfreq / 12)
= (11.0592 * 10^6) / 12
= 921.6 KHz
Baud rate = MCF/32
= (921.6 10^3) / 32
= 28800 Hz

Where MCF = Machine Cycle Frequency,


XTL = Crystal.
To synchronize with timer1 (TH1) to set the baud rate as 9600 we need to set those
register value as -3 (decimal) or FD (Hexadecimal) so as to divide the baud rate i.e.. 28800Hz
should be dividing with the decimal value of TH1 to get 9600 value.

XTAL1:Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL2:Output from the inverting oscillator amplifier.

Fig 3.4 c: Oscillator Connections

C1, C2 = 33pF.

3.5 HARDWARE DESIGN OF LCD

The LCD (Liquid Crystal Display) used to display the output to the user in the form of
GUI (Graphic User Interface) and a mono chromatic display. LCD used in this project is
JHD162A series .There are 16 pins in all. They are numbered from left to right 1 to 16 (if you
are reading from the backside). LCD shown above is marked to indicate which the 1st pin
was and which the 16th was.

In our project, we use a JHD162A LCD Display which has 2 rows and 16
characters. It contains internal 1 byte latch. It has a better contrast and a wider viewing angle.
To develop a protocol to interface this LCD with 89C51 first we have to understand how they
functions. These displays contain two internal byte-wide registers, one for command and
second for characters to be displayed. There are three control signals called R/W, RS and EN.
Select By making RS signal 0 you can send different commands to display. These commands
are used to initialize LCD, to display pattern, to shift cursor or screen etc. You can see the
markings right next to 1st and 16th pins. The 16by2 LCD with connections is as given below

Fig 3.5 a: Pin configuration of LCD

3.5.1 LCD screen:-

LCD screen consists of two lines with 16 characters each. Each character consists of 5*7 dot
matrix. Contrast on display depends on the power supply voltage and whether messages are
displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied on pin
marked as VEE. Trimmer potentiometer is usually used for that purpose. Some versions of
displays have built in backlight (blue or green diodes). When used during operating, a resistor
for current limitation should be used (like with any LE diode)

The main control pins on JHD162A are data lines, read or write and enable.

LCD is finding wide spread use replacing LEDs (seven segment LEDs or other multi segment
LEDs) because of the following reasons:
1.

The ability to display numbers, characters and graphics. This is in contrast to LEDs,

which are limited to numbers and a few characters.


2.

Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of

the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep
displaying the data.
3.

Ease of programming for characters and graphics.

4.

These components are specialized for being used with the microcontrollers, which

means that they cannot be activated by standard IC circuits. They are used for writing
different messages on a miniature LCD.

Fig 3.5b: LCD Display

3.5.2 PIN DESCRIPTION OF LCD

Data lines (D0-D7):


The data lines are connected to the parallel port of the microcontroller. While
connecting the data lines to port0 no pull up resistors are required. These data lines are used
to pass the data from CPU i.e. controller to LCD internal memory and to pass commands
from LCD to CPU .Pin 7 is the Least Significant Bit (LSB) and pin 14 is the Most Significant
Bit (MSB) of the data inputs. If you want to display some number or letter on the display, you
have to input the appropriate codes for that character on these pins. These pins are also used
for giving certain commands to the display like clearing the display or moving the cursor to a
different location. Upon giving the correct signals to the 3 control pins, the character codes or
the commands that you have given to the Data pins will be written to the display or executed
by the LCD respectively. To make it easier to give the appropriate inputs to these pin, i
recommend wiring up a DIP switch to these pins.

Read and write:


Generally, we always use the LCD to show things on the screen. However, in some
rare cases, we may need to read from the LCD what it is displaying. In such cases, the R/W
pin is used. However, this function is beyond the scope of post and will not be explained. For
all practical purposes, the R/W pin has to be permanently connected to GND.
The timing diagram for write and read operation of JHD162A is as follows
Write operation:

Fig 3.5 c: Timing diagram of write operation in LCD.

Read operation:

Fig 3.5 d : Timing diagram of read operation in LCD.

Enable Pin:
The enable pin has a very simple function. It is just the clock input for the LCD. The
instruction or the character data at the data pins (D0-D7) is processed by the LCD on the
falling edge of this pin. The Enable pin should be normally held at Vcc by a pull up resistor.
When a momentary button switch is pressed, the Pin goes low and back to high again when
you leave the switch. Your instruction or character will be executed on the falling edge of the
pulse. (i.e. the moment the switch closes).

3.5.3 SPECIFICATIONS:

Number of Characters: 16 characters x 2 Lines

Character Table: English-European (RS in Datasheet)

Module dimension: 80.0mm x 36.0mm x 13.2mm(MAX)

View area: 66.0 x 16.0 mm

Active area: 56.2 x 11.5 mm

Dot size: 0.56 x 0.66 mm

Character size: 2.96 x 5.46 mm

LCD type: Yellow/Green

To start with LCD the user should initialize it first which should be programmed with
its LCD commands. The LCD commands are given

Fig 3.5 e: LCD Interface with ATMEGA 16


3.5.4 Functionality of LCD in this project:

LCD is used to display the current temperature which is sensed by the temperature

sensor

3.6 HARDWARE DESIGN OF ADC

Analog to digital converter is a component which is used to convert the analog signal into
its equivalent digital signal .As we know microcontroller is doesnt understand the analog
signal so we have to convert it into digital signal.
In our project we are using ADC 0804 IC is used as a analog to digital converter. The
ADC0804 is a CMOS 8-bit successive-approximation analog-to-digital converter that uses a
modified potentiometric (256R) ladder. The ADC0804 is designed to operate from common
microcontroller control buses, with the 3-state output latches driving the data bus. The
ADC0804 can be made to appear to the microprocessor as a memory location or an I/O port.
3.6.1 PRINCIPLES OF OPERATION

The ADC0804 contains a circuit equivalent to a 256-resistor network. Analog switches are
sequenced by successive-approximation logic to match an analog differential input voltage
(VI+ VI) to a corresponding tap on the 256-resistor network. The most significant bit
(MSB) is tested first. After eight comparisons (64 clock periods), an 8-bit binary code (1111
1111 = full scale) is transferred to an output latch and the interrupt (INTR) output goes low.
The device can be operated in a free-running mode by connecting the INTR output to the
write (WR) input and holding the conversion start (CS) input at a low level. To ensure startup
under all conditions, a low-level WR input is required during the power-up cycle. Taking CS
low anytime after that will interrupt a conversion in process. When WR goes low, the
ADC0804 successive-approximation register (SAR) and 8-bit shift register are reset. As long
as both CS and WR remain low, the ADC0804 remains in a reset state. One to eight clock
periods after CS or WR makes a low-to-high transition, conversion starts. When CS and WR
are low, the start flip-flop is set and the interrupt flip-flop and 8-bit register are reset. The next
clock pulse transfers a logic high to the output of the start flip-flop. The logic high is AND ed
with the next clock pulse, placing a logic high on the reset input of the start flip-flop. If
either CS or WR have gone high, the set signal to the start flip-flop is removed, causing it to
be reset. A logic high is placed on the D input of the 8-bit shift register and the conversion
process is started. If CS and WR are still low, the start flip-flop, the 8-bit shift register, and
the SAR remain reset. This action allows for wide CS and WR inputs with conversion
starting from one to eight clock periods after one of the inputs goes high.

3.6.2 PIN DESCRIPTION OF ADC

Fig 3.6 a: PIN DESCRIPTION OF ADC


3.6.3 FUNCTIONALITY OF ADC IN THIS PROJECT

The functionality of ADC in this project is converting of analog signal to digital


signal which is generated by temperature sensor.
3.7 TEMPERATURE SENSOR

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage
is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an
advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to
subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The
LM35 does not require any external calibration or trimming to provide typical accuracies of
14C at room temperature and 34C over a full 55 to +150C temperature range. Low
cost is assured by trimming and calibration at the wafer level. The LM35s low output
impedance, linear output, and precise inherent calibration make interfacing to readout or
control circuitry especially easy. It can be used with single power supplies, or with plus and
minus supplies. As it draws only 60 A from its supply, it has very low self-heating, less than
0.1C in still air. The LM35 is rated to operate over a 55 to +150C temperature range,
while the LM35C is rated for a 40 to +110C range (10 with improved accuracy). The
LM35 series is available packaged in hermetic TO-46 transistor packages.

3.7.1 Features

Calibrated directly in Celsius (Centigrade)


Linear + 10.0 mV/C scale factor
0.5C accuracy guaranteable (at +25C)
Rated for full 55 to +150C range
Suitable for remote applications
Low cost due to wafer-level trimming
Operates from 4 to 30 volts
Less than 60 A current drain
Low self-heating, 0.08C in still air
Nonlinearity only 14C typical
Low impedance output, 0.1 W for 1 mA load

3.7.2 Pin Description of LM35

1. The first pin of the lm35 is power supply.


2. The second pin is the analog output pin.
3. The third pin is ground.
3.7.3 FUNCTIONALITY OF LM35 IN THIS PROJECT

The functionality of LM 35 in this project is sensing of temperature from its


surroundings.
3.8 Resistors
A resistor is a two-terminal passive electronic component that implements electrical
resistance as a circuit element. When a voltage V is applied across the terminals of a resistor,
a current I will flow through the resistor in direct proportion to that voltage. This constant of
proportionality is called conductance, G. The reciprocal of the conductance is known as the
resistance R, since, with a given voltage V, a larger value of R further "resists" the flow of
current I as given by Ohm's law:

Fig 3.8 a: Resistors


Practical resistors can be made of various compounds and films, as well as resistance wire
(wire made of a high-resistivity alloy, such as nickel-chrome). Resistors are also implemented

within integrated circuits, particularly analog devices, and can also be integrated into hybrid
and printed circuits.

3.9 Capacitors
A capacitor (formerly known as condenser) is a device for storing electric charge. The
forms of practical capacitors vary widely, but all contain at least two conductors separated by
a non-conductor. Capacitors used as parts of electrical systems, for example, consist of metal
foils separated by a layer of insulating film.
A capacitor is a passive electronic component consisting of a pair of conductors separated by
a dielectric (insulator). When there is a potential difference (voltage) across the conductors, a
static electric field develops across the dielectric, causing positive charge to collect on one
plate and negative charge on the other plate. Energy is stored in the electrostatic field. An
ideal capacitor is characterized by a single constant value, capacitance, measured in farads.
This is the ratio of the electric charge on each conductor to the potential difference between
them.

Fig 3.9 a: capacitors


Capacitors are widely used in electronic circuits for blocking direct current while allowing
alternating current to pass, in filter networks, for smoothing the output of power supplies, in
the resonant circuits that tune radios to particular frequencies and for many other purposes.
The capacitor is a reasonably general model for electric fields within electric circuits. An
ideal capacitor is wholly characterized by a constant capacitance C, defined as the ratio of
charge Q on each conductor to the voltage V between them:

3.10 Crystal oscillator


Crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a
vibrating crystal of piezoelectric material to create an electrical signal with a very precise
frequency. This frequency is commonly used to keep track of time (as in quartz
wristwatches), to provide a stable clock signal for digital integrated circuits, and to stabilize

frequencies for radio transmitters and receivers. The most common type of piezoelectric
resonator used is the quartz crystal, so oscillator circuits designed around them became
known as "crystal oscillators."

Fig 3.10 a: crystal oscillator


Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of
megahertz. More than two billion (2109) crystals are manufactured annually. Most are used
for consumer devices such as wristwatches, clocks, radios, computers, and cell phones.
Quartz crystals are also found inside test and measurement equipment, such as counters,
signal generators, and oscilloscopes.

CHAPTER IV
HARDWARE IMPLEMENTATION

4.1 Complete Schematic of temperature controlled fan

4.2 Connections of ATMEGA 16


In this project the microcontroller is connected to MAX232, LCD, Keypad, sensors.
The connections of microcontroller are given briefly below:

Number of Characters: 16 characters x 2 Lines

Pin1 to pin8 (Port 1) of controller are connected to the data lines of ADC (D0-D7).

The reset switch is connected to the 9th pin (RST) of ATMEGA 16, as it is used for

set reset the program.

13,14,15 pins are connected to ADC as controlled pins WR, RD, INTR respectively.

The crystal oscillator which gives a frequency of 11.0592 MHz for the required Baud

rate of 9600Hz to the microcontroller. This crystal oscillator is connected in between 18th
(XALT 1) and 19th (XALT 2) pins of ATMEGA 16 micro controller.

The 20th pin of controller is grounded.

The pins from 21st to 28th (port 2 data lines) are used for the external peripheral

connections.

The 29th pin is connected to an on-off switch so as to dump and execute the program.

Whenever the PSEN pin is connected to ground then we can execute the last dumped
program, likewise when 29th pin is connected to VCC then code can be dumped into the
controller.

Address Latch Enable pin (30th pin) of controller is connected to the ground hence no

connections need not to be given to this pin.

External Access Enable or programming supply voltage should be latched when RST

is released and any subsequent changes have no effect. This pin also receives the

programming supply voltage (VPP) during Flash programming. Hence the pin 31st must be
connected to high i.e. VCC.

Port0 (pins 32 to 39) are connected to LCD in this project. But these should be

connected to other peripherals through pull up resistors.


4.3 Pin connections of LCD

The LCD used for output display is JHD162A series. The detailed connections of LCD
is described briefly as

The 1st and 2nd pins of JHD162A LCD are connected to ground and high voltage

VCC respectively.

3rd pin of LCD is connected to the centre pin of the potentiometer or variable resistor

so as to adjust the contrast of LCD.

The 4th, 5th, 6th pins are connected to 26th (P 2.5), 27th (P 2.6), 28th (P 2.7) pins of

the microcontroller respectively.

The 7th to 14th pins are data pins and are connected to the 39th (P 0.0) to 32nd (P 0.7)

pins of the microcontroller respectively.

The 15th and 16th pins are used for backlight purpose. 15th pin is connected to VCC

and 16th pin to ground.


.

Fig 4.3: connection of LCD with ATMEGA 16


4.4 Pin connections of ADC

The detailed connections of LCD is described briefly as

The 1st pin of the ADC is chip select pin it should be always low to activate the IC so

it is connected to ground.

The 2nd pin of the ADC is RD, it is connected to the 14th pin of microcontroller.

The 3rd pin of ADC is WR, it is connected to the 13th pin of microcontroller.

The 4th and 19th pin of the ADC are connected to the RC circuit to provide a clock

frequency for the ADC .

The 5th (interrupt) pin of the ADC is connected to the 15th pin of microcontroller.

The 6th pin is the analog input for the ADC , it is connected to the output pin of

temperature sensor LM 35.

7th , 8th and 10th pins are connected to ground.

9th pin is connected to the 10k pot to access the half of reference voltage .

The data pins of ADC (11 to 18) are connected to port 1 (1 to 8) of the controller.

20th pin is supply for the ADC , it is connected to the 5v supply.

4.5 Pin connections of LM35

LM35 temperature sensor has three pins the connections are explained below.

The 1st pin is connected to the 5v power supply .

The 2nd pin is connected is the output pin which is connected to the 6th pin of

ADC .

The 3rd pin is connected to the ground .

CHAPTER V
SOFTWARE IMPLEMENTATION

This chapter explores some real world applications of theATMEGA 16, and also
includes how to interface the ATMEGA 16 to devices such as an LCD and its software
functionality using embedded C language. Embedded C is a set of language extensions for
the C Programming language by the C Standards committee to address commonality issues
that exist between C extensions for different embedded systems. Historically, embedded C
programming requires nonstandard extensions to the C language in order to support exotic
features such as fixed-point arithmetic, multiple distinct memory banks, and basic I/O
operations. In 2008, the C Standards Committee extended the C language to address these
issues by providing a common standard for all implementations to adhere to. It includes a
number of features not available in normal C, such as, fixed-point arithmetic, named address
spaces, and basic I/O hardware addressing.

5.1 JHD162A LCD INTERFACING


5.1.1 Initializing the LCD

Before you using the LCD, the program must initialize and configure it. This is
accomplished by sending a number of initialization instructions to the LCD.
The first instruction to send is the no of data for the LCD i.e., with an 8-bit or 4-bit
data bus. The other thing need to specify is display matrix; in the selected LCD it is a 5x8
dot character font. These two options are selected by sending the command 38h to the LCD
as a command. The command can give to the LCD by invoking the pre defined function call
lcdcmd with passing parameters value of 38H, the syntax for the same can be given like
lcdcmd(0x38).

5.1.2 The initialization sequence code

lcdcmd(0x38); // 2 lines and 5x7 matrix


lcdcmd(0xC0); // force cursor to beginning of 2nd line
lcdcmd(0x0E); // display on, cursor blinking
lcdcmd(0x01); //clear display screen
lcdcmd(0x06); // increment cursor (shift cursor right)
lcdcmd(0x80); // force cursor to beginning of 1st line

5.1.3 Checking the busy status of the LCD

Busy Flag (BF):


void lcdready(void)
{
busy=1;

rs=0;

//Register select command

rw=1;
while(busy==1)

// if Bit (D7) high, LCD still busy

{
en=0;

// Finish the command

MSDelay(1);
en=1;

// Start LCD command

}
}
5.1.4 Writing command to the Display

void lcdcmd (unsigned char value)

// LCD command initiation routine

{
Lcdready();

// wait till the LCD executes the instruction

ldata=value;

// Set the value(instruction) in Data bus

rs=0;

// register select as command

rw=0;
en=1;

// set the enable command

MSDelay(1);
en=0;

// Reset the enable command

5.1.5 Writing Data to Display


void lcddata (unsigned char value)

// LCD data placing routine

{
lcdready();

// wait till the LCD executes the instruction

ldata = value;

// Set the value(Data) in Data bus

rs=1;

//register select as data

rw=0;

//read command

en=1;

// Send Enable Signal to LCD

MSDelay(1); // This Function Gives Approximate Delay required For LCD


Initialization

en=0;

//Reset the Enable Command

}
5.1.6 Displaying the data in to the LCD
void WriteString(unsigned char count,unsigned char *MSG)
{
unsigned char i;
for(i=0;i<count;i++)
{
lcddata(MSG[i]);

//Display Character on LCD at Proper Location

}
}

5.2 FLOWCHARTS
5.2.1 Checking the busy status of the LCD
Busy Flag (BF):

When the busy flag is high or 1 the module is performing an internal operation and
the next instruction will not be accepted. The RS=0 is used to check the Busy flag bit too see
if the LCD is ready to receive information. The Busy flag is D7 and can be read when R/W =
1 and RS = 0, as follows: if R/W = 1, RS= 0.When D7=1 (busy flag), the LCD is busy taking
care of internal operations and will not accept any new information. When D7=0, the LCD is
ready to receive new information.

Busy flag flowchart

Fig 3.24: Busy flag flowchart

5.2.2 Writing command to the Display


To give a command to perform some special functions like move to position, clear
LCD ,blink the curser etc. the instruction sequence must follow like first instruction must be
set in the data bus set RS signal to logic 0 and enabling the LCD will receive the data . After
finishing the instruction sequence the application must wait till the LCD completes the
instruction by checking the LCD Busy status.

Writing command display flow chart

Fig 3.25: Writing command display flow chart


1. Check the Busy flag bit

2. Set the instruction in data lines (if it is writing)


3.Set RS bit to logic 1 to 0
4. Set R/W bit is to low
6. Set En line to high
7. Set line to low

5.2.3 Displaying the data in to the LCD


Writing the string in the LCD, to get the result first the address at which the string has to
display on the screen is given as command followed by displaying the individual characters
as LCD data .That finishes the data to be display in the LCD.
The complete flow chart representation of LCD working process is as follows:

Fig 3.26: Flow chart for the LCD function.

5.2.4 Complete Flow Chart Of Smart Energy Meter

Chapter VI
DEBUGGING TECHNIQUES

6.1 Keiluvision Debugger


6.1.1 Introduction to Keil IDE

Keil is a compiler that has 3 windows, project window, edit window, and build or
command window Schematic. Today, Keil Software provides a broad range of development

tools for the embedded systems marketplace. Their products include ANSIC compilers,
macro assemblers, debuggers, linkers, library managers, and real-time operating systems.
It was then that Keil Software implemented the first C compiler designed from the groundup specifically for the 89C51 microcontroller.

6.1.2 Features
1.

Nine basic data types, including 32-bit IEEE floating-point

2.

Flexible variable allocation with bit, data, bdata, idata, xdata, and pdata memory types

3.

Interrupt functions may be written in C

4.

Full use of the 8051 register banks

5.

Complete symbol and type information for source-level debugging

6.

Bit-addressable data objects

7.

Built-in interface for the RTX51 real-time kernel

8.

Support for dual data pointers on Atmel, AMD, Cypress, Dallas semiconductor,

Infineon, Philips, and Transcend microcontrollers


9.

Support for Phillips 8xC510,8xC71,and 8xC752 limited instruction sets

10.

Support for the Phillips 80C51 arithmetic unit.

The Keil 8051 Development Tools are designed to solve the complex problems facing
embedded software developers.

When starting a new project, simply select the microcontroller you use from the

Device Database and the vision IDE sets all compiler, assembler, linker, and memory
options for you.

Numerous example programs are included to help you get started with most popular

embedded 8051 devices.

The Keil Vision Debugger accurately simulates on-chip peripherals (CAN, UART,

SPI, Interrupts, I/O Ports, A/D Convertor, D/A convertor, and PWM Modules) of your 8051
device. Simulation helps you understand hardware configurations and avoids time wasted on
setup problems. Additionally, with simulation, you can write and test applications before
target hardware is available.

When you are ready to begin testing your software application with target hardware,

use the MON51, MONADI, or FlashMON51 Target Monitors, the ISD51 In-system
Debugger, or the ULINK USB-JTAG Adapter to download and test program code on your
target system.

6.1.3 Steps to follow while writing a program in keil:

1. InstallKeilMicro Vision in your PC, Then after Click on that Keiluvision icon. After
opening the window go to toolbar and select Project Tab then close previous project.
2. Next select New Project from Project Tab.
3. Then it will open Create New Project window. Select the path where you want to save
project and edit project name.
4. Next it opens Select Device for Target window, it shows list of companies and here you
can select the device manufacturer company.
5. For an example, for your project purpose you can select the chip as 89c51rd2xx from
Philips Group. Next Click OK Button, it appears empty window here you can observe left
side a small window i.e., Project Window. Next create a new file.
6. From the Main tool bar Menu select File Tab and go to New, then it will open a window,
there you can edit the program.
7. Here you can edit the program as which language will you prefer either Assembly or C.

8. After editing the program save the file with extension as .c or .asm, if you write a
program in Assembly Language save as .asm or if you write a program in C Language save
as .c in the selected path.
9. Then after saving the file, compile the program. For compilation go to project window
select source group and right click on that and go to Add files to Group.
10. Here it will ask which file has to add. For an example here you can add test.c as you
saved before
11. After adding the file, again go to Project Window and right click on your c file then
select Build target for compilation. If there is any Errors or Warnings in your program
you can check in Output Window that is shown bottom of the Keil window.
12. Here in this step you can observe the output window for errors and warnings
13. If you make any mistake in your program you can check in this slide for which error and
where the error is by clicking on that error
14. After compilation then next go to Debug Session. In Tool Bar menu go to Debug tab
and select Start/Stop Debug Session.
15. Write a program for Leds Blinking. LEDS are connected to PORT-1. you can observe
the output in that port.
16. To see the Ports and other Peripheral Features go to main toolbar menu and select
peripherals.
17. In this slide see the selected port i.e., PORT-1.
18. Start to trace the program in sequence manner i.e., step by step execution and observe the
output in port window
19. After completion of Debug Session Create an Hex file for Burning the Processor. Here to
create a Hex file goes to project window and right click on Target next select Option for
Target.
20. It appears one window; here in target tab modify the crystal frequency as you
connected to your microcontroller.
21. Next go to Output tab. In that Output tab click on Create HEX File and then click
OK.

22. Finally Once again compile your program. The Created Hex File will appear in your path
folder

6.2 LABTOOL-48UXP
The LABTOOL-48UXP is a high performance intelligent PC-based universal programmer
that works through your PCs parallel port., , , ,.
6.2.1 Features

It features 48-pin ZIF sockets

supports all kind of programmer chip in the market which include CPLD, EPROM,

EEPOM, Serial EEPROM, Flash memory and MCU

extremely high throughput

5V and 3V chip support in both Vcc and I/O

Three simple steps to erasing and programming a device and setting key options

lower voltage chip (for example 1.8V Vcc and I/O support) also possible through

special adapter,

device insertion and continuity checks, all within a PC-based design

Device updates are disseminated through software, giving our customers quicker and

more flexible access to new chip support.

The LABTOOL-48UXP allows users to select the verification voltage after chip

programming is complete, e.g., Vcc +/-5%, Vcc+/-10%, Vcc can range from 2V to 7.5V.
Verification ensures that the chips have been properly programmed, with no data retention
problems.

6.2.2 The steps for while using lab tool

1)

Click on the Labtool-48uxp icon on the desktop.

2)

Select the device as ATMEGA 16.

3)

Erase the program after fixing the microcontroller.

4)

Select the program which must be dumped into it and then load it.

5)

Select programming it starts loading into the microcontroller.

RESULTS

The system development precedes different stages and confirming that the present
stage is giving accurate results from one stage to other stage. The different stages in this
system are given like

Temperature controlled fan is designed.

The temperature sensor senses the temperature from surroundings

The lcd displayed the current temperature

FUTURE SCOPE

We can monitor more parameters like humidity, light and at the same time control

them.

We can send this data to a remote location using mobile or internet by connecting

GSM modem

BIBILOGRAPHY

Janci Gillespie Mazidi, Muhammad Ali Mazidi ,The 8051micro controller and

embedded systems, PHI Prentice hall India, Eastern Economy Edition, www.phindia.com.

Kenneth J. Ayala, The 8051 Microcontroller, architecture, Programming and

Applications, Pen ram international publishing Pvt. Ltd. 1996

Arnold S. Berger, Embedded systems design, an introduction to process, tools, and


Techniques, CMP Books, 2005. www.cmpbooks.com

Yashvant Kanetkar, Let Us C, BPB Publications, 1999 www.bpbpub.com

Dreamtech Software Team, Programming for Embedded systems, WILEY Publishing,


Inc, 2003.

http://en.wikipedia.org/wiki/Level_s

http://www,google.com

APPENDIX

PROJECTCODE
/* Source Code for Temp controlled Fan */
#include <at89x52.h>
#define MAX_TEMP 40
sfr ldata=0x80;

// Pre-processor Macros.
// This is Port-0 Addr. LCD

sbit rs=P2^7; //lcd control pins


sbit rw=P2^6;
sbit en=P2^5;
sbit busy=P0^7;

// LCD busy flag bit.

sbit ADC_RD = P3^4;


sbit ADC_WR = P3^3;
sbit ADC_INTR = P3^5;
sbit Buzzer = P2^2;

// Buzzer. for Local alarm.

sbit Motor = P2^1;


sbit Led = P2^0;
sfr Sense=0x90;

// address for the Port-1, sensor interface.

void lcdcmd(unsigned char);


void lcddata(unsigned char);
void lcdready(void);
void MSDelay(unsigned int);
void WriteString(unsigned char *);
void LCDClear(void);
void Start(void);
void Display(unsigned char);
void lcdcmd (unsigned char value)
{
lcdready();
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;

}
void lcddata (unsigned char value)
{
lcdready();
ldata=value;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
}
void lcdready(void)
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
}
void MSDelay(unsigned int Iter)

{
unsigned int i, j;
for(i=0;i<Iter;i++)
{
for(j=0;j<1275;j++);
}
}
void WriteString(unsigned char *MSG)
{
unsigned char i;
for(i=0;MSG[i]!='\0';i++)
{
lcddata(MSG[i]);
}
}
void LCDClear(void)
{
lcdcmd(0x80);
WriteString("

");

lcdcmd(0xC0);
WriteString("

");

}
void Display(unsigned char value)
{

unsigned char Buff[7];


unsigned char Loop;
LCDClear();
lcdcmd(0x80);
WriteString("Cur Temp:");
for(Loop=0;Loop<4;Loop++)
{
Buff[3-Loop]=(value%10)+0x30;
value/=10;
}
Buff[4]='\0';
WriteString(Buff);
lcdcmd(0xC0);
WriteString("Have a Good Day!");
}
void Start(void)
{
unsigned int Delay=0;
unsigned char Buff=0x00;
lcdcmd(0x80);
WriteString(" Booting Up... ");
lcdcmd(0xC0);
WriteString(" Please Wait ");
ADC_INTR = 1;

ADC_RD=1;
ADC_WR=1;
while(1)

// embedded supper loop or big-endless loop

{
ADC_WR=0;
ADC_WR=1;
while(ADC_INTR==1);
ADC_RD=0;
Buff = P1;
Display(Buff);
if(Buff=MAX_TEMP)
{
Buzzer = 0;
Motor = 1;
Led = 0;
//for(Delay=0;Delay<5000;Delay++);
}
else
{
Buzzer = 1;
Motor = 0;
Led = 1;
}
// P1 = 0x00;

ADC_INTR = 0;
ADC_RD=1;
ADC_WR=1;

}
}

void main(void)
{
ADC_INTR = 1;
ADC_RD=1;
ADC_WR=1;
Buzzer = 0;
Motor = 1;
Led = 0;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);

lcdcmd(0x80);
WriteString("Welcome to NCET!");
lcdcmd(0xC0);
WriteString(" e-Fan Control ");

Start();
}

Potrebbero piacerti anche