Sie sind auf Seite 1von 75

CONTENTS

ABSTRACT

Chapter No. Description Page No.

Chapter 1 INTRODUCTION 1

1.1 Block Diagram 3

Chapter 2 DESCRIPTION OF HARDWARE

COMPONENTS 4

2.1 AT89S52 4

2.1.1 Brief Histroy of 8051 4

2.1.2 Introduction to AT89S52 6

2.1.3 Features 7

2.1.4 Pin Description 8

2.2 POWER SUPPLY 20

2.2.1 Introduction 20

2.2.2 Transformer 21

2.2.3 Rectifier 21

2.2.4 Regulator 24

2.3 ADC and LM35 25

2.4 LCD

Chapter 3 CIRCUITS DIAGRAM 69

REFERENCES 72

APENDEX A 73

APENDEX B 89

1
APENDEX C 92

ABSTRACT

Refrigerator is the machine used to produce and maintain temp below that of the
ambient temperature. The compressor less solar energy refrigerator works on the peltier effect
by using photovoltaic cells. The photovoltaic module in the array converts sunlight into the
electricity which helps in the charging of the battery. The rechargeable batteries are used to
store electric energy for use during unavailability of the sunlight in the night or during poor
weather. Peltier effect creates a heat difference from an electric voltage. It occurs when a
current is passed through two dissimilar metals that are connected to each other by two
junctions (peltier junction).The current derives a transfer of heat from one junction to the other,
one junction cools off while the other heats up. The cooling junction can be used as refrigerator
which will absorb the heat from the desired space.

Peltier effect Thermo-electric cooling

The Peltier effect is the presence of heating or cooling at an electrified junction of two
different conductors and is named after French physicist Jean Charles Athanase Peltier, who
discovered it in 1834. When a current is made to flow through a junction between two
conductors A and B, heat may be generated (or removed) at the junction.
Thermoelectric cooling uses the Peltier effect to create a heat flux between the
junctions of two different types of materials. A Peltier cooler, heater, or thermoelectric heat
pump is a solid-state active heat pump which transfers heat from one side of the device to the
other, with consumption of electrical energy, depending on the direction of the current. Such
an instrument is also called a Peltier device, Peltier heat pump, solid state refrigerator, or
thermoelectric cooler (TEC). It can be used either for heating or for cooling, although in
practice the main application is cooling. It can also be used as a temperature controller that
either heats or cools.
This technology is far less commonly applied to refrigeration than vapor-compression
refrigeration. The primary advantages of a Peltier cooler compared to a vapor-compression
refrigerator are its lack of moving parts or circulating liquid, very long life and invulnerability
to potential leaks, and its small size and flexible shape. Many researchers and companies are
trying to develop Peltier coolers that are both cheap and efficient. A Peltier cooler can also be
used as a thermoelectric generator. When operated as a cooler, a voltage is applied across the
device, and as a result, a difference in temperature will build up between the two sides. When
operated as a generator, one side of the device is heated to a temperature greater than the other
side, and as a result, a difference in voltage will build up between the two sides. However, a
well-designed Peltier cooler will be a mediocre thermoelectric generator and vice versa, due to
different design and packaging requirements.

2
CHAPTER 1

INTRODUCTION

Thermoelectric cooling uses the Peltier effect to create a heat flux between the junction of
two different types of materials. A Peltier cooler, heater, or thermo electricheat pump is a
solid-state active heat pump which transfers heat from one side of the device to the other,
with consumption of electrical energy, depending on the direction of the current. Such an
instrument is also called a Peltier device, Peltier heat pump, solid state refrigerator, or
thermoelectric cooler (TEC). It can be used either for heating or for cooling, although in
practice the main application is cooling. It can also be used as a temperature controller that
either heats or cools.

This technology is far less commonly applied to refrigeration than vapor-compression


refrigeration is. The primary advantages of a Peltier cooler compared to a vapor-compression
refrigerator are its lack of moving parts or circulating liquid, very long life, invulnerability to
leaks, small size and flexible shape. Its main disadvantage is high cost and poor power
efficiency. Many researchers and companies are trying to develop Peltier coolers that are both
cheap and efficient. (See Thermoelectric materials.)

A Peltier cooler can also be used as a thermoelectric generator. When operated as a cooler, a
voltage is applied across the device, and as a result, a difference in temperature will build up

3
between the two sides. When operated as a generator, one side of the device is heated to a
temperature greater than the other side, and as a result, a difference in voltage will build up
between the two sides (the Seebeck effect). However, a well-designed Peltier cooler will be a
mediocre thermoelectric generator and vice versa, due to different design and packaging
requirements.

HARDWARE COMPONENTS

1. AT89S52 MICROCONTROLLER

2. POWER SUPPLY.

SIMULATION

TOOL : KEIL MICROVISION


PLATFORM : WINDOWS
LANGUAGE : EMBEDDED ‘C’

4
1.1 BLOCK DIAGRAM

5
CHAPTER 2
DESCRIPTION OF HARDWARE COMPONENTS

2.1 AT89S52

2.2.1 A BRIEF HISTORY OF 8051

In 1981, Intel corporation introduced an 8 bit microcontroller called 8051. this


microcontroller had 128 bytes of RAM, 4K bytes of chip ROM, two timers, one serial port,
and four ports all on a single chip. At the time it was also referred as “ A SYSTEM ON A
CHIP”

The 8051 is an 8-bit processor meaning that the CPU can work only on 8 bits data at a
time. Data larger than 8 bits has to be broken into 8 bits pieces to be processed by the CPU.
The 8051 has a total of four I\O ports each 8 bit wide.

There are many versions of 8051 with different speeds and amount of on-chip ROM
and they are all compatible with the original 8051. this means that if you write a program for
one it will run on any of them.

The 8051 is an original member of the 8051 family. There are two other members in
the 8051 family of microcontrollers. They are 8052 and 8031. All the three Microcontrollers
will have the same internal architecture, but they differ in the following aspects.

 8031 has 128 bytes of RAM, two timers and interrupts.

 8051 has 4K ROM, 128 bytes of RAM, two timers and 6 interrupts.

 8052 has 8K ROM, 256 bytes of RAM, three timers and 8 interrupts.

6
Of the three microcontrollers, 8051 is the most preferable. Microcontroller supports
both serial and parallel communication.

In the concerned project 8052 microcontroller is used. Here microcontroller used is


AT89S52, which is manufactured by ATMEL laboratories.

NECESSITY OF MICRO CONTROLLERS

Microprocessors brought the concept of programmable devices and made many


applications of intelligent equipment. Most applications, which do not need large amount of
data and program memory, tended to be costly.

The microprocessor system had to satisfy the data and program requirements so,
sufficient RAM and ROM are used to satisfy most applications .The peripheral control
equipment also had to be satisfied. Therefore, almost all peripheral chips were used in the
design. Because of these additional peripherals cost will be comparatively high.

An Example
8085 chip needs

An Address latch for separating address from multiplex address and data.32-KB RAM and
32-KB ROM to be able to satisfy most applications. As also Timer / Counter, Parallel
programmable port, Serial port, and Interrupt controller are needed for its efficient applications.

In comparison a typical Micro controller 8051 chip has all that the 8051 board has except a
reduced memory as follows.

4K bytes of ROM as compared to 32-KB, 128 Bytes of RAM as compared to 32-KB.

Bulky

On comparing a board full of chips (Microprocessors) with one chip with all
components in it (Microcontroller).

Debugging

7
Lots of Microprocessor circuitry and program to debug. In Micro controller there is no
Microprocessor circuitry to debug.

Slower Development time: As we have observed Microprocessors need a lot of


debugging at board level and at program level, where as, Micro controller do not have the
excessive circuitry and the built-in peripheral chips are easier to program for operation.

So peripheral devices like Timer/Counter, Parallel programmable port, Serial


Communication Port, Interrupt controller and so on, which were most often used were
integrated with the Microprocessor to present the Micro controller .RAM and ROM also were
integrated in the same chip. The ROM size was anything from 256 bytes to 32Kb or more.
RAM was optimized to minimum of 64 bytes to 256 bytes or more.

Microprocessor has following instructions to perform.

1. Reading instructions or data from program memory ROM.

2. Interpreting the instruction and executing it.

3. Microprocessor Program is a collection of instructions stored in a Nonvolatile memory.

4. Read Data from I/O device.

5. Process the input read, as per the instructions read in program memory.

6. Read or write data to Data memory.

7. Write data to I/O device and output the result of processing to O/P device.

2.1.2 INTRODUCTION TO AT89S52

The system requirements and control specifications clearly rule out the use of 16, 32 or
64 bit micro controllers or microprocessors. Systems using these may be earlier to implement
due to large number of internal features. They are also faster and more reliable but, the above
application is satisfactorily served by 8-bit micro controller. Using an inexpensive 8-bit
Microcontroller will doom the 32-bit product failure in any competitive market place. Coming
to the question of why to use 89S52 of all the 8-bit Microcontroller available in the market the
main answer would be because it has 8kB Flash and 256 bytes of data RAM32 I/O lines, three
16-bit timer/counters, a Eight-vector two-level interrupt architecture, a full duplex serial port,
on-chip oscillator, and clock circuitry.

