Вы находитесь на странице: 1из 74

List of Experiments

EXPERIMENT #1

Introduction to C programming in 8051...................................................2

EXPERIMENT #2

Introduction to Keil & Proteus software...................................................5

EXPERIMENT #3

Test Bench for 89S51 or 89C51 microcontroller...............................19

EXPERIMENT #4

Show

up

and

down

counter

on

LEDs

using

89S51

microcontroller

....................................................................................................28

EXPERIMENT #5

Identification of Valid and Invalid BCD codes...................................32

EXPERIMENT #6

........................................................................................................ Alarm system using 89S51 with the help of a single bit based

36

alarm system.

EXPERIMENT #7

Interfacing of LDR and Thermistor with 89S51.................................39

EXPERIMENT #8

Four Way Traffic Light System using 89S51.......................................47

EXPERIMENT #9

Interfacing of 89S51 with DC Motor.......................................................50

EXPERIMENT #10

Interfacing of 89S51 with Stepper Motor..............................................55

EXPERIMENT #11

Interfacing the 89S51 microcontroller with ADC0804 chip.........61

1

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.

EXPERIMENT NO 1 Introduction to C programming in 8051 Objective: To get familiar with the basic

8051 extension types:

Sbit:

(Table 1-1)

The sbit keyword is a widely used 8051 C data type designed specifically to access single bit addressable registers. It allows access to the single bit of the SFR register.

2

Bit and SFR:

The bit data type allows access to single bits of a bit addressable memory spaces 20- 2FH. The sbit data type is used for bit addressable SFRs and the bit data type is used for the bit addressable section of RAM space 20-2FH.

Time Delay:

There are two ways to create a time delay in 8051 C:

Using a simple “for loop”

Using the 8051 timers

I/O Programming in 8051 C:

We will discuss here both byte and bit I/O programming.

Byte size I/O:

We see in fig 1.1 that ports P0-P3 byte are accessible. We use the P0-P3 labels as defined in the 8051/52 header file.

Bit-addressable I/O programming:

The I/O ports of P0-P3 are bit-addressable. We can access a single bit without disturbing the rest of the port. We use the sbit data type to access a single bit of P0-P3. P1^7 indicates P1.7. When using this method, we need to include the reg51.h file.

Logical Operations in 8051 C:

One of the most important and powerful features of the C language is the ability to perform bit manipulation. They are listed in table 1-2.

Bitwise operation in C:

Every C programmer is familiar with the logical operators AND(&&), OR(||), and NOT(!), many C programmers are less familiar with the bit-wise operators AND(&), OR(|)< EX-OR(^), Inverter(~), Shift Right(>>), and Shift Left(<<). Table 1-2 shows different logical operations.

Bit and SFR: The bit data type allows access to single bits of a bit addressable

(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

Data << number of bits to be shifted left

Advantages of C language over assembly language:

Here are some advantages of C language over assembly language:

It is small and reasonably simpler to learn, understand, program and debug.

C Compilers are available for almost all embedded devices in use today, and there is a large pool of experienced C programmers.

Unlike assembly, C has advantage of processor-independence and is not specific to any particular microprocessor/ microcontroller or any system. This makes it convenient for a user to develop programs that can run on most of the systems.

As C combines functionality of assembly language and features of high level languages, C is treated as a „middle-level computer languageor „high level assembly language

It is fairly efficient

It supports access to I/O and provides ease of management of large embedded projects.

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?

__________________________________________________________________

4

EXPERIMENT NO 2

Introduction to Keil & Proteus software

Objective:

Introduction to Keil software.

How it is different from other compilers.

Procedure to make project on Keil compiler.

Creating Hex file on Keil compiler.

How to debug a program on Keil compiler.

To understand how to link hex file to microcontroller in Proteus (software).

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. Select New μVision Project from the Project Menu. 4. Name the project „Toggle ‟ .

3. Select New μVision Project from the Project Menu.

3. Select New μVision Project from the Project Menu. 4. Name the project „Toggle ‟ .
  • 4. Name the project „Toggle.

  • 5. Click on the Save Button.

6

6. The device window will be displayed. 7. Select the part you will be using to
  • 6. The device window will be displayed.

7.

Select the part you will be using to test with. For now we will use the Atmel Semiconductor part 89S51 or 89C51.

  • 8. Double Click on the Atmel Semiconductor.

6. The device window will be displayed. 7. Select the part you will be using to
  • 9. Scroll down and select the AT89S51Part. 10. Click OK.

7

Creating Source File: 1. Click File Menu and select New. 2. A new window will open

Creating Source File:

  • 1. Click File Menu and select New.

Creating Source File: 1. Click File Menu and select New. 2. A new window will open

2. A new window will open up in the Keil IDE.

8

3. Copy the example to the Right into the new window. This file will toggle Ports
  • 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)

{

P1=0x55;

//another way to do it forever

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++);

}

  • 4. Click on File menu and select Save As…

9

5. Name the file Toggle.c 6. Click the Save Button 7. Change file type to Asm
  • 5. Name the file Toggle.c

  • 6. Click the Save Button

5. Name the file Toggle.c 6. Click the Save Button 7. Change file type to Asm
  • 7. Change file type to Asm Source File (*.c).

  • 8. Select toggle.c

  • 9. Click Add button 10. Click Close button.

10

11 . Expand the Source Group 1 in the Tree menu to ensure that the file

