0% found this document useful (0 votes)
66 views227 pages

ESD1

The document provides information on interfacing various input and output devices with an 8051 microcontroller, including: - Serial communication using RS232 and asynchronous communication protocols. A MAX232 level converter is needed to interface with RS232. - Interfacing a 4x4 matrix keypad by scanning rows and detecting pressed keys on the columns. - Interfacing a 7-segment display by connecting segments to ports and scanning digits. - Interfacing a 16x2 LCD display by initializing it and sending data or commands to the data and control lines. - Interfacing a stepper motor by connecting windings to ports through a ULN2003 driver chip to control rotation direction.

Uploaded by

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

ESD1

The document provides information on interfacing various input and output devices with an 8051 microcontroller, including: - Serial communication using RS232 and asynchronous communication protocols. A MAX232 level converter is needed to interface with RS232. - Interfacing a 4x4 matrix keypad by scanning rows and detecting pressed keys on the columns. - Interfacing a 7-segment display by connecting segments to ports and scanning digits. - Interfacing a 16x2 LCD display by initializing it and sending data or commands to the data and control lines. - Interfacing a stepper motor by connecting windings to ports through a ULN2003 driver chip to control rotation direction.

Uploaded by

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

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Reset Circuit Diagram

WATCH DOG TIMER BLOCK DIAGRAM


BLOCK DIAGRAM OF REAL TIME CLOCK
I/O Sub Systems
8051 Interfacing

Serial Communication Interface (RS232)

Serial communication means transfer data bit by bit serially at a time, where as in parallel
communication, the number of bits that can be transferred at a time depends upon the number of
data lines available for communication.

Two methods of serial communication are


1. Synchronous Communication: Transfer of bulk data in framed structure at a time
2. Asynchronous Communication: Transfer of a byte data in framed structure at a time
8051 has built in UART with RXD (serial data receive pin) and TXD (serial data transmit pin) on
PORT3.0 and PORT3.1 respectively.

Asynchronous communication: Asynchronous serial communication is widely used for byte


oriented transmission.

Frame structure in Asynchronous communication:


START bit: It is a bit with which serial communication start and it is always low.
Data bits packet: Data bits can be 5 to 9 bits packet. Normally we use 8 data bit packet, which is
always sent after START bit.
STOP bit: This is one or two bits. It is sent after data bits packet to indicate end of frame. Stop bit is
always logic high.
In asynchronous serial communication frame, first START bit followed by data byte and at last
STOP bit, forms a 10-bit frame. Sometimes last bit is also used as parity bit.

Interface standard

 8051 serial communication has TTL voltage level which are 0 v for logic 0 and 5 v for logic 1.
 In computers and most of the old devices for serial communication, RS232 protocol with
DB9 connector is used. RS232 serial communication has different voltage levels than 8051
serial communication. i.e. +3 v to +25 v for logic zero and -3 v to -25 v for logic 1.
 So to communicate with RS232 protocol, we need to use voltage level converter like
MAX232 IC.
 Although there are 9 pins in DB9 connector, we don’t need to use all the pins. Only 2nd
Tx(Transmit), 3rd Rx(Receive) and 5th GND pin needs to be connected.
 serial communication has different voltage levels than 8051 serial communication. i.e. +3 v
to +25 v for logic zero and -3 v to -25 v for logic 1.
 So to communicate with RS232 protocol, we need to use voltage level converter like
MAX232 IC.
 Although there are 9 pins in DB9 connector, we don’t need to use all the pins. Only 2nd
Tx(Transmit), 3rd Rx(Receive) and 5th GND pin needs to be connected.
Keypad & 7 Segment Display Interface

Keypad Interface:

Matrix Keypad

Matrix Keypads are commonly used in calculators, telephones etc where a number of input
switches are required. We know that matrix keypad is made by arranging push button switches in
row and columns. In the straight forward way to connect a 4×4 keypad (16 switches) to a
microcontroller we need 16 inputs pins. But by connecting switches in the following way we can
read the status of each switch using 8 pins of the microcontroller.

 The status of each keys can be determined by a process called Scanning. For the sake of