8
In addition, the AT89S52 is designed with static logic for operation down to zero
frequency and supports two software selectable power saving modes. The Idle Mode stops the
CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue
functioning. The Power Down Mode saves the RAM contents but freezes the oscillator,
disabling all other chip functions until the next hardware reset. The Flash program memory
supports both parallel programming and in Serial In-System Programming (ISP). The 89S52 is
also In-Application Programmable (IAP), allowing the Flash program memory to be
reconfigured even while the application is running.

By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel
AT89S52 is a powerful microcomputer which provides a highly flexible and cost effective
solution to many embedded control applications.

2.1.3 FEATURES

• Compatible with MCS-51® Products


• 8K Bytes of In-System Programmable (ISP) Flash Memory
• Endurance: 1000 Write/Erase Cycles
• 4.0V to 5.5V Operating Range
• Fully Static Operation: 0 Hz to 33 MHz
• Three-level Program Memory Lock
• 256 x 8-bit Internal RAM
• 32 Programmable I/O Lines
• Three 16-bit Timer/Counters
• Eight Interrupt Sources
• Full Duplex UART Serial Channel
• Low-power Idle and Power-down Modes
• Interrupt Recovery from Power-down Mode
• Watchdog Timer
• Dual Data Pointer
• Power-off Flag

9
PIN DIAGRAM

Fig-2.1 PIN DIAGRAM OF 89S52 IC

2.1.4 PIN DESCRIPTION

Pin Description

VCC: Supply voltage.

10
GND: Ground.

PORT 0

Port 0 is an 8-bit open drain bi-directional 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 pro-gram and data memory. In this mode, P0 has internal pullups

Port 0 also receives the code bytes during Flash programmi ng an d ou tpu t s the c o de bytes
during prog r a m verification. External pullups are required during program verification.

PORT 1

Port 1 is an 8-bit bi-directional I/O port with internal pullups. 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 pullups and can be used as inputs. As inputs, Port 1 pins that are externally being
pulled low will source current because of the internal pullups. 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 duringFlash programming and verification

Port Pin Alternate Functions


P1.0 T2 (external count input to Timer/Counter 2),
clock-out
P1.1 T2EX (Timer/Counter 2 capture/reload trigger and
direction control)

PORT 2

Port 2 is an 8-bit bi-directional I/O port with internal pullups. 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 pullups and can be used as inputs. As inputs, Port 2 pins that are externally being
pulled low will source current because of the internal pullups.Port 2 emits the high-order
address byte during fetches from external program memory and during accesses to external
data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses
strong internal pullups when emitting 1s. During accesses to external data memory that use
8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.

11
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 bi-directional I/O port with internal pullups. 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 pullups and can be used as inputs. As inputs, Port 3 pins that are externally being
pulled low will source current because of the pullups. Port 3 also serves the functions of
various special features of the AT89S51, as shown in the following table. Port 3 also receives
some control signals for Flash programming and verification.

Port Pin Alternate Functions


P3.0 RXD (serial input port)
P3.1 TXD (serial output port)
P3.2 INT0 (external interrupt 0)
P3.3 INT1 (external interrupt 1)
P3.4 T0 (timer 0 external input)
P3.5 T1 (timer 1 external input)
P3.6 WR (external data memory write strobe)
P3.7 RD (external data memory read strobe)

RST

Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device.

ALE/PROG

Address Latch enable is an output pulse for latching the low byte of the address
during access to external memory. This pin is also the program pulse input(PROG) during
flash programming.

In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency
and may be used for external timing or clocking Note, however, that one ALE pulse is
skipped during each access to external data memory. If desired, ALE operation can be

12
disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a
MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-
disable bit has no effect if the microcontroller is in external execution mode.

Fig.2.2 Functional block diagram of microcontroller

The 8052 Oscillator and Clock

The heart of the 8051 circuitry that generates the clock pulses by which all the
internal all internal operations are synchronized. Pins XTAL1 And XTAL2 is provided for
connecting a resonant network to form an oscillator. Typically a quartz crystal and capacitors
are employed. The crystal frequency is the basic internal clock frequency of the
microcontroller. The manufacturers make 8051 designs that run at specific minimum and
maximum frequencies typically 1 to 16 MHz.

13
Fig.2.3 Oscillator and timing circuit

MEMORIES

Types of memory

The 8052 have three general types of memory. They are on-chip memory, external Code
memory and external Ram. On-Chip memory refers to physically existing memory on the
micro controller itself. External code memory is the code memory that resides off chip. This
is often in the form of an external EPROM. External RAM is the Ram that resides off chip.
This often is in the form of standard static RAM or flash RAM.

a) Code memory

Code memory is the memory that holds the actual 8052 programs that is to be run. This
memory is limited to 64K. Code memory may be found on-chip or off-chip. It is possible to
have 8K of code memory on-chip and 60K off chip memory simultaneously. If only off-chip

14
memory is available then there can be 64K of off chip ROM. This is controlled by pin provided
as EA.

b) Internal RAM

The 8052 have a bank of 256 bytes of internal RAM. The internal RAM is found on-
chip. So it is the fastest Ram available. And also it is most flexible in terms of reading and
writing. Internal Ram is volatile, so when 8051 is reset, this memory is cleared. 256 bytes of
internal memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank
contains 8 registers. Internal RAM also contains 256 bits, which are addressed from 20h to
2Fh. These bits are bit addressed i.e. each individual bit of a byte can be addressed by the user.
They are numbered 00h to FFh. The user may make use of these variables with commands such
as SETB and CLR.

Special Function registered memory

Special function registers are the areas of memory that control specific functionality of
the 8052 micro controller.

a) Accumulator (0E0h)

As its name suggests, it is used to accumulate the results of large no of instructions. It


can hold 8 bit values.

b) B registers (0F0h)

The B register is very similar to accumulator. It may hold 8-bit value. The b register is
only used by MUL AB and DIV AB instructions. In MUL AB the higher byte of the product
gets stored in B register. In div AB the quotient gets stored in B with the remainder in A.

c) Stack pointer (81h)

The stack pointer holds 8-bit value. This is used to indicate where the next value to be
removed from the stack should be taken from. When a value is to be pushed onto the stack, the
8052 first store the value of SP and then store the value at the resulting memory location. When
a value is to be popped from the stack, the 8052 returns the value from the memory location
indicated by SP and then decrements the value of SP.

d) Data pointer

15
The SFRs DPL and DPH work together work together to represent a 16-bit value called
the data pointer. The data pointer is used in operations regarding external RAM and some
instructions code memory. It is a 16-bit SFR and also an addressable SFR.

e) Program counter

The program counter is a 16 bit register, which contains the 2 byte address, which tells
the 8052 where the next instruction to execute to be found in memory. When the 8052 is
initialized PC starts at 0000h. And is incremented each time an instruction is executes. It is
not addressable SFR.

f) PCON (power control, 87h)

The power control SFR is used to control the 8051’s power control modes. Certain
operation modes of the 8051 allow the 8051 to go into a type of “sleep mode” which consumes
much lee power.

g) TCON (timer control, 88h)

The timer control SFR is used to configure and modify the way in which the 8051’s
two timers operate. This SFR controls whether each of the two timers is running or stopped
and contains a flag to indicate that each timer has overflowed. Additionally, some non-timer
related bits are located in TCON SFR. These bits are used to configure the way in which the
external interrupt flags are activated, which are set when an external interrupt occurs.

h) TMOD (Timer Mode, 89h)

The timer mode SFR is used to configure the mode of operation of each of the two
timers. Using this SFR your program may configure each timer to be a 16-bit timer, or 13 bit
timer, 8-bit auto reload timer, or two separate timers. Additionally you may configure the

16
timers to only count when an external pin is activated or to count “events” that are indicated
on an external pin.

i) TO (Timer 0 low/high, address 8A/8C h)

These two SFRs taken together represent timer 0. Their exact behavior depends on how
the timer is configured in the TMOD SFR; however, these timers always count up. What is
configurable is how and when they increment in value.

j) T1 (Timer 1 Low/High, address 8B/ 8D h)

These two SFRs, taken together, represent timer 1. Their exact behavior depends on how
the timer is configured in the TMOD SFR. However, these timers always count up.

k) P0 (Port 0, address 90h, bit addressable)

This is port 0 latch. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of
port 0 is pin P0.0, bit 7 is pin p0.7. Writing a value of 1 to a bit of this SFR will send a high
level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

l) P1 (port 1, address 90h, bit addressable)

This is port latch1. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of
port 0 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high
level on the corresponding I/O pin whereas a value of 0 will bring it to low level

m) P2 (port 2, address 0A0h, bit addressable)

This is a port latch2. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of
port 0 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high
level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

17
n) P3 (port 3, address B0h, bit addressable)