11. Expand the Source Group 1 in the Tree menu to ensure that the file was added to the project.

11 . Expand the Source Group 1 in the Tree menu to ensure that the file

Creating HEX for the Part:

  • 1. Click on Target 1 in Tree menu

  • 2. Click on Project Menu and select Options for Target 1

11

3. Select Target Tab 4. Change Xtal (MHz) from 33.0 to11.0592 or 12MHz. Change the code
  • 3. Select Target Tab

4.

Change Xtal (MHz) from 33.0 to11.0592 or 12MHz. Change the code ROM size small: program 2K or less

3. Select Target Tab 4. Change Xtal (MHz) from 33.0 to11.0592 or 12MHz. Change the code
  • 5. Select Output Tab

  • 6. Click on Create Hex File check box

12

7. Click OK Button.

7. Click OK Button. 8. Click on Project Menu and select Rebuild all Target Files. 9.
  • 8. Click on Project Menu and select Rebuild all Target Files.

  • 9. In the Build Window it should report „0 Errors (s), 0 Warnings.

10. You are now ready to Program your Part.

7. Click OK Button. 8. Click on Project Menu and select Rebuild all Target Files. 9.

13

Testing Program in Debugger:

  • 1. Click on Debug Menu and Select Start/Stop Debug Session.

Testing Program in Debugger: 1. Click on Debug Menu and Select Start/Stop Debug Session. 2. If
  • 2. If you use a free version of Keil the dialog appears. Click OK

Testing Program in Debugger: 1. Click on Debug Menu and Select Start/Stop Debug Session. 2. If
  • 3. The Keil Debugger should be now Running.

Testing Program in Debugger: 1. Click on Debug Menu and Select Start/Stop Debug Session. 2. If
  • 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. 5. Now press

A new window should will pop up. This represents the Ports and Pins.

A new window should will pop up. This represents the Ports and Pins. 5. Now press
  • 5. Now press F5 to run the debugging.

15

6. To exit out, Click on Debug Menu and Select Start/Stop Debug Session or press icon.
  • 6. To exit out, Click on Debug Menu and Select Start/Stop Debug Session or press

6. To exit out, Click on Debug Menu and Select Start/Stop Debug Session or press icon.

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

Step2: Place cursor on microcontroller 89S51 and double click it. A window will

open, on program file option click on folder icon

Step2: Place cursor on microcontroller 89S51 and double click it. A window will open, on program

and add directory of your hex file

(Keil\C51\Examples\HELLO\toggle.hex) where you create it on Keil.

Step2: Place cursor on microcontroller 89S51 and double click it. A window will open, on program

Step 3: Simulate the circuit.

17

Review questions:

1) What is Keil compiler?

2) What should be the frequency of oscillator (XTAL) of Atmel 89S51 in options for target at Keil?

3) How we link Hex file on Proteus schematic?

4) What is the identification of creating Hex file on 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:

89S51 or 89C51 microcontroller

8 LEDs

Buzzer

Relay

Resistors (330Ω (16),1kΩ (1),10kΩ(8) & 8.2kΩ(1))

Capacitors (10uF(1) & 30pF(2))

12MHz Crystal Oscillator

7-Segment Display

74LS47 (BCD to 7-Segment Decoder)

Theoretical Background:

  • I. Pin Layout of 89S51/89C51 Microcontroller:

89S51/89C51 has 40 pins dedicated for various functions such as I/O, -RD, -WR, address, data, and interrupts. Pin diagram of 89C51/89S51 microcontroller is shown in figure 1. Their description is as follows.

Vcc:

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

GND:

Pin 20 is the ground.

XTAL1 and XTAL2:

The 8051 has an on-chip oscillator but requires an external clock to run it. A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18). If you use a frequency source other than a crystal oscillator, such as a TTL Oscillator, it will be connected to XTAL1 and XTAL2 is left unconnected

RST:

Figure 1

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

20

the registers to be lost. It will set program counter to all 0s. 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.

10uF 5V 12MHz 30pF 8.2k 30pF 0 0
10uF
5V
12MHz
30pF
8.2k
30pF
0
0

U1

21

 

39

39 P0.0/AD0 P2.0/A8

P0.0/AD0

P2.0/A8

38 37 P0.1/AD1 P2.1/A9 22 23

38

37

P0.1/AD1

P2.1/A9

22

23

36 P0.2/AD2 P2.2/A10 24

36

P0.2/AD2

P2.2/A10

24

35 P0.3/AD3 P2.3/A11 25

35

P0.3/AD3

P2.3/A11

25

34 33 P0.4/AD4 P0.5/AD5 P2.4/A12 P2.5/A13 26 27
34 33 P0.4/AD4 P0.5/AD5 P2.4/A12 P2.5/A13

34

33

P0.4/AD4

P0.5/AD5

P2.4/A12

P2.5/A13

26

27

32 P0.6/AD6 P2.6/A14 28

32

P0.6/AD6

P2.6/A14

28

P0.7/AD7 P2.7/A15

P0.7/AD7

P2.7/A15

1 10
  • 1 10

  • 2 P3.0/RXD

P1.0/T2

3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
3 P3.2/ INT0 P1.2/ECI 4 5 P3.3/INT1 P1.3/CEX0 6 7 P3. 5/T1 P1.5/CEX2 P1.4/CEX1 P3.4/T0 P1.1/T2EX
  • 3 P3.2/INT0

