0% found this document useful (0 votes)
25 views96 pages

4.implimentation of Obstacle Sensing Robo

The document details the implementation of an obstacle sensing robot using a microcontroller and infrared sensors for navigation and obstacle avoidance. It describes the hardware components, including the microcontroller AT89S52, and the software tools used for programming. The project aims to create an autonomous robotic vehicle capable of indoor navigation without human intervention, detecting obstacles within a range of 10 to 80 cm.

Uploaded by

Jaruknath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views96 pages

4.implimentation of Obstacle Sensing Robo

The document details the implementation of an obstacle sensing robot using a microcontroller and infrared sensors for navigation and obstacle avoidance. It describes the hardware components, including the microcontroller AT89S52, and the software tools used for programming. The project aims to create an autonomous robotic vehicle capable of indoor navigation without human intervention, detecting obstacles within a range of 10 to 80 cm.

Uploaded by

Jaruknath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 96

IMPLIMENTATION OF OBSTACLE SENSING ROBO

1. INTRODUCTION
 OBJECTIVE OF THE PROJECT
 BLOCK DIAGRAM

2. HARDWARE DESCRIPTION
 MICROCONTROLLER
 Led PANNEL
 POWER SUPPLY
 PRINTED CIRCUIT BOARD
 IR PAIRS

3. DESCRIPTION OF THE PROJECT


 CIRCUIT DESCRIPTION
SCHEMATIC DIAGRAM

 WORKING DESCRIPTION

4. SOFTWARE DESCRIPTION
 KEIL COMPILER
 PROGRAM
INTRODUCTION

An embedded system is a combination of software and hardware to perform a dedicated task.

An embedded system can be defined as a computing device that does a specific focused job. Appliances
such as the air-conditioner, VCD player, DVD player, printer, fax machine, mobile phone etc. are exampl
es of embedded systems. Each of these appliances will have a processor and special hardware to meet t
he specific requirement of the application along with the embedded software that is executed by the pr
ocessor for meeting that specific requirement. The embedded software is also called “firm ware”. The de
sktop/laptop computer is a general purpose computer. You can use it for a variety of applications such a
s playing games, word processing, accounting, software development and so on. In contrast, the softwar
e in the embedded systems is always fixed listed below:

· Embedded systems do a very specific task, they cannot be programmed to do different things. Embed
ded systems have very limited resources, particularly the memory. Generally, they do not have second
ary storage devices such as the CDROM or the floppy disk. Embedded systems have to work against so
me deadlines. A specific job has to be completed within a specific time. In some embedded systems, ca
lled real-time systems, the deadlines are stringent. Missing a deadline may cause a catastrophe-loss of
life or damage to property. Embedded systems are constrained for power. As many embedded system
s operate through a battery, the power consumption has to be very low.

· Some embedded systems have to operate in extreme environmental conditions such as very high tem
peratures and humidity.

Some of the main devices used in embedded products are Microprocessors and Microcontrollers.
Microprocessors are commonly referred8051
to as general purpose processors as they simply accept
the inputs, process it and give the output.
In contrast, a microcontroller not only accepts the data as inputs but also manipulates it,
interfaces the data with various devices, controls the data and thus finally gives the result.
All these tasks are possible with the microcontroller because the microcontroller has a CPU
in addition to a fixed amount of RAM, ROM, I/O ports and timer all on a single chip. This

IR
PAIRS
Reset circu BUZEER
it
Crystal MOTOR1
fixed amount of RAM, ROM and number of I/O ports in microcontroller makes them ideal
for many applications where cost and space are critical.

Driver
Circuit
MOTOR2
ABSTRACT
IMPLIMENTATION OF OBSTACLE SENSING ROBO

Nowadays, Wheeled Mobile Robots (WMRs) are built and the control system that used to
control them are made by Electronic Engineers. Depend on their desire design of WMR, Technic
ians made used of Microcontrollers as controlling machines and DC Motors for motion control.
Autonomous robotic vehicle guidance for indoor navigation has been developed for Mobile Indu
strial Robot model. The resulting design will navigate the environs in a building without the need
of human intervention.

The guidance system consists of infrared sensors for obstacle detection, range determinati
on and avoidance. It can detect the obstacles within the range 10 to 80 cm. This paper represents
mainly on software implementation of obstacle detection and avoidance system for Wheeled Mo
bile Robot. This system consists of infrared sensors and microcontroller. In this system three infr
ared sensors are used for left, front and right. In this robot system, the input signal is received fro
m sensor circuit and PIC is operated according to the received sensor’s signal. The infrared senso
r reading is taken and processed to avoid the obstacles. The 5V power supply is used to operate P
IC board and sensor circuit board. The obstacle avoidance algorithm is simply evaluated on PIC
16F877 microcontroller based mobile robot. The type of infrared sensor is GP2D12 distance mea
suring sensor. The desired goal of this system is to avoid obstacles along its path and to determin
e the distance.
BridgeRectifier
Step
FilterCircuit
DownTra
nsformer

2. HARDWARE DESCRIPTION

MICROCONTROLLERS:

Microprocessors and microcontrollers are widely used in embedded systems


products. Microcontroller is a programmable device. A microcontroller has a CPU in addition to
a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed
amount of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal
for many applications in which cost and space are critical.
The Intel 8051 is a Harvard architecture, single chip microcontroller (µC) which was
developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early
1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-
compatible processor cores that are manufactured by more than 20 independent manufacturers
including Atmel, Infineon Technologies and Maxim Integrated Products.

8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a
time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. 8051
is available in different memory types such as UV-EPROM, Flash and NV-RAM.

The microcontroller used in this project is AT89S52. Atmel Corporation introduced this
89S52 microcontroller. This microcontroller belongs to 8051 family. This microcontroller had
256 bytes of RAM, 8K bytes of on-chip ROM, two timers, one serial port and four ports (each 8-
bits wide) all on a single chip.

The present project is implemented on Keil Uvision. In order to program the device,
Proload tool has been used to burn the program onto the microcontroller.

The features, pin description of the microcontroller and the software tools used are
discussed in the following sections.

Microprocessors and microcontrollers are widely used in embedded systems products.


Microcontroller is a programmable device. A microcontroller has a CPU in addition to a fixed
amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed amount
of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal for many
applications in which cost and space are critical.

The Intel 8051 is Harvard architecture, single chip microcontroller (µC) which was
developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early
1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-
compatible processor cores that are manufactured by more than 20 independent manufacturers
including Atmel, Infineon Technologies and Maxim Integrated Products.

8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a
time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. 8051
is available in different memory types such as UV-EPROM, Flash and NV-RAM.

The present project is implemented on Keil Uvision. In order to program the device,
Proload tool has been used to burn the program onto the microcontroller.

The features, pin description of the microcontroller and the software tools used are
discussed in the following sections.
FEATURES OF AT89s52:

 8K Bytes of Re-programmable Flash Memory.


 RAM is 256 bytes.
 4.0V to 5.5V Operating Range.
 Fully Static Operation: 0 Hz to 33 MHz’s
 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.
 Fast programming time.
 Flexible ISP programming (byte and page mode).

Description:

The AT89s52 is a low-voltage, high-performance CMOS 8-bit microcomputer with 8K bytes of


Flash programmable memory. The device is manufactured using Atmel’s high density
nonvolatile memory technology and is compatible with the industry-standard MCS-51
instruction set. The on chip flash allows the program memory to be reprogrammed in system or
by a conventional non volatile memory programmer. 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.
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.

Fig: Pin diagram


Fig: Block diagram
PIN DESCRIPTION:

Vcc Pin 40 provides supply voltage to the chip. The voltage source is +5V.

GND Pin 20 is the ground.

Port 0

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

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

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. The port 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 receives some control signals for
Flash programming and verification.

Port 3 also serves the functions of various special features of the AT89S52, as shown in the
following table.
RST

Reset input. A high on this pin for two machine cycles while the oscillator is running resets the
device. This pin drives high for 98 oscillator periods after the Watchdog times out. The DISRTO
bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit
DISRTO, the RESET HIGH out feature is enabled.