This is a port latch3. Each bit of this SFR corresponds to one of the pins on a micro
controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of
port 0 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high
level on the corresponding I/O pin whereas a value of 0 will bring it to low level.

o) IE (interrupt enable, 0A8h)


The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7
bits of the SFR are used to enable/disable the specific interrupts, where the MSB bit is used to
enable or disable all the interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled
regardless of whether an individual interrupt is enabled by setting a lower bit.

p) IP (Interrupt Priority, 0B8h)

The interrupt priority SFR is used to specify the relative priority of each interrupt. On
8051, an interrupt maybe either low or high priority. An interrupt may interrupt interrupts. For
e.g., if we configure all interrupts as low priority other than serial interrupt. The serial interrupt
always interrupts the system, even if another interrupt is currently executing. However, if a
serial interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine
since the serial interrupt routine has the highest priority.

q) PSW (Program Status Word, 0D0h)

The program Status Word is used to store a number of important bits that are set and
cleared by 8052 instructions. The PSW SFR contains the carry flag, the auxiliary carry flag,
the parity flag and the overflow flag. Additionally, it also contains the register bank select flags,
which are used to select, which of the “R” register banks currently in use.

18
r) SBUF (Serial Buffer, 99h)

SBUF is used to hold data in serial communication. It is physically two registers. One
is writing only and is used to hold data to be transmitted out of 8052 via TXD. The other is
read only and holds received data from external sources via RXD. Both mutually exclusive
registers use address 99h.

I/O PORTS
One major feature of a microcontroller is the versatility built into the input/output (I/O)
circuits that connect the 8052 to the outside world. The main constraint that limits numerous
functions is the number of pins available in the 8051 circuit. The DIP had 40 pins and the
success of the design depends on the flexibility incorporated into use of these pins. For this
reason, 24 of the pins may each used for one of the two entirely different functions which
depend, first, on what is physically connected to it and, then, on what software programs are
used to “program” the pins.

PORT 0
Port 0 pins may serve as inputs, outputs, or, when used together, as a bi directional low-
order address and data bus for external memory. To configure a pin as input, 1 must be written
into the corresponding port 0 latch by the program. When used for interfacing with the external
memory, the lower byte of address is first sent via PORT0, latched using Address latch enable
(ALE) pulse and then the bus is turned around to become the data bus for external memory.

PORT 1
Port 1 is exclusively used for input/output operations. PORTS 1 pin have no dual
function. When a pin is to be configured as input, 1 is to be written into the corresponding Port
1 latch.

PORT 2

19
Port 2 may be used as an input/output port. It may also be used to supply a high –order
address byte in conjunction with Port 0 low-order byte to address external memory. Port 2 pins
are momentarily changed by the address control signals when supplying the high byte a 16-bit
address. Port 2 latches remain stable when external memory is addressed, as they do not have
to be turned around (set to 1) for data input as in the case for Port 0.

PORT 3
Port 3 may be used to input /output port. The input and output functions can be
programmed under the control of the P3 latches or under the control of various special function
registers. Unlike Port 0 and Port 2, which can have external addressing functions and change
all eight-port b se, each pin of port 3 maybe individually programmed to be used as I/O or as
one of the alternate functions. The Port 3 alternate uses are.

Pin (SFR) Alternate Use

P3.0-RXD (SBUF) Serial data input

P3.1-TXD (SBUF) Serial data output

P3.2-INTO 0 (TCON.1) External interrupt


0

P3.3 - INTO 1 (TCON.3) External interrupt


1

P3.4 - T0 (TMOD) External Timer 0 input

P3.5 – T1 (TMOD) External timer 1


input

P3.6 - WR External memory write pulse

P3.7 - RD External memory read pulse


INTERRUPTS

20
The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and
INT1), three timer interrupts (Timers0, 1, and 2), and the serial port interrupt. These interrupts
are all shown in Figure 10. Each of these interrupt sources can be individually enabled or
disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global
disable bit, EA, which disables all interrupts at once. Note that Table 5 shows that bit position
IE.6 is unimplemented. In the AT89S52, bit position IE.5 is also unimplemented. User software
should not write 1s to these bit positions, since they may be used in future AT89 products.

Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register
T2CON. Neither of these flags is cleared by hardware when the service routine is vectored
to. In fact, the service routine may have to determine whether it was TF2 or EXF2 that
generated the interrupt, and that bit will have to be cleared in software.The Timer 0 and Timer
1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow. The values are
then polled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set at S2P2
and is polled in the same cycle in which the timer overflows.

21
2.2 POWER SUPPLY

2.2.1 INTRODUCTION

There are many types of power supply. Most are designed to convert high voltage AC
mains electricity to a suitable low voltage supply for electronics circuits and other devices. A
power supply can by broken down into a series of blocks, each of which performs a particular
function. For example a 5V regulated supply can be shown as below

230V Transfor Smoothi Regulato Regulated


Rectifier
AC mer ng r 5V DC
Mains

Fig.2.4 Block Diagram of a Regulated Power Supply System

22
Similarly, 12v regulated supply can also be produced by suitable selection of the
individual elements. Each of the blocks is described in detail below and the power supplies
made from these blocks are described below with a circuit diagram and a graph of their output

2.2.2 TRANSFORMER

A transformer steps down high voltage AC mains to low voltage AC. Here we are using
a center-tap transformer whose output will be sinusoidal with 36volts peak to peak value.

Fig.2.5 Output Waveform of transformer

The low voltage AC output is suitable for lamps, heaters and special AC motors. It is
not suitable for electronic circuits unless they include a rectifier and a smoothing capacitor.
The transformer output is given to the rectifier circuit.

2.2.3 RECTIFIER

A rectifier converts AC to DC, but the DC output is varying. There are several types of
rectifiers; here we use a bridge rectifier.

The Bridge rectifier is a circuit, which converts an ac voltage to dc voltage using both
half cycles of the input ac voltage. The Bridge rectifier circuit is shown in the figure. The circuit
has four diodes connected to form a bridge. The ac input voltage is applied to the diagonally
opposite ends of the bridge. The load resistance is connected between the other two ends of the
bridge.

For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas
diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series with the
load resistance RL and hence the load current flows through RL.

23
For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct whereas,
D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load
resistance RL and hence the current flows through RL in the same direction as in the previous
half cycle. Thus a bi-directional wave is converted into unidirectional.

Fig.2.6 Rectifier circuit

Now the output of the rectifier shown in Figure 3.3 is shown below in Figure 3.4

Fig.2.7 Output of the Rectifier

The varying DC output is suitable for lamps, heaters and standard motors. It is not
suitable for lamps, heaters and standard motors. It is not suitable for electronic circuits unless
they include a smoothing capacitor.

24
Smoothing

The smoothing block smoothes the DC from varying greatly to a small ripple and the
ripple voltage is defined as the deviation of the load voltage from its DC value. Smoothing is
also named as filtering.

Filtering is frequently effected by shunting the load with a capacitor. The action of this
system depends on the fact that the capacitor stores energy during the conduction period and
delivers this energy to the loads during the no conducting period. In this way, the time during
which the current passes through the load is prolonging Ted, and the ripple is considerably
decreased. The action of the capacitor is shown with the help of waveform.

Fig.2.8 Smoothing action of capacitor

Fig.2.9 Waveform of the rectified output smoothing

2.2.4 REGULATOR
25
Regulator eliminates ripple by setting DC output to a fixed voltage. Voltage regulator
ICs are available with fixed (typically 5V, 12V and 15V) or variable output voltages.
Negative voltage regulators are also available

Many of the fixed voltage regulator ICs has 3 leads (input, output and high impedance).
They include a hole for attaching a heat sink if necessary. Zener diode is an example of fixed
regulator which is shown here.

Fig.2.10 Regulator

Transformer + Rectifier + Smoothing + Regulator

Fig.2.11 Power supply output

26
2.3 ADC and LM35
ADC0804 is one of the most commonly used analog to digital converter IC. In many
applications it is required to convert the output of the sensor, which is analogue in nature to a
digital form. The data in digital format can then be utilized for further processing by the
digital processors. Typical applications include sound processing, temperature processing etc.
This circuit demonstrates the principle and operation of interfacing a simple ADC 0804 using
8051 microcontroller (AT89C51).

ADC0804 is connected as shown in the circuit diagram. Here the input is taken from a preset,
which gives different analog signals to the ADC. The output pins of the ADC are connected
to LEDs. The control pins of the ADC are connected to the microcontroller AT89C51.

ADC0804 is a single channel analog to digital convertor i.e., it can take only one analog
signal. An ADC has n bit resolution (binary form) where n can be 8,10,12,16 or even 24 bits.
ADC 0804 has 8 bit resolution. The higher resolution ADC gives smaller step size. Step size
is smallest change that can be measured by an ADC. For an ADC with resolution of 8 bits,
the step size is 19.53mV (5V/255).