P1.2/ECI

  • 4
    5 P3.3/INT1

P1.3/CEX0

  • 6
    7 P3.5/T1

P1.5/CEX2

P1.4/CEX1

P3.4/T0

P1.1/T2EX

P3.1/TXD

  • 8 P3.6/WR

P1.6/CEX3

11

12

13

14

15

16

P1.7/CEX4 P3.7/RD 17
P1.7/CEX4 P3.7/RD 17

P1.7/CEX4

P3.7/RD

17

19

X1

ALE

30

18

31

X2

18 31 X2 PSEN
18 31 X2 PSEN

PSEN

29

 

EA

GN

D

9 40
9
40

RST

VCC

GN D 9 40 VCC
 

80C51

20 the registers to be lost. It will set program counter to all 0 ‟ s.

(a)

5V

30pF 12MHz 0 30pF 10uF 8.2k 0 SW PUSHBUTTON 0
30pF
12MHz
0
30pF
10uF
8.2k
0
SW PUSHBUTTON
0

20 GND

U1

 

21

39

39
  • P0.0/AD0

38

P2.0/A8

  • P0.1/AD1

  • P0.2/AD2

  • P0.3/AD3

35

  • P0.4/AD4

  • P0.5/AD5

33

  • P0.6/AD6

32

  • P0.7/AD7

34

36

37

P2.1/A9

P2.2/A10

P2.3/A11

P2.4/A12

P2.5/A13

P2.6/A14

P2.7/A15

23

24

25

26

27

28

  • 1 10

  • P3.0/RXD

P3.0/RXD P1.0/T2 2 P1.1/T2EX P3.1 /TXD P3.2/ INT0 4 P1.3/CEX0 P3.3/INT1 P3.4/T0 6 P1.5/CEX2 P3.5

P1.0/T2

  • 2 P1.1/T2EX

  • P3.1/TXD

  • P3.2/INT0

    • 4 P1.3/CEX0

  • P3.3/INT1

  • P3.4/T0

    • 6 P1.5/CEX2

  • P3.5/T1

  • P3.6/WR

    • 8 P1.7/CEX4

  • P3.7/RD

    • 7 P1.6/CEX3

    • 5 P1.4/CEX1

    • 3 P1.2/ECI

P3.0/RXD P1.0/T2 2 P1.1/T2EX P3.1 /TXD P3.2/ INT0 4 P1.3/CEX0 P3.3/INT1 P3.4/T0 6 P1.5/CEX2 P3.5

11

12

13

14

15

16

17

19

  • X1

ALE

19 X1 ALE 30

30

18

X2

PSEN

29

22
22

31

EA

  • 9 RST

  • 40 VCC

20 GND U1 21 39 P0.0/AD0 38 P2.0/A8 P0.1/AD1 P0.2/AD2 P0.3/AD3 35 P0.4/AD4 P0.5/AD5 33 P0.6/AD6
20 GND U1 21 39 P0.0/AD0 38 P2.0/A8 P0.1/AD1 P0.2/AD2 P0.3/AD3 35 P0.4/AD4 P0.5/AD5 33 P0.6/AD6

80C51

