Total slides: 109
Light Emitting Diodes
Seven Segment LED
LCD Interfacing
Stepper Motor Interfacing
Digital to Analog Converter
ADC Interfacing
Keyboard Interfacing
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
ย
Applications of Microcontroller 8051
1. Applications of 8051 Microcontroller
Dr. Nilesh Bhaskarrao Bahadure
https://www.sites.google.com/site/nileshbbahadure/home
July 25, 2021
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 1 / 109
2. Overview I
1 Light Emitting Diodes
Introduction to LED
Example - 1: Single LED
Example - 2: Multiple LED
Example - 3: Multiple LED
2 Seven Segment LED
Introduction to Seven Segment LED
Example - 1: Single 7 - Segment to display number 3
Example - 2: Single 7 - Segment for display 0 - 9
Example - 3: Single 7 - Segment for display 0 - 9 using 7447 Decoder
Example - 4: Two 7 - Segment for display 31
3 LCD Interfacing
LCD Introduction
LCD Commands
Example - 1: Display NB Bahadure on LCD
4 Stepper Motor Interfacing
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 2 / 109
3. Overview II
Introduction to Stepper Motor
Stepper motor types
Step Sequence
Step Angle
Example - 1: Rotate Stepper Motor Clockwise
Example - 2: Rotate Stepper Motor Clockwise in Half Step Sequence
Example - 3: Rotate Stepper Motor Clockwise - Counter Clockwise
based on Switch
5 Digital to Analog Converter
Introduction to DAC
Example - 1: Generate Sawtooth Waveform
Example - 2: Generate Reverse Sawtooth Waveform
Example - 3: Generate 200 Triangular Waveform
Example - 4: Generate Sine Waveform
6 ADC Interfacing
Introduction to ADC
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 3 / 109
4. Overview III
Example - 1: Interfacing ADC 0804 with 8051
7 Keyboard Interfacing
Introduction to Keyboard
Example - 1: Interfacing of 4 x 4 Matrix Keyboard with 8051
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 4 / 109
5. Light Emitting Diodes
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 5 / 109
6. Introduction to LED
Light emitting diodes, commonly called LEDs, are real unsung heroes in
the electronics world. They do dozens of different jobs and are found
in all kinds of devices. Among other things, they form numbers ondigi-
tal clocks, transmit information fromremote controls, light up watches and
tell you when your appliances are turned on. Collected together, they can
form images on ajumbo television screenorilluminate a traffic light. Alight-
emitting diode(LED) is a two-leadsemiconductorlight source that resembles
a basicPN-junctiondiode, except that an LED also emits light.When an
LEDโs anode lead has a voltage that is more positive than its cathode lead
by at least the LEDโs forward voltage drop, current flows.Electronsare able
to recombine withholeswithin the device, releasing energy in the form of-
photons. This effect is calledelectroluminescent, and the color of the light
(corresponding to the energy of the photon) is determined by the energy
bandof the semiconductor. An LED is often small in area, and integrated
optical components may be used to shape itsradiation pattern.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 6 / 109
7. Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 7 / 109
8. To interface LEDโs with microprocessor or Microcontroller based system, we
must consider the following
LEDโs glow only when they are forward biased and
Their resistance is almost zero for all practical purpose.
It means that they must be interfaced with proper polarity and with a proper
value of resistance in series. This resistance is a current limiting resistor,
and its value is to be calculated as per the supplied voltage applied to the
LED and current limit of the LED.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 8 / 109
9. Example
Show the interfacing of LED with port pin P2.1 of Microcontroller 8051 and
write an assembly language program to blink LED continuously. Assume
that operating frequency of 8051 Microcontroller is 11.0592 MHz.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 9 / 109
10. Method - I
Assembly Language Program
ORG 0000h
LOOP: CLR P2.1
ACALL DELAY
SETB P2.1
ACALL DELAY
JMP LOOP
DELAY: MOV R3, #0FFH
REP: MOV R2, #0FFH
HERE: DJNZ R2, HERE
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 10 / 109
11. Method - II
Assembly Language Program
ORG 0000h
LOOP: CPL P2.1
ACALL DELAY
JMP LOOP
DELAY: MOV R3, #0FFH
REP: MOV R2, #0FFH
HERE: DJNZ R2, HERE
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 11 / 109
12. Example
Show the interfacing of 8 - LEDโs using common anode arrangement with
port 2 pins of 8051 microcontroller. Write an assembly language program
to blink the LEDโs continuously. Assume operating frequency of 8051 Mi-
crocontroller is 11.0592 MHz.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 12 / 109
13. Assembly Language Program
ORG 0000h
MOV A, #55h
LOOP: CPL A
MOV P2, A
ACALL DELAY
SETB P2.1
ACALL DELAY
JMP LOOP
DELAY: MOV R3, #0FFH
REP: MOV R2, #0FFH
HERE: DJNZ R2, HERE
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 13 / 109
15. Example
Show the interfacing of LED with port pin P2.0 of Microcontroller 8051 and
write an assembly language program to ON the LED when the key K1 is
pressed and OFF the LED when key is pressed k2. Assume that operating
frequency of 8051 Microcontroller is 11.0592 MHz.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 15 / 109
16. Assembly Language Program
ORG 0000h
SETB P1.0 ; Set port pin P1.0 as input (key K1)
SETB P1.1 ; Set port pin P1.1 as input (key K2)
LOOP: MOV A, P1 ; Read key values
RRC A ; Rotate towards right to check key K1
JC KEY K2 ; If carry key K1 is not pressed go for key K2
CLR P2.0 ; if no carry key K1 is pressed ON the LED
ACALL DELAY
SJMP LOOP
KEY K2: RRC A ; Rotate towards right to check key K2
JC LOOP ; If carry read the keys again and repeat
SETB P2.0 ; If no carry key K2 is pressed OFF the LED
ACALL DELAY
SJMP LOOP
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 16 / 109
17. Assembly Language Program
DELAY: MOV R3, #0FFH
REP: MOV R2, #0FFH
HERE: DJNZ R2, HERE
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 17 / 109
19. Seven Segment LED
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 19 / 109
20. Introduction to Seven Segment LED
The Light Emitting Diode (LED) finds its place in many applications in these
modern electronic fields. One of them is the Seven Segment Display. Seven-
segment displays contains the arrangement of the LEDโs in โEightโ (8)
passion, and a Dot (.) with a common electrode, lead (Anode or Cathode).
The purpose of arranging it in that passion is that we can make any number
out of that by switching ON and OFF the particular LEDโs. Figure 1 shows
the block diagram of the Seven Segment LED arrangement.
Figure : Seven Segment Display
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 20 / 109
21. Introduction to Seven Segment LED...
7 segment displays are basically 7 LEDโs. There are two types of 7 segment
displays common cathode and common anode.
(a) Common Cathode - where all the segment share the same cathode.
(b) Common Anode - where all the segment share the sane anode.
In common Anode in order to turn ON a segment the corresponding pin must
be set to 0 and to turn it OFF it is set to 1. Similarly in common cathode
in order to turn ON a segment the corresponding pin must be set to 1 and
to turn it OFF it is set to 0. As shown in the figure 2 in common anode
type, all the anodes of LEDโs are connected common with the +5V power
supply and hence the name common anode 7 - segment LED. Similarly for
common cathode configuration, it shows that all the cathodes of LEDs are
connected common to the ground, and hence the name common cathode 7
- segment LED.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 21 / 109
22. Introduction to Seven Segment LED...
Figure : Seven Segment Display
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 22 / 109
23. There 2 methods of interfacing LED with the Microcontroller Intel 8051/
AT89C51.
(a) Using lookup table. This uses 7 output pins of Microcontroller
(b) Using 7447 decoder. This method uses 4 output pins of Microcontroller
The difference between the two main methods is simple and clear. In both
the cases, Microcontroller communicates with external world through its
ports. But, in the 1st case, we connect all the 8 pins of the port directly to
the LED and control the voltage through the ports manually to display the
desired number. But, in the second case, we send the BCD of the number
that we wanted to display to a middleware IC 7447, the BCD to LED code
converter, which by itself gives out the correspondent 7 segment codes to
the LED.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 23 / 109
24. Look - up table for Seven Segment LED
Hex
Code
seven segment conversion 7 - seg equivalent
dot g f e d c b a
0 1 1 0 0 0 0 0 0 C0H
1 1 1 1 1 1 0 0 1 F9H
2 1 0 1 0 0 1 0 0 A4H
3 1 0 1 1 0 0 0 0 B0H
4 1 0 0 1 1 0 0 1 99H
5 1 0 0 1 0 0 1 0 92H
6 1 0 0 0 0 0 1 0 82H
7 1 1 1 1 1 0 0 0 F8H
8 1 0 0 0 0 0 0 0 80H
9 1 0 0 1 1 0 0 0 98H
Table : 7 - segment display code for the common anode configuration
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 24 / 109
25. Look - up table for Seven Segment LED
Hex
Code
seven segment conversion 7 - seg equivalent
dot g f e d c b a
0 0 0 1 1 1 1 1 1 3FH
1 0 0 0 0 0 1 1 0 06H
2 0 1 0 1 1 0 1 1 5BH
3 0 1 0 0 1 1 1 1 4FH
4 0 1 1 0 0 1 1 0 66H
5 0 1 1 0 1 1 0 1 6DH
6 0 1 1 1 1 1 0 1 7DH
7 0 0 0 0 0 1 1 1 07H
8 0 1 1 1 1 1 1 1 7FH
9 0 1 1 0 0 1 1 1 67H
Table : 7 - segment display code for the common cathode configuration
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 25 / 109
26. Example
Show the interfacing of seven segment display device of common anode
type with 8051 Microcontroller and write an assembly language program
to display digit 3 continuously. Assume that operating frequency of 8051
Microcontroller is 11.0592 MHz.
Solution
Figure : Hardware arrangement
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 26 / 109
27. Assembly Language Program
using common anode
ORG 0000H
MOV P2, #0FFH ; OFF all the LEDโs
LOOP: MOV P2, #0B0H ; display code for 3
ACALL DELAY
SJMP LOOP
DELAY: MOV R3, #0FFH
REP: MOV R2, #0FFH
HERE: DJNZ R2, HERE
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 27 / 109
29. Example
Show the interfacing of seven segment display device common anode type
with 8051 Microcontroller and write an assembly language program to dis-
play digit 0 to 9 continuously. Assume that operating frequency of 8051
Microcontroller is 11.0592 MHz.
Solution
Figure : Hardware arrangement
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 29 / 109
30. Assembly Language Program
using common anode
ORG 0000h
REPEAT: MOV R2, #10
MOV DPTR, #MSG
LOOP: CLR A
MOVC A, @A+DPTR
MOV P2,A
ACALL DELAY
INC DPTR
DJNZ R2, LOOP
LJMP REPEAT
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 30 / 109
31. Assembly Language Program
DELAY: MOV R3, #0FFH
REP: MOV R4, #0FFH
MOV R5, #0FFH
HERE: DJNZ R5, HERE
HERE1: DJNZ R4, HERE1
DJNZ R3, REP
RET
MSG: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,98H
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 31 / 109
32. Example
Show the interfacing of seven segment display device of common anode type
using 7447 decoder with 8051 Microcontroller and write an assembly lan-
guage program to display digits 0 to 9 continuously. Assume that operating
frequency of 8051 Microcontroller is 11.0592 MHz.
Solution
Figure : Hardware arrangement
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 32 / 109
33. Assembly Language Program
ORG 0000h
AGAIN: MOV A, #00H ; Start form zero
UP: MOV P2, A ; Move to Port 2
ACALL DELAY
INC A
CJNE A, #0AH, UP ; send only from 0 to 9
SJMP AGAIN
DELAY: MOV R3, #0FFH
REP: MOV R4, #0FFH
MOV R5, #0FFH
HERE: DJNZ R5, HERE
HERE1: DJNZ R4, HERE1
DJNZ R3, REP
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 33 / 109
35. Example
Show the interfacing of two 7 - segment LED with Microcontroller 8051,
and write an assembly language program to display digit 31 continuously.
For the delay, assume that operating frequency of 8051 Microcontroller is
11.0592 MHz.
Solution
Figure : Interfacing of two 7 - segment LED in Common anode configuration with
8051 Microcontroller
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 35 / 109
36. Assembly Language Program
ORG 0000h
CLR P3.0
CLR P3.1
MOV P2, #0FFh ; Off All seven segment display
Loop: CLR P3.0
SETB P3.1
MOV P2, #0B0h
CALL delay
CLR P3.1
SETB P3.0
MOV P2, #0F9h
CALL delay
AJMP Loop
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 36 / 109
38. The most commonly used Character based LCDs are based on Hitachiโs
HD44780 controller or other which are compatible with HD44580. In this
application, we will discuss about character based LCDs, their interfacing
with Microcontroller 8051
Figure : Character LCD type HD44780 pin diagram
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 38 / 109
39. Table : Pin description of character LCD type HD44780
Pin No. Name Description
1 VSS Power Supply (GND)
2 VCC Power Supply (+5V)
3 VEE Contrast adjust
4 RS Register Select
0 = To select command register
1 = To select Data register
5 R/W Read/Write
0 = Write to the LCD
1 = Read from the LCD
6 EN Enable Signal
7 D0 Data bus line D0 (LSB)
8 D1 Data bus line D1
9 D2 Data bus line D2
10 D3 Data bus line D3
11 D4 Data bus line D4
12 D5 Data bus line D5
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 39 / 109
40. LCD Commands
Only the instruction register (IR) and the data register (DR) of the LCD
can be controlled by the MCU. Before starting the internal operation of
the LCD, control information is temporarily stored into these registers to
allow interfacing with various MCUs, which operate at different speeds, or
various peripheral control devices. The internal operation of the LCD is
determined by signals sent from the MCU. These signals, which include
register selection signal (RS), read/write signal (R/W), and the data bus
(DB0 to DB7), make up the LCD instructions
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 40 / 109
41. LCD Commands...
Command code (Hex) Command to the LCD instruction register
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor (shift cursor to right)
05 Shift display right
07 Shift display left
08 Display off, cursor off
0A Display off, cursor on
0C Display on, cursor off
0E Display on, cursor on (cursor blinking)
0F Display on, cursor on (cursor blinking)
Table : LCD Commands
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 41 / 109
42. LCD Commands...
Command code (Hex) Command to the LCD instruction register
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning on the first line
C0 Force cursor to beginning on the second line
38 Initialization of the LCD / 2 lines and 5 x 7 matr
Table : LCD Commands
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 42 / 109
43. Example
Show the interfacing of 16x2 LCD with Microcontroller 8051 and write an
assembly language program to display text message โNB BAHADUREโ.
Solution
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 43 / 109
44. Assembly Language Program
Method - I
; P2.0 is connected to the RS pin of LCD
; P2.1 is connected to the R/W pin of LCD
; P2.2 is connected to the E pin of LCD
ORG 0000H
MOV A, #38H ; initialize 16 x 2 LCD
ACALL COMMAND ; send command
ACALL DELAY ; delay for some time
MOV A, #0EH ; display on cursor on
ACALL COMMAND
ACALL DELAY
MOV A, #01H ; clear LCD
ACALL COMMAND
ACALL DELAY
MOV A, #06 ; shift cursor right
ACALL COMMAND
ACALL DELAY
MOV A, #84h ; cursor at line 1, position 4
ACALL COMMAND
ACALL DELAY
MOV A, #โNโ ; display letter N
ACALL DATA
ACALL DELAY
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 44 / 109
45. Assembly Language Program
MOV A, #โBโ ; display letter B
ACALL DATA
ACALL DELAY
MOV A, #โ โ ; display space
ACALL DATA
ACALL DELAY
MOV A, #โBโ ; display letter B
ACALL DATA
ACALL DELAY
MOV A, #โAโ ; display letter A
ACALL DATA
ACALL DELAY
MOV A, #โHโ ; display letter H
ACALL DATA
ACALL DELAY
MOV A, #โAโ ; display letter A
ACALL DATA
ACALL DELAY
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 45 / 109
46. Assembly Language Program
MOV A, #โDโ ; display letter D
ACALL DATA
ACALL DELAY
MOV A, #โUโ ; display letter U
ACALL DATA
ACALL DELAY
MOV A, #โRโ ; display letter R
ACALL DATA
ACALL DELAY
MOV A, #โEโ ; display letter E
ACALL DATA
ACALL DELAY
AGAIN: SJMP AGAIN
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 46 / 109
47. Assembly Language Program
COMMAND: MOV P1, A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATA: MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY: MOV R3, #75H
H2: MOV R4,#0FFH
H1: DJNZ R4,H1
DJNZ R3,H2
RET
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 47 / 109
48. Assembly Language Program
Method - II
; P2.0 is connected to the RS pin of LCD
; P2.1 is connected to the R/W pin of LCD
; P2.2 is connected to the E pin of LCD
ORG 0000H
MOV DPTR, #COM TAB
BACK: CLR A
MOVC A, @A+DPTR
JZ DATA SEND
ACALL COMMAND
ACALL DELAY
INC DPTR
SJMP BACK
DATA SEND: MOV DPTR, #DATA TAB
BACK1: CLR A
MOVC A, @A+DPTR
JZ STOP
ACALL DATA
ACALL DELAY
INC DPTR
SJMP BACK1
STOP: SJMP STOP
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 48 / 109
49. Assembly Language Program
COMMAND: MOV P1, A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DATA: MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY
CLR P2.2
RET
DELAY: MOV R3, #75H
H2: MOV R4,#0FFH
H1: DJNZ R4,H1
DJNZ R3,H2
RET
COM TAB: DB 38H, 01H, 06H, 0EH, 84H, 00H
DATA TAB: DB โNB BAHADUREโ, 00H
END
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 49 / 109
52. Introduction to Stepper Motor
A stepper motor is widely used device that translate electrical pulses into
mechanical movement. In application such as disk drives, dot matrix printers
and robotics, the stepper motor is used for position control. The sequence of
the applied pulses is directly related to the direction of motor shafts rotation.
The speed of the motor shafts rotation is directly related to the frequency
of the input pulses and the length of rotation of input pulses applied. The
advantages and disadvantages of stepper motor are given below.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 52 / 109
53. Advantages of Stepper Motor
1 The rotation angle of the motor is proportional to the input pulse.
The motor has full torque at stand still (if the winding are energized)
Precise positioning and repeatability of movement since good stepper
motors.
Have an accuracy of 3 -5% of a step and this error is non cumulative
from one step to the next.
Excellent response to starting stopping reversing.
Very reliable since there are no contact brushes in the motor.
Therefore the life to the motor is simply dependant on the life of the
bearing.
The motors response to digital input pulses provides open-loop
control, making the motor simpler and less costly to control.
It is possible to achieve very low speed synchronous rotation with a
load that is directly coupled to the shaft.
A wide range of rotational speed is proportional to the frequency of
the input pulses.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 53 / 109
54. Disadvantages of Stepper Motor
9 1 Resonance can occur if not properly controlled.
Not easy to operate at extremely high speeds.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 54 / 109
55. 2 The stepper motors commonly have a permanent magnet called rotor (also
called shaft) surrounded by a stator. There are also stepper motors called
variable reluctance stepper motor that do not have permanent magnet rotor.
The most common stepper motors have four stator winding that are paired
with a center tapped common as shown in figure 8
Figure : Stepper Motor
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 55 / 109
56. Table : Stepping sequence for stepper motor
Clockwise
โ
Step Winding A Winding B Winding C Winding D
Counter
Clockwise
โ
1 1 0 0 1
2 1 1 0 0
3 0 1 1 0
4 0 0 1 1
It is to be important to note that although we can start with any of the
sequence in table 6, once we start we must continue in the proper order.
For example if we start with step - 3 we must continue in the sequence of
steps 4 - 1 - 2 - 3 - 4 - 1etc.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 56 / 109
57. Stepper Motor Types
1 Active rotor: Permanent Magnet (PM)
2 Reactive rotor: Variable reluctance (VR)
3 Combination of VR and PM: Hybrid (HB)
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 57 / 109
58. Stepper Motor Types I
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 58 / 109
59. Stepper Motor Types II
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 59 / 109
60. Stepper Motor Types III
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 60 / 109
61. Stepper Motor Interfacing Types
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 61 / 109
62. Connecting Unipolar Stepper Motor using L293D
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 62 / 109
63. Connecting Unipolar Stepper Motor using ULN2003A
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 63 / 109
64. Step Sequence
1. Full Step Sequence
2. Half Step Sequence
Table : Full Step Sequence
Clockwise
โ
Step A B C D
Counter
Clockwise
โ
1 ON OFF OFF ON
2 ON ON OFF OFF
3 OFF ON ON OFF
4 OFF OFF ON ON
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 64 / 109
65. Half Step Sequence
Table : Half Step Sequence
Clockwise
โ
Step A B C D
Counter
Clockwise
โ
1 ON ON OFF OFF
2 OFF ON OFF OFF
3 OFF ON ON OFF
4 OFF OFF ON OFF
5 OFF OFF ON ON
6 OFF OFF OFF ON
7 ON OFF OFF ON
8 ON OFF OFF OFF
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 65 / 109
66. Step Angle
Step angle = 360
Steps per Revolutions
Step angle Steps per revolution
0.72 500
1.8 200
2.0 180
2.5 144
5.0 72
7.5 48
15 24
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 66 / 109
67. Example
Show the interfacing of stepper motor with 8051 Microcontroller and write
an assembly language program to rotate stepper motor clockwise
continuously. Assume the oscillator frequency of 8051 is 11.0592 MHz.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 67 / 109
68. Assembly Language Program
Method - I
MOV A, #66h ; Load step sequence
BACK: MOV P0, A ; Issue sequence to motor
RR A ; Rotate right (clockwise pattern)
ACALL DELAY ; Wait for some time
SJMP BACK ; Keep going
DELAY: MOV R7,#04
WAIT2: MOV R6,#0FFH
WAIT1: MOV R5,#0FFH
WAIT: DJNZ R5,WAIT
DJNZ R6,WAIT1
DJNZ R7,WAIT2
RET
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 68 / 109
69. Assembly Language Program
Method - II
ORG 0000H
STEPPER EQU P0
SJMP MAIN
ORG 0030H ; bypass interrupt vector location
MAIN: MOV STEPPER, #0CH
ACALL DELAY
MOV STEPPER, #06H
ACALL DELAY
MOV STEPPER, #03H
ACALL DELAY
MOV STEPPER, #09H
ACALL DELAY
SJMP MAIN
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 69 / 109
70. Assembly Language Program
DELAY: MOV R7,#04
WAIT2: MOV R6,#0FFH
WAIT1: MOV R5,#0FFH
WAIT: DJNZ R5,WAIT
DJNZ R6,WAIT1
DJNZ R7,WAIT2
RET
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 70 / 109
72. Example
Show the interfacing of stepper motor with 8051 Microcontroller and write
an assembly language program to rotate stepper motor clockwise
continuously in half step sequence. Assume the oscillator frequency of
8051 is 11.0592 MHz.
Solution
Hardware Arrangement:
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 72 / 109
73. Assembly Language Program
ORG 0000H
STEPPER EQU P0
SJMP MAIN
ORG 0030H ; bypass interrupt vector location
MAIN: MOV STEPPER, #08H
ACALL DELAY
MOV STEPPER, #0CH
ACALL DELAY
MOV STEPPER, #04H
ACALL DELAY
MOV STEPPER, #06H
ACALL DELAY
MOV STEPPER, #02H
ACALL DELAY
MOV STEPPER, #03H
ACALL DELAY
MOV STEPPER, #01H
ACALL DELAY
MOV STEPPER, #09H
ACALL DELAY
SJMP MAIN
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 73 / 109
74. Assembly Language Program
DELAY: MOV R7,#04
WAIT2: MOV R6,#0FFH
WAIT1: MOV R5,#0FFH
WAIT: DJNZ R5,WAIT
DJNZ R6,WAIT1
DJNZ R7,WAIT2
RET
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 74 / 109
76. Example
A switch is connected to port pin P2.0. Write a program to monitor the
status of switch and perform the following.
(a) If SW = 0 then stepper motor moves clockwise
(b) If SW = 1 then stepper motor moves anticlockwise.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 76 / 109
78. Assembly Language Program
SETB P2.0 ; Initialize port pin P2.0 as an input port
MOV A, #66h
MOV P0, A
TURN: JB P2.0, CCW
RR A
MOV P0, A
ACALL DELAY
SJMP TURN
CCW: RL A
MOV P0, A
ACALL DELAY
SJMP TURN
DELAY: MOV R7, #04
WAIT2: MOV R6,#0FFH
WAIT1: MOV R5,#0FFH
WAIT: DJNZ R5,WAIT
DJNZ R6,WAIT1
DJNZ R7,WAIT2
RET
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 78 / 109
80. Introduction to DAC
Adigital-to-analog converteris a function that converts digital data (usually
binary) into ananalog signal(current,voltage, orelectric charge).
Ananalog-to-digital converter(ADC) performs the reverse function. Unlike
analog signals,digital datacan be transmitted, manipulated, and stored
without degradation, albeit with more complex equipment. But a DAC is
needed to convert the digital signal to analog to drive an earphone or
loudspeaker amplifier in order to produce sound (analog air pressure
waves).
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 80 / 109
81. Introduction to DAC...
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 81 / 109
82. Example
Show the interfacing of DAC0808 with 8051 microcontroller. Write an
ALP to generate a saw tooth wave form (stair step ramp) on port P1.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 82 / 109
83. Assembly Language Program
CLR A
AGAIN: MOV P1, A ; Send data to DAC
INC A ; Count from 00 to FF
ACALL DELAY ; Let DAC recover
SJMP AGAIN
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 83 / 109
84. Example
Show the interfacing of DAC0808 with 8051 Microcontroller. Write an
ALP to generate a reverse sawtooth wave form (stair step ramp) on port
P1.
Solution
Hardware Arrangement:
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 84 / 109
85. Assembly Language Program
MOV A, #0FFh
AGAIN: MOV P1, A ; Send data to DAC
DEC A ; Count from FF to 00
ACALL DELAY ; Let DAC recover
SJMP AGAIN
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 85 / 109
86. Example
Show the interfacing of DAC0808 with 8051 microcontroller and write an
assembly language program to generate triangular waveform at the DAC
output using port P1 of the microcontroller. Generate 200 cycles use P1.
Solution
Hardware Arrangement:
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 86 / 109
87. Assembly Language Program
MOV R2, #200
AGAIN: MOV R3, #0FEH
MOV R4, #0FEh
CLR A
L1: MOV P1, A
INC A
ACALL DELAY
DJNZ R3, L1
MOV A, #0FFh
L2: MOV P1, A
DEC A
ACALL DELAY
DJNZ R4, L2
DJNZ R2, AGAIN
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 87 / 109
88. Example
Show the interfacing of DAC 0808 with Microcontroller 8051 and write an
assembly language program to generate sine wave continuously on DAC. The
values to be sent to the DAC for the generation of sine wave is calculated
using the formula given below
VOUT = 5V + (5V ร sin(ฮธ))
Use port P1 of the 8051. Assume oscillator frequency of the 8051 is 11.0592
MHz. The angle ฮธ should be from 0o to 360o in the increment of 15o.
Solution
To find the values sent to the DAC for various angles we simply multiply
Vout by 25.6 because there are 256 steps and full scale Vout is 10V.
Therefore 256 steps
10V = 25.6 steps per volts
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 88 / 109
89. Solution
Table : Values send to DAC for sine wave generation for example 4
Angle (decimal) sin ฮธ VOUT = 5V + (5V ร sin(ฮธ)) Values send to DAC
= VOUT ร 25.6
0 0 5 128
15 0.259 6.295 161
30 0.5 7.5 192
45 0.707 8.535 218
60 0.866 9.33 238
75 0.966 9.83 251
90 1 10 256
105 0.966 9.83 251
120 0.866 9.33 238
135 0.707 8.535 218
150 0.5 7.5 192
165 0.259 6.295 161
180 0 5 128
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 89 / 109
90. Solution
Table : Values send to DAC for sine wave generation for example 4
Angle (decimal) sin ฮธ VOUT = 5V + (5V ร sin(ฮธ)) Values send to DAC
= VOUT ร 25.6
195 -0.259 3.705 94
210 - 0.5 2.5 64
225 -0.707 1.465 37
240 -0.866 0.67 17
255 -0.966 0.17 4
270 -1 0 0
285 -0.966 0.17 4
300 -0.866 0.67 17
315 -0.707 1.465 37
330 -0.5 2.5 64
345 -0.259 3.705 94
360 0 5 128
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 90 / 109
91. Assembly Language Program
REP: MOV DPTR, #SIN TABLE
MOV R2, #25 ; for total 25 values from 0 to 360
AGAIN: CLR A
MOVC A, @A+DPTR
MOV P1, A
ACALL DELAY
INC DPTR
DJNZ R2, AGAIN
SJMP REP
DELAY: MOV R7, #20H
BACK: MOV R6, #0FFH
BACK1: MOV R5, #0FFH
HERE: DJNZ R5, HERE
DJNZ R6, BACK1
DJNZ R7, BACK
RET
SIN TABLE: DB 128, 161, 192, 218, 238, 251, 256 . 128
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 91 / 109
93. Introduction to ADC
Analog-to-digital converter is a device that converts a continuous physical
quantity (usually voltage) to a digital number that represents the quantityโs
amplitude. The conversion involves quantization of the input, so it necessar-
ily introduces a small amount of error. Instead of doing a single conversion,
an ADC often performs the conversions periodically. The result is a sequence
of digital values that have converted a continuous-time and continuous-
amplitude analog signal to a discrete-time and discrete-amplitude digital
signal.
The table 11 shows the various analog to digital converters that are most
commonly used with the Microcontroller 8051 and family.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 93 / 109
94. Introduction to ADC...
Table : Analog to digital converter ICโs
Name of the IC Description
ADC 0800 8 - bit ADC
ADC 0801 8 - bit ADC, 100 ยตs, 0.25 LSB
ADC 0802 8 - bit ADC, 100 ยตs, 0.5 LSB
ADC 0804 8 - bit ADC, 100 ยตs, 1.0 LSB
ADC 0808 8 - bit 8 channel ADC, 100 ยตs
ADC 0809 8 - bit 8 channel ADC (equivalent to ADC 0808)
AD 571 10 bit, ADC, with reference and clock signals
MAX 1204 5V, 8 - channel, serial, 10 bit ADC with 3V digital interface
MAX 1202 5V, 8 - channel, serial, 12 bit ADC with 3V digital interface
MAX 195 1 6 - bit, self calibrating, 10 ยตs sampling ADC
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 94 / 109
95. Example
Show the interfacing of ADC 0804 with Microcontroller 8051 and write an
assembly language program to read the value and store in internal memory
location 30h.
Solution
Pin configuration of ADC 0804
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 95 / 109
97. Solution
The following points are observed to start the conversion
1 Make chip select (CS) signal low to select the ADC 0804
2 Make write (WR) signal low.
3 Make chip select high
4 Wait for INTR signal to go low, when it goes low, indicates
conversion ends.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 97 / 109
98. Solution
Once the conversion in ADC is done, the data is available in the output
latch of the ADC. Data of new conversion is only available for reading after
ADC 0804 made INTR signal low or say when the conversion is completed.
Below are the steps observed to read output from the ADC 0804.
1 Make chip select (CS) pin low.
2 Make read (RD) signal low.
3 Read the data from port where ADC is connected.
4 Make read (RD) signal high.
5 Make chip select (CS) high.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 98 / 109
99. Assembly Language Program
RD EQU P1.0 ; Read signal P1.0
WR EQU P1.1 ; Write signal P1.1
CS EQU P1.2 ; Chip select signal P1.2
INTR EQU P1.3 ; INTR signal P1.3
ADC PORT EQU P2 ; ADC data port pin P2
ORG 0000h
START: ACALL CONV ; Start ADC Conversion
ACALL READ ; Read converted value
MOV P3, 30h ; Move the value to the port P3
SJMP START ; repeat the process
CONV: CLR CS ; make CS low
CLR WR ; make WR low
NOP ; give small delay
SETB WR ; make WR high
SETB CS ; make CS high
WAIT: JB INTR, WAIT ; Wait for INTR signal
RET ; Conversion completed
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 99 / 109
100. Assembly Language Program
READ: CLR CS ; make CS low
CLR RD ; make RD low
MOV A, ADC PORT ; Read the converted value
MOV 30h, A ; Store the converted value in internal RAM 30h
SETB RD ; make RD high
SETB CS ; Make CS high
RET ; Reading completed
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 100 / 109
102. Introduction to Keyboard
Keyboards are organized in a matrix of rows and columns. The CPU accesses
both rows and columns through ports therefore with two 8 bit ports an
8 x 8 matrix of keys can be connected to the Microcontroller. When a
key is pressed, a row and a column make a contact; otherwise there is no
connection between rows and column.
Scanning and identification of the key:
Figure shows a 4 x 4 matrix keyboard connected to two ports. The rows are
connected to the output port and the columns are connected to the input
port. If no key has been pressed, reading the input port will yield 1s for all
columns. Since they are all connected to the high (Vcc). If all the rows are
grounded and a key is pressed one of the column will have 0 since the key is
pressed provides the path to ground. If the function of the Microcontroller
to scan the keyboard continuously to detect and identify the key pressed.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 102 / 109
104. Introduction to Keyboard...
Grounding rows and reading the column:
To detect a pressed key, the Microcontroller grounds all rows by providing
0 to the output latch then it reads the column. If the data read from the
column is D3 - D0 = 1111, no key has been pressed and process continuous
until a key pressed is detected. However, if one of the column bit has a zero,
this means that a key has occurred. For ex: if D3 - D0 = 1101, this means
that a key in D1 column has been pressed. After a key press is detected, the
Microcontroller will go through the process of identifying the key. Starting
with the top row, the Microcontroller grounds it by providing a low to row
D0 only; then it reads the column. If the data read is all 1โs, no key in that
row is activated and the process is moved to the next row. It grounds the
next row, reads the column and check for any zero. This process continuous
until the row is identified. After identification if the row in which the key
has been pressed, the next task is to find out which column the pressed key
belongs to. This should be easy since Microcontroller knows at any time
which row and column are being occurred.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 104 / 109
105. Example
Interface 4 x 4 matrix keyboards with Microcontroller 8051. Write an ALP
to read the keypad and send the ASCII code of pressed key to port P0.
P1.0 - P1.3 connected to rows (Output)
P2.0 - P 2.3 connected to the column (Input)
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 105 / 109
106. Assembly Language Program
MOV P2, #0FFh ; P2 input
K1: MOV P1, #00h ; Grounds all rows at once
MOV A, P2 ; Reads column ensure all key open
ANL A, #0Fh ; mask unused bits
CJNE A, #0Fh, K1 ; check till all keys are released
ACALL DELAY ; 20ms DELAY
K2: MOV A, P2 ; SEE ANY KEY PRESSED
ANL A, #0F
CJNE A, #0F, OVER
SJMP K2
OVER: ACALL DELAY
MOV A, P2
ANL A, #0F
CJNE A, #0F, OVER1 ; Key pressed find row
SJMP K2 ; if none keep poling
OVER1: MOV P1, #11111110B ; GROUND ROW 0
MOV A, P2
ANL A, #0F
CJNE A, #0F, ROW 0
MOV P1, #11111101B ; GROUND ROW 1
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 106 / 109
107. Assembly Language Program
MOV A, P2
ANL A, #0F
CJNE A, #0F, ROW 1
MOV P1, #11111011B ; GROUND ROW 2
MOV A, P2
ANL A, #0F
CJNE A, #0F, ROW 2
MOV P1, #11110111B ; GROUND ROW 3
MOV A, P2
ANL A, #0F
CJNE A, #0F, ROW 3
LJMP K2 ; IF NONE FALSE INPUT, REPEAT
ROW 0: MOV DPTR, #KCODE0
SJMP FIND
ROW 1: MOV DPTR, #KCODE1
SJMP FIND
ROW 2: MOV DPTR, #KCODE2
SJMP FIND
ROW 3: MOV DPTR, #KCODE3
SJMP FIND
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 107 / 109
108. Assembly Language Program
FIND: RRC A ; See if any CY bit is low
JNC ASC ; if zero get ASCII code
INC DPTR
SJMP FIND
; Suppose A= 11111110 it means column 0 is detected so send ASCII
ASC: CLR A
MOVC A, @A+DPTR
MOV P0, A
LJMP K1
; ASCII Look up table for each row
KCODE0: DB โ0โ, โ1โ, โ2โ, โ3โ ; row 0
KCODE1: DB โ4โ, โ5โ, โ6โ, โ7โ ; row 1
KCODE2: DB โ8โ, โ9โ, โAโ ,โBโ ; row 2
KCODE3: DB โCโ, โDโ, โEโ, โFโ ; row 3
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 108 / 109
109. Thank you
Please send your feedback at nbahadure@gmail.com
For more details and updates kindly visit
https://sites.google.com/site/nileshbbahadure/home
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - IV (Part I) July 25, 2021 109 / 109