The time taken by the ADC to convert analog data into digital form is dependent on the
frequency of clock source. ADC0804 can be given clock from external source. It also has an
internal clock. However the conversion time cannot be more than110us. To use the internal
clock a capacitor and resistor is connected to pin 19 and 4 as shown in the circuit diagram. The
frequency is given by the relation f= 1/ (1.1RC). The circuit uses a resistance of 10k and a
capacitor of 150pF to generate clock for ADC0804. Vin, which is the input pin, is connected
to a preset to provide analog input.

Pin Description
1. CS, Chip Select: This is an active low pin and used to activate the ADC0804.
2. RD, Read: This is an input pin and active low. After converting the analog data, the ADC
stores the result in an internal register. This pin is used to get the data out of the ADC 0804
chip. When CS=0 & high to low pulse is given to this pin, the digital output is shown on the
pins D0-D7.
3. WR, Write: This is an input pin and active low. This is used to instruct the ADC to start
the conversion process. If CS=0 and WR makes a low to high transition, the ADC starts the
conversion process.
4. CLK IN, Clock IN: This is an input pin connected to an external clock source.
5. INTR, Interrupt: This is an active low output pin. This pin goes low when the conversion
is over.
6. Vin+ : Analog Input .
7. Vin- : Analog Input. Connected to ground.
8. AGND: Analog Ground.
9. Vref/2: This pin is used to set the reference voltage. If this is not connected the default
reference voltage is 5V. In some application it is required to reduce the step size. This can be
done by using this pin.

27
10. DGND: Digital Ground.
11-18. Output Data Bits (D7-D0).
19. CLKR: Clock Reset.
20. Vcc: Positive Supply

In this circuit microcontroller is used to provide the control signals to the ADC. CS pin of ADC
is directly connected to ground. The pin P1.1, P1.0 and P1.2 are connected to the pin WR, RD
and INTR of the ADC respectively. When the input voltage from the preset is varied the output
of ADC varies which can be seen on the LCD. When the preset is at minimum level, no LED
glows and when the preset is at maximum position all the LEDs starts glowing.

The following steps are used to interface the ADC0804.


1. Send a low to high pulse to pin WR to start the conversion.
2. Keep monitoring the INTR pin. If INTR is low, go to next step else keep checking the
status.
3. A high to low pulse is sent to the RD pin to bring the converted data on the output pins.

28
Signal control on ADC0804
1. Make CS = 0 and send a L-to-H pulse to pin WR to start the conversion.
2. Keep monitoring the INTR pin. If INTR is low, the conversion is finished and we can go to
the next step. If INTR is high, keep polling until it goes low.
3. After the INTR has become low, we make CS = 0 and send a H-to-L pulse to the RD pin to
get the data out of the ADC0804 IC chip.

Note: CS is set to low for both RD and WR pulses.

29
Write a program to monitor the INTR pin and bring the digital input value into register A.
Then call a subroutine to display the input value on a 7-segment display.

LM35 Temperature Sensor Introduction and Fundamentals


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
±¼°C at room temperature and ±¾°C over a full -55 to +150°C temperature range. Low cost
is assured by trimming and calibration at the wafer level. The LM35's 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.1°C in still air.
The LM35 is rated to operate over a -55° to +150°C temperature range. A digital thermometer
can be easily created by using LM35 temperature sensor and can be interfaced any
microcontrollers.

The LM 35 IC generates a 10mV variation to its output voltage for every degree Celsius change
in temperature. The Output of the temperature sensor is analog in nature so we need an analog
to digital converter for converting the analog input to its equivalent binary output. The ADC
0804 is the analog to digital converter IC used in the project. 0804 is a single channel converter
which converts the analog input up to a range of 5V to an equivalent 8-bit binary output.

Features of LM35 Temperature Sensors - 8051 Microcontrollers:

30
Calibrated directly in ° Celsius (Centigrade)

Linear + 10.0 mV/°C scale factor


0.5°C accuracy guarantee able (at +25°C)
Rated for full -55° to +150°C 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.08°C in still air
Nonlinearity only ±¼°C typical
Low impedance output, 0.1 Ohm for 1 mA load
Interfacing LM25 Temperature Sensor With 8051 Microcontroller:
This Digital Thermometer Design can be integrated by using the 8051 microcontroller and
analog to digital converter IC ADC 804 and interfaced with any microcontroller AT8051,
AT8052, AT89C51, AT89C52, AT89S51, AT89s52 and the output can be displayed on any

output device may be computer monitor or any LCD display. The sensor used for this design
is the LM35 which output an analogue voltage per centigrade Celsius. A circuit amplification
is done between the LM35 and the microcontroller.
About ADC 804 Analog To Digital Converter
The ADC804 is an analog to digital converter whic is used to convert analog signals to digital
so that any microcontroller can sense the signal and works accordingly. Resolution of this IC
is 8 bits and works with +5V. If input voltage 5V then converted digital output is FF.

Pin description of ADC805 :


CS : Chip Select:
It is an active low input used to activate the ADC804 IC. To activate ADC804, this pin must
be low.

31
RD : Read:
It is an active low input used to get the converted data out of the ADC chip. The ADC converts
the analog input to its binary equivalent and holds in an internal register. When a CS = 0 and
high-to-low pulse is applied to the RD pin, then 8-bit digital output is available at the D0-D7
data pins.
WR : Write:
This is an active low input used to inform the ADC to start the conversion process. ADC starts
converting analog input to digital, when CS = 0 and a low-to-high pulse is applied to WR pin.
The amount it takes to convert varies depending on the CLK IN and CLK R values. When the
data conversion is complete, the INTR pin is forced low by the ADC804.

Interfacing Circuit ADC 804 Analog To Digital Converter with 8051 Microcontroller
Here ADC 0804 is connected to port1 of 8051. WR and INTR of ADC is connected to P3.4
and P3.5 respectively. Analog input is applied to pin 6 of ADC. Here WR is the start of
conversion and INTR is the end of conversion.

32
Example of ADC Application
Temperature detection
A temperature sensor (LM34 or LM35) is interfaced to the 8051 via an ADC (ADC0804)
The output voltage from the LM34/LM35 is linearly proportional to the measuring
temperature
The ADC0804 converts the output voltages from the LM34/LM35 into digital signals, which
correspond to the measured temperature.They are then handled by the 8051
Interfacing with the LM35 (Temperature Sensor)

ADC Application:-
The ADC0804 converts the output voltages from the LM35 into digital signals, which
correspond to the measured temperature.
Step size of the ADC0804 = (1.28)x(2)/255 = 0.01004V
Clock input to the ADC0804 = clock frequency / 4
If the following data of LM35 are given
the temperature range of the temperature sensor LM35 is -55C to 150C and its output scale is
10mV/C, and the output value of the ADC0804 is 00H when the LM35 senses -55C
then the value output from the ADC0804 for a measuring temperature 100 C is:

33
2.4 LCD

LCD Backgorund
Frequently, an 8051 program must interact with the outside world using input and output
devices that communicate directly with a human being. One of the most common devices attached to
an 8051 is an LCD display. Some of the most common LCDs connected to the 8051 are 16x2 and
20x2 displays. This means 16 characters per line by 2 lines and 20 characters per line by 2 lines,
respectively.

Fortunately, a very popular standard exists which allows us to communicate with the vast
majority of LCDs regardless of their manufacturer. The standard is referred to as HD44780U,
which refers to the controller chip which receives data from an external source (in this case,
the 8051) and communicates directly with the LCD.

44780 BACKGROUND