(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, port 0 provides both address and

data.

The

5V

8051

multiplexes

address and data through port 0 to save pins. ALE indicates if P0 has address or data.

When ALE=0, it provides data D0-D7.

When

ALE=1,

it

has

address A0-A7.

 

It can be used for input or output,

each pin must

be

connected

externally to a 10K ohm pull-up

resistor. This

is

due to

the

fact

330 330 330 330 330 330 330 330 U1 39 21 38 P0.0/AD0 P2.0/A8 22 P0.1/AD1
330 330
330
330
330
330
330 330
U1
39
21
38
P0.0/AD0
P2.0/A8
22
P0.1/AD1
P2.1/A9
37
23
P0.2/AD2
P2.2/A10
36
24
35
25
P0.4/AD4 P0.3/AD3
P2.4/A12 P2.3/A11
34
26
P0.5/AD5
P2.5/A13
33
27
32
P0.6/AD6
P2.6/A14
28
P0.7/AD7
P2.7/A15
1
10
P1.0/T2
P3.0/RXD
2
11
P1.1/T2EX
P3.1/TXD
3
12
P1.2/ECI
P3.2/INT0
4
13
P1.3/CEX0
P3.3/INT1
5
14
P1.4/CEX1
P3.4/T0
6
15
P1.5/CEX2
P3.5/T1
7
16
P1.6/CEX3
P3.6/WR
8
17
P1.7/CEX4
P3.7/RD
19
30
X1
ALE
18
29
X2
PSEN
Figure 3
31
EA
9
RST
40
VCC
80C51
20 GND

that P0 is an open drain, unlike P1, P2, and P3. This is shown in figure 3.

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

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

5V 0 10k 10k 10k 10k 10k 10k 10k 10k U1 39 21 P0.0/AD0 P2.0/A8 38
5V
0
10k 10k
10k
10k 10k
10k
10k
10k
U1
39
21
P0.0/AD0
P2.0/A8
38
22
P0.1/AD1
P2.1/A9
37
23
P0.2/AD2
P2.2/A10
36
24
P0.3/AD3
P2.3/A11
35
25
P0.4/AD4
P2.4/A12
34
26
P0.5/AD5
P2.5/A13
33
27
P0.6/AD6
P2.6/A14
32
28
P0.7/AD7
P2.7/A15
330
1
10
P1.0/T2
P3.0/RXD
330
2
11
P1.1/T2EX
P3.1/TXD
330
3
12
P1.2/ECI
P3.2/INT0
330
4
13
P1.3/CEX0
P3.3/INT1
330
5
14
V5
P1.4/CEX1
P3.4/T0
330
6
15
P1.5/CEX2
P3.5/T1
330
7
16
P1.6/CEX3
P3.6/WR
330
8
17
P1.7/CEX4
P3.7/RD
19
30
X1
ALE
0
18
29
X2
PSEN
31
EA
30pF
9
RST
12MHz
10uF
40
VCC
30pF
80C51
8.2k
0
5V
0
0
Figure 5
20
GND

22

AI.

Seven Segment Display:

7-Segment Display consists of seven individual coloured LEDs

(called the segments), within one single display package. In order to produce the required numbers or HEX characters from 0 to 9 and A to F respectively, on the display the correct combination of LED segments need to be illuminated and BCD to 7-Segment Display Decoder 74LS47 does that. A standard 7- Segment LED display generally has 8 input connections, one for each LED segment and one that acts as a common terminal or connection for all the internal display segments. We are using common anode configuration of display.In the common anode configuration, all the anode connections of the LEDs are joined together to logic “1″ and the individual segments are illuminated by connecting the individualcathode terminals to a “LOW”, logic “0″ signal.74LS47 has 4 BCD inputs and 7 output lines, one for each

AI. Seven Segment Display: 7-Segment Display consists of seven individual coloured LED ‟ s (called the

LED segment. This allows a smaller 4-bit binary number (half a byte) to be used to display all the decimal numbers from 0 to 9.

Figure 6
Figure 6

BI.

Buzzer:

A buzzer or beeper is an audio signalling device, which may be mechanical, electromechanical, or piezoelectric. A buzzer is a device that can produce an audible tone in the influence of an externally applied voltage. This audible output may be either in the form of a buzzing or a beeping sound. The sound is created by

23

AI. Seven Segment Display: 7-Segment Display consists of seven individual coloured LED ‟ s (called the

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 „bellor warning alarm for digital systems.

5V 0 10k 10k 10k 10k 10k 10k 10k 10k U1
5V
0
10k 10k
10k 10k 10k
10k
10k 10k
U1

5V

0
0
BUZZER 10uF 30pF 5V 8.2k 30pF 0 0
BUZZER
10uF
30pF
5V
8.2k
30pF
0
0
330 12MHz 21 39 P2.0/A8 38 P0.1/AD1 36 P2.2/A10 P0.2/AD2 37 P2.1/A9 22 23 24 35
330 12MHz
330
12MHz
 

21

39 P2.0/A8 38 P0.1/AD1 36 P2.2/A10 P0.2/AD2
  • 39 P2.0/A8

38

P0.1/AD1

  • 36 P2.2/A10

P0.2/AD2

  • 37 P2.1/A9

22
22

23

24

  • 35 P2.4/A12

  • 34 P2.5/A13

P0.5/AD5

  • 33 P2.6/A14

P0.6/AD6

P0.4/AD4

P0.0/AD0 P0.3/AD3

P2.3/A11

25

26

27

P0.7/AD7

  • 32 P2.7/A15

1

28
28
28

P1.0/T2

2

3

P1.1/T2EX

P1.2/ECI

4

P3.0/RXD

P3.1/TXD

P3.2/INT0

10

P1.0/T2 2 3 P1.1/T2EX P1.2/ECI 4 P3.0/RXD P3.1 /TXD P3.2/ INT0 10
12 11 13
12
11
13
P1.3/CEX0 P3.3/INT1

P1.3/CEX0

P3.3/INT1

P1.3/CEX0 P3.3/INT1

5

P1.4/CEX1

P3.4/T0

14

5 P1.4/CEX1 P3.4/T0 14
5 P1.4/CEX1 P3.4/T0 14

6

7

6 7 P1 5/CEX2 P3 5/T1

P1 5/CEX2

P3 5/T1

15

16

21 39 P2.0/A8 38 P0.1/AD1 36 P2.2/A10 P0.2/AD2 37 P2.1/A9 22 23 24 35 P2.4/A12 34
21 39 P2.0/A8 38 P0.1/AD1 36 P2.2/A10 P0.2/AD2 37 P2.1/A9 22 23 24 35 P2.4/A12 34

P1.6/CEX3

8

P1.7/CEX4

P3.6/WR

P3.7/RD

17
17
 
21 39 P2.0/A8 38 P0.1/AD1 36 P2.2/A10 P0.2/AD2 37 P2.1/A9 22 23 24 35 P2.4/A12 34

19

X1

ALE

30

29
29
29

29

29

18

18 X2 PSEN

X2

PSEN

18 X2 PSEN

31

31

9

EA

GND

40

RST

VCC

GND RST VCC
GND RST VCC
 
 

80C51

20
20
5V IV. Relay:
5V
IV.
Relay:

0

Figure 7

Figure 8
Figure 8

A relay is an electrically operated switch that uses an electromagnet to move the switch from off to on position instead of a person moving a switch. It is an electromagnetic device which is used to isolate two circuits electrically and connect them magnetically. They are often used to interface an electronic circuit (working at a low voltage) to an electrical circuit which works at very high voltage.

24

Construction and Working:

Construction and Working: A relay switch can be divided into two parts: input and output. The

A relay switch can be divided into two parts: input and output. The input section has a coil which generates magnetic field when a small voltage from an electronic circuit is applied to it. This voltage is called the operating voltage. Commonly used relays are available in different configuration of operating voltages like 6V, 9V, 12V, 24V etc. The output section consists of contactors which connect or disconnect mechanically. Relays come in different configurations like SPST, SPDT, DPDT etc. which have different number of changeover contacts. We have used SPDT configuration on the test bench. In SPDT relay there are three contacts: normally open (NO), normally closed (NC) and common (COM).At no input state, the COM is connected to NC. When the operating voltage is applied the relay coil gets energized and the COM changes contact to NO. Working of relay is shown in figure 9.

Freewheeling/Fly-back diode:

A relay coil is not only an electromagnet but it is also an inductor. When power is applied to the coil the current in the coil builds up and levels off at its rated current (depends on the DC resistance of the coil, I = V/R). Some energy is now stored in the

coil's magnetic field (E = 05LI 2 ). When the current in the coil is turned off this stored energy has to go somewhere. The voltage across the coil quickly increase trying to keep the current in the coil flowing in the same direction (V = Ldi/dt). This voltage spike can reach hundreds or thousands of volts and can damage electronic parts.

By adding a flyback diode the current has a path to continue flowing through coil until the stored energy is used up. The diode also clamps the voltage across the coil to about 0.7V protecting the electronics. The stored energy dissipates quickly in the diode (E = V*I*t). The current stops flowing and the relay turns off. The diode should be able to handle the coil current for a short time and switch relatively fast. Note: A resistor or zener diode can be placed in series with the diode to use up the stored energy quicker. This increases the amplitude of the voltage spike above 0.7V but the energy is used up quicker (i.e. the voltage spike won't last as long). Usually it doesn't matter if the relay takes 1ms or 100ms to turn off.

25

5V
5V

0

_____ 39 21 P0.0/AD0 P2.0/A8 38 22 P0.1/AD1 P2.1/A9 _ 37 23 P0.2/AD2 P2.2/A10 36 24
_____
39
21
P0.0/AD0
P2.0/A8
38
22
P0.1/AD1
P2.1/A9
_
37
23
P0.2/AD2
P2.2/A10
36
24
P0.3/AD3
P2.3/A11
35
25
1k
P0.4/AD4
P2.4/A12
34
26
P0.5/AD5
P2.5/A13
33
27
_____
P0.6/AD6
P2.6/A14
32
28
P0.7/AD7
P2.7/A15
_____
1
10
P1.0/T2
P3.0/RXD
2
11
Q1
_____
P1.1/T2EX
P3.1/TXD
3
12
2N1069
P1.2/ECI
P3.2/INT0
4
13
_____
P1.3/CEX0
P3.3/INT1
5
14
P1.4/CEX1
P3.4/T0
6
15
P1.5/CEX2
P3.5/T1
_____
7
16
P1.6/CEX3
P3.6/WR
0
8
17
P1.7/CEX4
P3.7/RD
_____
19
30
X1
ALE
_____
18
29
X2
PSEN
10uF
31
_____
EA
30pF
9
RST
5V
12MHz
_____
40
VCC
_____
8.2k
30pF
80C51
_____
0
_____
0
___
5V
26
20
GND

Review Questions:

0

Figure 9

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

0

EXPERIMENT NO. 4

Show up and down counter on LED’s using 89S51 microcontroller.

Objective:

We are showing up and down counter on leds 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:

Asynchronous (ripple) counter – changing state bits are used as clocks to subsequent state flip-flops. Synchronous counter – all state bits change under control of a single clock.

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?

3)

How can up counters be made?

4)

What are the applications of counters?

5)

Name some reversible counters.

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.

89S51 Microcontroller.

ii.

74LS47 Decoder.

iii.

Seven Segment Display (common anode).

iv.

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 LEDs so it is called seven segment display. There are 2 types of seven segment display

  • I. Common Anode II. Common Cathode

32

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

Made the circuit according to schematic shown in figure.

 

ii.

Now write the C-code for invalid BCD codes that correspond to binary numbers from 1010 to 1111.

iii.

Compile the program in Keil and burn it into 89S51 using burner.

iv.

Insert the programmed microcontroller into its base on test bench.

 

v.

Check connections between Seven segment display and decoder and between decoder and microcontroller.

vi.

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.

Schematic

33

Figure 2 C-Code for valid BCD codes: #include<reg51.h> Void main() { unsigned char z; for(z=0;z<=40000;z++) {

Figure 2

C-Code for valid BCD codes:

#include<reg51.h>

Void main()

{

unsigned char z;

for(z=0;z<=40000;z++)

{

P1=0x00; // P1 is set as port for sending the data.

for(z=0;z<=40000;z++);

P1=0x01;

for(z=0;z<=40000;z++);

P1=0x02;

for(z=0;z<=40000;z++);

P1=0x03;

for(z=0;z<=40000;z++);

P1=0x04;

for(z=0;z<=40000;z++);

P1=0x05;

for(z=0;z<=40000;z++);

P1=0x06;

for(z=0;z<=40000;z++);

P1=0x07;

for(z=0;z<=40000;z++);

P1=0x08;

for(z=0;z<=40000;z++);

P1=0x09;

for(z=0;z<=40000;z++);

}

}

C-Code for Invalid BCD codes:

34

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

Test bench of 89S51

2 Resistors (330Ω)

Buzzer

LED

Theoretical Background:

An alarm system is needed to prevent any bad condition or situation which we dont 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 330 10uF 30pF 5V 12MHz 8.2k 30pF
5V
10k 10k
10k
10k 10k
5V
0
BUZZER
330
10uF
30pF
5V
12MHz
8.2k
30pF
0
0
0

Figu

re 1

37

0

0

U1

  • P0. 0/AD0 P0. 1/AD1 P0. 2/AD2 P0. 3/AD3 P0. 4/AD4 P0. 5/AD5 P0. 6/AD6 P0. 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

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 20 GND
VCC
80C51
20
GND

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
P3.6/WR
P3.7/RD
ALE
PSEN

21

22

23

24

25

26

27

28

10

11

12

13

14

15

16

17

30

29

Result: Setting the value at „0 ‟ led will be ON indicating correct code .While setting

Result:

Setting the value at „0led 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?

  • 2. Which voltage should you take from the 89S51 microcontroller?

  • 3. What are the types of audible alarms?

  • 4. What is the magnitude of sound required to perform the expected task?

  • 5. What type of actuation signal will be available?

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.

EXPERIMENT NO 7 Interfacing of LDR and Thermistor with 89S51 Components:  LDR  Thermistor 

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.

light dependent resistors are semiconductors, when used as a photo-resistor, they are used only as a

Photoresistor or photocell with interdigital contact pattern

40

It is also possible to use a polycrystalline semiconductor that is deposited onto a substrate such as ceramic. This makes for a very low cost light dependent resistor.

Photoresistor applications

The photoresistor or light dependent resistor is attractive in many electronic circuit designs because of its low cost, simple structure and rugged features. While it may not have some of the features of the photo-diode and photo-transistor, it is ideal for many applications. As a result the photo-resistor is widely used in circuits such as photographic meters, flame or smoke detectors, burglar alarms, card readers, controls for street lighting and many others.

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.

It is also possible to use a polycrystalline semiconductor that is deposited onto a substrate such

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 in Figure.
Thermistors
symbols
are
shown
in
Figure.

41

Graph of NTC and PTC Principle of Working of Thermistors As mentioned earlier the resistance of

Graph of NTC and PTC

Principle of Working of Thermistors

As mentioned earlier the resistance of the thermistors decreases with the increase its temperature. The resistance of thermistor is given by:

R = R o e

k

K = β(1/T – 1/T o )

Where R is the resistance of the thermistor at any temperature T in o K (degree Kelvin) R o

is the resistance of the thermistors at particular reference temperature T o in

o

K

e is the base of the Naperian logarithms

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

Measure the voltages by DC voltmeter without throwing light on LDR. The voltage should lie between 0V to 0.8V for this condition and LED should remain OFF.

Measure the voltages by DC voltmeter again by throwing required intensity of light on LDR. The voltage should lie between 2V to 5V for this condition and LED should glow.

Record the voltages against the two intensity levels of light, in table.

Minute light (less than 40 At light effect (2000 lux) lux)

 

0.35V

2.22V

Experiment can be repeated for different light intensities by changing value of variable resistor.

43

Figure 1 Thermistor  Make connections of thermistor with 89S51 test bench as shown in the
Figure 1
Thermistor
Make connections of thermistor with 89S51 test bench as shown in the figure.
 Place a 330Ω resistor in series with parallel combination of 10uF capacitor
and thermistor. Also connect an LED and DC voltmeter in parallel for
measuring voltages for the ON state and OFF state of LED.

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.

Measure the voltages by DC voltmeter at room temperature without heating. The voltage should lie between 0V to 0.8V for this condition and LED should remain OFF.

Measure the voltages by DC voltmeter again by heating to boiling point. The voltage should lie between 2V to 5V for this condition and LED should glow.

Record the voltages against the two temperature levels, in table.

 
 

Room Temperature (25C)

At heating effect (100C)

0.31V

2.19V

44

Figure 2 C-Code
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 electro- mechanical 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:

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++);

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

