You are on page 1of 44

Microprocessors and Microcontrollers – 11EC311

Interfacing with 8051


LED Interfacing

● Output Control (Pin or Port)


– SETB PX.Y
– CLR PX.Y
– MOV P1,A

● Input Reading (Switch)


– JB PX.Y,label
– JNB PX.Y,label
– MOV A,P1

22/09/15 8051 Interfacing - Copyleft 2


7 Segment Interfacing

MOV A,#06H
MOV P1,A

22/09/15 8051 Interfacing - Copyleft 3


LCD Interfacing

22/09/15 8051 Interfacing - Copyleft 4


LCD Pin Description

22/09/15 8051 Interfacing - Copyleft 5


LCD Command Codes

22/09/15 8051 Interfacing - Copyleft 6


LCD Interfacing with 8051

D1 P1.0
D2 P1.1
P1.2
D3
P1.3
D4 P1.4
D5 P1.5
D6 P1.6
D7 P1.7
8051
UC

P3.0
P3.1
P3.2
22/09/15 8051 Interfacing - Copyleft 7
Programming LCD

● List out Inputs and Outputs from LCD Pin Diagram


● Allot Pins of 8051 to above and List down
● Programming Command Mode (Configuring LCD)
Send a Value to Port

● RS = 0

● RW = 0

● EN = HIGH TO LOW

● Programming Data Mode (Printing Data on LCD)


● Send a Value to Port
● RS = 1
● RW = 0
● EN = HIGH TO LOW
22/09/15 8051 Interfacing - Copyleft 8
Program to print KLU on LCD
MOV A,#38H
ACALL CMD
MOV A,#06H
ACALL CMD
MOV A,#01H
ACALL CMD
MOV A,#0EH
ACALL CMD
MOV A,#80H
ACALL CMD
MOV A,#'K'
ACALL DAT
MOV A,#'L'
ACALL DAT
MOV A,#'U'
ACALL DAT
SJMP $

22/09/15 8051 Interfacing - Copyleft 9


Program to print KLU on LCD(cont.)
CMD:MOV P1,A
CLR P3.0
CLR P3.1
SETB P3.2
ACALL DELAY
CLR P3.2
RET
DAT:MOV P1,A
SETB P3.0
CLR P3.1
SETB P3.2
ACALL DELAY
CLR P3.2
RET
22/09/15
END
8051 Interfacing - Copyleft 10
Example : LCD Program

22/09/15 8051 Interfacing - Copyleft 11


LTC Programs on LCD Interfacing

● Display “CSE” on Line 1 of LCD

● Display “Hello World” on Line 2 of LCD using Indexed

● Display “Success” on Middle of Line 1 of LCD Display if a


switch connected to P2.1 is Pressed

22/09/15 8051 Interfacing - Copyleft 12


Keypad Interfacing with 8051

22/09/15 8051 Interfacing - Copyleft 13


Keypad Interfacing

22/09/15
Keypad Interfacing Flowchart

22/09/15 Sripath Roy


Keypad Interfacing Flowchart

22/09/15 Sripath Roy


Keypad Interfacing Program
Keypad Interfacing Program(cont.)
Keypad Interfacing Program(cont.)
Analog to Digital Converter(ADC) Interfacing With 8051
Analog to Digital Convereter


Sensors takes the environmental change and converts
into Analog Electrical Signal

Microcontroller Understand only Digital Logic

ADC Converts Analog Signal to Digital Signal

Voltage is Coverted into Bits of Data

High the resolution of ADC more the data samples

8 Bit ADC = 256 Samples
ADC0804 Interfacing Diagram
ADC0804 Pin Description


WR

Start of Conversion (O/P for 8051)

Low to High Transaction

Converts Analog Input into 8 bit Digital

INTR

End of Conversion(I/P for 8051)

Active Low

RD

Output Enable (I/P for 8051)

To get the 8-bit data from ADC out of D0-D7 Lines
ADC0804 Timing Diagram

22/09/15 8051 Interfacing - Copyleft 24


Program for ADC0804

RD BIT P2.5
WR BIT P2.6
INTR BIT P2.7
MYDATA EQU P1
MOV P1,#0FFH
SETB INTR
CLR WR
SETB WR
HERE: JB INTR, HERE
CLR RD
MOV A,MYDATA

SETB RD
SJMP BACK
22/09/15 8051 Interfacing - Copyleft 25
Digital to Analog(DAC) Interfacing with 8051

22/09/15 8051 Interfacing - Copyleft 26


Digital to Analog(DAC Converter)

● Converts Digital Signal to Analog


● Binary Data of n-bit into Voltages
● To control Analog Devices
● Example : DC Motor Speed Control etc

22/09/15 8051 Interfacing - Copyleft 27


DAC0808 Interfacing Diagram

22/09/15 8051 Interfacing - Copyleft 28


Generation of Square Wave using DAC0808

BACK:
MOV A,#0FFH
MOV P1,A
ACALL DELAY
MOV A,#00H
MOV P1,A
ACALL DELAY
SJMP BACK
END