The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus.
The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus.
If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the
4 lines for the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data
lines (3 control lines plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.

The EN line is called "Enable." This control line is used to tell the LCD that you are sending
it data. To send data to the LCD, your program should make sure this line is low (0) and then
set the other two control lines and/or put data on the data bus. When the other lines are
completely ready, bring EN high (1) and wait for the minimum amount of time required by
the LCD datasheet (this varies from LCD to LCD), and end by bringing it low (0) again.

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high
(1), the data being sent is text data which sould be displayed on the screen. For example, to
display the letter "T" on the screen you would set RS high.

The RW line is the "Read/Write" control line. When RW is low (0), the information on the
data bus is being written to the LCD. When RW is high (1), the program is effectively
querying (or reading) the LCD. Only one instruction ("Get LCD status") is a read command.
All others are write commands--so RW will almost always be low.

34
Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by
the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3,
DB4, DB5, DB6, and DB7.

Hex Command to LCD instructions


code
0x01 To clear the LCD screen
0x02 Return Home
0x04 Decrement cursor (shift cursor to left)
0x06 Increment cursor (shift cursor to left)
0x05 Shift display right
0x07 Shift display left
0x08 Display off, Cursor off
0x0A Display Off, Cursor On
0x0C Display On, Cursor Off
0x0E Display On, Cursor blinking
0x0F Display On, Cursor blinking
0x10 Shift Cursor Position to left
0x14 Shift Cursor Position to right
0x18 Shift the entire display to the left
0x1C Shift the entire display to the right
0x80 Force Cursor to beginning of 1st line first position
0xCO Force Cursor to beginning of 2nd line first position
0x38 2line and 5x8 matrix
0x30 Passing a alphanumeric value

Example :

void banner()
{
command(0x38);
delay();
command(0x0c);
delay();
command(0x06);
delay();
command(0x80);
delay();
command(0x01);
delay();
command(0x82);
display('W');
display('E');
display('L');
display(' ');
display('C');
display('O');
display('M');
display('E');
display(' ');
display('T');
display('O');
command(0xc0);
display('H');

35
display('U');
display('M');
display('A');
display('N');
display(' ');
display('D');
display('E');
display('T');
display('E');
display('C');
display('T');
display('I');
display('O');
display('N');
msdeley();
command(0x01);
delay();

AN EXAMPLE HARDWARE CONFIGURATION

As we've mentioned, the LCD requires either 8 or 11 I/O lines to communicate with. For the
sake of this tutorial, we are going to use an 8-bit data bus--so we'll be using 11 of the 8051's
I/O pins to interface with the LCD.

Let's draw a sample psuedo-schematic of how the LCD will be connected to the 8051.

As you can see, we've established a 1-to-1 relation between a pin on the 8051 and a line on
the 44780 LCD. Thus as we write our assembly program to access the LCD, we are going to
equate constants to the 8051 ports so that we can refer to the lines by their 44780 name as
opposed to P0.1, P0.2, etc. Let's go ahead and write our initial equates:

DB0 EQU P1.0


DB1 EQU P1.1
DB2 EQU P1.2
DB3 EQU P1.3
DB4 EQU P1.4
DB5 EQU P1.5

36
DB6 EQU P1.6
DB7 EQU P1.7
EN EQU P3.7
RS EQU P3.6
RW EQU P3.5
DATA EQU P1

Having established the above equates, we may now refer to our I/O lines by their 44780 name. For
example, to set the RW line high (1), we can execute the following insutrction:

SETB RW

HANDLING THE EN CONTROL LINE

As we mentioned above, the EN line is used to tell the LCD that you are ready for it to
execute an instruction that you've prepared on the data bus and on the other control lines.
Note that the EN line must be raised/lowered before/after each instruction sent to the LCD
regardless of whether that instruction is read or write, text or instruction. In short, you must
always manipulate EN when communicating with the LCD. EN is the LCD's way of knowing
that you are talking to it. If you don't raise/lower EN, the LCD doesn't know you're talking to
it on the other lines.

Thus, before we interact in any way with the LCD we will always bring the EN line low with
the following instruction:

CLR EN

And once we've finished setting up our instruction with the other control lines and data bus lines, we'll
always bring this line high:

SETB EN

The line must be left high for the amount of time required by the LCD as specified in its datasheet.
This is normally on the order of about 250 nanoseconds, but check the datasheet. In the case of a
typical 8051 running at 12 MHz, an instruction requires 1.08 microseconds to execute so the EN line
can be brought low the very next instruction. However, faster microcontrollers (such as the
DS89C420 which executes an instruction in 90 nanoseconds given an 11.0592 Mhz crystal) will
require a number of NOPs to create a delay while EN is held high. The number of NOPs that must be
inserted depends on the microcontroller you are using and the crystal you have selected.

The instruction is executed by the LCD at the moment the EN line is brought low with a final
CLR EN instruction.

Programming Tip: The LCD interprets and executes our command at the instant the EN line
is brought low. If you never bring EN low, your instruction will never be executed.
Additionally, when you bring EN low and the LCD executes your instruction, it requires a
certain amount of time to execute the command. The time it requires to execute an instruction
depends on the instruction and the speed of the crystal which is attached to the 44780's
oscillator input.

37
CHECKING THE BUSY STATUS OF THE LCD

As previously mentioned, it takes a certain amount of time for each instruction to be executed
by the LCD. The delay varies depending on the frequency of the crystal attached to the
oscillator input of the 44780 as well as the instruction which is being executed.

While it is possible to write code that waits for a specific amount of time to allow the LCD to
execute instructions, this method of "waiting" is not very flexible. If the crystal frequency is
changed, the software will need to be modified. Additionally, if the LCD itself is changed for
another LCD which, although 44780 compatible, requires more time to perform its
operations, the program will not work until it is properly modified.

A more robust method of programming is to use the "Get LCD Status" command to
determine whether the LCD is still busy executing the last instruction received.

The "Get LCD Status" command will return to us two tidbits of information; the information
that is useful to us right now is found in DB7. In summary, when we issue the "Get LCD
Status" command the LCD will immediately raise DB7 if it's still busy executing a command
or lower DB7 to indicate that the LCD is no longer occupied. Thus our program can query the
LCD until DB7 goes low, indicating the LCD is no longer busy. At that point we are free to
continue and send the next command.

Since we will use this code every time we send an instruction to the LCD, it is useful to make
it a subroutine. Let's write the code:

WAIT_LCD:

CLR EN ;Start LCD command


CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
SETB EN ;Clock out command to LCD
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET

Thus, our standard practice will be to send an instruction to the LCD and then call our WAIT_LCD
routine to wait until the instruction is completely executed by the LCD. This will assure that our
program gives the LCD the time it needs to execute instructions and also makes our program
compatible with any LCD, regardless of how fast or slow it is.

Programming Tip: The above routine does the job of waiting for the LCD, but were it to be
used in a real application a very definite improvement would need to be made: as written, if
the LCD never becomes "not busy" the program will effectively "hang," waiting for DB7 to
go low. If this never happens, the program will freeze. Of course, this should never happen
and won't happen when the hardware is working properly. But in a real application it would
be wise to put some kind of time limit on the delay--for example, a maximum of 256 attempts

38
to wait for the busy signal to go low. This would guarantee that even if the LCD hardware
fails, the program would not lock up.

INITIALIZING THE LCD

Before you may really use the LCD, you must initialize and configure it. This is
accomplished by sending a number of initialization instructions to the LCD.

The first instruction we send must tell the LCD whether we'll be communicating with it with
an 8-bit or 4-bit data bus. We also select a 5x8 dot character font. These two options are
selected by sending the command 38h to the LCD as a command. As you will recall from the
last section, we mentioned that the RS line must be low if we are sending a command to the
LCD. Thus, to send this 38h command to the LCD we must execute the following 8051
instructions:

CLR RS
MOV DATA,#38h
SETB EN
CLR EN
LCALL WAIT_LCD

Programming Tip: The LCD command 38h is really the sum of a number of option bits. The
instruction itself is the instruction 20h ("Function set"). However, to this we add the values
10h to indicate an 8-bit data bus plus 08h to indicate that the display is a two-line display.

We've now sent the first byte of the initialization sequence. The second byte of the
initialization sequence is the instruction 0Eh. Thus we must repeat the initialization code
from above, but now with the instruction. Thus the the next code segment is:

CLR RS
MOV DATA,#0Eh
SETB EN
CLR EN
LCALL WAIT_LCD

Programming Tip: The command 0Eh is really the instruction 08h plus 04h to turn the LCD
on. To that an additional 02h is added in order to turn the cursor on.

The last byte we need to send is used to configure additional operational parameters of the
LCD. We must send the value 06h.

CLR RS
MOV DATA,#06h
SETB EN
CLR EN
LCALL WAIT_LCD

Programming Tip: The command 06h is really the instruction 04h plus 02h to configure the
LCD such that every time we send it a character, the cursor position automatically moves to
the right.

39
So, in all, our initialization code is as follows:

INIT_LCD:

CLR RS
MOV DATA,#38h
SETB EN
CLR EN
LCALL WAIT_LCD
CLR RS
MOV DATA,#0Eh
SETB EN
CLR EN
LCALL WAIT_LCD
CLR RS
MOV DATA,#06h
SETB EN
CLR EN
LCALL WAIT_LCD
RET

Having executed this code the LCD will be fully initialized and ready for us to send display data to it.

CLEARING THE DISPLAY

When the LCD is first initialized, the screen should automatically be cleared by the 44780
controller. However, it's always a good idea to do things yourself so that you can be
completely sure that the display is the way you want it. Thus, it's not a bad idea to clear the
screen as the very first opreation after the LCD has been initialiezd.

An LCD command exists to accomplish this function. Not suprisingly, it is the command
01h. Since clearing the screen is a function we very likely will wish to call more than once,
it's a good idea to make it a subroutine:

CLEAR_LCD:

CLR RS
MOV DATA,#01h
SETB EN
CLR EN
LCALL WAIT_LCD
RET

How that we've written a "Clear Screen" routine, we may clear the LCD at any time by simply
executing an LCALL CLEAR_LCD.

Programming Tip: Executing the "Clear Screen" instruction on the LCD also positions the
cursor in the upper left-hand corner as we would expect.

40
WRITING TEXT TO THE LCD

Now we get to the real meat of what we're trying to do: All this effort is really so we can
display text on the LCD. Really, we're pretty much done.

Once again, writing text to the LCD is something we'll almost certainly want to do over and
over--so let's make it a subroutine.

WRITE_TEXT:

SETB RS
MOV DATA,A
SETB EN
CLR EN
LCALL WAIT_LCD
RET

The WRITE_TEXT routine that we just wrote will send the character in the accumulator to the LCD
which will, in turn, display it. Thus to display text on the LCD all we need to do is load the
accumulator with the byte to display and make a call to this routine. Pretty easy, huh?

A "HELLO WORLD" PROGRAM

Now that we have all the component subroutines written, writing the classic "Hello World"
program--which displays the text "Hello World" on the LCD is a relatively trivial matter.
Consider:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT

41
MOV A,#'D'
LCALL WRITE_TEXT

The above "Hello World" program should, when executed, initialize the LCD, clear the LCD screen,
and display "Hello World" in the upper left-hand corner of the display.

CURSOR POSITIONING

The above "Hello World" program is simplistic in the sense that it prints its text in the upper
left-hand corner of the screen. However, what if we wanted to display the word "Hello" in the
upper left-hand corner but wanted to display the word "World" on the second line at the tenth
character? This sounds simple--and actually, it is simple. However, it requires a little more
understanding of the design of the LCD.

The 44780 contains a certain amount of memory which is assigned to the display. All the text
we write to the 44780 is stored in this memory, and the 44780 subsequently reads this
memory to display the text on the LCD itself. This memory can be represented with the
following "memory map":

In the above memory map, the area shaded in blue is the visible display. As you can see, it measures
16 characters per line by 2 lines. The numbers in each box is the memory address that corresponds to
that screen position.

Thus, the first character in the upper left-hanad corner is at address 00h. The following
character position (character #2 on the first line) is address 01h, etc. This continues until we
reach the 16th character of the first line which is at address 0Fh.

However, the first character of line 2, as shown in the memory map, is at address 40h. This
means if we write a character to the last position of the first line and then write a second
character, the second character will not appear on the second line. That is because the second
character will effectively be written to address 10h--but the second line begins at address 40h.

Thus we need to send a command to the LCD that tells it to position the cursor on the second
line. The "Set Cursor Position" instruction is 80h. To this we must add the address of the
location where we wish to position the cursor. In our example, we said we wanted to display
"World" on the second line on the tenth character position.

Referring again to the memory map, we see that the tenth character position of the second
line is address 4Ah. Thus, before writing the word "World" to the LCD, we must send a "Set
Cursor Position" instruction--the value of this command will be 80h (the instruction code to
position the cursor) plus the address 4Ah. 80h + 4Ah = CAh. Thus sending the command
CAh to the LCD will position the cursor on the second line at the tenth character position:

CLR RS
MOV DATA,#0CAh
SETB EN

42
CLR EN
LCALL WAIT_LCD

The above code will position the cursor on line 2, character 10. To display "Hello" in the upper left-
hand corner with the word "World" on the second line at character position 10 just requires us to
insert the above code into our existing "Hello World" program. This results in the following:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
CLR RS
MOV DATA,#0CAh
SETB EN
CLR EN
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT

SUMMARY

This tutorial has presented the underlying concepts of programming an LCD display.
Obviously it has not addresses all issues. The 44780 LCD controller offers many other
functions which are accessed using other commands, and some of the commands already
presented include other options that were not discussed here. However, this tutorial should
get you going in the right direction.

43
PROGRAMMING LCD IN 4-BIT MODE:

In the first tutorial we have seen that character LCD's based on the HD44780 chip can be
driven in 8bits mode, which requires in total 11 lines from you microcontroller. If we want
(or need) to spare some lines for other purposes it is possible to drive the display in 4bits
mode, which requires 7 lines. It is possible to use only 6 lines, in which case R/W is tied to
GrouND. This configuration is seen many times in projects. Instead of reading the busy flag
(which is somewhat trickier than it is in 8 bit modus) we have to use delay loops. These
delayloops have to be recalculated when using other oscillator frequencies. In this tutorial we
use the somewhat harder solution, making use of the busy flag and being independent of the
oscillator frequency. The only drawback using 4 bits is that commands and data have to be
sent in two nibbles (4bit parts) to the display, which take slightly more time. In many cases
that won't be a problem.

To keep things simple, I will take the examples from the first tutorial, make the necessary
changes and only explain the differences.

HARDWARE CONFIGURATION

The only difference with the 8bit version is DB0, DB1, DB2 and DB3 on the displaymodule
side. These lines are not connected to the processor. Leave those lines unconnected, DON'T
SHORT THEM TO GROUND as seen in projects where R/W is tied to ground.

So the initial equates are:

DB4 EQU P1.4


DB5 EQU P1.5
DB6 EQU P1.6
DB7 EQU P1.7
EN EQU P3.7
RS EQU P3.6
RW EQU P3.5
DATA EQU P1

Again, if you want to know how to handle the control lines in your programs, please read the
first tutorial on LCD displays. In 4-bit mode, we have to read and write databytes and
commandbytes in two separate 'nibbles' (4bit parts). To make only minor changes to the
original example, we make two subroutines; one to read two nibbles from the LCD, and the
other to write two nibbles to the LCD. Furthermore, the toggling of the EN-line is also taken
to these subroutines, because we have to toggle for each nibble.

READ_2_NIBBLES:
ORL DATA,#0F0 ;Be sure to release datalines (set outputlatches
;to '1') so we can read the LCD
SETB EN
MOV A,DATA ;Read first part of the return value (high nibble)
CLR EN

44
ANL A,#0F0h ;Only high nibble is usable
PUSH ACC
SETB EN
MOV A,DATA ;Read second part of the return value (low nibble)
CLR EN
ANL A,#0F0h ;Only high nibble is usable
SWAP A ;Last received is actually low nibble, so put it in place
MOV R7,A
POP ACC
ORL A,R7 ;And combine it with low nibble
RET
WRITE_2_NIBBLES:
PUSH ACC ;Save A for low nibble
ORL DATA,#0F0h ;Bits 4..7 <- 1
ORL A,#0Fh ;Don't affect bits 0-3
ANL DATA,A ;High nibble to display
SETB EN
CLR EN
POP ACC ;Prepare to send
SWAP A ;...second nibble
ORL DATA,#0F0h ; Bits 4...7 <- 1
ORL A,#0Fh ; Don't affect bits 0...3
ANL DATA,A ;Low nibble to display
SETB EN
CLR EN
RET

As we see in the WRITE_2_NIBBLES routine, there are some logic instructions (ORL, ANL) so I/O lines P1.0
to P1.3 are not affected. These lines are thus free for input or output and not affected by this routine.

CHECKING THE BUSY STATUS OF THE LCD

WAIT_LCD:
CLR RS ;It's a command
SETB RW ;It's a read command
LCALL READ_2_NIBBLES ;Take two nibbles from LCD in A
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR RW ;Turn off RW for future commands
RET

INITIALIZING THE LCD

Before you may really use the LCD, you must initialise and configure it. This is
accomplished by sending a number of initialisation instructions to the LCD.

The first instruction we send must tell the LCD we'll be communicating with it with a 4-bit
data bus. We also select a 5x8 dot character font. These two options are selected by sending
the command 28h to the LCD as a command. After powering up the LCD, it is in 8-bit mode.
Because only four bits are connected, the first command has to be send twice; the first time to
switch to 4-bits mode, (the lower 4 bits of the command are not seen), the second time to
send it as two nibbles so the lower part is received, too.

45
CLR RS
CLR RW
CLR EN
SETB EN
MOV DATA,#28h
CLR EN
LCALL WAIT_LCD
MOV A,#28h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

Programming Tip: The LCD command 28h is really the sum of a number of option
bits. The instruction itself is the instruction 20h ("Function set"). However, to this we
add the values 0h to indicate a 4-bit data bus plus 08h to indicate that the display is a
two-line display.

We've now sent the first byte of the initialisation sequence. The second byte of the
initialisation sequence is the instruction 0Eh. Thus we must repeat the initialisation code from
above, but now with the instruction. Thus the next code segment is:

MOV A,#0Eh
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

Programming Tip: The command 0Eh is really the instruction 08h plus 04h to turn
the LCD on. To that an additional 02h is added in order to turn the cursor on.

The last byte we need to send is used to configure additional operational parameters of the
LCD. We must send the value 06h.

MOV A,#06h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD

Programming Tip: The command 06h is really the instruction 04h plus 02h to configure the LCD
such that every time we send it a character, the cursor position automatically moves to the right.

So, in all, our initialisation code is as follows:

INIT_LCD:
CLR RS
CLR RW
CLR EN
SETB EN
MOV DATA,#28h
CLR EN
LCALL WAIT_LCD
MOV A,#28h

46
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#0Eh
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#06h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
RET

Having executed this code the LCD will be fully initialised and ready for us to send display
data to it.

CLEARING THE DISPLAY


CLEAR_LCD:
CLR RS
MOV A,#01h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD
RET

WRITING TEXT TO THE LCD


WRITE_TEXT:
SETB RS
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
RET

THE "HELLO WORLD" PROGRAM


LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT

47
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT

The above "Hello World" program should, when executed, initialise the LCD, clear the LCD
screen, and display "Hello World" in the upper left-hand corner of the display. As you see, no
difference in this routine with the 8bit drive routines.

CURSOR POSITIONING

Let's again, write the word 'world' on the second line now, from the tenth position:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
CLR RS
MOV A,#0C9h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT

SUMMARY

This tutorial has presented the underlying concepts of programming an LCD display in 4bit
modus. If things in this document are not clear, please be sure to read again the first tutorial
on using LCD modules.

48
MORE BACKGROUND INFORMATION ABOUT DIFFERENT SIZED LCD
MODULES

The HD44780 or compatible controller is basically designed to build LCDisplays with one or
two lines with a maximum of 40 characterpositions each. A single HD44780 is able to
display two lines of 8 characters each. If we want more, the HD44780 has to be expanded
with one or more expansion chips, like the HD 44100 (2 x 8 characters expansion) or the HD
66100 (2 x 16 characters expansion). Seen from the HD44780, the first line starts with 00h;
the second line with 40h.

LAYOUT OF DISPLAY MODULES WITHOUT EXPANSION CHIP(S):

1. 8 characters x 1 line

First Line:00 01 02 03 04 05 06 07

2. The module has to be initialised as a ONE line display.


3. 8 characters x 2 lines

First Line: 00 01 02 03 04 05 06 07
Second Line:40 41 42 43 44 45 46 47

4. To use the second line, don't forget to initialise the display as a TWO lines display.
5. 16 characters x 1 line

First Line:00 01 02 03 04 05 06 07 40 41 42 43 44 45 46 47

6. In fact, in this case the two lines are placed one after another. So when we want to use
the display from the ninth position, it has to be initialised as if it were a TWO lines
display! Mind the ninth position is addressed as 40h, not 08h.

LAYOUT OF DISPLAY MODULES WITH EXPANSION CHIP(S)

1. 16 characters x 1 line

First Line:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

49
2. On the outside this module looks the same like #3 above, but all characterpositions
are addressed continuously. The module has to be initialised as a ONE-line display.
3. 20 characters x 1 line

First Line: 00 01 02 03 04 05 06 07 08 09 40 41 42 43 44 45 46 47 48 49

4. In fact, from HD44780 point of view, in this case two lines are placed one after
another. So when we want to use the display from the eleventh position, it has to be
initialised as if it were a TWO lines display! Mind the eleventh position is addressed
as 40h, not 0Ah.
5. 40 characters x 1 line

First Line:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11...27

6. The module has to be initialised as a TWO lines display, if we also want to use the
second line.
7. 24 characters x 2 lines

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15
First Line:
16 17
Second
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55
Line:
56 57

8. The module has to be initialised as a TWO lines display, if we also want to use the
second line.
9. 40 characters x 2 lines

First Line: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11... 27


Second Line:40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51... 67

10. The module has to be initialised as a TWO lines display, if we also want to use the
second line. This is also the maximum configuration which is possible with one
HD44780 + extension chips (80 characters).
11. 16 characters x 4 lines

50
First Line: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
Second Line:40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
Third Line: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
Fourth Line: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F

12. To use the second and the fourth line, the module has to be initialised as a TWO lines
display (strange, no?). In fact, the third line is continuous to the first line, and the
fourth line is continuous two the second line (from addressing point of view).
13. 20 characters x 4 lines

First Line: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
Second Line:40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53
Third Line: 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
Fourth Line: 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67

14. To use the second and the fourth line, the module has to be initialised as a TWO lines
display. In fact, the third line is continuous to the first line, and the fourth line is
continuous two the second line (from addressing point of view).

15. 24 characters x 4 lines

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15
First Line: 16 17
Second 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35
Line: 36 37
Third Line: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55
Fourth 56 57

Line: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75
76 77

51
16. To use the THIRD and the FOURTH line, the module has to be initialised as a TWO
lines display. Look out! There is a small 'view'-gap between the address ing of the
first and the second line (and the third and fourth line respectively).
17. 40 characters x 4 lines

First Line: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12... 27


Second Line:40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52... 67
Third Line: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12... 27
Fourth Line: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52... 67

18. These modules uses two HD44780's (each with expansion chips) and can be seen as
two 40 x 2 modules in one. All wiring is common, except for the EN (enable) lines,
which are separate to drive each HD44780 apart.
19. Tip:If you are not sure what configuration your display has, you can do use
the following trick: Imagine you have a 16 characters x 1 line display. You
want to know if it has configuration #3 in the first section or #1 in this section.
Just connect the contrast input of your module to GND (= maximum contrast)
and apply only power (+5V) to the module. The module will be initialised by
an internal routine, which puts it in single line modus. Only the positions that
belong to the first line will be black.
20. Conclusion: If all positions are black, we have a module as described under
#1 of this section. If only the first 8 characters are black, you have a module as
described under # of the previous section.

Not all possible module configurations are described here, but with the help of this
information you must be able to work with different modules. Some (functional, not
necessary pin-) compatible chips; to help you to determine your module:

Controller:
HD44780 (Hitachi)
KS0066 (Samsung)
SED1278 (Epson)

52
Expansion 8 x 2:
HD44100 (Hitachi)
KS0061 (Samsung)
M5259 (OKI)

Expansion 12 x 2:
SED1181 (Epson)

Expansion 16 x 2:
HD66100 (Hitachi)

CHAPTER 3
CIRCUIT DIAGRAM

Fig.3.1 Power supply

53
Fig.3.2 Microcontrollor

Complete circuit diagram

54
REFERENCES

1. "The 8051 Microcontroller Architecture, Programming & Applications"

By Kenneth J Ayala.

2. "The 8051 Microcontroller & Embedded Systems" by Mohammed Ali Mazidi and
Janice Gillispie Mazidi

3. "Power Electronics” by M D Singh and K B Khanchandan

4. "Linear Integrated Circuits” by D Roy Choudary & Shail Jain

5. "Electrical Machines” by S K Bhattacharya

6. "Electrical Machines II” by B L Thereja

7. www.8051freeprojectsinfo.com

55
APENDEX A
SOFTWARE DEVELOPMENT
Introduction

In this chapter the software used and the language in which the program code is defined
is mentioned and the program code dumping tools are explained. The chapter also documents
the development of the program for the application. This program has been termed as “Source
code”. Before we look at the source code we define the two header files that we have used in
the code.

Tools Used

56
Figure 4.1 Keil Software- internal stages

Keil development tools for the 8051 Microcontroller Architecture support every level
of software developer from the professional applications.

C51 Compiler & A51 Macro Assembler

Source files are created by the µVision IDE and are passed to the C51 Compiler or A51
Macro Assembler. The compiler and assembler process source files and create replaceable
object files.
The Keil C51 Compiler is a full ANSI implementation of the C programming language
that supports all standard features of the C language. In addition, numerous features for direct
support of the 8051 architecture have been added.

µVISION

µVision3 adds many new features to the Editor like Text Templates, Quick Function
Navigation, and Syntax Coloring with brace high lighting Configuration Wizard for dialog
based startup and debugger setup. µVision3 is fully compatible to µVision2 and can be used in
parallel with µVision2.

µVision3 is an IDE (Integrated Development Environment) that helps you write,


compile, and debug embedded programs. It encapsulates the following components:

 A project manager.
 A make facility.
 Tool configuration.
 Editor.
 A powerful debugger.
To help you get started, several example programs (located in the \C51\Examples,
\C251\Examples, \C166\Examples, and \ARM\...\Examples) are provided.

 HELLO is a simple program that prints the string "Hello World" using the Serial Interface.
 MEASURE is a data acquisition system for analog and digital systems.
 TRAFFIC is a traffic light controller with the RTX Tiny operating system.
 SIEVE is the SIEVE Benchmark.

57
 DHRY is the Dhrystone Benchmark.
 WHETS is the Single-Precision Whetstone Benchmark.
Additional example programs not listed here are provided for each device architecture.

BUILDING AN APPLICATION IN µVISION


To build (compile, assemble, and link) an application in µVision2, you must:
1. Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2).
2. Select Project - Rebuild all target files or Build target.
µVision2 compiles, assembles, and links the files in your project.