explanation lets assume that all the column pins (C1 – C4) are connected to the inputs pins
and all the row pins are connected to the output pins of the microcontroller. In the normal
case all the column pins are pulled up (HIGH state) by internal or external pull up resistors.
Now we can read the status of each switch through scanning.
 A logic LOW is given to R1 and others (R2 – R4) HIGH
 Now each Column is scanned. If any switch belongs to 1st row is pressed corresponding
column will pulled down (logic LOW) and we can detect the pressed key.
 This process is repeated for all rows.
 This article is about how to interface a seven segment LED display to an 8051
microcontroller.
 If you need to save more pins of your microcontroller then you can interface keypad using
the ADC module of your microcontroller
7 Segment Display:

 7 segment LED display is very popular and it can display digits from 0 to 9 and quite a few
characters like A, b, C, ., H, E, e, F, n, o,t,u,y, etc. Knowledge about how to interface a seven
segment display to a micro controller is very essential in designing embedded systems.
 A seven segment display consists of seven LEDs arranged in the form of a
squarish ‘8’ slightly inclined to the right and a single LED as the dot character.
 Seven segment displays are of two types, common cathode and common anode.
 In common cathode type , the cathode of all LEDs are tied together to a single terminal which
is usually labeled as ‘com‘ Â and the anode of all LEDs are left alone as individual pins
labeled as a, b, c, d, e, f, g & Â h (or dot) .

 In common anode type, the anode of all LEDs are tied together as a single terminal and
cathodes are left alone as individual pins. The pin out scheme and picture of a typical 7
segment LED display is shown in the image above.
 The circuit diagram shown above is of an AT89S51 microcontroller based 0 to 9 counter
which has a 7 segment LED display interfaced to it in order to display the count.
 This simple circuit illustrates two things. How to setup simple 0 to 9 up counter using 8051
and more importantly how to interface a seven segment LED display to 8051 in order to
display a particular result.
 The common cathode seven segment display D1 is connected to the Port 1 of the
microcontroller (AT89S51) as shown in the circuit diagram. R3 to R10 are current limiting
resistors.
 S3 is the reset switch and R2,C3 forms a de bouncing circuitry.
 C1, C2 and X1 are related to the clock circuit. The software part of the project has to do the
following tasks.
 Form a 0 to 9 counter with a predetermined delay (around 1/2 second here).
 Convert the current count into digit drive pattern.
 Put the current digit drive pattern into a port for displaying.
LCD Interfacing
LCD DISPLAY:

LCD Initialization

 For initializing the LCD display, the following are the steps which are given below and
these steps are same for almost all the applications.
 Send 38H to the 8-bit data line for initialization
 Send 0FH for making LCD ON, cursor ON, cursor blinking ON
 Send 06H for incrementing cursor position
 Send 01H for clearing the display and return the cursor
 Sending Data to the LCD
 The following are the steps for sending the data the LCD module which is given below.
The logic state of these pins that make the module to determine whether a given data
input is a data or command to be displayed.
 Make R/W low
 Make RS=1, if the data byte is a data to be displayed and make
 RS=0, if data byte is a command.
 Place data byte on the data register
 Then pulse E from high to low

Repeat above steps for sending other data

Circuit Diagram of LCD interfacing of 8051 Microcontroller

 The circuit diagram of Interfacing 16×2 LCD module with AT89S51 Microcontroller is as
shown below.
 Resistor R3, Capacitor C3 and push button switch S1 will form the reset circuitry.
 Crystal X1 and ceramic capacitors C1, C2 is related to the clock circuitry which will produce
the system clock frequency.
 P1.0 to P1.7 pins of the microcontroller is connected to the module DB0 to DB7 pins
respectively, this route the data which go to the LCD module.
 P3.3, P3.3 and P3.5 connect to the E, R/W, RS pins of microcontroller and this route the
control signals which are transferred to the LCD module.
 R1 resistor limits the current through the LED backlight and the backlight intensity.
 POT R2 is used for adjusting the contrast of the display.
Stepper Motor Interfacing

A stepper motor is an electro mechanical device which generates discrete displacement


(motion) in response to DC electric signals. It differs from normal DC motor in its operation. The DC
motor produces continuation rotation on applying DC voltage whereas a stepper motor produces
discrete rotation in response to the DC voltage applied to it.

Stepper motors widely used in embedded system applications, Consumer electronics like some disk
drives, dot matrix printers and robotic control systems. Paper feeding mechanism of a printer
makes use of stepper motor for its functioning.

The main advantage of using the stepper motor is the position control. Stepper motors generally
have a permanent magnet shaft (rotor), and it is surrounded by a stator.

Based on the coil winding arrangements, a 2 phase stepper motor is classified into Two. They are

1. Unipolar 2. Bipolar

Unipolar: A Unipolar stepper motor contains 2 windings per phase. The direction of rotation
(Clock wise / anti clock wise) of a stepper motor is controlled by changing the direction of current
flow. Current in one direction flows through one coil and in opposite direction flows through other
coil. It is easy to shift direction of rotation by switching the terminals to which coils are connected.

Bipolar: A bipolar stepper motor contains single winding per phase. For reversing the motor
rotation the current flow through the windings is reversed dynamically. It requires complex
circuitry for current flow reversal.
Interfacing Stepper Motor with 8051 Microcontroller

We are using Port P0 of 8051 for connecting the stepper motor. HereULN2003 is used. This is
basically a high voltage, high current Darlington transistor array. Each ULN2003 has seven NPN
Darlington pairs. It can provide high voltage output with common cathode clamp diodes for
switching inductive loads.

The Unipolar stepper motor works in three modes.

 Wave Drive Mode: In this mode, one coil is energized at a time. So all four coils are energized
one after another. This mode produces less torque than full step drive mode.

The following table is showing the sequence of input states in different windings.

Steps Winding A Winding B Winding C Winding D

1 1 0 0 0

2 0 1 0 0

3 0 0 1 0

4 0 0 0 1

 Full Drive Mode: In this mode, two coils are energized at the same time. This mode produces
more torque. Here the power consumption is also high

The following table is showing the sequence of input states in different windings.

Steps Winding A Winding B Winding C Winding D

1 1 1 0 0

2 0 1 1 0

3 0 0 1 1

4 1 0 0 1
 Half Drive Mode: In this mode, one and two coils are energized alternately. At first, one coil is
energized then two coils are energized. This is basically a combination of wave and full drive
mode. It increases the angular rotation of the motor

The following table is showing the sequence of input states in different windings.

Steps Winding A Winding B Winding C Winding 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

Two phase unipolar stepper motors are the popular choice for embedded applications. The
current requirement for stepper motor is little high and hence the port pins of micro controller not
able to drive them directly. Also supply voltage required to operate stepper motor varies in the
range 5V to 24V. Depending on the current and voltage requirements, Special driving circuits are
required to interface stepper motor with the micro controller.
 Resistor R3, Capacitor C3 and push button switch S1 will form the reset circuitry.
 Crystal X1 and ceramic capacitors C1, C2 is related to the clock circuitry which will produce
the system clock frequency
8255 Interfacing (PPI)
BSR MODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
III Unit (ES) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
Reset Circuit Diagram

WATCH DOG TIMER BLOCK DIAGRAM


BLOCK DIAGRAM OF REAL TIME CLOCK
16
15
17
18
19
Timers / Counters
8051 has two 16-bit programmable UP timers/counters. They can be configured to operate either as
timers or as event counters. The names of the two counters are T0 and T1 respectively. The timer
content is available in four 8-bit special function registers, viz, TL0,TH0,TL1 and TH1 respectively.