22/09/15 8051 Interfacing - Copyleft 29


Generation of Triangular Wave using DAC0808

BACK:MOV A,#00H
INCRE:MOV P1,A
INC A
CJNE A,#0FFH,INCRE
DECRE:MOV P1,A
DEC A
CJNE A,#00H,DECRE
SJMP BACK
END

22/09/15 8051 Interfacing - Copyleft 30


Generation of Sawtooth Wave using DAC0808

BACK:MOV A,#00H
INCRE:MOV P1,A
INC A
CJNE A,#0FFH,INCRE
SJMP BACK
END

22/09/15 8051 Interfacing - Copyleft 31


Generation of Step Wave using DAC0808
BACK:MOV A,#00H
INCRE:MOV P1,A
ADD A,#51D
ACALL DELAY
CJNE A,#255D,INCRE
DECRE:MOV P1,A
SUBB A,#55D
ACALL DELAY
CJNE A,#00D,DECRE
SJMP BACK
END
22/09/15 8051 Interfacing - Copyleft 32
Stepper Motor Interfacing with 8051

22/09/15 8051 Interfacing - Copyleft 33


Stepper Motor

● Rotor – Permanent Magnet


● Stator – 4 Windings
● Rotation of Current in Windings
Rotates the Motor
● 4 Phase Stepper Motor
● Poles or Teeth changes in Stator
● Step Angle(in Degrees) = 360/no.of Teeth
● Ex: Disk Drives, Dot Matrix Printers, Robots
● Working of Stepper Motor - Video

22/09/15 8051 Interfacing - Copyleft 34


Normal 4-Step Sequence

CLOCKWISE STEP WINDING A WINDING B WINDING C WINDING D COUNTER


CLOCKWISE

1 1 1 0 0

2 0 1 1 0

3 0 0 1 1

4 1 0 0 1

22/09/15 8051 Interfacing - Copyleft 35


Half Step 8-Step Sequence

CLOCKWISE STEP WINDING A WINDING B WINDING C WINDING D COUNTER


CLOCKWISE

1 1 0 0 1
2 1 0 0 0
3 1 1 0 0
4 0 1 0 0
5 0 1 1 0
6 0 0 1 0
7 0 0 1 1
8 0 0 0 1

22/09/15 8051 Interfacing - Copyleft 36


Wave Drive 4-Step Sequence

CLOCKWISE STEP WINDING A WINDING B WINDING C WINDING D COUNTER


CLOCKWISE

1 1 0 0 0

2 0 1 0 0

3 0 0 1 0

4 0 0 0 1

22/09/15 8051 Interfacing - Copyleft 37


Stepper Motor Interfacing Diagram

22/09/15 8051 Interfacing - Copyleft 38


Program to Rotate Stepper Motor Clock Wise
Using Wave Drive Sequence Continuously
START:
MOV A,#08H
MOV P2,A
ACALL DELAY
MOV A,#04H
MOV P2,A
ACALL DELAY
MOV A,#02H
MOV P2,A
ACALL DELAY
MOV A,#01H
MOV P2,A
ACALL DELAY
SJMP START
22/09/15 8051 Interfacing - Copyleft 39
Program to Rotate Stepper Motor Clock Wise

Using Normal 4 Step Sequence for 50 Steps


MOV R0,#50D
MOV A,#33H
BACK:
MOV P2,A
ACALL DELAY
RR A
DJNZ R0,BACK
END
22/09/15 8051 Interfacing - Copyleft 40
Program to Rotate Stepper Motor Anti Clock Wise

Using 200 Poles Stepper Motor for 180 Degrees


MOV R0,#100D
MOV A,#33H
BACK: Calculations:
MOV P2,A Step Angle = 360/200 = 1.8
Required Steps = 180/1.8 = 100
ACALL DELAY
RL A
DJNZ R0,BACK
END
22/09/15 8051 Interfacing - Copyleft 41
Stepper Motor LTC Programs

● Rotate the stepper Motor having 180 Poles 90 Degrees


Clockwise using wave drive sequence

● Rotate the Stepper Motor having 90 Poles using Normal 4


Step Sequence 270 Degrees Anti Clock Wise and then 720
Degrees Clock Wise

● Program to run the stepper Motor Clock wise if a switch


connected to P1.1 is Pressed and Anti-Clock Wise if Switch
Connected to P1.0 is Pressed

22/09/15 8051 Interfacing - Copyleft 42


References

● https://www.sites.google.com/site/sripathroykoganti/my-forms

● The 8051 Microcontroller, 3rd Edition, Ayala, CENGAGE


Learning
● Microcontrollers[Theory and Applications], Ajay V
Deshmukh, Tata McGraw Hill
● The 8051 Microcontroller and Embedded Systems,
Muhammad Ali Mazidi, Pearson Education

22/09/15 8051 Interfacing - Copyleft 43


Thank You

22/09/15 8051 Interfacing - Copyleft 44

You might also like