ALE/PROG

Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during
accesses 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 purposes. Note, however, that one ALE pulse is skipped
during each access to external data memory.

If desired, ALE operation can be 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.
PSEN

Program Store Enable (PSEN) is the read strobe to external program memory. When the
AT89S52 is executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to external data
memory.

EA/VPP

External Access Enable:

EA must be strapped to GND in order to enable the device to fetch code from external program
memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is
programmed, EA will be internally latched on reset.

EA should be strapped to VCC for internal program executions. This pin also receives the 12-
volt programming enable voltage (VPP) during Flash programming.

XTAL1

Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

XTAL2

Output from the inverting oscillator amplifier.

Oscillator Connections

C1, C2 = 30 pF ± 10 pF for Crystals

= 40 pF ± 10 pF for Ceramic Resonators


External Clock Drive Configuration

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be
configured for use as an on-chip oscillator. Either a quartz crystal or ceramic resonator may be
used. To drive the device from an external clock source, XTAL2 should be left unconnected
while XTAL1 is driven. There are no requirements on the duty cycle of the external clock signal,
since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but
minimum and maximum voltage high and low time specifications must be observed.
Special Function Registers

A map of the on-chip memory area called the Special Function Register (SFR) space is shown in
the following table.

It should be noted that not all of the addresses are occupied and unoccupied addresses may not
be implemented on the chip. Read accesses to these addresses will in general return random data,
and write accesses will have an indeterminate effect.

User software should not write 1s to these unlisted locations, since they may be used in future
products to invoke new features. In that case, the reset or inactive values of the new bits will
always be 0.

Timer 2 Registers:

Control and status bits are contained in registers T2CON and T2MOD for Timer 2. The register
pair (RCAP2H, RCAP2L) is the Capture/Reload register for Timer 2 in 16-bit capture mode or
16-bit auto-reload mode.

Interrupt Registers:

The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the
six interrupt sources in the IP register.
Dual Data Pointer Registers:

To facilitate accessing both internal and external data memory, two banks of 16-bit Data Pointer
Registers are provided: DP0 at SFR address locations 82H-83H and DP1 at 84H and 85H. Bit
DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1. The user should ALWAYS
initialize the DPS bit to the appropriate value before accessing the respective Data Pointer
Register.

Power Off Flag:

The Power Off Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR. POF is set to “1”
during power up. It can be set and rest under software control and is not affected by reset.
Memory Organization

MCS-51 devices have a separate address space for Program and Data Memory. Up to 64K bytes
each of external Program and Data Memory can be addressed.

Program Memory

If the EA pin is connected to GND, all program fetches are directed to external memory. On the
AT89S52, if EA is connected to VCC, program fetches to addresses 0000H through 1FFFH are
directed to internal memory and fetches to addresses 2000H through FFFFH are to external
memory.

Data Memory

The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel
address space to the Special Function Registers. This means that the upper 128 bytes have the
same addresses as the SFR space but are physically separate from SFR space.

When an instruction accesses an internal location above address 7FH, the address mode used in
the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR
space. Instructions which use direct addressing access the SFR space.
For example, the following direct addressing instruction accesses the SFR at location 0A0H
(which is P2).

MOV 0A0H, #data

Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, the
following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at
address 0A0H, rather than P2 (whose address is 0A0H).

MOV @R0, #data

Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data
RAM are available as stack space.

Watchdog Timer (One-time Enabled with Reset-out)


The WDT is intended as a recovery method in situations where the CPU may be subjected to
software upsets. The WDT consists of a 14-bit counter and the Watchdog Timer Reset
(WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a
user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H).

When the WDT is enabled, it will increment every machine cycle while the oscillator is running.
The WDT timeout period is dependent on the external clock frequency. There is no way to
disable the WDT except through reset (either hardware reset or WDT overflow reset). When
WDT overflows, it will drive an output RESET HIGH pulse at the RST pin.

Using the WDT


To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST
register (SFR location 0A6H). When the WDT is enabled, the user needs to service it by writing
01EH and 0E1H to WDTRST to avoid a WDT overflow. The 14-bit counter overflows when it
reaches 16383 (3FFFH), and this will reset the device. When the WDT is enabled, it will
increment every machine cycle while the oscillator is running. This means the user must reset the
WDT at least every 16383 machine cycles.

To reset the WDT the user must write 01EH and 0E1H to WDTRST. WDTRST is a
write-only register. The WDT counter cannot be read or written. When WDT overflows, it will
generate an output RESET pulse at the RST pin. The RESET pulse duration is 98xTOSC, where
TOSC = 1/FOSC. To make the best use of the WDT, it should be serviced in those sections of
code that will periodically be executed within the time required to prevent a WDT reset.

WDT during Power-down and Idle

In Power-down mode the oscillator stops, which means the WDT also stops. While in Power
down mode, the user does not need to service the WDT. There are two methods of exiting
Power-down mode: by a hardware reset or via a level-activated external interrupt which is
enabled prior to entering Power-down mode. When Power-down is exited with hardware reset,
servicing the WDT should occur as it normally does whenever the AT89S52 is reset. Exiting
Power-down with an interrupt is significantly different.

The interrupt is held low long enough for the oscillator to stabilize. When the interrupt is brought
high, the interrupt is serviced. To prevent the WDT from resetting the device while the interrupt
pin is held low, the WDT is not started until the interrupt is pulled high. It is suggested that the
WDT be reset during the interrupt service for the interrupt used to exit Power-down mode.

To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best
to reset the WDT just before entering Power-down mode.
Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whether
the WDT continues to count if enabled. The WDT keeps counting during IDLE (WDIDLE bit =
0) as the default state. To prevent the WDT from resetting the AT89S52 while in IDLE mode,
the user should always set up a timer that will periodically exit IDLE, service the WDT, and
reenter IDLE mode. With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and
resumes the count upon exit from IDLE.

UART

The Atmel 80C51 Microcontrollers implement three general purpose, 16-bit timers/ counters. They are i
dentified as Timer 0, Timer 1 and Timer 2 and can be independently configured to operate in a variety of
modes as a timer or as an event counter. When operating as a timer, the timer/counter runs for a progra
mmed length of time and then issues an interrupt request. When operating as a counter, the timer/coun
ter counts negative transitions on an external pin. After a preset number of counts, the counter issues a
n interrupt request. The various operating modes of each timer/counter are described in the following s
ections.

A basic operation consists of timer registers THx and TLx (x= 0, 1) connected in cascade

to form a 16-bit timer. Setting the run control bit (TRx) in TCON register turns the timer on by allowing th
e selected input to increment TLx. When TLx overflows it increments THx; when THx overflows it sets th
e timer overflow flag (TFx) in TCON register. Setting the TRx does not clear the THx and TLx timer register
s. Timer registers can be accessed to obtain the current count or to enter preset values. They can be rea
d at any time but TRx bit must be cleared to preset their values, otherwise the behavior of the timer/cou
nter is unpredictable.