this

experiment using just 2 ports

of

____________________________________________________________

____________________________________________________________

  • 3. Can you add a Seven segment display counter to this experiment?

____________________________________________________________

____________________________________________________________

  • 4. Is it possible to use just one resistance for three LED’s?

____________________________________________________________

____________________________________________________________

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:

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:

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

DC Motor Switching and Control:

The maximum current that can be sourced or sunk from an 8051 microcontroller is 15 mA at 5v. But a DC Motor need currents very much more than that and it need voltages 6v, 12v, 24v etc. depending upon the type of motor used. Another problem is that the back emf produced by the motor may affect the proper functioning of the microcontroller. Due to these reasons we cant connect a DC Motor directly to a microcontroller.

To overcome these problems, H-Bridge can be used using transistors. Freewheeling diodes or Clamp diodes should be used to avoid problems due to back emf. Thus it requires transistors, diodes and resistors, which may make our circuit bulky and difficult to assembly.

An efficient way is to use L293D line driver IC. This is because it is a Quadruple Half H-Bridge driver and it can solve the problem completely. So, no transistors and diodes are needed to connect in this case.

DC motor control using Darlington transistor TIP120:

A Darlington transistor may also be used were a higher current rating is required to control the motor from a single power supply. The TIP120 is an NPN Power Darlington Transistor. By varying the amount of base current flowing into the transistor the speed of the motor can be controlled for example, if the transistor is turned on “half way”, then only half of the supply voltage goes to the motor. If the transistor is turned “fully ON” (saturated), then all of the supply voltage goes to the motor and it rotates faster. For a Unidirectional (one direction only) motor control, a continuous logic “1” or logic “0” is applied to the input of the circuit to turn the motor “ON” (saturation) or “OFF” (cut-off) respectively.