Creating Your Own Application in µVision2


To create a new project in µVision2, you must

1. Select Project - New Project.


2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device
Database™.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the source
files to the project.
6. Select Project - Options and set the tool options. Note when you select the target device from
the Device Database™ all special options are set automatically. You typically only need to
configure the memory map of your target hardware. Default memory model settings are
optimal for most applications.
7. Select Project - Rebuild all target files or Build target.
Debugging an Application in µVision2
To debug an application created using µVision2, you must:

1. Select Debug - Start/Stop Debug Session.


2. Use the Step toolbar buttons to single-step through your program. You may enter G, main in
the Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step, Go, Break, and so on.

Starting µVision2 and Creating a Project

58
µVision2 is a standard Windows application and started by clicking on the program icon. To
create a new project file select from the µVision2 menu

Project – New Project…. This opens a standard Windows dialog that asks you for the new
project file name.We suggest that you use a separate folder for each project. Youcan simply
usethe icon Create New Folder in this dialog to get a new empty folder. Thenselect this folder
and enter the file name for the new project, i.e. Project1.µVision2creates a new project file with
the name PROJECT1.UV2 which contains a default target and file group name. You can see
these names in the Project

Window – Files.
Now use from the menu Project – Select Device for Target and select a CPUfor your
project.The Select Device dialog box shows the µVision2 devicedatabase. Just select the
microcontroller you use. We are using for our examples the Philips 80C51RD+
CPU.Thisselection sets necessary tool options for the 80C51RD+ device and simplifies in this
way the tool Configuration

Building Projects and Creating a HEX Files


Typical, the tool settings under Options – Target are all you need to start a new
application. You may translate all source files and line the application with aclick on the Build
Target toolbar icon. When you build an application withsyntax errors, µVision2 will display
errors and warning messages in the Output Window – Build page. A double click on a message
line opens the source file on the correct location in a µVision2 editor window. Once you have
successfully generated your application you can start debugging.

After you have tested your application, it is required to create an Intel HEX file to
download the software into an EPROM programmer or simulator. µVision2 creates HEX files
with each build process when Create HEX files under Options for Target – Output is enabled.
You may start your PROM programming utility after the make process when you specify the
program under the option Run User Program #1.

CPU Simulation

59
µVision2 simulates up to 16 Mbytes of memory from which areas can be mapped for
read, write, or code execution access. The µVision2 simulator trapsand reports illegal memory
accesses.

In addition to memory mapping, the simulator also provides support for theintegrated
peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have
selected are configured from the Device

Database selection

You have made when you create your project target. Refer to page 58 for more
information about selecting a device. You may select and display the on-chip peripheral
components using the Debug menu. You can also change the aspects of each peripheral using
the controls in the dialog boxes.

Start Debugging

You start the debug mode of µVision2 with the Debug – Start/Stop DebugSession
command. Depending on the Options for Target – DebugConfiguration, µVision2 will load the
application program and run the startupcode µVision2 saves the editor screen layout and
restores the screen layout of the last debug session. If the program execution stops, µVision2
opens aneditor window with the source text or shows CPU instructions in the disassembly
window. The next executable statement is marked with a yellow arrow. During debugging,
most editor features are still available.