The C/Tx# control bit (in TCON register) selects timer operation, or counter operation, by selecting the di
vided-down peripheral clock or external pin Tx as the source for the counted signal. TRx bit must be clea
red when changing the mode of operation, otherwise the behavior of the timer/counter is unpredictable
For timer operation (C/Tx# = 0), the timer register counts the divided-down peripheral clock. The timer r
egister is incremented once every peripheral cycle (6 peripheral clock periods). The timer clock rate is FP
ER / 6, i.e. FOSC / 12 in standard mode or FOSC / 6 in X2 mode. For counter operation (C/Tx# = 1), the ti
mer register counts the negative transitions on the Tx external input pin. The external input is sampled e
very peripheral cycle. When the sample is high in one cycle and low in the next one, the counter is incre
mented.

Since it takes 2 cycles (12 peripheral clock periods) to recognize a negative transition,

the maximum count rate is FPER / 12, i.e. FOSC / 24 in standard mode or FOSC / 12 in X2 mode. There ar
e no restrictions on the duty cycle of the external input signal, but to

ensure that a given level is sampled at least once before it changes, it should be held for

at least one full peripheral cycle. In addition to the “timer” or “counter” selection, Timer 0 and Timer 1 h
ave four operating modes from which to select which are selected by bit-pairs (M1, M0) in TMOD. Mode
s 0, 1and 2 are the same for both timer/counters. Mode 3 is different.

The four operating modes are described below. Timer 2, has three modes of operation: ‘capture’, ‘auto-r
eload’ and ‘baud rate generator’.

Timer 0

Timer 0 functions as either a timer or event counter in four modes of operation. Timer 0 is controlled by
the four lower bits of the TMOD register and bits 0, 1, 4 and 5 of the TCON register. TMOD register selec
ts the method of timer gating (GATE0), timer or counter operation (T/C0#) and mode of operation (M10
and M00). The TCON register provides timer 0 control functions: overflow flag (TF0), run control bit (TR
0), interrupt flag (IE0) and interrupt type control bit (IT0).

For normal timer operation (GATE0= 0), setting TR0 allows TL0 to be incremented by the selected input.
Setting GATE0 and TR0 allows external pin INT0# to control timer

operation.

Timer 0 overflow (count rolls over from all 1s to all 0s) sets TF0 flag, generating an interrupt request. It is
important to stop timer/counter before changing mode.

Mode 0 (13-bit Timer)

Mode 0 configures timer 0 as a 13-bit timer which is set up as an 8-bit timer (TH0 register) with a modul
o 32 prescaler implemented with the lower five bits of the TL0 register. The upper three bits of TL0 regis
ter are indeterminate and should be ignored. Prescaler overflow increments the TH0 register.

As the count rolls over from all 1’s to all 0’s, it sets the timer interrupt flag TF0. The counted input is ena
bled to the Timer when TR0 = 1 and either GATE = 0 or INT0 = 1. (Setting GATE = 1 allows the Timer to be
controlled by external input INT0, to facilitate pulse width measurements). TR0 is a control bit in the Spe
cial Function register TCON. GATE is in TMOD.

The 13-bit register consists of all 8 bits of TH0 and the lower 5 bits of TL0. The upper 3

bits of TL0 are indeterminate and should be ignored. Setting the run flag (TR0) does not

clear the registers.

Mode 0 operation is the same for Timer 0 as for Timer 1. There are two different GATE bits, one for Time
r 1 (TMOD.7) and one for Timer 0 (TMOD.3).

Timer/Counter x (x = 0 or 1) in Mode 0

Mode 1 (16-bit Timer)

Mode 1 is the same as Mode 0, except that the Timer register is being run with all 16 bits. Mode 1 config
ures timer 0 as a 16-bit timer with the TH0 and TL0 registers connected in cascade. The selected input in
crements the TL0 register.

Timer/Counter x (x = 0 or 1) in Mode 1
Mode 2 (8-bit Timer with Auto-Reload)

Mode 2 configures timer 0 as an 8-bit timer (TL0 register) that automatically reloads from the TH0 regist
er. TL0 overflow sets TF0 flag in the TCON register and reloads TL0 with the contents of TH0, which is pre
set by software.

When the interrupt request is serviced, hardware clears TF0. The reload leaves TH0 unchanged. The next
reload value may be changed at any time by writing it to the TH0 register. Mode 2 operation is the same
for Timer/Counter 1.

Timer/Counter x (x = 0 or 1) in Mode 2

Mode 3 (Two 8-bit Timers)

Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. This mode is p
rovided for applications requiring an additional 8-bit timer or counter. TL0 uses the timer 0 control bits C
/T0# and GATE0 in the TMOD register, and TR0 and TF0 in the TCON register in the normal manner. TH0
is locked into a timer function (counting FPER /6) and takes over use of the timer 1 interrupt (TF1) and ru
n control (TR1) bits. Thus, operation of timer 1 is restricted when timer 0 is in mode 3.

Timer/Counter 0 in Mode 3: Two 8-bit Counters

Timer 1

Timer 1 is identical to timer 0, except for mode 3, which is a hold-count mode. The following comments
help to understand the differences:

• Timer 1 functions as either a timer or event counter in three modes of operation. Timer

1’s mode 3 is a hold-count mode.

• Timer 1 is controlled by the four high-order bits of the TMOD register and bits 2, 3, 6 and 7 of the TCO
N register. The TMOD register selects the method of timer gating (GATE1), timer or counter operation (C
/T1#) and mode of operation (M11 and M01). The TCON register provides timer 1 control functions: ove
rflow flag (TF1), run control bit (TR1), interrupt flag (IE1) and interrupt type control bit (IT1).

• Timer 1 can serve as the baud rate generator for the serial port. Mode 2 is best suited for this purpose.

• For normal timer operation (GATE1 = 0), setting TR1 allows TL1 to be incremented by the selected inpu
t. Setting GATE1 and TR1 allows external pin INT1# to control timer operation.

• Timer 1 overflow (count rolls over from all 1s to all 0s) sets the TF1 flag generating an interrupt reques
t.

• When timer 0 is in mode 3, it uses timer 1’s overflow flag (TF1) and run control bit (TR1). For this situa
tion, use timer 1 only for applications that do not require an interrupt (such as a baud rate generator for
the serial port) and switch timer 1 in and out of mode 3 to turn it off and on.

• It is important to stop timer/counter before changing modes.

Mode 0 (13-bit Timer)

Mode 0 configures Timer 1 as a 13-bit timer, which is set up as an 8-bit timer (TH1 register) with a modul
o-32 prescaler implemented with the lower 5 bits of the TL1 register. The upper 3 bits of the TL1 register
are ignored. Prescaler overflow increments the TH1 register.

Mode 1 (16-bit Timer)

Mode 1 configures Timer 1 as a 16-bit timer with the TH1 and TL1 registers connected

in cascade. The selected input increments the TL1 register.

Mode 2 (8-bit Timer with Auto Reload)

Mode 2 configures Timer 1 as an 8-bit timer (TL1 register) with automatic reload from

the TH1 register on overflow. TL1 overflow sets the TF1 flag in the TCON register and reloads TL1 with th
e contents of TH1, which is preset by software. The reload leaves TH1 unchanged.

Mode 3 (Halt)

Placing Timer 1 in mode 3 causes it to halt and hold its count. This can be used to halt

Timer 1 when TR1 run control bit is not available i.e., when Timer 0 is in mode 3.
Timer 2

Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The type of op
eration is selected by bit C/T2 in the SFR T2CON (shown in Table 5-2). Timer 2 has three operating mode
s: capture, auto-reload (up or down counting), and baud rate generator. The modes are selected by bits i
n T2CON, as shown in Table 10-1. Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer functi
on, the TL2 register is incremented every machine cycle. Since a machine cycle consists of 12 oscillator p
eriods, the count rate is 1/12 of the oscillator frequency.
In the Counter function, the register is incremented in response to a 1-to-0 transition at its
corresponding external input pin, T2. In this function, the external input is sampled during S5P2
of every machine cycle. When the samples show a high in one cycle and a low in the next cycle,
the count is incremented. The new count value appears in the register during S3P1 of the cycle
following the one in which the transition was detected. Since two machine cycles (24 oscillator
periods) are required to recognize a 1-to-0 transition, the maximum count rate is 1/24 of the
oscillator frequency. To ensure that a given level is sampled at least once before it changes, the
level should be held for at least one full machine cycle.

Capture Mode

In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2
is a 16-bit timer or counter which upon overflow sets bit TF2 in T2CON. This bit can then be
used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0
transition at external input T2EX also causes the current value in TH2 and TL2 to be captured
into RCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 in
T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt.
Timer in Capture Mode

Auto-reload (Up or Down Counter)

Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This f
eature is invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD. Upon reset, the DC
EN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or dow
n, depending on the value of the T2EX pin.

T2MOD – Timer 2 Mode Control Register


The above figure shows Timer 2 automatically counting up when DCEN = 0. In this mode, two
options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and
then sets the TF2 bit upon overflow. The overflow also causes the timer registers to be reloaded
with the 16-bit value in RCAP2H and RCAP2L. The values in Timer in Capture ModeRCAP2H
and RCAP2L are preset by software. If EXEN2 = 1, a 16-bit reload can be triggered either by an
overflow or by a 1-to-0 transition at external input T2EX. This transition also sets the EXF2 bit.
Both the TF2 and EXF2 bits can generate an interrupt if enabled.

Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 10-2. In this
mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count
up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16-bit
value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2,
respectively.

A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal
the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH
to be reloaded into the timer registers.

The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit
of resolution. In this operating mode, EXF2 does not flag an interrupt.
Baud Rate Generator

Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON. Note
that the baud rates for transmit and receive can be different if Timer 2 is used for the receiver or
transmitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK puts Timer 2
into its baud rate generator mode.

The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2 causes
the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L,
which are preset by software.

The baud rates in Modes 1 and 3 are determined by Timer 2’s overflow rate according to the
following equation.
The Timer can be configured for either timer or counter operation. In most applications, it is
configured for timer operation (CP/T2 = 0). The timer operation is different for Timer 2 when it
is used as a baud rate generator. Normally, as a timer, it increments every machine cycle (at 1/12
the oscillator frequency). As a baud rate generator, however, it increments every state time (at
1/2 the oscillator frequency). The baud rate formula is given below.

Where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsigned
integer.

Timer 2 as a baud rate generator is shown in the below figure. This figure is valid only if RCLK
or TCLK = 1 in T2CON. Note that a rollover in TH2 does not set TF2 and will not generate an
interrupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX will set EXF2 but will not
cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus, when Timer 2 is in use as a baud
rate generator, T2EX can be used as an extra external interrupt.

Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator mode, TH2 or
TL2 should not be read from or written to. Under these conditions, the Timer is incremented
every state time, and the results of a read or write may not be accurate. The RCAP2 registers
may be read but should not be written to, because a write might overlap a reload and cause write
and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or
RCAP2 registers.
Timer 2 in Baud Rate Generator Mode
Programmable Clock Out

A 50% duty cycle clock can be programmed to come out on P1.0, as shown in the below figure.
This pin, besides being a regular I/O pin, has two alternate functions. It can be programmed to
input the external clock for Timer/Counter 2 or to output a 50% duty cycle clock ranging from
61 Hz to 4 MHz (for a 16-MHz operating frequency).

Timer 2 in Clock-Out Mode

To configure the Timer/Counter 2 as a clock generator, bit C/T2 (T2CON.1) must be cleared and
bit T2OE (T2MOD.1) must be set. Bit TR2 (T2CON.2) starts and stops the timer. The clock-out
frequency depends on the oscillator frequency and the reload value of Timer 2 capture registers
(RCAP2H, RCAP2L), as shown in the following equation.
In the clock-out mode, Timer 2 roll-overs will not generate an interrupt. This behavior is similar
to when Timer 2 is used as a baud-rate generator. It is possible to use Timer 2 as a baud-rate
generator and a clock generator simultaneously. Note, however, that the baud rate and clock-out
frequencies cannot be determined independently from one another since they both use RCAP2H
and RCAP2L.

Interrupts

The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three
timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. These interrupts are all shown
in Figure 13-1.

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 13-1 shows that bit position IE.6 is unimplemented. User
software should not write a 1 to this bit position, since it 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.
Idle Mode

In idle mode, the CPU puts itself to sleep while all the on-chip peripherals remain active. The
mode is invoked by software. The content of the on-chip RAM and all the special functions
registers remain unchanged during this mode. The idle mode can be terminated by any enabled
interrupt or by a hardware reset.

Note that when idle mode is terminated by a hardware reset, the device normally resumes
program execution from where it left off, up to two machine cycles before the internal reset
algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but
access to the port pins is not inhibited. To eliminate the possibility of an unexpected write to a
port pin when idle mode is terminated by a reset, the instruction following the one that invokes
idle mode should not write to a port pin or to external memory.

Power-down Mode

In the Power-down mode, the oscillator is stopped, and the instruction that invokes Power-down
is the last instruction executed. The on-chip RAM and Special Function Registers retain their
values until the Power-down mode is terminated. Exit from Power down mode can be initiated
either by a hardware reset or by an enabled external interrupt. Reset redefines the SFRs but does
not change the on-chip RAM. The reset should not be activated before VCC is restored to its
normal operating level and must be held active long enough to allow the oscillator to restart and
stabilize.

Status of External Pins During Idle and Power-down Modes

Program Memory Lock Bits


The AT89S52 has three lock bits that can be left un programmed (U) or can be programmed (P) to obtain
the additional features listed in the table.

Lock Bit Protection Modes

When lock bit 1 is programmed, the logic level at the EA pin is sampled and latched during reset. If the d
evice is powered up without a reset, the latch initializes to a random value and holds that value until res
et is activated. The latched value of EA must agree with the current logic level at that pin in order for the
device to function properly.

Programming the Flash – Parallel Mode

The AT89S52 is shipped with the on-chip Flash memory array ready to be programmed. The programmin
g interface needs a high-voltage (12-volt) program enable signal and is compatible with conventional thir
d-party Flash or EPROM programmers.

The AT89S52 code memory array is programmed byte-by-byte.

Programming Algorithm:

Before programming the AT89S52, the address, data, and control signals should be set up according to t
he “Flash Programming Modes”. To program the AT89S52, take the following steps:
1. Input the desired memory location on the address lines.

2. Input the appropriate data byte on the data lines.

3. Activate the correct combination of control signals.

4. Raise EA/VPP to 12V.

5. Pulse ALE/PROG once to program a byte in the Flash array or the lock bits. The byte write
cycle is self-timed and typically takes no more than 50 µs. Repeat steps 1 through 5, changing
the address and data for the entire array or until the end of the object file is reached.
Data Polling:

The AT89S52 features Data Polling to indicate the end of a byte write cycle. During a write
cycle, an attempted read of the last byte written will result in the complement of the written data
on P0.7. Once the write cycle has been completed, true data is valid on all outputs, and the next
cycle may begin. Data Polling may begin any time after a write cycle has been initiated.

Ready/Busy:

The progress of byte programming can also be monitored by the RDY/BSY output signal. P3.0 is
pulled low after ALE goes high during programming to indicate BUSY. P3.0 is pulled high again
when programming is done to indicate READY.

Program Verify:

If lock bits LB1 and LB2 have not been programmed, the programmed code data can be read
back via the address and data lines for verification. The status of the individual lock bits can be
verified directly by reading them back.

Reading the Signature Bytes:

The signature bytes are read by the same procedure as a normal verification of locations 000H,
100H, and 200H, except that P3.6 and P3.7 must be pulled to a logic low. The values returned
are as follows.

(000H) = 1EH indicates manufactured by Atmel

(100H) = 52H indicates AT89S52

(200H) = 06H

Chip Erase:

In the parallel programming mode, a chip erase operation is initiated by using the proper
combination of control signals and by pulsing ALE/PROG low for a duration of 200 ns - 500 ns.
In the serial programming mode, a chip erase operation is initiated by issuing the Chip Erase
instruction. In this mode, chip erase is self-timed and takes about 500 ms. During chip erase, a
serial read from any address location will return 00H at the data output.

Programming the Flash – Serial Mode

The Code memory array can be programmed using the serial ISP interface while RST is pulled to
VCC. The serial interface consists of pins SCK, MOSI (input) and MISO (output). After RST is
set high, the Programming Enable instruction needs to be executed first before other operations
can be executed. Before a reprogramming sequence can occur, a Chip Erase operation is
required.

The Chip Erase operation turns the content of every memory location in the Code array into
FFH. Either an external system clock can be supplied at pin XTAL1 or a crystal needs to be
connected across pins XTAL1 and XTAL2. The maximum serial clock (SCK) frequency should
be less than 1/16 of the crystal frequency. With a 33 MHz oscillator clock, the maximum SCK
frequency is 2 MHz.

Serial Programming Algorithm

To program and verify the AT89S52 in the serial programming mode, the following sequence is
recommended:

1. Power-up sequence:

a. Apply power between VCC and GND pins.

b. Set RST pin to “H”.

If a crystal is not connected across pins XTAL1 and XTAL2, apply a 3 MHz to 33 MHz clock to
XTAL1 pin and wait for at least 10 milliseconds.
2. Enable serial programming by sending the Programming Enable serial instruction to
pin MOSI/P1.5. The frequency of the shift clock supplied at pin SCK/P1.7 needs to be less
than the CPU clock at XTAL1 divided by 16.

3. The Code array is programmed one byte at a time in either the Byte or Page mode. The write
cycle is self-timed and typically takes less than 0.5 ms at 5V.

4. Any memory location can be verified by using the Read instruction which returns the content
at the selected address at serial output MISO/P1.6.

5. At the end of a programming session, RST can be set low to commence normal device
operation.

Power-off sequence (if needed):

1. Set XTAL1 to “L” (if a crystal is not used).

2. Set RST to “L”.

3. Turn VCC power off.

Data Polling:

The Data Polling feature is also available in the serial mode. In this mode, during a write cycle
an attempted read of the last byte written will result in the complement of the MSB of the serial
output byte on MISO.

Serial Programming Instruction Set

The Instruction Set for Serial Programming follows a 4-byte protocol and is shown in the table
given below.
Serial Programming Instruction Set

Programming Interface – Parallel Mode

Every code byte in the Flash array can be programmed by using the appropriate combination of control s
ignals. The write operation cycle is self-timed and once initiated, will automatically time itself to comple
tion.
Flash Programming Modes
After Reset signal is high, SCK should be low for at least 64 system clocks before it goes high to
clock in the enable data bytes. No pulsing of Reset signal is necessary. SCK should be no faster
than 1/16 of the system clock at XTAL1.

For Page Read/Write, the data always starts from byte 0 to 255. After the command byte and
upper address byte are latched, each byte thereafter is treated as data until all 256 bytes are
shifted in/out. Then the next instruction will be ready to be decoded.

LIGHT EMITING DIODES

It is a semiconductor diode having radioactive recombination .


It requires a definite amount of energy to generate an electron-hole pair.

The same energy is released when an electron recombines with a hole. This releas
ed energy may result in the emission of photon and such a recombination. Hear t
he amount of energy released when the electro reverts from the conduction band
to the valence band appears in the form of radiation. Alternatively the released e
nergy may result in a series of phonons causing lattice vibration. Finally the releas
ed energy may be transferred to another electron. The recombination radiation m
ay be lie in the infra-red and visible light spectrum. In forward is peaked around t
he band gap energy and the phenomenon is called injection luminescence. I n a ju
nction biased in the avalanche break down region , there results a spectrum of ph
otons carrying much higher energies . Almost White light then gets emitted from
micro-plasma breakdown region in silicon junction. Diodes having radioactive rec
ombination are termed as Light Emitting Diode , abbreviated as LEDs.

In gallium arsenide diode , recombination is predominantly a radiation reco


mbination and the probability of this radioactive recombination far exceeds that i
n either germanium or silicon . Hence GaAs LED has much higher efficiency in ter
ms of

Photons emitted per carrier. The internal efficiency of GaAs LED may ba very close
to 100% but because of high index of refraction, only a small fraction of the intern
al radiation can usually come out of the device surface. In spite of this low efficie
ncy of actually radiated light , these LEDs are efficiency used as light emitters in vis
ual display units and in optically coupled circuits, The efficiency of light generation
increases with the increase of injected current and with decreases in temperatur
e. The light so generated is concentrated near the junction since most of the char
ge carriers are obtained within one diffusion length of the diode junction.

The following are the merits of LEDs over conventional incandescent and
other types of lamps

1. Low working voltages and currents


2. Less power consumption
3. Very fast action
4. Emission of monochromatic light
5. small size and weight
6. No effect of mechanical vibrations
7. Extremely long life
Typical LED uses a forward voltage of about 2V and current of 5 to 10mA.

GaAs LED produces infra-red light while red, green and orange lights are produced by gallium arsenid
e phosphide (GaAs) and gallium phosphide(Gap) .

Light Emitting Diodes (LEDs)


Example: Circuit symbol:

Function

LEDs emit light when an electric current passes through them.

Connecting and soldering

LEDs must be connected the correct way round, the diagram may be labelled a or + for anode an
d k or - for cathode (yes, it really is k, not c, for cathode!). The cathode is the short lead and there may b
e a slight flat on the body of round LEDs. If you can see inside the LED t he cathode
is the larger electrode (but this is not an official identification method).

LEDs can be damaged by heat when soldering, but the risk is s mall unless
you are very slow. No special precautions are needed for soldering most LEDs.

Testing an LED

Never connect an LED directly to a battery or power supply!


It will be destroyed almost instantly because too much current will pass through and burn it out. LEDs m
ust have a resistor in series to limit the current to a safe value, for quick testing purposes a 1k resistor i
s suitable for most LEDs if your supply voltage is 12V or less. Remember to connect the LED the correct
way round!

Colours of LEDs

LEDs are available in red, orange, amber, yellow, green, blue and white. Blue and white LEDs are much
more expensive than the other colours.
The colour of an LED is determined by the se micon
ductor material, not by the colouring of the 'packa
ge' (the plastic body). LEDs of all colours are availab
le in uncoloured packages which may be diff used
(milky) or clear (often described as 'water cl ear'). T
he coloured packages are also available as di ffused
(the standard type) or transparent.

Tri-colour LEDs

The most popular type of tri-colour LED has a red and a green LED combined in one package wit
h three leads. They are called tri-colour because mixed red and green light appears to be yellow and this
is produced when both the red and green LEDs are on.

The diagram shows the construction of a tri-colour LED. Note the different lengths of the three l
eads. The centre lead (k) is the common cathode for both LEDs, the outer leads (a1 and a2) are the anod
es to the LEDs allowing each one to be lit separately, or both together to give the third colour.

Bi-colour LEDs

A bi-colour LED has two LEDs wired in 'inverse parallel' (one forwards, one backwards) combined in one
package with two leads. Only one of the LEDs can be lit at one time and they are less useful than the tri-
colour LEDs described above.
Sizes, Shapes and Viewing angles of LEDs

LEDs are available in a wide variety of sizes and shapes. The 'standard'
LED has a round cross-section of 5mm diameter and this is probably the best ty
pe for general use, but 3mm round LEDs are also popular.

Round cross-section LEDs are frequently used and they are very easy to LED Clip

install on boxes by drilling a hole of the LED diameter, adding a spot of glue will Photograph © Rapid Electronics
help to hold the LED if necessary. LED clips are also available to secure LEDs in holes. Other cross-section
shapes include square, rectangular and triangular.

As well as a variety of colours, sizes and shapes, LEDs also vary in their viewing angle. This tells y
ou how much the beam of light spreads out. Standard LEDs have a viewing angle of 60° but others have
a narrow beam of 30° or less. Rapid Electronics stock a wide selection of LEDs and their catalogue is a go
od guidetotherangeavailable.

Calculating an LED resistor value

An LED must have a resistor connected in series to limit the current through the LED, otherwise it will bu
rn out almost instantly.

The resistor value, R is given by


R = (VS - VL) / I

VS = supply voltage
VL = LED voltage (usually 2V, but 4V for blue and white LEDs)
I = LED current (e.g. 20mA), this must be less than the maximum permitted

If the calculated value is not available choose the nearest standard resistor value which is greate
r, so that the current will be a little less than you chose. In fact you may wish to choose a greater resistor
value to reduce the current (to increase battery life for example) but this will make the LED less bright.

. Working out the LED resistor formula using Ohm's law

Ohm's law says that the resistance of the resistor, R = V/I,

where:
V = voltage across the resistor (= VS - VL in this case)

I = the current through the resistor

So R = (VS - VL) / I

Connecting LEDs in series

If you wish to have several LEDs on at the same time it may be possible to connect them in serie
s. This prolongs battery life by lighting several LEDs with the same current as just one LED.

All the LEDs connected in series pass the same current so it is best if they are all the same type.
The power supply must have sufficient voltage to provide about 2V for each LED (4V for blue and white)
plus at least another 2V for the resistor. To work out a value for the resistor you must add up all the LED
voltages and use this for VL.

Avoid connecting LEDs in parallel!


Connecting several LEDs in parallel with just one resistor shared between them is generally not a
good idea.

If the LEDs require slightly different voltages only the lowest voltage LED will light and it may be
destroyed by the larger current flowing through it. Although identical LEDs can be successfully connecte
d in parallel with one resistor this rarely offers any useful benefit because resistors are very cheap and th
e current used is the same as connecting the LEDs individually.

POWER SUPPLY:

The input to the circuit is applied from the regulated power supply. The a.c. input i.e., 230V from
the mains supply is step down by the transformer to 12V and is fed to a rectifier. The output
obtained from the rectifier is a pulsating d.c voltage. So in order to get a pure d.c voltage, the
output voltage from the rectifier is fed to a filter to remove any a.c components present even after
rectification. Now, this voltage is given to a voltage regulator to obtain a pure constant dc
voltage.

230V AC D.C

50Hz Output
Step down Bridge
transformer Rectifier Regulator
Filter

Fig: Power supply

Transformer:

Usually, DC voltages are required to operate various electronic equipment and these
voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c input
available at the mains supply i.e., 230V is to be brought down to the required voltage level. This
is done by a transformer. Thus, a step down transformer is employed to decrease the voltage to a
required level.

Rectifier:

The output from the transformer is fed to the rectifier. It converts A.C. into pulsating
D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier is
used because of its merits like good stability and full wave rectification.

Filter:

Capacitive filter is used in this project. It removes the ripples from the output of rectifier
and smoothens the D.C. Output received from this filter is constant until the mains voltage and
load is maintained constant. However, if either of the two is varied, D.C. voltage received at this
point changes. Therefore a regulator is applied at the output stage.

Voltage regulator:

As the name itself implies, it regulates the input applied to it. A voltage regulator is
an electrical regulator designed to automatically maintain a constant voltage level. In this project,
power supply of 5V and 12V are required. In order to obtain these voltage levels, 7805 and 7812
voltage regulators are to be used. The first number 78 represents positive supply and the numbers
05, 12 represent the required output voltage levels.

REGULATED POWER SUPPLY

DESCRIPTION

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

Circuit). The IC is shown below.

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.

CIRCUIT FEATURES

 Brief description of operation: Gives out well regulated +5V output, output
current capability of 100 mA
 Circuit protection: Built-in overheating protection shuts down output when
regulator IC gets too hot
 Circuit complexity: Very simple and easy to build
 Circuit performance: Very stable +5V output voltage, reliable operation
 Availability of components: Easy to get, uses only very common basic comp
onents
 Design testing: Based on datasheet example circuit, I have used this circuit s
uccessfully as part of many electronics projects
 Applications: Part of electronics devices, small laboratory power supply
 Power supply voltage: Unregulated DC 8-18V power supply
 Power supply current: Needed output current + 5 mA
 Component costs: Few dollars for the electronics components + the input tr
ansformer cost
 BLOCK DIAGRAM

CIRCUIT DIAGRAM
POWER SUPPLY REQUIREMENTS

BASIC POWER SUPPLY CIRCUIT

Above is the circuit of a basic unregulated dc power supply. A bridge rectifier D1 to D4 rectifies th
e ac from the transformer secondary, which may also be a block rectifier such as WO4 or even four indivi
dual diodes such as 1N4004 types. (See later re rectifier ratings).
The principal advantage of a bridge rectifier is you do not need a centre tap on the secondary
of the transformer. A further but significant advantage is that the ripple frequency at the output is twice
the line frequency (i.e. 50 Hz or 60 Hz) and makes filtering somewhat easier.

As a design example consider we wanted a small unregulated bench supply for our projects. H
ere we will go for a voltage of about 12 - 13V at a maximum output current (I L) of 500ma (0.5A). Maximu
m ripple will be 2.5% and load regulation is 5%.

Now the RMS secondary voltage (primary is whatever is consistent with your area) for our power transfo
rmer T1 must be our desired output Vo PLUS the voltage drops across D2 and D4 ( 2 * 0.7V) divided by 1.
414.

This means that Vsec = [13V + 1.4V] / 1.414 which equals about 10.2V. Depending on the VA rating of yo
ur transformer, the secondary voltage will vary considerably in accordancewith the applied load. The sec
ondary voltage on a transformer advertised as say 20VA will be much greater if the secondary is only ligh
tly loaded.

If we accept the 2.5% ripple as adequate for our purposes then at 13V this becomes 13 * 0.02
5 = 0.325 Vrms. The peak to peak value is 2.828 times this value. Vrip = 0.325V X 2.828 = 0.92 V and this
value is required to calculate the value of C1. Also required for this calculation is the time interval for ch
arging pulses. If you are on a 60Hz system it it 1/ (2 * 60 ) = 0.008333 which is 8.33 milliseconds. For a 50
Hz system it is 0.01 sec or 10 milliseconds.

Remember the tolerance of the type of capacitor used here is very loose. The important thing
to be aware of is the voltage rating should be at least 13V X 1.414 or 18.33. Here you would use at least
the standard 25V or higher (absolutely not 16V).With our rectifier diodes or bridge they should have a PI
V rating of 2.828 times the Vsec or at least 29V. Don't search for this rating because it doesn't exist. Use
the next highest standard or even higher. The current rating should be at least twice the load current ma
ximum i.e. 2 X 0.5A or 1A. A good type to use would be 1N4004, 1N4006 or 1N4008 types.

These are rated 1 Amp at 400PIV, 600PIV and 1000PIV respectively. Always be on the lookout f
or the higher voltage ones when they are on special.

TRANSFORMER RATING - In our example above we were taking 0.5A out of the Vsec of 10V. The VA req
uired is 10 X 0.5A = 5VA. This is a small PCB mount transformer available in Australia and probably elsew
here.

This would be an absolute minimum and if you anticipated drawing the maximum current all the
time then go to a higher VA rating.

The two capacitors in the primary side are small value types and if you don't know precisely and I
mean precisely what you are doing then OMIT them. Their loss won't cause you heartache or terrible pr
oblems.

THEY MUST BE HIGH VOLTAGE TYPES RATED FOR A.C USE

The fuse F1 must be able to carry the primary current but blow under excessive current, in th
is case we use the formula from the diagram. Here N = 240V / 10V or perhaps 120V / 10V. The fuse calcu
lates in the first instance to [ 2 X 0.5A ] / [240 / 10] or .04A or 40 ma. In the second case .08A or 80 ma. T
he difficulty here is to find suitable fuses of that low a current and voltage rating. In practice you use the
closest you can get (often 100 ma ). Don't take that too literal and use 1A or 5A fuses.

CONSTRUCTION

The whole project MUST be enclosed in a suitable box. The main switch (preferably double po
le) must be rated at 240V or 120V at the current rating. All exposed parts within the box MUST be fully i
nsulated, preferably with heat shrink tubing.
PRINTED CIRCUIT BOARD

Printed circuit boards may be covered in two topics namely

1) Technology

2) Design