Freewheeling diode 1N4004:

A flywheeling diode is connected across the motor terminals to protect the switching transistor or MOSFET from any back emf generated by the motor when the transistor turns the supply “OFF”. As for the 1N4004 diode, it allows current to pass in one direction from positive to negative but will block any stray current that tries to go in the opposite direction, which might have undesirable effects on your circuit.

Optoisolator ILD74:

An opto-isolator, also called an optocoupler, is a component that transfers electrical signals between two isolated circuits by using light. An optoisolator contains a source (emitter) of light, almost always a near infrared LED, that converts electrical input signal into light, a closed optical channel and a photo sensor, which detects incoming light and either generates electric energy directly, or modulates electric flowing from an external power supply. The main function of an opto-isolator is to block such high voltages and voltage transients, so that a surge in one part of the system will not disrupt or destroy the other parts and this is the same function it performs in DC motor drive circuitry.

51

Figure 1 Disadvantage of this control method: While controlling the speed of a DC motor with

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.

Schematic:

52

Figure 1 Disadvantage of this control method: While controlling the speed of a DC motor with

1

10k 10k 10k 10k 10k 10k 10k 10k 5V
10k
10k 10k
10k 10k
10k 10k
10k
5V

12V

1 10k 10k 10k 10k 10k 10k 10k 10k 5V 12V 0 2 U1 P0.0/AD0 P0.1/AD1
0 2
0
2

