Documente Academic
Documente Profesional
Documente Cultură
EXPERIMENT #1
alarm system.
EXPERIMENT #7
EXPERIMENT NO 1
Introduction to C programming in 8051
Objective:
To get familiar with the basic C programming in 8051 family microcontroller
Theoretical Background:
Both C language and assembly language is used for programming in 8051 but here we
will talk about C only. We briefly discuss here about major reasons for using C, data
types of C, 8051 extension types, time delay, I/O programming in C and Logic
operations in 8051 C.
Data Types:
Following data types are used in C language. Their ranges are also given in this table
1-1.
(Table 1-1)
Time Delay:
There are two ways to create a time delay in 8051 C:
Using a simple for loop
Using the 8051 timers
(Table 1-2)
Bit-wise Shift operation in C:
There are two bit-wise shift operations in C: (1) shift right (>>), and (2) shift left(<<)
Their format in C is as follow:
Data >> number of bits to be shifted right
3
C Compilers are available for almost all embedded devices in use today, and
there is a large pool of experienced C programmers.
Review Questions:
1) What is the main advantage of sbit function?
__________________________________________________________________
2) What is main disadvantage of C language over assembly language?
__________________________________________________________________
3) Which data type is used for decimal digits in C language?
__________________________________________________________________
4) Which data type is used to define memory addresses?
__________________________________________________________________
EXPERIMENT NO 2
Introduction to Keil & Proteus software
Objective:
Theoretical Background:
A Compiler is a program used to convert a High Level Language to object code.
Compilers produce an output object code for the underlying microprocessor but not
for other microprocessors.
Keil Software:
Keil was founded in 1982 by Gunter and Reinhard Keil. In April 1985, the company
was converted to Keil Electronic GmbH to market add-on products for the
development tools provided by many of the silicon vendors. 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 implemented the first C compiler designed from the ground-up specifically for
the 8051 microcontroller. Keil provides a broad range of development tools like ANSI
C compiler, macro assemblers, debuggers and stimulators, linkers, IDE, library
managers, real-time operating systems and evaluation boards fir Intel 8051,Intel
MCS-251,ARM,and XCI6x/C16x/ST10 families.
Keil Software different families:
Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the
multitude of 8051 derivatives. Keil provides following tools for 8051 development
1. C51 Optimizing C Cross Compiler,
2. A51 Macro Assembler,
3. 8051 Utilities (linker, object file converter, library manager),
4. Source-Level Debugger/Simulator,
5. Vision for Windows Integrated Development Environment.
Creating a new Assembler/Compiler Project:
1. Open Keil from the Start menu.
2. The Figure below shows the basic names of the windows referred in this document.
5
3. Copy the example to the Right into the new window. This file will toggle Ports 1
and 2 continuously with a delay.
#include <reg51.h>
void MSDelay(unsigned int);
void main (void)
{
while(1) //another way to do it forever
{
P1=0x55;
P2=0x55;
MSDelay(250);
P1=0xAA;
P2=0xAA;
MSDelay(250);
}
}
void MSDelay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
10
11. Expand the Source Group 1 in the Tree menu to ensure that the file was added to
the project.
11
7. Click OK Button.
13
4. Click on Peripherals. Select I/O Ports, Select Port 1. Repeat for Port 2.
14
A new window should will pop up. This represents the Ports and Pins.
15
6. To exit out, Click on Debug Menu and Select Start/Stop Debug Session or
press
icon.
Proteus Software:
Proteus PCB design combines the ISIS schematic capture and ARES PCB layout
programs to provide a powerful, integrated and easy to use suite of tools for
professional PCB Design. All Proteus PCB design products include an integrated
shape based autorouter and a basic SPICE simulation capability as standard. More
advanced routing modes are included in Proteus PCB Design Level 2 and higher
whilst simulation capabilities can be enhanced by purchasing the Advanced
Simulation option and/or micro-controller simulation capabilities.
Proteus is a single integrated application with ISIS, ARES and 3D Viewer modules
appearing as tabbed modules. The program enables changes on the schematic to be
reflected across PCB, BOM and Design Explorer in real time. Proteus stores the
design (DSN), layout (LYT) and common database in a single project file (PDSPRJ).
Proteus is perfect tool for engineers to test their microcontroller designs before
constructing a physical prototype in real time. This program allows users to interact
with the design using on-screen indicators and/or LED and LCD displays and, if
attached to the PC, switches and buttons.
Loading a Microcontroller with a hex file in proteus:
Step1: Place your components from the library and make schematic.
16
Step2: Place cursor on microcontroller 89S51 and double click it. A window will
open, on program file option click on folder icon
and add directory of your hex file
(Keil\C51\Examples\HELLO\toggle.hex) where you create it on Keil.
17
Review questions:
1) What is Keil compiler?
5) Why Keil compiler is used for creating Hex files for microcontrollers?
18
EXPERIMENT NO 3
Test Bench for 89S51 or 89C51 microcontroller
Objective:
Description of test bench
Components:
Theoretical Background:
I.
RST:
RESET pin is an input and is active high (normally low). Upon applying a high pulse
to this pin, the microcontroller will reset and terminate all activities. This is often
referred to as a power-on reset. Activating a power-on reset will cause all values in
19
the registers to be lost. It will set program counter to all 0 s. In order for the RESET
input to be effective, it must have a minimum duration of 2 machine cycles. In other
words, the high pulse must be high for a minimum of 2 machine cycles before it is
allowed to go low. Figure 2 (a) and (b) show two ways of connecting the RST pin to
power-on reset circuitry. Figure 2 (b) uses a momentary switch for reset circuitry.
U1
39
38
37
36
35
34
33
32
1
2
3
4
5
6
7
8
21
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
19 X1
ALE
X2
PSEN
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
30
29
18
10uF
31
12MHz
30pF
8.2k
RST
VCC
20
40
GN
D
EA
5V
30pF
80C51
0
0
(a)
30pF
0
30pF
10uF
5V
8.2k
0
SW PUSHBUTTON
12MHz
U1
39
38
37
36
35
34
33
32
1
2
3
4
5
6
7
8
19
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
ALE
PSEN
31
9 EA
RST
40
VCC
GND
X1
X2
80C51
20
18
21
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
30
29
(b)
Figure 2: Power-On RESET Circuit
-EA:
-EA, external access, is an input pin and must be connected to Vcc or GND. The
8051 family members all come with on-chip ROM to store programs. So -EA pin is
connected to Vcc. The 8031 and 8032 family members do not have on-chip ROM, so
20
code is stored on an external ROM and is fetched by 8031/32. So -EA pin must be
connected to GND to indicate that the code is stored externally.
-PSEN:
-PSEN, program store enable, is an output pin. This pin is connected to the OE pin
of the
ROM in 8031 based systems.
ALE:
ALE, address latch enable, is an output pin and is active high in 8031 based
systems.
Ports 0, 1, 2 and 3:
The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins. All the ports upon RESET
are configured as output, ready to be used as input ports.
P0:
Port 0 is also designated as AD0-AD7, allowing it to be used for both address and
data. When connecting
an
8051/31 to an external memory,
5V
port 0 provides both address and
330 330 330 330 330 330 330 330
U1
data. The
8051 multiplexes
39
0
38 P0.0/AD0
address and data through port 0
37 P0.1/AD1
36 P0.2/AD2
to save pins. ALE indicates if P0
35 P0.3/AD3
34 P0.4/AD4
has address or data.
33 P0.5/AD5
32 P0.6/AD6
P0.7/AD7
19
X1
18
X2
31
EA
9
RST
40
VCC
GND
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
80C51
20
1
2
3
4
5
6
7
8
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
ALE
PSEN
P1 and P2:
Both P1 and P2 are used as simple I/O pins.
P3:
Port 3 can be used as input or output. Port 3 has the additional function of providing
some extremely important signals. They are listed in figure 4.
21
P2.0/A8
P2.1/A9
P2.2/A10
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
30
29
Figure 4
8 LEDs panel:
For visual representation of data from microcontroller we use 8 LEDs panel on the
test bench. These are connected from the microcontroller in sink in configuration.
The anodes of LEDs are provided 5V DC supply through 330 resistors and the
cathodes are connected to the microcontroller ports through female header.
5V
0
10k 10k
10k
10k 10k
10k
10k
10k
U1
1
2
3
4
5
6
7
8
330
330
330
V5
330
330
330
19
18
31
9
30pF
12MHz
10uF
40
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
X1
X2
EA
RST
VCC
80C51
30pF
5V
8.2k
0
5V
0
0
Figure 5
22
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
ALE
PSEN
GND
330
330
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
20
39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
30
29
AI.
Figure 6
BI.
Buzzer:
inducing rapid movements in the diaphragm of the buzzer. In electronic buzzers these
vibrations are made by an oscillator circuit which drives a piezo to produce the sound.
Buzzers may be AC operated or DC operated. In our test bench we are using DC
buzzer. It has a built-in driver circuit and requires only a DC voltage to drive it.
Working with a 24V DC supply voltage, this tiny unit can supply sound levels of over
95 dB at a 30 cm distance. The unit will operate well with 5V TTL voltages, drawing
only around 2 mA. It will therefore make an excellent bell or warning alarm for
digital systems.
5V
0
10k 10k 10k 10k 10k 10k 10k 10k
U1
5V
0
BUZZER
10uF
30pF
5V
8.2k
0
0
30pF
21
39
38
37
36
35
34
33
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P0.1/AD1
P0.2/AD2
P0.0/AD0
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
32 P0.7/AD7
1
2 P1.1/T2EX
P1.0/T2
P3.0/RXD
P3.1/TXD
P1.2/ECI
P3.2/INT0
P1.3/CEX0
P3.3/INT1
P1.4/CEX1
P3.4/T0
3
4
5
6
7 P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
8
330
P3.5/T1
P3.6/WR
P3.7/RD
19 X1
ALE
X2
PSEN
22
23
24
25
26
27
28
10
12
11
13
14
15
16
17
30
29
18
31
RST
40 VCC
80C51
GND
EA
20
9
12MHz
5V
Figure 7
IV.
Relay:
25
5V
39
38
37
36
35
34
33
32
1
2
3
4
5
6
7
8
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
19
18 X1
X2
8.2k
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
_____
_
1k
Q1
2N1069
30
29
31
9 EA
RST
12MHz
40
30pF
VCC
GND
5V
30pF
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
ALE
PSEN
80C51
20
10uF
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
0
5V
_____
_____
_____
_____
_____
_____
_____
_____
_____
_____
_____
_____
___
26
Figure 9
Review Questions:
1) Why pull-up resistors are used with Port-0?
_________________________________________________________
______
_________________________________________________________
_____
2) Why crystal oscillator of 12MHz is used?
_________________________________________________________
______
_________________________________________________________
______
3) Why LEDs are connected in sink in configuration with
microcontroller?
_________________________________________________________
______
_________________________________________________________
______
4) Why pins EA and PSEN are not used in 8051 microcontroller?
_________________________________________________________
______
_________________________________________________________
______
5) What is the difference between 89C51 and 89S51?
_________________________________________________________
5
V
27
EXPERIMENT NO. 4
Show up and down counter on LEDs using 89S51
microcontroller.
Objective:
We are showing up and down counter on led s which are solded on test bench.
Components:
89S51 microcontroller
8 LEDs
8 resistors (330)
Connecting wires
Power supply (5V)
Theoretical Background:
In digital logic and computing, a counter is a device which stores (and sometimes
displays) the number of times a particular event or process has occurred, often in
relationship to a clock signal. In practice, there are two types of counters:
Up counters, which increase (increment) in value
Down counters, which decrease (decrement) in value
In electronics, counters can be implemented quite easily using register-type circuits
such as the flip-flop, and a wide variety of classifications exist:
Up/down counter counts both up and down, under command of a control input.
Each is useful for different applications. Usually, counter circuits are digital in nature,
and count in natural binary. Occasionally there are advantages to using a counting
sequence other than the natural binary sequence, such as the binary coded decimal
counter, a linear feedback shift register counter, or a Gray-code counter. Counters are
useful for digital clocks and timers, and in oven timers, VCR clocks, etc.
Procedure:
Write up and down counter code in Keil software. Create its hex file.
Burn the program on microcontroller with the help of burner.
Make test bench with LEDs, resistors, capacitors and 89S51.
After burning program insert microcontroller in its base in test bench.
Connect pins of port1 to LEDs through jumper wires.
Provide power supply from trainer to test bench.
28
You will see combination of binary numbers being displayed on LEDs from
down to up (0000 to 1001) and then up to down (1001 to 0000).
C-Code:
#include<reg51.h>
void main(void)
{
unsigned int
x; for(;;)
{
P1=0x00;
for(x=0;x<40000;x++);
P1=0x01;
for(x=0;x<40000;x++);
P1=0x02;
for(x=0;x<40000;x++);
P1=0x03;
for(x=0;x<40000;x++);
P1=0x04;
for(x=0;x<40000;x++);
P1=0x05;
for(x=0;x<40000;x++);
P1=0x06;
for(x=0;x<40000;x++);
P1=0x07;
for(x=0;x<40000;x++);
P1=0x08;
for(x=0;x<40000;x++);
P1=0x09;
for(x=0;x<40000;x++);
P1=0x08;
for(x=0;x<40000;x++);
P1=0x07;
for(x=0;x<40000;x++);
P1=0x06;
for(x=0;x<40000;x++);
P1=0x05;
for(x=0;x<40000;x++);
P1=0x04;
for(x=0;x<40000;x++);
P1=0x03;
for(x=0;x<40000;x++);
P1=0x02;
for(x=0;x<40000;x++);
P1=0x01;
for(x=0;x<40000;x++);
P1=0x00;
for(x=0;x<40000;x++);
}
29
Schematic:
Results:
The counter is displaying on LEDs numbers from 0000 to 1001(0 to 9) in
ascending and then descending order according to the code developed. We can use it
in many applications.
Review Questions:
1) In which configuration LEDs are connected to form counter?
30
2) LEDs will glow when they receive from microcontroller logic 1 or logic 0?
31
EXPERIMENT NO 5
Identification of Valid and Invalid BCD codes
Objective:
Identify the valid BCD and invalid BCD codes by using a microcontroller 8951.
Components:
i.
ii.
iii.
iv.
89S51 Microcontroller.
74LS47 Decoder.
Seven Segment Display (common anode).
Power Supply 5V.
Theoretical Background:
The codes mostly used today are in binary but they are in special form called BCD.
But depending upon the no of inputs some BCD codes generate valid number but
other display invalid no at a displaying unit like seven segment.
Here some terms are important to perform the experiment. These are,
Valid BCD codes:
It is said that the entire binary numbers mostly operate in BCD today. So if a BCD
code generates the number 0 to 9 then it is called valid BCD.
Invalid BCD codes:
If the BCD codes combinations of binary dont generate a digit from 0 to 9 then it is
called invalid BCD code.
For example, for BCD codes the binary are in the sequence or group of 4. So if we set
the binary combination as 0000=0, or 0001=1, or 0010=2 these are the valid BCD
because they generate the number from 0 to 9 and the sequence 1010 generate A type
letter at seven segment display. As A is not in range from 0 to 9 so this is an invalid
BCD code.
Seven segment display:
The displaying unit at which the BCD generated number is displayed or visible is
called seven segment display. Seven segment is made up of combination of 7 LED s
so it is called seven segment display.
There are 2 types of seven segment display
I.
32
Figure 1
Main difference in use of above displays is that segment is common cathode (ground)
at 1 pin or segment is common anode (5V) at 1 pin. The pin configuration can be seen
in the datasheet of segment display.
7447 Decoder:
It is the common concept that everything in reality needs some support and that
support run that thing in reality. The thing which interfaces a unit with reality or
practically with real work is called driver. Similarly seven segment displays also
require a driver for its operation in reality or real world. The driver used for the seven
segment is 7447 an IC type shape. This driver also called a decoder which converts
the BCD in that manner so that on applying the valid BCD the valid number at seven
segment display is displayed. 7447 is a driver as well as decoder for driving seven
segment display of common anode configuration and 7448 is decoder and driver for
common cathode type seven segment display.
Procedure:
i.
Now write the C-code for invalid BCD codes that correspond to binary
numbers from 1010 to 1111.
Compile the program in Keil and burn it into 89S51 using burner.
Insert the programmed microcontroller into its base on test bench.
v.
Check connections between Seven segment display and decoder and between
decoder and microcontroller.
Provide power supply to test bench through trainer.
vii.
Observe and record the random figures that are formed on Seven segment
display for each invalid BCD code.
iii.
iv.
vi.
Schematic
33
Figure 2
#include<reg51.h>
Void main()
{
unsigned char z;
for(z=0;z<=40000;z++)
{
P1=0x0A // P1 is set as port for sending the data.
for(z=0;z<=40000;z++);
P1=0x0B
for(z=0;z<=40000;z++);
P1=0x0C
for(z=0;z<=40000;z++);
P1=0x0D
for(z=0;z<=40000;z++);
P1=0x0E
for(z=0;z<=40000;z++);
P1=0x0F
for(z=0;z<=40000;z++);
}
}
Review Questions:
1) Why we use 74LS47 decoder in above experiment?
__________________________________________________________________
__________________________________________________________________
2) Differentiate between 7447 and 7448?
__________________________________________________________________
__________________________________________________________________
3) Why common anode configuration of Seven segment display is used?
__________________________________________________________________
__________________________________________________________________
4) 7447 is just a decoder or a driver or both?
__________________________________________________________________
__________________________________________________________________
35
EXPERIMENT NO 6
Alarm system using 89S51 with the help of a single bit based
alarm system.
Objective:
Design of alarm system using 89C51 with the help of single bit based alarm system.
Components:
Theoretical Background:
An alarm system is needed to prevent any bad condition or situation which we don t
want to face. When alarm device is installed then we can avoid unsuitable
circumstances as we can use a fire alarm, antitheft alarm device etc. So we need an
alarm system which can be implemented for antitheft purpose. An alarm device or
system gives an audible, visual or any other form of signal during a problem or any
unavoidable circumstances. They are often connected with a buzzer or siren. They
have a capability of causing a fight or flight response in humans. In this condition a
person will panic and either flee the perceived danger or attempt to eliminate it. This
buzzer makes sound when the force is applied to the force sensitive resistor. This acts
as an alarm system and it is connected through the RF module so it can be called as
wireless alarm system. When some force is applied to the force sensitive resistor the
signal is transmitted to the receiver and the buzzer makes sound which serves as an
alarm. The alarm blows for 2 sec and then it is off.
Procedure:
Write a code for the single bit based alarm system using 89S51 in keil
software.
Burn the program on 89S51 using burner.
Insert the programmed 89S51 into its base on test bench..
Connect the buzzer and resistor to port P2^1.
Connect the led and resistor to P2^2
Take the port P2^0 as a input.
When the input is connected to low logic, led will be ON giving the indication
of correct alarm.
When the input is connected to high logic, buzzer will be ON giving the
indication of wrong alarm.
C-Code:
#include<reg51.h>
sbit input=P2^0;
sbit buzzer=P2^1;
36
sbit led=P2^2;
void main()
{
while(1)
{
if(input==0)
{
led=0;
buzzer=1;
}
else if(input==1)
{
buzzer=0;
led=1;
}
}
}
Schematic:
5V
10k 10k
10k
10k 10k
5V
0
BUZZER
10uF
5V
8.2k
330
30pF
12MHz
30pF
0
0
Figu
re 1
37
U1
21
P0.
P0.
P0.
P0.
P0.
P0.
P0.
P0.
0/AD0
1/AD1
2/AD2
3/AD3
4/AD4
5/AD5
6/AD6
7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
22
23
24
25
26
27
28
P1.
P1.
P1.
P1.
P1.
P1.
P1.
0/T2
1/T2EX
2/ECI
3/CEX0
4/CEX1
5/CEX2
6/CEX3
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P1. 7/CEX4
P3.7/RD
10
11
12
13
14
15
16
17
30
X1
X2
ALE
PSEN
GND
EA
RST
80C51
20
VCC
29
Result:
Setting the value at 0 led will be ON indicating correct code .While setting value at
1buzzer will be ON indicating wrong code.
Review Questions:
1. Why the buzzer does not turn ON in simulation without transistor?
38
EXPERIMENT NO 7
Interfacing of LDR and Thermistor with 89S51
Components:
LDR
Thermistor
Variable resistors (2)
330 resistor (1)
LEDs (2)
10uF capacitor
DC voltmeter
Torch
Heating Element
Theoretical Background:
LDR
The light dependent resistor, LDR, is known by many names including
the photo resistor, photoconductor, photoconductive cell, or simply the
photocell. It is probably the term photocell that is most widely used in
data and instruction sheets for domestic equipment.
Light dependent resistor symbol
The circuit symbol used for the light dependent resistor or photoresistor combines its resistor
action while indicating that it is sensitive to light. The basic light dependent resistor symbol has
the rectangle used to indicate its resistor action, and then has two incoming arrows - the same as
those used for photodiodes and phototransistors to indicate its light sensitivity.
For most applications, the light dependent resistor symbol used will be that with the
resistor with arrows, but in some instances those drawing circuit diagrams prefer to
encase the resistor in a circle. The more commonly used photo-resistor symbol is the
resistor without the circle around it.
Photo-resistor mechanism
A photo-resistor or photocell is a component that uses a photconductor between two
contacts. When this is exposed to light a change in resistance is noted.
Photoconductivity - the mechanism behind the photoresistor - results from the
generation of mobile carriers when photons are absorbed by the semiconductor
material used for the photoconductor. While the different types of material used for
39
light dependent resistors are semiconductors, when used as a photo-resistor, they are
used only as a resistive element and there are no PN junctions. Accordingly the device
is purely passive.
There are two types of photoconductor and hence photoresistor:
1) Intrinsic photoresistor:
This type of photoresistor uses a photoconductive material that involves excitation of
charge carriers from the valence bands to the conduction band.
2) Extrinsic photoresistor:
This type of photoresistor uses a photoconductive material that involves excitation of
charge carriers between an impurity and the valence band or conduction band. It
requires shallow impurity dopants that are not ionised in the presence of light.
Extrinisc photoresistors or photocells are generally designed for long wavelength
radiation - often infra-red, but to avoid thermal generation they need to be operated at
low temperature
Basic photoresistor structure
Although there are many ways in which light dependent resistors, or photo resistors
can be manufactured, there are naturally a few more common methods that are seen.
Essentially the photoresisitor or photocell consists of a resistive material sensitive to
light that is exposed to light. The photo resistive element comprises section of the
material with contacts at either end.
A typical structure for a light dependent or photo resistor uses an active
semiconductor layer that is deposited on an insulating substrate. The semiconductor is
normally lightly doped to enable it to have the required level of conductivity. Contacts
are then placed either side of the exposed area. Within the basic photo resistor or
photocell structure, the resistance of the material itself is a key issue. To ensure the
resistance changes resulting from the light dominate, contact resistance is minimized.
To achieve this, the area around the contacts is normally heavily doped to reduce the
resistance in this region. In many instances the area between the contacts is in the
form of a zig zag, or inter digital pattern. This maximizes the exposed area and by
keeping the distance between the contacts small it reduces the spurious resistance
levels and enhances the gain.
40
Thermistor
A resistor made of semiconductors having resistance that varies rapidly and
predictably with temperature is called thermistor. The thermistor is a resistor whose
resistance strongly depends on temperature, showing a nonlinear V-I characteristic.
Specific to this temperature dependence, compared with that of fixed linear resistors,
is the fact that for a temperature variation with one degree the value of the thermistors
resistance changes by tens of percent. In other words, it is possible that within a
narrow temperature range the thermistor would halve or double its resistance value.
Thermistor sysmbol
Decrease or increase in resistance is closely correlated with the type of the thermistor,
which can be:
a) Negative temperature coefficient, NTC
b) Positive temperature coefficient, PTC.
Thermistors
symbols
are
shown
41
in
Figure.
K = (1/T 1/To)
is a constant whose value ranges from 3400 to 3900 depending on the material used
for the thermistors and its composition.
The thermistor acts as the temperature sensor and it is placed on the body whose
temperature is to be measured. It is also connected in the electric circuit. When the
temperature of the body changes, the resistance of the thermistor also changes, which
is indicated by the circuit directly as the temperature since resistance is calibrated
against the temperature. The thermistor can also be used for some control which is
dependent on the temperature.
Applications of Thermistor
PTC thermistors can be used as current-limiting devices for circuit protection, as replacements
for fuses. Current through the device causes a small amount of resistive heating. If the current
is large enough to generate more heat than the device can lose to its surroundings, the device
heats up, causing its resistance to increase. This creates a self-reinforcing effect that drives the
resistance upwards, therefore limiting the current.
PTC thermistors were used as timers in the degaussing coil circuit of most CRT displays.
When the display unit is initially switched on, current flows through the thermistor and
degaussing coil. The coil and thermistor are intentionally sized so that the current flow will
heat the thermistor to the point that the degaussing coil shuts off in under a second. For
effective degaussing, it is necessary that the magnitude of the alternating magnetic field
produced by the degaussing coil decreases smoothly and continuously, rather than sharply
switching off or decreasing in steps; the PTC thermistor accomplishes this naturally as it heats
up. A degaussing circuit using a PTC thermistor is simple, reliable (for its simplicity), and
inexpensive.
42
Procedure
There are the following steps involving in this experiment.
LDR
Make connections of LDR with 89S51 test bench as shown in the figure.
Place a 330 resistor in series with LDR and connect an LED in parallel.
Connect a DC voltmeter in parallel to the LED for measuring voltages for the
ON state and OFF state of LED.
Obtain required levels of light for which LED glows and for which it stays
OFF by inserting a variable resistor in series with the LDR. Increasing the
resistance will reduce the intensity level of light for which LED glows.
43
Figure 1
Thermistor
Make connections of thermistor with 89S51 test bench as shown in the figure.
Obtain required levels of heat/temperature for which LED glows and for
which it stays OFF by inserting a variable resistor in series with the LDR
instead of 330 resistor. Increasing the resistance will reduce the intensity
level of heat for which LED glows.
44
Figure 2
C-Code
Same code is used for LDR and thermistor when these are connected to any pin of I/O
port.
#include <reg51.h>
sbit abit=P1^0;
//input reference from LDR or thermistor
sbit lock1=P1^5; //input to the application to turn on or off
void main(void)
{
while(1)
{
if(abit==1)
lock1=0;
//means use the bit at the ground side of application
else
lock1=1;
}
}
Review Questions
1) What is main difference between the LDR and thermistor?
_______________________________________________________________
_______________________________________________________________
2) Why we use variable resistor in the LDR and thermistor circuit?
45
_______________________________________________________________
_______________________________________________________________
3) What is the reason that we are taking input point before the resistor?
_______________________________________________________________
_______________________________________________________________
4) What practical application in daily life you got from this experiment?
_______________________________________________________________
_______________________________________________________________
46
Experiment No 8
Four Way Traffic Light System using 89S51
Objective:
To show the Four Way traffic Circuit solded on Verum Board and Connected with
89C51
Theoretical Background:
Vehicular traffic at intersecting streets is typically controlled by traffic control lights.
The function of traffic lights requires sophisticated control and coordination to ensure
that traffic moves as smoothly and safely as possible. In recent days electromechanical controllers are replaced by electronic circuits. The accuracy & fault
tolerant drive towards electronic circuits. Microcontroller AT89c51 is the brain of this
experiment which initiates the traffic signal at a junction. The leds are automatically
on and off by making the corresponding port in of the micro controller low. There are
three ports of Microcontroller used and twenty four LEDs are used
Procedure:
Select three LEDs 1 red, 1 green and 1 yellow and make 8 such groups of
LEDS
There are four ways on which we have to control the traffic so make use 2
groups of three LEDs for each way one is controlling the traffic flow from
the front and other from side.
Connect the cathode of LEDs with port 0,2 and 3(through female header) and
their anodes with 5V through 330 resistors.
Make the arrangement of LEDs on varum board just like four way traffic
lights.
Program the microcontroller for operating the LED in active Low mode.
47
Circuit Diagram:
C-Code:
#include <reg51.h>
void main(void)
{
unsigned int
x; for(;;)
{
P0=0x64;P2=0x92;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x52;P2=0x92;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x89;P2=0x94;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x09;P2=0x99;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x89;P2=0x94;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x22;P3=0x25;
48
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x42;P3=0x26;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x22;P3=0x25;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x92;P3=0x48;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x92;P3=0x90;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x49;P2=0x92;P3=0x48;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
P0=0x52;P2=0x92;P3=0x24;
for(x=0;x<65535;x++);
for(x=0;x<65535;x++);
}
}
Review Questions:
1. What will be the effect of operating LED in active high mode?
____________________________________________________________
____________________________________________________________
2. How can you perform this experiment using just 2 ports of
microcontroller?
____________________________________________________________
____________________________________________________________
3. Can you add a Seven segment display counter to this experiment?
____________________________________________________________
____________________________________________________________
4. Is it possible to use just one resistance for three LEDs?
____________________________________________________________
____________________________________________________________
49
Experiment No 9
Interfacing of 89S51 with DC Motor
Objective:
The objective of this experiment is to interface DC motor with 89S51 microcontroller
and control the speed of DC motor.
Equipment Required:
I.
AT89S51 Microcontroller
Opto-isolator ILD74
Darlington Transistor TIP120
Diode 1N4004
Resistors (330, 10k, 100k)
Capacitor (0.1Uf)
Simple DC Motor
Components for 89S51 test bench circuitry
Theoretical Background:
DC Motor:
The DC Motor is the most commonly used actuator for producing continuous
movement and whose speed of rotation can easily be controlled, making them ideal
for use in applications were speed control, servo type control, and/or positioning is
required. A DC motor consists of two parts, a Stator which is the stationary part and
a Rotor which is the rotating part. The result is that there are basically three types of
DC Motor available.
Brushed Motor:
This type of motor produces a magnetic field in a wound rotor (the part that rotates)
by passing an electrical current through a commutator and carbon brush assembly,
hence the term Brushed. The stators (the stationary part) magnetic field is produced
by using either a wound stator field winding or by permanent magnets. Generally
brushed DC motors are cheap, small and easily controlled.
Brushless Motor:
This type of motor produce a magnetic field in the rotor by using permanent magnets
attached to it and commutation is achieved electronically. They are generally smaller
but more expensive than conventional brushed type DC motors because they use
Hall effect switches in the stator to produce the required stator field rotational
sequence but they have better torque/speed characteristics, are more efficient and have
a longer operating life than equivalent brushed types.
Servo Motor:
This type of motor is basically a brushed DC motor with some form of positional
feedback control connected to the rotor shaft. They are connected to and controlled by
a PWM type controller and are mainly used in positional control systems and radio
controlled models.
50
AI.
51
Figure 1
Disadvantage of this control method:
While controlling the speed of a DC motor with a single transistor has many
advantages it also has one main disadvantage, the direction of rotation is always the
same, its a Unidirectional circuit. In many applications we need to operate the
motor in both directions forward and back. To control the direction of a DC motor, the
polarity of the DC power applied to the motors connections must be reversed
allowing its shaft to rotate in the opposite direction.
Procedure:
1. Equip Microcontroller 89S51 with the external clock and reset circuitry.
2. Connect pin1 of Optoisolator ILD74 to 5V through 330 resistor and its pin 2
to P2^0 of Microcontroller.
3. Connect pin 4 of Optoisolator ILD74 to base of Darlington transistor TIP120
while its pin 5 is connected to 12V.
4. Connect freewheeling diode 1N4004, 0.1uF capacitor and DC motor in
parallel with one terminal connected to 12 V and the other terminal connected
to Collector terminal of TIP120.
5. Program the microcontroller, turn on power supplies and observe results.
52
Schematic:
12V
5V
2
M1
MOTOR DC
0.1uF
330
1N4004
1
U1
33
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
32
P0.7/AD7
P2.7/A15
37
36
35
34
2
3
4
5
6
7
8
30pF
10uF
5V
8.2k
30pF
19
18
12MHz
31
9
40
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P3.6/WR
P1.7/CEX4
X1
X2
P3.7/RD
ALE
PSEN
Q1
23
10k
24
25
26
27
TIP122
12V
28
10
11
ISO1
OPTO ISOLATOR
100k
12
13
14
15
16
17
30
29
EA
RST
VCC
80C51
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
22
GND
38
21
20
39
5V
C Code:
#include<reg51.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2 = 0x01;
delay(100);
P2 = 0x00;
delay(100);
}
while(1);
}
void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}
53
Result:
The motor stepping sequence was observed as follows:
P2.0/IN
0
1
Motor Status
Moves CLOCKWISE
Stops
Review Questions:
1) Why optocouplers are used in the DC motor drive circuit?
_______________________________________________________________
______________________________________________________________
2) What is the advantage of using L293D line driver IC?
_______________________________________________________________
_______________________________________________________________
3) What is the disadvantage of using Darlington transistor to drive DC
motor?
_______________________________________________________________
_______________________________________________________________
4) Why decoupling capacitor is connected across DC motor?
_______________________________________________________________
_______________________________________________________________
5) What is the purpose of using 1N4004?
_______________________________________________________________
_______________________________________________________________
54
Experiment # 10
Interfacing of 89S51 with Stepper Motor
Objective:
The objective of this experiment is to interface stepper motor with 89S51
microcontroller and to control the speed of the motor.
Equipment Required:
I.
AT89S51 Microcontroller
Motor Driver ULN2003 IC
Unipolar Stepper Motor
Resistors (4.7k)
Components for 89S51 test bench circuitry
Theoretical Background:
Stepper Motor:
A stepper motor is a widely used device that translates electrical pulses into
mechanical movement. In applications such as disk drives, dot matrix printers, and
robotics, the stepper motor is used for position control. Stepper motors commonly
have a permanent magnet rotor (also called the shaft) surrounded by a stator. There
are also steppers called variable reluctance stepper motors that do not have a PM
rotor. The most common stepper motors have four stator windings that are paired with
a center-tapped common. This type of stepper motor is commonly referred to as a
four-phase unipolar stepper motor. The center tap allows a change of current direction
in each of two coils when a winding is grounded, thereby resulting in a polarity
change of the stator.
A Stepper Motor is basically brushless, synchronous DC Motor. The total rotation of
the motor is divided into steps. The angle of a single step is known as the stepper
angle of the motor.
AI.
55
BI.
Unipolar stepper motors can be used in various modes. Three of most common are the
Wave Drive, Full Drive and Half Drive mode.
Wave Drive:
In this mode only one electromagnet is energized at a time. Generated torque will be
less when compared to full drive in which two electromagnets are energized at a time
but power consumption is reduced. It has same number of steps as in the full drive.
This method is used in this experiment
Wave Drive Stepping Sequence
Step
A
1
1
2
0
3
0
4
0
B
0
1
0
0
C
0
0
1
0
56
D
0
0
0
1
Full Drive:
In this mode two electromagnets are energized at a time, so the torque generated will
be larger when compared to Wave Drive. This drive is commonly used than others.
Power consumption will be higher than other modes.
Full Drive Stepping Sequence
Step
A
1
1
2
0
3
0
4
1
B
1
1
0
0
C
0
1
1
0
D
0
0
1
1
Half Drive:
In this mode alternatively one and two electromagnets are energized, so it is a
combination of Wave and Full drives. This mode is commonly used to increase the
angular resolution of the motor but the torque will be less, about 70% at its half step
position. We can see that the angular resolution doubles when using Half Drive.
Half Drive Stepping Sequence
Step
A
1
1
2
1
3
0
4
0
5
0
6
0
7
0
8
1
B
0
1
1
1
0
0
0
0
C
0
0
0
1
1
1
0
0
D
0
0
0
0
0
1
1
1
IV.
ULN2003 Driver:
Procedure:
1. Equip Microcontroller 89S51 with the external clock and reset circuitry.
2. Connect input pins 1 to 4 of ULN2003 driver IC P2^0 to P2^3 respectively and
also to 5V supply through 4.7k resistors.
57
3. Short center tap (common wire) of both windings of unipolar stepper motor
and connect to 5V supply.
4. Connect remaining two ends of each winding one by one to collectors of photo
Darlington pairs in ULN2003A i.e. pins 13 to 16 of ULN2003.
5. Program the microcontroller, turn on power supplies and observe results.
Schematic:
5V
5V
0
4.7k
10k 10k 10k 10k 10k 10k 10k 10k
4.7k
4.7k
4.7k
U1
34
P0.0/AD0
P0.1/AD1
P0.2/AD2
P2.0/A8
P2.1/A9
P2.2/A10
P0.3/AD3
P2.3/A11
P0.4/AD4
P2.4/A12
33 P0.5/AD5
P0.6/AD6
32 P0.7/AD7
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
1 P1.0/T2
3 P1.1/T2EX
4 P1.2/ECI
2
P3.2/INT0
21
28
10
12
13
P3.3/INT1
14
P3.4/T0
15
4C
5B
5C
6C
7C
16
15
14
13
12
11
10
11
P1.4/CEX1
P3.6/WR
P3.7/RD
4B
7 6B
7B
9
COMGND
26
P1.3/CEX0
7 P1.6/CEX3
P1.7/CEX4
1C
2C
3C
27
P3.5/T1
1B
2B
3B
2
3
4
5
P1.5/CEX2
22
23
24
25
39
38
37
36
35
M1
MOTOR STEPPER
U4
ULN2003A
5V
16
17
30
30pF
12MHz
80C51
29
GND
PSEN
20
8.2k
ALE
X2
31
9 EA
RST
40
VCC
30pF
10uF
5V
19
18 X1
5V
0
0
Figure 3: Unipolar stepper motor interfacing with 89C51 using driver ULN2003
C Code:
#include<reg51.h>
#include<stdio.h>
void delay(int);
void main()
{
do
{
P2 = 0x03; //0011
delay(1000);
P2 = 0x06; //0110
delay(1000);
P2 = 0x0C; //1100
58
delay(1000);
P2 = 0x09; //1001
delay(1000);
}
while(1);
}
void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}
Result:
The motor stepping sequence was observed as follows:
Resulting Sequence
Step
1
2
3
4
A
0
0
1
1
B
0
1
1
0
C
1
1
0
0
D
1
0
0
1
Review Questions:
1) What is the difference between ULN2003 and ULN2803 drivers?
_______________________________________________________________
______________________________________________________________
2) Can we drive a unipolar stepper motor using driver L293? Justify your
answer
_______________________________________________________________
_______________________________________________________________
3) What is the role of ULN2003 in stepper motor driving circuitry?
_______________________________________________________________
_______________________________________________________________
4) How can bipolar stepper motor be distinguished from unipolar stepper
motor using DMM?
_______________________________________________________________
59
_______________________________________________________________
5) Why stepper motor is named so?
_______________________________________________________________
_______________________________________________________________
60
Experiment # 11
Interfacing the 89S51 microcontroller with ADC0804 chip
Objective:
The objective of this experiment is to interface ADC0804 chip with 89SC51
microcontroller and to display the result on LCD.
Equipment Required:
AT89S51 Microcontroller
ADC0804 IC
16*2 LCD Display
Potentiometer (10k)
Capacitor (150pF)
Components for 89S51 test bench circuitry
Theoretical Background:
In embedded system, it is essential that microcontrollers take analog input. Sensors
and transducers used in industry are analog in nature. It is needed to convert the
analog output from the sensors to digital so that the corresponding signal can be
processed by the controller. These are generally used in control operation and
instrumentation in industries. ADCs are used everywhere when we have to process,
store or transmit an analog signal in digital form.
ADCs are used in TV tuner cards and for digital data processing in microcontrollers in
the form of on chip 8 bit, 10 bit ADCs. Commercial ADCs are also used as integrated
circuits. Convertors with a resolution of 8 to 24 bits are used and its sample frequency
is in order of some KHz, Mega and Giga sample analog to digital convertors are also
used. They may be required in digital video cameras. Digital to Analog Convertors
may also be required in applications such as CD players, data which will be stored in
binary form may be converted into analog form by the digital to analog convertors. In
this experiment ADC 0804 is used. It is an 8-channel multiplexer, 8-bit analog to
digital converter and microprocessor compatible control logic.
I.
ADC0804:
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 (AT89S51).
ADC0804 is a single channel analog to
61
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:
Pin No.
1
2
3
4
5
6
7
8
9
10
11-18
19
20
AI.
Pin Functions
Pin Name
16*2 LCD:
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very
commonly used in various devices and circuits. These modules are preferred over
seven segments and other multi segment LEDs. The reasons being: LCDs are
economical; easily programmable; have no limitation of displaying special & even
custom characters (unlike in seven segments), animations and so on.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In
this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers,
namely, Command and Data.
The command register stores the command instructions given to the LCD. A
command is an instruction given to LCD to do a predefined task like initializing it,
62
clearing its screen, setting the cursor position, controlling display etc. The data
register stores the data to be displayed on the LCD. The data is the ASCII value of the
character to be displayed on the LCD. Here 16*2 LCD display is used for displaying
8-bit value from ADC0804.
The potentiometer in the circuitry is used to adjust the contrast of LCD.
Procedure:
1. Equip Microcontroller 89S51 with the external clock and reset circuitry.
2. Connect LCD to P0 of the microcontroller. Connect Rs, Rw and E pins of
LCD to P2^0, P2^1 and P2^2 of microcontroller respectively. Connect data
pins (DB0-DB7) to P1 of microcontroller.
3. Connect P2^3, P2^4 and P2^5 of 89S51 to RD pin (to enable read operation),
WR pin (to enable write operation) and INTR pin of ADC respectively.
Ground pins 1, 7, 8 and 10 of ADC0804.
4. Now make CS=0 and send a low to high pulse to WR pin to start the
conversion.
5. Keep checking the INTR pin. INTR will be 1 if conversion is not finished and
INTR will be 0 if conversion is finished
6. If conversion is not finished (INTR=1), poll until it is finished
7. If conversion is finished (INTR=0), go to the next step
8. Make CS=0 and send a high to low pulse to RD pin to read the data from the
ADC.
9. Observe and record results from LCD.
63
Schematic:
VEEVCCVSS
321
DB7DB6DB5DB4DB3DB2DB1DB0
ER/WRS
654
1413121110987
LCD
10k
5V
U1
0
39
38
37
36
35
34
33
32
U6
INTR
VCC/VREF
ADC0804
10
P1.0/T2
P1.1/T2EX
P1.2/ECI
P1.3/CEX0
P1.4/CEX1
P1.5/CEX2
P1.6/CEX3
P1.7/CEX4
19
18 X1
30pF
10uF
5V
5V
8.2k
30pF
40
12MHz
EA
RST
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
PSEN
VCC
80C51
5V
0
0
C Code:
#include<reg51.h> sbit
rs = P2^0; sbit rw =
P2^1 sbit en = P2^2
sbit rd = P2^3; sbit wr
= P2^4; sbit intr =
P2^5; void init_lcd();
void lcd_comm(unsigned char value1); void
lcd_data(unsigned char value2); void
lcd_msg(unsigned char *ch); void
delay(unsigned int ms);
void adc_init(); void
adc_read();
void Converter(unsigned char v4);
unsigned char ascii_lut[] = "0123456789ABCDEF"; void
main()
{
P0 = 0x00;
P1 = 0xFF;
P2 = 0x00;
64
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
30
ALE 29
X2
31
9
GND
CS
20
1
2
3
4
5
6
7
8
GND
150pF
18
17
16
15
14
13
12
11
AGND
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
10k
6
7 +IN
-IN
9
VREF/2
4
19 CLKIN
CLKR
2
3 RD
1 WR
20
10k
POT
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
init_lcd();
adc_init();
lcd_comm(0x80);
lcd_msg("ADC=");
while(1)
{
adc_read();
}
}
void adc_init()
{
wr = 1;
rd = 1;
intr = 1; } void adc_read()
{
unsigned char
v; wr = 0;
wr = 1;
while(intr == 1);
rd = 0;
v = P1;
Converter(v);
intr = 0;
}
void Converter(unsigned char v4)
{
//---Converter to analog input voltage
float g,h;
unsigned int d,t;
g = ((v4 *
5)/255); d = g;
h = g - d;
t = h * 100; lcd_comm(0x85);
lcd_data(d|(0x30));
lcd_data('.');
lcd_data(((t/10)%10)|(0x30));
lcd_data(((t)%10)|(0x30));
lcd_data('V');
lcd_comm(0xC0);
lcd_msg("D=");
lcd_data(((v4/100)%10)|(0x30));
lcd_data(((v4/10)%10)|(0x30));
lcd_data(((v4)%10)|(0x30));
lcd_comm(0xC7);
lcd_msg("H=");
lcd_data(ascii_lut[((v4 & 0xF0)>>4)]);
lcd_data(ascii_lut[((v4 & 0x0F))]);
65
void init_lcd()
{
lcd_comm(0x38);
delay(10);
lcd_comm(0x0E);
delay(10);
lcd_comm(0x01);
delay(10);
lcd_comm(0x06);
delay(10);
lcd_comm(0x80);
delay(10);
}
void lcd_comm(unsigned char value1)
{
P0 = value1;
rs = 0;
rw = 0;
en = 1;
delay(1);
en = 0;
}
void lcd_data(unsigned char value2)
{
P0 = value2;
rs = 1;
rw = 0;
en = 1;
delay(1);
//----1ms delay
en = 0;
}
void lcd_msg(unsigned char *ch)
{
while(*ch != 0
{
lcd_data(*ch);
ch++;
}
}
void delay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<=ms;i++)
for(j=0;j<=120;j++);
}
Results:
The following result appeared on LCD(in accordance with the analog data given to
ADC0804 ):
D=051 , H=33
66
Review Questions:
1) What is the purpose of using potentiometer in the circuitry?
_______________________________________________________________
______________________________________________________________
2) What indication the interrupt pin of ADC gives?
_______________________________________________________________
_______________________________________________________________
3) What is the step size for an ADC with resolution of 8 bits?
_______________________________________________________________
_______________________________________________________________
4) How internal clock of ADC0804 can be used?
_______________________________________________________________
_______________________________________________________________
5) What does 16*2 LCD mean?
_______________________________________________________________
_______________________________________________________________
67