Introduction to printed circuit boards:

It is called PCB in short, printed circuit consists of conductive circuit pattern

Applied to one or both sides of an insulating base, depending upon that, it is called single sided PCB or d
ouble-sided PCB.

(SSB and DSB).

Conductor materials available are silver, brass, aluminium and copper. Copper is most widely used. The t
hickness of conducting material depends upon the current carrying capacity of circuit. Thus a thicker cop
per layer will have more current carrying capacity.

The printed circuit boards usually serves three distinct functions.

1) it provides mechanical support for the components mounted on it.


2) It provides necessary electrical interconnections.
3) It acts as heat sink that is provides a conduction path leading to removal of the heat generated i
n the circuit.
Advantages of PCB

1) When a number of identical assemblies are required. PCB’s provide cost saving because once a lay
out is approved there is no need to check the circuit every time.

2) For large equipments such as computers, the saving on checking connections or wires is substanti
al.

3) PCB’s have controllable and predictable electrical and mechanical properties.

4) A more uniform product is produced because wiring errors are eliminated.

5) The distributed capacitances are constant from one production to another.

6) Soldering is done in one operation instead of connecting discrete components by wires.

7) The PCB construction lands itself for automatic assembly.

8) Spiral type of inductors may be printed.

9) Weight is less.

10) It has miniaturization potential.