U1

1 10k 10k 10k 10k 10k 10k 10k 10k 5V 12V 0 2 U1 P0.0/AD0 P0.1/AD1
  • 39 P0.0/AD0

    • 38 P0.1/AD1

  • 37 P0.2/AD2

  • 36 P0.3/AD3

  • 35 P0.4/AD4

  • 34 P0.5/AD5

  • 33 P0.6/AD6

P0.7/AD7

P1.0/T2

P1.1/T2EX

P1.2/ECI

P1.3/CEX0

  • 5
    6 P1.4/CEX1

  • 7 P1.5/CEX2

19

18

1 10k 10k 10k 10k 10k 10k 10k 10k 5V 12V 0 2 U1 P0.0/AD0 P0.1/AD1

P1.7/CEX4

X1

X2

  • 8 P1.6/CEX3

330 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2.3/A11 24 P2.4/A12 25 P2.5/A13 26 P2.6/A14 27 P2.7/A15
330
P2.0/A8
21
P2.1/A9
22
P2.2/A10
23
P2.3/A11
24
P2.4/A12
25
P2.5/A13
26
P2.6/A14
27
P2.7/A15
28
10
ISO1
P3.0/RXD
11
OPTO ISOLATOR
P3.1/TXD
P3.2/INT0
12
13
P3.3/INT1
14
P3.4/T0
15
P3.5/T1
16
P3.6/WR
17
P3.7/RD
30
ALE
29
PSEN

TIP122

0 0.1uF 1N4004
0
0.1uF
1N4004
Q1 10k
Q1
10k
12V 100k
12V
100k

0

30pF 5V 10uF 12MHz 30pF 8.2k 0 0
30pF
5V
10uF
12MHz
30pF
8.2k
0
0
31 EA 9 RST 40 VCC 80C51 5V 20 GND
31
EA
9
RST
40
VCC
80C51
5V
20
GND
1 10k 10k 10k 10k 10k 10k 10k 10k 5V 12V 0 2 U1 P0.0/AD0 P0.1/AD1

0

M1

MOTOR DC

C Code:

#include<reg51.h>

#include<stdio.h>

Figure 2: Interfacing DC motor with 89C51

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

Motor Status

  • 0 Moves CLOCKWISE

  • 1 Stops

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

AT89S51 Microcontroller

Motor Driver ULN2003 IC

Unipolar Stepper Motor

Resistors (4.7kΩ)

Components for 89S51 test bench circuitry

Theoretical Background:

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

Two phase Stepper Motors:

There are two basic winding arrangements for the electromagnetic coils in a two phase stepper motor: bipolar and unipolar.

Bipolar stepper motor:

The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. They can be distinguished from unipolar steppers by measuring the resistance between the wires. One should find two pairs of wires with equal resistance. If youve got the leads of your meter connected to two wires that are not connected (i.e. not attached to the same coil), you should see infinite resistance (or no continuity).Bipolar stepper motors have no center tap and having equal coil resistances.

55

Figure 1: Bipolar stepper motor coils Unipolar stepper motor: A unipolar stepper motor has one winding

Figure 1: Bipolar stepper motor coils

Unipolar stepper motor:

