330_09

  • Upload
    salitha

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

  • 7/25/2019 330_09

    1/38

    Input/Output Ports and Interfacing

    ELEC 330Digital Systems Engineering

    Dr. Ron ayne

    Images Courtesy of Ramesh Gaonkar and Delmar Learning

  • 7/25/2019 330_09

    2/38

    !asic I/O Concepts

    Perip"erals suc" as LEDs and #eypads are essential

    components of microcontroller$%ased systems Input de&ices

    Pro&ide digital information to an 'P( E)amples* s+itc", #ey%oard, scanner, and digital camera

    Output de&ices Recei&e digital information from an 'P( E)amples* LED, se&en$segment display, LCD, and printer

    De&ices are interfaced to an 'P( using I/O ports

    -3300

  • 7/25/2019 330_09

    3/38

    I/O Interfacing

    33300

  • 7/25/2019 330_09

    4/38

    Interfacing and ddressing

    I/O ports !uffers and latc"es on t"e 'C( c"ip

    ssigned %inary addresses %y decoding t"e address %us

    1enerally %idirectional

    Internal data direction registers

    2o read %inary data from an input perip"eral

    'P( places t"e address of an input port on t"e address %us

    Ena%les t"e input port %y asserting t"e RD signal

    Reads data using t"e data %us

    2o +rite %inary data to an output perip"eral 'P( places t"e address of an output port on t"e address %us

    Places data on data %us

    sserts t"e R signal to ena%le t"e output port

    43300

  • 7/25/2019 330_09

    5/38

    PIC56748-/48-0 I/O Ports

    'C( includes fi&e I/O ports POR2, POR2!, POR2C, POR2D, POR2E

    Ports are multiple)ed Can %e set up to perform &arious functions

    Eac" I/O port is associated +it" se&eral S7Rs POR2

    7unctions as a latc" or a %uffer

    2RIS

    Data direction register

    Logic 0 sets up t"e pin as an output

    Logic 5 sets up t"e pin as an input

    L2 Output latc" similar to POR2

    83300

  • 7/25/2019 330_09

    6/38

    PIC56748-/48-0 I/O Ports

    POR2* E)ample of 'ultiple 7ns

    Digital I/O* R9$R0

    nalog Input* :0$:4

    ; RE7< * /D Reference Plus ;

    ; RE7$ * /D Reference 'inus ;

    2OC=5* 2imer0 E)t. Cloc#

    SS* SPI Sla&e Select Input

    L;DI:* Lo+ ; Detect Input

    93300

  • 7/25/2019 330_09

    7/38

    PIC56748-/48-0 I/O Ports

    POR2!

    >3300

  • 7/25/2019 330_09

    8/38

    I/O E)ample

    rite instructions to set up pins R!>$R!4 of

    POR2! as inputs and pins R!3$R!0 as outputs

    3300 6

    Opcode Operands Comments'O;L 0)70 ?Load !@55550000@ into RE1

    'O;7 2RIS! ?Set POR2! 2RIS Reg

  • 7/25/2019 330_09

    9/38

    Interfacing Output Perip"erals

    Commonly used output perip"erals in em%edded systems LEDs Se&en$Segment Displays LCDs

    2+o +ays of connecting LEDs to I/O ports Common Cat"ode

    LED cat"odes are grounded Logic 5 from t"e I/O port turns on t"e LEDs Current is supplied %y t"e I/O port called current sourcing

    Common node LED anodes are connected to t"e po+er supply Logic 0 from t"e I/O port turns on t"e LEDs Current is recei&ed %y t"e c"ip called current sin#ing

    3300

  • 7/25/2019 330_09

    10/38

    Interfacing Output Perip"erals

    Common Cat"ode Common node

    503300

  • 7/25/2019 330_09

    11/38

    Se&en$Segment Display

    Se&en$segment Displays (sed to display !CD digits

    0 t"ru

    group of > LEDs p"ysically

    mounted in t"e s"ape of t"e num%er

    eig"t Plus a decimal point

    Eac" LED is called a segment

    Aa@ t"roug" Ag@ 2+o types

    Common anode

    Common cat"ode

    553300

  • 7/25/2019 330_09

    12/38

  • 7/25/2019 330_09

    13/38

    Se&en$Segment Display

    Common Cat"ode ll cat"odes are connected toget"er to ground nodes are connected to data lines

    Logic 5 turns on a segment

    E)ample* 2o display digit 5 ll segments e)cept % and c s"ould %e off 00000550 B 09

    533300

  • 7/25/2019 330_09

    14/38

    E)ample .4

    Interfacing Se&en$Segment Display to POR2! Common node

    2a%le Loo#$(p

    543300

  • 7/25/2019 330_09

    15/38

  • 7/25/2019 330_09

    16/38

    Interfacing Input Perip"erals

    Commonly used input perip"erals DIP s+itc"es, pus"$%utton #eys, #ey%oards, and /D con&erters

    DIP s+itc"

    One side of t"e s+itc" is tied "ig" 2o a po+er supply t"roug" a resistor called a pull$up resistor

    2"e ot"er side is grounded

    2"e logic le&el c"anges +"en t"e position is s+itc"ed

    Pus"$%utton #ey Same as t"e DIP s+itc" e)cept t"at contact is momentary

    593300

  • 7/25/2019 330_09

    17/38

    Interfacing Dip S+itc"es

    5>3300

  • 7/25/2019 330_09

    18/38

    Reading from an I/O Port

    Read input s+itc"es on POR2! R!>$R!4 R!0 set I 5

    S+itc"es Open B LO 0

    S+itc"es Closed B I1 5

    Display on POR2C

    3300 56

    Opcode Operands Comments

    'O;L 0)70 ?Load !@55550000@ into RE1

    'O;7 2RIS! ?Set POR2! 2RIS RegCLR7 2RISC ?Set POR2C as Output

    !S7 POR2!,0 ?Set R!0 ig"

    'O;7 POR2!, ?Read POR2!

    'O;7 POR2C ?Display on POR2C

  • 7/25/2019 330_09

    19/38

    Internal Pull$(p Resistor

    2urning off t"e internal 7E2

    pro&ides a pull$up resistor

    !it> R!P( in t"e I:2CO:-

    register ena%les or disa%les t"e

    pull$up resistor Instruction to Ena%le Pull (p

    Resistors*

    !C7 I:2CO:-,>

    53300

  • 7/25/2019 330_09

    20/38

    Interfacing Pus"$!utton =eys

    "en a #ey is pressed or released, mec"anical metalcontact %ounces momentarily and can %e read as multipleinputs

    =ey de%ounce

    Eliminating reading of one contact as multiple inputs ard+are or Soft+are

    -03300

  • 7/25/2019 330_09

    21/38

    =ey De%ounce 2ec"niues

    ard+are tec"niue 2+o ::D gates

    S$R latc"

    2"e output of t"e latc" is

    a pulse +it"out a %ounce

    Soft+are tec"niue ait for 50 to -0 ms

    after detection of a

    s+itc" closure

    If t"e reading is still t"e

    same it is accepted

    3300 -5

  • 7/25/2019 330_09

    22/38

    Interfacing a 'atri) =eypad

    Pro%lem statement Interface a 4 ) 4 e) #eypad to POR2!

    rite a program to recogniFe a #ey pressed and

    encode t"e #ey in its %inary &alue Display %inary code on POR2C

    --3300

  • 7/25/2019 330_09

    23/38

    Interfacing a 'atri) =eypad

    ard+are PIC56 Simulator 4 ) 4 matri) #eypad organiFed in t"e ro+ and

    column format 7our columns are connected to t"e lo+er "alf of

    POR2! R!0$R!3 7our ro+s are connected to upper "alf of POR2!

    R!4$R!> "en a #ey is pressed, it ma#es a contact +it"

    t"e corresponding ro+ and column

    -33300

  • 7/25/2019 330_09

    24/38

    Interfacing a 'atri) =eypad

    PIC56 Simulator =eypad 'atri)

    -43300

    5

    4

    >

    -

    8

    6

    0

    3

    9

    !

    C

    D

    E

    7

  • 7/25/2019 330_09

    25/38

  • 7/25/2019 330_09

    26/38

  • 7/25/2019 330_09

    27/38

    2ime 'ultiple) Scanning

    ard+are Eig"t data lines of POR2! are connected to t"e anodes of

    eac" display

    Eac" cat"ode is connected to POR2C RC3$RC0 t"roug" a

    transistor

    2ransistors and LEDs can %e turned on %y sending logic 5

    Eac" display is turned on and off in a seuence to display a

    digit

    ->3300

  • 7/25/2019 330_09

    28/38

  • 7/25/2019 330_09

    29/38

    2ime 'ultiple) Scanning

    Soft+are Codes of t"e num%ers to %e displayed are stored in data

    registers in seuence 2"e program gets t"e codes from t"e data registers %y

    using t"e pointer 7SR0 and sends t"em out to t"e LEDsegments t"roug" POR2!

    One display at a time is turned on %y sending logic 5 to t"ecorresponding transistor connected to POR2C

    fter an appropriate delay, t"e first display is turned offand t"e ne)t display is turned on 2urning displays on/off is repeated in seuence

    -3300

  • 7/25/2019 330_09

    30/38

  • 7/25/2019 330_09

    31/38

  • 7/25/2019 330_09

    32/38

    Interfacing LCD

    3-3300

  • 7/25/2019 330_09

    33/38

    Interfacing LCD

    Dri&er D44>60 6$%it data %us RD>$RD0 2"ree control signals

    RS G Register Select R3R/ G Read/rite R-E G Ena%le R5

    2"ree po+er connectionsPo+er, ground, and &aria%le resistor to control %rig"tness

    333300

  • 7/25/2019 330_09

    34/38

  • 7/25/2019 330_09

    35/38

    Interfacing LCD

    LCD Operation "en t"e 'P( +rites an instruction to IR or data to DR,

    t"e controller* Sets D!> "ig" indicating t"at t"e controller is %usy

    Sets D!> lo+ after t"e completion of t"e operation 2"e 'P( s"ould al+ays c"ec# +"et"er D!> is lo+

    %efore sending an instruction or a data %yte

    383300

  • 7/25/2019 330_09

    36/38

  • 7/25/2019 330_09

    37/38

  • 7/25/2019 330_09

    38/38