11) It has reproducible performance.

12) All the signals are accessible for testing at any point along conductor track.

Classifications of laminates :

Laminates
Glass base lamination Paper base lamination

There materials are built from several layers of paper or glass, which are bound together under heat
and pressure to form rigid sheets. The binder is usually a phenolic resin in the case of glass base.

The copper layer is formed on either side or two sides of the laminate.

Because of the different filters and binding resins the characteristic properties of copper clad la
minates change.

The rigid sheets of filters which form reinforcement use paper in the form of alpha cellulose, cra
ft or rags. These are cheaper and have easy machinbillity. Glass filter uses glass fibers which are wove
n to give cloth like appearance. This gives a high mechanical strength, they are better moisture resist
ant than above type.

Binding resins are either phenolic or epoxy as mentioned before in addition to these; phenol for
maldehyde and polyesters are also used. Of these, Epoxy resin has

Good electrical and mechanical properties.


Manufacture of cu clad laminate:

The base of laminate is either paper or glass fiber cloth, as mentioned before.

The copper foil is produced by electroplating a thin layer of copper on a large rotating drum of stainle
ss steel. As the drum runs the deposited copper layer is peeled off and forms a continuous length, wh
ich is coiled into rolls for use. To ensure good adhesion between copper foils and base material, surf
ace of copper on the laminate and both are kept under hydraulic press for proper adhesion.

