Top Banner
Interfacing of 8051 UNIT 4
44

Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Dec 17, 2015

Download

Documents

Jonah Sherman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Interfacing of 8051

UNIT 4

Page 2: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Contents

• Interfacing of 7 segment display, LCD and keyboard.

• Interfacing of DC motor, stepper motor and relay.

• Interfacing of ADC, DAC and sensors.

Page 3: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

7 segment display

Page 4: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 5: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 6: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Interfacing of 7 segment display

Page 7: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

7 segment code for CC

DP G F E D C B A NUMBER

0 0 0 0 0 1 1 0 1

0 1 0 1 1 0 1 1 2

0 1 0 0 1 1 1 1 3

Page 8: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

PROGRAM 7 SEGMENT DISPLAY

• To display ‘1’

MOV A,#06HMOV P1,ASJMP $

Page 9: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

LCD Interfacing

Page 10: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 11: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Pin No: Name Function

1 VSS This pin must be connected to the ground

2 VCC Positive supply voltage pin (5V DC)

3 VEE Contrast adjustment4 RS Register selection5 R/W Read or write6 E Enable7 DB0 Data8 DB1 Data9 DB2 Data10 DB3 Data11 DB4 Data12 DB5 Data13 DB6 Data14 DB7 Data15 LED+ Back light LED+16 LED- Back light LED-

Page 12: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

1 Clear display screen2 Return Home4 Decrement cursor (shift cursor to left)5 Increment cursor (shift cursor to right)6 shift display right7 shift display left8 Display off, cursor offA Display off, cursor onC Display on, cursor offE Display on, cursor blinkingF Display on, cursor blinking10 Shift cursor position to left14 Shift cursor position to right18 Shift the entire display to the left1C Shift the entire display to the right80 Force cursor to the beginning of 1st lineC0 Force cursor to the beginning of 2nd line38 2 lines and 5 x 7 matrix

Page 13: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 14: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Interface ProgramMOV A,#38H // Use 2 lines and 5x7 matrixACALL CMNDMOV A,#0FH // LCD ON, cursor ON, cursor blinking ONACALL CMNDMOV A,#01H //Clear screenACALL CMNDMOV A,#06H //Increment cursorACALL CMNDMOV A,#82H //Cursor line one , position 2ACALL CMNDMOV A,#3CH //Activate second lineACALL CMND

MOV A,#’W’ACALL DISPMOV A,#’E’ACALL DISPMOV A,#’L’ACALL DISPMOV A,#’C’ACALL DISPMOV A,#OACALL DISPMOV A,#’M’ACALL DISPMOV A,#’E’ACALL DISP

Page 15: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

CMND: MOV P1,ACLR P3.5CLR P3.4SETB P3.3CLR P3.3ACALL DELYRET;

DISP:MOV P1,ASETB P3.5CLR P3.4SETB P3.3CLR P3.3ACALL DELYRET;

Page 16: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

DELY: MOV R0,#0FFHHERE: DJNZ R0, HERE

RET;

• Subroutine CMND sets the logic of the RS, R/W, E pins of the LCD module so that the module recognizes the input data ( given to DB0 to DB7) as a command.

• Subroutine DISP sets the logic of the RS, R/W, E pins of the module so that the module recognizes the input data as a data to be displayed .

Page 17: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

8051 & dc motor interface

Page 18: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 19: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

ORG 00H // initial starting addressMAIN: MOV P1,#00000001B // motor runs clockwiseACALL DELAY // calls the 1S DELAYMOV P1,#00000010B // motor runs anti clockwiseACALL DELAY // calls the 1S DELAYSJMP MAIN // jumps to label MAIN for repeating the cycle

DELAY: MOV R4,#0FHWAIT1: MOV R3,#0FFHWAIT2: MOV R2,#0FFHWAIT3: DJNZ R2,WAIT3DJNZ R3,WAIT2DJNZ R4,WAIT1RETEND

Page 20: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Stepper Motor Interfacing

• What is stepper motor?– Stepper motors consist of a permanent magnetic

rotating shaft, called the rotor, and electromagnets on the stationary portion that surrounds the motor, called the stator.

– a motor with a resolution of 5 degrees would move its rotor 5 degrees per step, thereby requiring 72 pulses (steps) to complete a full 360 degree rotation.

Page 21: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Stepper motor operation

Page 22: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

• At position 1, we can see that the rotor is beginning at the upper electromagnet, which is currently active (has voltage applied to it).

• To move the rotor clockwise (CW), the upper electromagnet is deactivated and the right electromagnet is activated, causing the rotor to move 90 degrees CW, aligning itself with the active magnet.

• This process is repeated in the same manner at the south and west electromagnets until we once again reach the starting position.

Page 23: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

• In the above example, we used a motor with a resolution of 90 degrees or demonstration purposes.

• In reality, this would not be a very practical motor for most applications. The average stepper motor's resolution -- the amount of degrees rotated per pulse is much higher than this.

• You may double the resolution of some motors by a process known as "half-stepping".

Page 24: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 25: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

• Instead of switching the next electromagnet in the rotation on one at a time, with half stepping you turn on both electromagnets, causing an equal attraction between, thereby doubling the resolution.

• Both the top and right electromagnets are active, causing the rotor to position itself between the two active poles

Page 26: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 27: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 28: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 29: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Sequence Polarity Name Description

0001001001001000

---+--+--+--+---

Wave Drive, One-Phase

Consumes the least power. Only one phase is energized at a time. Assures positional accuracy regardless of any winding imbalance in the motor.

0011011011001001

--++-++-++--+--+

Hi-Torque, Two-Phase

Hi Torque - This sequence energizes two adjacent phases, which offers an improved torque-speed product and greater holding torque.

Page 30: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

00010011001001100100110010001001

---+--++--+--++--+--++--+---+--+

Half-Step

Half Step - Effectively doubles the stepping resolution of the motor, but the torque is not uniform for each step. (Since we are effectively switching between Wave Drive and Hi-Torque with each step, torque alternates each step.) This sequence reduces motor resonance which can sometimes cause a motor to stall at a particular resonant frequency. Note that this sequence is 8 steps.

Page 31: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 32: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Stepper motor programmingorg 0H

stepper equ P3

main:mov stepper, #0CHacall delaymov stepper, #06Hacall delaymov stepper, #03Hacall delaymov stepper, #09Hacall delaysjmp main

delay:mov r7,#4wait2:mov r6,#0FFHwait1:mov r5,#0FFHwait:djnz r5,waitdjnz r6,wait1djnz r7,wait2ret

Page 33: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Analog to Digital Converter• Commonly used ADC device – ADC804• Pin out of ADC

– CS – Chip Select , active low– RD – Read Digital data from ADC, H-L edge triggered– WR -- Start conversion, L-H pulse edge triggered– INTR -- end of conversion, Goes low to indicate conversion done– Data bits -- D0-D7

• CLK IN & CLK R– CLK IN is an input pin connected to an external clock source when an external clock is used for timing. However, ADC804 has an internal clock generator.

• To use the internal clock generator of the ADC804, the CLK IN and CLK R pins are connected to a capacitor and a resistor. In that case, the clock frequency is determined by the equation. f = 1/1.1RC R=10K and C=150pF f=606Hz the conversion time is 110us.

Page 34: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Input Voltage range of ADC

Vref/2 (Volts)

Vin (Volts)

Step size (mV)

Open (2.5) 0 to 5 5/256 = 19.53

2.56 0 to 5.12 5.12/256 =20

1.28 0 to 2.56 2.56/256 = 10

0.5 0 to 1 1/256=3.90

Page 35: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

• Default 0-5V. Can be changed by setting different value for Vref/2 pin. Vin=Vin(+) – Vin (-)

• Range = 0 to 2x Vref/2. for Vin = 2x Vref/2. we get 256 as a digital output on D0-D7

• Step Size a Smallest change– (2 x Vref/2)/ 256 for ADC804for eg for step size 10mv ,digital output on D0-D7 changes by one count for every 10mv change of the input analog voltage.

Page 36: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Algorithm• Make CS=0 and send a low-to-high to pin WR to start the conversion.• Keep monitoring INTR– If INTR =0, the conversion is finished and we can go to the next step.– If INTR=1, keep polling until it goes low.• After INTR=0, we make CS=0 and send a high-to-low pulse to RD to get the data out of the ADC804 chip.

Page 37: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

ADC Interfacing

Page 38: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

ADC_IO: mov P1, #0xff ; To configure as inputsetb p3.4clr p3.7 ;Chip selectAGAINsetb P3.6 ;RD=1clr P3.5 ;WR=0setb P3.5 ;WR=1- low to high transition WAIT: jb P3.4, WAIT ;wait for INTRclr P3.6 ;RD=0 -High to low transition mov A, P1 ;read digital o/psjmp AGAIN

Page 39: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

DAC Interfacing

Page 40: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 41: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.
Page 42: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

• Iout= Iref (D7/2+D6/4+D5/8+D4/16+D3/32+D2/64+D1/128+D0/256)

• Vout=Iout x R

Page 43: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Interfacing of Relay with 8051

Page 44: Interfacing of 8051 UNIT 4. Contents Interfacing of 7 segment display, LCD and keyboard. Interfacing of DC motor, stepper motor and relay. Interfacing.

Interfacing LDR with 8051