In the "timer" function mode, the counter is incremented in every machine cycle. Thus, one can think of
it as counting machine cycles. Hence the clock rate is 1/12 th of the oscillator frequency.

In the "counter" function mode, the register is incremented in response to a 1 to 0 transition at its
corresponding external input pin (T0 or T1). It requires 2 machine cycles to detect a high to low
transition. Hence maximum count rate is 1/24 th of oscillator frequency.

The operation of the timers/counters is controlled by two special function registers, TMOD and TCON
respectively.

Timer Mode control (TMOD) Special Function Register:


TMOD register is not bit addressable.
TMOD
Address: 89 H

Various bits of TMOD are described as follows -


Gate: This is an OR Gate enabled bit which controls the effect of on START/STOP of Timer. It is
set to one ('1') by the program to enable the interrupt to start/stop the timer. If TR1/0 in TCON is set
and signal on pin is high then the timer starts counting using either internal clock (timer mode)
or external pulses (counter mode).

It is used for the selection of Counter/Timer mode.


Mode Select Bits:

M1 and M0 are mode select bits.


Timer/ Counter control logic:

Fig 8.1 Timer/Counter Control Logic

Timer control (TCON) Special function register:


TCON is bit addressable. The address of TCON is 88H. It is partly related to Timer and partly to
interrupt.

Fig 8.2 TCON Register


The various bits of TCON are as follows.
TF1 : Timer1 overflow flag. It is set when timer rolls from all 1s to 0s. It is cleared when processor
vectors to execute ISR located at address 001BH.
TR1 : Timer1 run control bit. Set to 1 to start the timer / counter.
TF0 : Timer0 overflow flag. (Similar to TF1)
TR0 : Timer0 run control bit.
IE1 : Interrupt1 edge flag. Set by hardware when an external interrupt edge is detected. It is cleared
when interrupt is processed.
IE0 : Interrupt0 edge flag. (Similar to IE1)
IT1 : Interrupt1 type control bit. Set/ cleared by software to specify falling edge / low level triggered
external interrupt.
IT0 : Interrupt0 type control bit. (Similar to IT1)
As mentioned earlier, Timers can operate in four different modes. They are as follows
Timer Mode-0:
In this mode, the timer is used as a 13-bit UP counter as follows.

Fig. 8.3 Operation of Timer on Mode-0


The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count. Upper 3 bits of TLX are ignored.
When the counter rolls over from all 0's to all 1's, TFX flag is set and an interrupt is generated.

The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and Gate bit is 0, the counter
continues counting up. If TR1/0 bit is 1 and Gate bit is 1, then the operation of the counter is controlled
by input. This mode is useful to measure the width of a given pulse fed to input.

Timer Mode-1:
This mode is similar to mode-0 except for the fact that the Timer operates in 16-bit mode.

Fig 8.4 Operation of Timer in Mode 1

Timer Mode-2: (Auto-Reload Mode)


This is a 8 bit counter/timer operation. Counting is performed in TLX while THX stores a constant
value. In this mode when the timer overflows i.e. TLX becomes FFH, it is fed with the value stored in
THX. For example if we load THX with 50H then the timer in mode 2 will count from 50H to FFH. After
that 50H is again reloaded. This mode is useful in applications like fixed time sampling.

Fig 8.5 Operation of Timer in Mode 2


Timer Mode-3:

Timer 1 in mode-3 simply holds its count. The effect is same as setting TR1=0. Timer0 in mode-3
establishes TL0 and TH0 as two separate counters.

Fig 8.6 Operation of Timer in Mode 3


Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3 while TR0 and TF0 are
available to Timer-0 lower 8 bits(TL0).
1
III Unit (ES)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
V Unit (ES) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
VI Unit (ES) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
VIII Unit (ES)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

You might also like