Types of laminates:

National electrical manufactures association (NEMA) has various grades of laminates that are obtaine
d by different resins and filters.

(1) Phenolic:

Phenol and formaldehyde produce phenolic paper base laminate has phenolic resins
with proper filter. The co lour of this base material is usually brown and it is opaque. Certain
additives and the grid is called FR grade.

Disadvantages:

(1) They are attacked by alkalis

(2) They have poor are resistance.

(3) Moisture resistant property is poor than other laminates.

(2) Epoxy laminates;

They can be divided into (a) epoxy glass (b) epoxy paper

Epoxy paper: this is also paper base is impregnated with epoxy resin. The co lour is yellowish white and i
t is translucent.

Epoxy glass: this base material is more expensive but is combines relative strength and good is mainly be
cause of glass fiber. The co lour of this material is usually green and it is semitransparent.

Properties of epoxy laminates:

(a) They are tougher than phenolic and polyesters.

(b) Chemical nature of epoxies gives good adhesion.

(c) They have better mechanical strength as mentioned before due to low shrinkage.

(d) They have high alkali resistance.

(e) They exhibit good electrical properties over different temperature.

(f) They are moisture resistant.

(3) Polyester laminates:

They are mostly used with glass fiber. Their water resistance is good.

(4) Dilly phthalate laminate:

These are mostly used with glass fiber. Their maximum temperature limit is 165C.

(5) PTEF laminates:

Advantages:

(a)It has low dissipation factor over wide rang of temperature, humidity and frequency rang.

(b) Electric strength is high.

(c) High insulation resistance.

(6) Melamine laminates:


This is normally used with glass. It has high are resistance.

(7) Silicone laminates:

They have good heat resistance and good electrical properties .However their mechanical properties
are not good.

(8) Polyamide laminates:

This is the best polymer for heat resistance. When used with glass this gives good mechanical proper
ties. They has better adhesion to copper. Normally used for military and space applications.

There are a number of specifications that are applicable to copper clad laminated e.g.

DIN is use for German standard.

IS is used for join Indian standard.

JSS is used for join services specifications (ministry of defence)

MIL is used for military standard (U.S.A)

NEMA National Electrical Manufactory’s Association.

By these standards, following parameters are checked:

(1) Pull off strength

(2) Surface resistively

(3) Permittivity and resistance

(4) Temperature resistance

(5) Blistering after heat shock.

Before any pattern is transferred the copper surface is cleaned.

Oxides, hydroxides and salts normally treated as contaminants on copper surface. Wet brushing is
used after scrubbing. Acid dip may also used.
IR SECTION:

WHAT IS INFRARED?

Infrared is an energy radiation with a frequency below our eyes sensitivity, so we cannot see it.
Even that we can not "see" sound frequencies, we know that it exist, we can listen them.

Even that we can not see or hear infrared, we can feel it at our skin temperature sensors.
When you approach your hand to fire or warm element, you will "feel" the heat, but you can't see
it. You can see the fire because it emits other types of radiation, visible to your eyes, but it also
emits lots of infrared that you can only feel in your skin.

INFRARED IN ELECTRONICS

Infra-Red is interesting, because it is easily generated and doesn't suffer electromagnetic


interference, so it is nicely used to communication and control, but it is not perfect, some other
light emissions could contains infrared as well, and that can interfere in this communication. The
sun is an example, since it emits a wide spectrum or radiation.

The adventure of using lots of infra-red in TV/VCR remote controls and other applications,
brought infra-red diodes (emitter and receivers) at very low cost at the market.

From now on you should think as infrared as just a "red" light. This light can means something
to the receiver, the "on or off" radiation can transmit different meanings. Lots of things can
generate infrared, anything that radiate heat do it, including out body, lamps, stove, oven, friction
your hands together, even the hot water at the faucet.

To allow a good communication using infra-red, and avoid those "fake" signals, it is imperative
to use a "key" that can tell the receiver what is the real data transmitted and what is fake. As an
analogy, looking eye naked to the night sky you can see hundreds of stars, but you can spot
easily a far away airplane just by its flashing strobe light. That strobe light is the "key", the
"coding" element that alerts us.

Similar to the airplane at the night sky, our TV room may have hundreds of tinny IR sources, our
body, the lamps around, even the hot cup of tea. A way to avoid all those other sources, is
generating a key, like the flashing airplane. So, remote controls use to pulsate its infrared in a
certain frequency. The IR receiver module at the TV, VCR or stereo "tunes" to this certain
frequency and ignores all other IR received. The best frequency for the job is between 30 and
60kHz, the most used is around 36kHz

IR GENERATION

To generate a 36kHz pulsating infrared is quite easy, more difficult is to receive and identify
this frequency. This is why some companies produce infrared receives, that contains the filters,
decoding circuits and the output shaper, that delivers a square wave, meaning the existence or
not of the 36kHz incoming pulsating infrared.

It means that those 3 dollars small units, have an output pin that goes high (+5V) when there
is a pulsating 36kHz infrared in front of it, and zero volts when there is not this radiation.
A square wave of approximately 27uS (microseconds) injected at the base of a transistor, can
drive an infrared LED to transmit this pulsating light wave. Upon its presence, the
commercial receiver will switch its output to high level (+5V).If you can turn on and off this
frequency at the transmitter, your receiver's output will indicate when the transmitter is on or off.

Those IR demodulators have inverted logic at its output, when a burst of IR is sensed it drives its

output to low level, meaning logic level = 1.

The TV, VCR, and Audio equipment manufacturers for long use infra-red at their remote
controls. To avoid a Philips remote control to change channels in a Panasonic TV, they use
different codification at the infrared, even that all of them use basically the same transmitted
frequency, from 36 to 50kHz. So, all of them use a different combination of bits or how to code
the transmitted data to avoid interference.
3 DESCRIPTION OF THE PROJECT

CIRCUIT DESCRIPTION

SCHEMATIC DIAGRAM:

SCHEMATIC DIAGRAM OF CONROLLER


5v

D7
D6 5v 5v R1 R2
D5
D4 10k 10k 1k 1k
D3
D2 5v
D1 SC L
D0 C1 0 .1 u F SD A
R 3R 4R 5R 6R 7R 8R 9R 1 0 R 1R1 1R2 1R3 1R4 1R5 1R6 1R7 1 8

U1

40
JP1 JP2