A unipolar stepper motor has one winding with center tap per phase. Since in this arrangement a magnetic pole can be reversed without switching the direction of current, the commutation circuit can be made very simple (e.g., a single transistor) for each winding. Typically, given a phase, the center tap of each winding is made common: giving three leads per phase and six leads for a typical two phase motor. Often, these two phase commons are internally joined, so the motor has only five leads. Windings of this motor can be identified by touching the terminal wires together in PM motors. If the terminals of a coil are connected, the shaft becomes harder to turn. One way to distinguish the center tap (common wire) from a coil-end wire is by measuring the resistance. Resistance between common wire and coil-end wire is always half of what it is between coil-end and coil-end wires. Due to the ease of operation unipolar stepper motor is commonly used. We are using it in this experiment too.

Figure 1: Bipolar stepper motor coils Unipolar stepper motor: A unipolar stepper motor has one winding

Figure 2: Unipolar stepper motor coils

BI.

Driving Unipolar Stepper with 89C51:

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

B

C

D

  • 1 1

0

0

0

  • 2 0

1

0

0

  • 3 0

0

1

0

  • 4 0

0

0

1

56

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

B

C

D

1

1

1

0

0

2

0

1

1

0

3

0

0

1

1

4

1

0

0

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

B

C

D

1

1

0

0

0

2

1

1

0

0

3

0

1

0

0

4

0

1

1

0

5

0

0

1

0

6

0

0

1

1

7

0

0

0

1

8

1

0

0

1

In this experiment, unipolar stepper motor will be interfaced with 89C51 microcontroller using ULN2003A to obtain wave drive mode.

IV.

ULN2003 Driver:

The ULN2003 is a high-voltage high-current Darlington transistor array. It consists of seven NPN Darlington pairs that feature high-voltage outputs with common-cathode clamp diodes for switching inductive loads. The collector-current rating of a single Darlington pair is 500 mA. Applications include relay drivers, hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers, and logic buffers. The ULN2003A has a 2.7-kΩ series base resistor for each Darlington pair for operation directly with TTL or 5-V CMOS devices. In the motor driving circuit ULN2003 reduces back EMF.

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 4.7k 0 4.7k 10k 10k 10k 10k 10k 10k 10k 10k 4.7k M1
5V
0
4.7k
4.7k
0
4.7k
10k
10k
10k
10k
10k
10k 10k
10k
4.7k
M1
U1
U4
MOTOR STEPPER
ULN2003A
39
21
1
16
P0.0/AD0
P2.0/A8
1B
1C
38
22
2
15
P0.1/AD1
P2.1/A9
2B
2C
37
23
3
14
P0.2/AD2
P2.2/A10
3B
3C
36
24
4
13
35
P0.3/AD3
P2.3/A11
25
5
4B
4C
12
34
P0.4/AD4
P2.4/A12
26
6
5B
5C
11
P0.5/AD5
P2.5/A13
6B
6C
33
27
7
10
P0.6/AD6
P2.6/A14
7B
7C
32
P0.7/AD7
28
9
P2.7/A15
COMGND
1
P3.0/RXD
P1.0/T2
10
2
11
P1.1/T2EX
P3.1/TXD
3
12
4
P1.2/ECI
P3.2/INT0
13
5
14
P1.3/CEX0
P3.3/INT1
6
P1.4/CEX1
P3.4/T0
15
5V
P1.5/CEX2
P3.5/T1
7
P1.6/CEX3
P3.6/WR
16
P1.7/CEX4
P3.7/RD
8
17
30
19
18
X1
ALE
29
X2
PSEN
0
31
30pF
EA
9
RST
5V
10uF
40
VCC
12MHz
30pF
8.2k
80C51
5V
0
0
0
20
GND
8

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

A

B

C

D

  • 1 0

0

1

1

  • 2 0

1

1

0

  • 3 1

1

0

0

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

Experiment # 11 Interfacing the 89S51 microcontroller with ADC0804 chip Objective: The objective of this experiment

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. V in , which is the input pin, is connected to a preset to provide analog input.

Pin Description:

 

Pin No.

 

Pin Functions

 

Pin Name

 
 
  • 1 Make this pin low to active ADC

1 Make this pin low to active ADC
 

Chip Select (CS)

 

Read (RD)

  • 2 Input pin: High to low pulse brings the data from internal registers to the output

 

pins after conversion

  • 3 Input pin: Low to high pulse is given to

Write (WR)

start the conversion

start the conversion

  • 4 Clock input pin: Connect external clock

Clock IN (CLK IN)

 

here

  • 5 Output pin: Goes low after conversion

5 Output pin: Goes low after conversion

Interrupt (INTR)

  • 6 Analog non-inverting input

6 Analog non-inverting input

Vin(+)

  • 7 Analog inverting input; ground for DC

7 Analog inverting input; ground for DC

Vin(-)

  • 8 Ground

8 Ground
 

Analog Ground(AGND)

  • 9 Input pin: sets the reference voltage for

Vref/2

analog input

analog input

  • 10 Ground

10 Ground
 

Digital Ground(DGND)

11-18

11-18

D7-D0: Output 8-bit pins

D7-D0

  • 19 Used with Clock IN pin when internal Clock R(CLK R)

 

clock source is used

  • 20 +5V

 

Vcc

AI.

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.

Schematic:

63

LCD 10k 10k 10k 10k 10k 10k 10k 10k 5V 5V U1 0 39 21 P0.0/AD0
LCD
10k 10k
10k
10k
10k 10k
10k
10k
5V
5V
U1
0
39
21
P0.0/AD0
P2.0/A8
38
22
0
P0.1/AD1
P2.1/A9
37
23
P0.2/AD2
P2.2/A10
36