For example, you can use the find command or correct program errors. Program source
text of your application is shown in the same windows. The µVision2 debug mode differs from
the edit mode in the following aspects:

The “Debug Menu and Debug Commands” described below are available. The
additional debug windows are discussed in the following.
The project structure or tool parameters cannot be modified. All build Commands are
disabled.
Disassembly Window

The Disassembly window shows your target program as mixed source and assembly
program or just assembly code. A trace history of previously executed instructions may be

60
displayed with Debug – View Trace Records. To enable the trace history, set Debug –
Enable/Disable Trace Recording.

If you select the Disassembly Window as the active window all program step
commands work on CPU instruction level rather than program source lines. You can select a
text line and set or modify code breakpoints using toolbar buttons or the context menu
commands.

You may use the dialog Debug – Inline Assembly… to modify the CPU instructions.
That allows you to correct mistakes or to make temporary changes to the target program you
are debugging.

CODE DEVELOPMENT

1.Click on the Keil uVision Icon on Desktop.


2.The following fig will appear.

3.Click on the Project menu from the title bar.


4.Then Click on New Project.

61
5.Save the Project by typing suitable project name with no extension in u r own folder sited in
either C:\ or D:\

6.Then Click on Save button above.


7.Select the component for u r project. i.e. Atmel.
8.Click on the + Symbol beside of Atmel .

62
9.Select AT89C51 as shown below.

10.Then Click on “OK”.


11.The Following fig will appear.

63
12.Then Click either YES or NO………mostly “NO”
13.Now your project is ready to USE.
14.Now double click on the Target1, you would get another option “Source group 1” as shown
in next page.

15.Click on the file option from menu bar and select “new”.

64
16.The next screen will be as shown in next page, and just maximize it by double clicking on
its blue border.

17.Now start writing program in either in “C” or “ASM”.


18.For a program written in Assembly, then save it with extension “. asm” and for “C” based
program save it with extension “ .C”.

65
19.Now right click on Source group 1 and click on “Add files to Group Source”.

20.Now you will get another window, on which by default “C” files will appear.

66
21.Now select as per your file extension given while saving the file.
22.Click only one time on option “ADD”.
23.Now Press function key F7 to compile. Any error will appear if so happen.

24.If the file contains no error, then press Control+F5 simultaneously.


25.The new window is as follows

67
26.Then Click “OK”
27.Now Click on the Peripherals from menu bar, and check your required port as shown in fig
below

28.Drag the port a side and click in the program file.

68
29.Now keep Pressing function key “F11” slowly and observe.
30.You are running your program successfully.

Flash Magic
Features
 Straightforward and intuitive user interface.
 Five simple steps to erasing and programming a device and setting any options desired.
 Programs Intel Hex Files.
 Automatic verifying after programming.
 Fills unused flash to increase firmware security.
 Ability to automatically program checksums. Using the supplied checksum calculation
routine your firmware can easily verify the integrity of a Flash block, ensuring no
unauthorized or corrupted code can ever be executed.
 Program security bits.
 Check which Flash blocks are blank or in use with the ability to easily erase all blocks
in use.
 Read the device signature.
 Read any section of Flash and save as an Intel Hex File.
 Reprogram the Boot Vector and Status Byte with the help of confirmation features that
prevent accidentally programming incorrect values.

69
 Displays the contents of Flash in ASCII and Hexadecimal formats.
 Single-click access to the manual, Flash Magic home page and NXP Microcontrollers
home page.
 Ability to use high-speed serial communications on devices that support it. Flash Magic
calculates the highest baud rate that both the device and your PC can use and switches
to that baud rate transparently.
 Command Line interface allowing Flash Magic to be used in IDEs and Batch Files.
 Manual in PDF format.
 supports half-duplex communications.
 Verify Hex Files previously programmed.
 Save and open settings.
 Able to reset Rx2 and 66x devices (revision G or higher).
 Able to control the DTR and RTS RS232 signals when connected to RST and /PSEN to
place the device into Boot ROM and Execute modes automatically. An example circuit
diagram is included in the Manual. This is essential for ISP with target hardware that is
hard to access.
 This enables us to send commands to place the device in Boot ROM mode, with support
for command line interfaces. The installation includes an example project for the Keil
and Raisonance 8051 compilers that show how to build support for this feature into
applications.
 Able to play any Wave file when finished programming.
 Powerful, flexible Just In Time Code feature. Write your own JIT Modules to generate
last minute code for programming.
 Uses include

a) Serial number generation

b) Copy protection and copy authorization

c) Storing program date and time - manufacture date

d) Storing program operator and location

e) Lookup table generation

f) Language tables or language selection

g) Centralized record keeping

70
Requirements

Flash Magic works on any version of Windows, except Windows 95. 10Mb of
disk space is required. As mentioned earlier , we are automating two different routines in our
project and hence we used the method of polling to continuously monitor those tasks and act
accordingly.

BIBILOGRAPHY

1. WWW.MITEL.DATABOOK.COM
2. WWW.ATMEL.DATABOOK.COM
3. WWW.FRANKLIN.COM
4. WWW.KEIL.COM

APENDEX B
SAMPLE PROGRAMS
Example 1

71
org 00h // Starting Of The Program From 00h memory
back: mov P1,#55h //Move 55h to Port1
acall delay // Call Delay Function
mov P1,#0AAh //Move 55h to Port1
lcall delay // Call Delay Function
sjmp back
delay: mov r5,#30h
again: djnz r5,again // Generating delay
ret // Return Of Loop
end // End Of Program

Example 2
#include<reg51.h>
void delay(unsigned int); //Global Declaration Of Delay
void main()
{
P0=0x00; // Clearing Of Port O
while(1) //Infinite Loop
{
P0=0xAA;
delay(30);
P0=0x55;
delay(30);
}
}
void delay(unsigned int x) //Delay Main Function
{
unsignedinti,j;
for(i=0;i<=x;i++)

72
for(j=0;j<=1275;j++);
}

Example 3
#include<reg51.h>
sbit SWITCH=P1^0; // Input to P1.0
sbit LED =P2^5; // Out to P2.5
void main()
{
while(1) //Infinite Loop
{
if (SWITCH==0)
{
LED=1;
}
else
{
LED=0;
}
}
}

Example 4

#include<reg51.h>

73
unsigned char str[10]="MAGNI5"; // String Of Data
void main()
{
unsignedinti=0;
TMOD=0X20; // Timer1, Mode2
SCON=0X50; //1 Start Bit And 1 Stop Bit
TH1=-3; // Baud Rate 9600
TR1=1; //Start Timer 1
While(1)
{
for(i=0;i<10;i++)
{
SBUF=str[i];
while(TI==0); // Wait Data Till Bit Of Data
TI=0;
}
}

APENDEX C
SOURCE CODE

74
75

Das könnte Ihnen auch gefallen