VC C
39 8
8 38 P 0.0/AD 0 P 1.7 7 1
7 37 P 0.1/AD 1 P 1.6 6 2
6 36 P 0.2/AD 2 P 1.5 5 3
5v 5 P 0.3/AD 3 P 1.4 4
35 4
4 34 P 0.4/AD 4 P 1.3 3 5
3 33 P 0.5/AD 5 P 1.2 2 6
C2 2 32 P 0.6/AD 6 P 1.1 1 7
C 1 P 0.7/AD 7 P 1.0 8
CON1 9 CON2
R ST

C3 33pF 18 JP3
R 19 XTA L 2 21
8.2k Y1 P 2.0/A8 22 1
P 2.1/A9 23 2
C4 19 P 2.2/A10 24 3
33pF XTA L 1 P 2.3/A11 4
1 1 .5 9 MH z 25
JP4 P 2.4/A12 26 5
17 P 2.5/A13 27 6
8 16 P 3.7/R D P 2.6/A14 28 7
7 15 P 3.6/W R P 2.7/A15 8
6 14 P 3 . 5 / T1
CON4
5 13 P 3 . 4 / TO 29 R 2R0 2R1 2R2 2R3 2R4 2R5 2R6 2 7
CON3 4 12 P 3 . 3 / I N T1 PSEN 30
3 P 3 . 2 / I N TO ALE/PR O G RS
11 31 EN
2 P 3 . 1 / TXD EA/VPP
GND

10 R TC _ D ATA
1 P 3 . 0 / R XD
R TC _ C L K
A T8 9 C 5 1 R TC _ R S T
R XD R 2R9 3R0 3R1 3R2 3R3 3R4 3R5 3 6
20

TXD R 28
1k
5v

5v

5v

SCHEMATIC DIAGRAM OF DISPLAY


5V

2
R 40
1 3
10K POT J4
10K POT 1
2
3
RS 4
5
EN 6
D0 7
D1 8
D2 9
D3 10
D4 11
D5 12
D6 13
D7 14
15
16
5V LC D _C O N

C 13 0 .1 u F

U4
8

SD A 5 1
SD A A0
VC C

2
6 A1 3
SC L SC L A2
VSS

7
WP
2 4 A TC 1 6
4

SCHEMATIC DIAGRAM OF PERIPHARAL


5V

5V

C5 0.1uF
R 3R8 3 9 P1
R R 5
9

16
U2 4
RX 12
R 1O U T R 1IN
13 8

VC C
TX 11
T1 I N
3
8 14 7
10 R 2IN T1 O U T 7 2
T2 I N T2 O U T 9 6
1 R 2O U T 5 1
C6

C+ C 2-

0.1uF C7 C O N N E C TO R D B 9

3 4 C
C 1- C 2+
M A X2 3 2
5V
6 C8
V- 2
V+
GND

C9
0.1uF
C
15

5V
C 10 0 .1 u F
C 11 6uF U3

1
Y2 2
X1

VC C
3 6 R TC _ D ATA
C 12 X2 I/O
6 u F 3 2 .7 6 8 K H z
7 R TC _ C L K
SC LK
8 5 R TC _ R S T
VC C R ST

GND
B T1

3 .3 V D S1302

4
CIRCUIT DESCRIPTION

The main parts of this schematic diagram are:

1. POWER SUPPLY.
2. (AT89S52) MICROCONTROLLER.
3. RELAY 1 LAMP
4. RELAY 2 FAN
5. RELAY 3 TV

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 Bridge Rectifier and a
dditional Filter Circuits are used where the ripples or noised in the DC voltage are removed and at last a
7805 Regulator 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 Gnd(20) pins of the AT89S51 micro
controller. Now the microcontroller is powered up to do the specified controlling action given by the us
er.

2. AT89S51 (microcontroller): This is a special microcontroller manufactured by the Atmel Corpo


ration where “AT” stands for ATMEL company and ‘C’ for CMOS technology.

Concerned to the schematic the Port Pins connections are as follows:

.
Port 2: The Port2 is connected to the IR SENSOR’S .

Port 1: The P1.0 and P1.1 is connected to motors

Here the rest of the port pins are left unconnected.

5. SOFTWARE DESCRIPTION

KEIL COMPILER:

Keil compiler is software used where the machine language code is written and compiled. After
compilation, the machine source code is converted into hex code which is to be dumped into the
microcontroller for further processing. Keil compiler also supports C language code.
PRELOAD:

Preload is software which accepts only hex files. Once the machine code is converted into hex
code, that hex code has to be dumped into the microcontroller and this is done by the Preload.
Preload is a programmer which itself contains a microcontroller in it other than the one which is
to be programmed. This microcontroller has a program in it written in such a way that it accepts
the hex file from the Keil compiler and dumps this hex file into the microcontroller which is to
be programmed. As the Preload programmer kit requires power supply to be operated, this power
supply is given from the power supply circuit designed above. It should be noted that this
programmer kit contains a power supply section in the board itself but in order to switch on that
power supply, a source is required. Thus this is accomplished from the power supply board with
an output of 12volts.

Building an Application in µVision2

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 Data
base™.
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 t
o the project.
6. Select Project - Options and set the tool options. Note when you select the target device from th
e Device Database™ all special options are set automatically. You typically only need to configur
e the memory map of your target hardware. Default memory model settings are optimal for mos
t 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

µ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. You can simply use

the icon Create New Folder in this dialog to get a new empty folder. Then

select this folder and enter the file name for the new project, i.e. Project1.

µVision2 creates 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 CPU

for your project. The Select Device dialog box shows the µVision2 device
database. Just select the microcontroller you use. We are using for our examples the Philips 80C51RD+ C
PU. This selection 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 a

click on the Build Target toolbar icon. When you build an application with

syntax 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 w
hen Create HEX file under Options for Target – Output is enabled. You may start your PROM programmi
ng utility after the make process when you specify the program under the option Run User Program #1.

CPU Simulation

µVision2 simulates up to 16 Mbytes of memory from which areas can be

mapped for read, write, or code execution access. The µVision2 simulator traps

and reports illegal memory accesses.

In addition to memory mapping, the simulator also provides support for the

integrated 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 usi
ng 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 Debug

Session command. Depending on the Options for Target – Debug

configuration, µVision2 will load the application program and run the startup

code µVision2 saves the editor screen layout and restores the screen lay out of the last debug session. If
the program execution stops, µVision2 opens an

editor window with the source text or shows CPU instructions in the disassembly window. The next exec
utable statement is marked with a yellow arrow. During debugging, most editor features are still availabl
e.

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

_ The “Debug Menu and Debug Commands” described on page 28 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 asse
mbly code. A trace history of previously executed instructions may be displayed with Debug – View Trac
e 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 ins
truction level rather than program source lines. You can select a text line and set or modify code breakp
oints using toolbar buttons or the context menu commands.

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

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

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

9. Select AT89C51 as shown below


10. Then Click on “OK”
11. The Following fig will appear

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”
16. The next screen will be as shown in next page, and just maximize it by d
ouble clicking on its blue boarder.

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

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

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.

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

#include<reg51.h>

#define ON 0

#define OFF 1

void delay_ms(unsigned int );

sbit ir1 = P2^4;

sbit ir2 = P2^0;

sbit ir3 = P2^2;

sbit ir4 = P2^1;

sbit ir5 = P2^3;

sbit sw1 = P1^0; //ir1 side right

sbit sw2 = P1^1; //ir5 side left

void main(void)

unsigned char i=0;

sw1 =0;

sw2=0;

if(ir1 == 1 && ir5 == 1 && ir3 == 0)//normal case


{

sw1 = 1;

sw2 = 1;

delay_ms(1000);

else if (ir3 == 1) //line end

sw1 = 0;

sw2 = 0;

delay_ms(1000);

else if( ir1 == 0 )//right case

sw1 = 0;

sw2 = 1;

delay_ms(1000);

else if( ir5 == 0 )//right case

sw1 = 1;

sw2 = 0;

delay_ms(1000);

}
void delay_ms(unsigned int i)

unsigned int j;

while(i-->0)

for(j=0;j<500;j++)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy