m.tech Lab Manual JNTUH

Embed Size (px)

Citation preview

  • 8/13/2019 m.tech Lab Manual JNTUH

    1/80

    1. Program to toggle all the bits of PORT P1 continuously with 250ms delay.

    AI!

    The basic program on a microcontroller is to operate the input and output functionality of

    the pins. AT89S51 is the controller having the 8051 architecture. In this proect !e are

    programming to control the output devices li"e #$%s such that& ma"e all pins of '()T '1 high

    at once and off at once.

    A""aratus!

    1. I%$ * +iel uvision ,.0&

    -. Simulator* 'rofessional 'roteus ..

    Theory!

    Here we are using AT89S51 to glow an LED. For this simple project we hae to !nowthe power "#$ %& o' an LED as to suppl( 'orm the controller. %n eer( project 'irst o' all we hae

    to !now the operation o' each )eice in)ii)uall( an) then em*e) them accor)ingl(.

    Working of an LED:

    A light+emitting )io)e "LED& is a semicon)uctor light source. LEDs are use) as in)icator lampsin man( )eices an) are increasingl( use) 'or other lighting. ,hen a light+emitting )io)e is

    'orwar)+*iase) "switche) on&$ electrons are a*le to recom*ine with electron holes within the

    )eice$ releasing energ( in the 'orm o' photons. This e''ect is calle) electroluminescence an) the

    color o' the light "correspon)ing to the energ( o' the photon& is )etermine) *( the energ( gap o'the semicon)uctor. LEDs present man( a)antages oer incan)escent light sources inclu)ing

    lower energ( consumption$ longer li'etime$ improe) ph(sical ro*ustness$ smaller si-e$ an)

    'aster switching.

    Light+emitting )io)es are use) in applications as )ierse as aiation lighting$ automotie

    lighting$ a)ertising$ general lighting$ an) tra''ic signals. LEDs hae allowe) new tet$ i)eo

    )ispla(s$ an) sensors to *e )eelope)$ while their high switching rates are also use'ul in

    a)ance) communications technolog(. %n'rare) LEDs are also use) in the remote control units o'man( commercial pro)ucts inclu)ing teleisions$ D#D pla(ers$ an) other )omestic

    appliances.LEDs wor! 'or a oltage greater than 1./# an) )epen) on the color$ 'or maimum

    *rightness we nee) 0.0# suppl(. Hence$ we nee) to suppl( more than 0.0# 'rom a controller.

    s*it+ This is the !e(wor) to assign an( pin to a aria*le.

    Working of AT89S51:

  • 8/13/2019 m.tech Lab Manual JNTUH

    2/80

    AT89S51 reuires a oltage o' 5.2# an) 13# when programming the microcontroller. The

    current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller an) the

    consumption o' LED. The controller wor!s on 11.2593 4H- 'reuenc(.

    ote6 %t is suggeste) to use 522mA an) 13# D7 power suppl(.

    Algorithm!

    1. In this proect !e need to toggle all the bits of port1 of at89c51.

    -. To provide output& first !e need to clear the storage or available data in port register.

    /. To get output at port '1 assign logic 1 i.e.& 0ff to the '1 register as it is 8 bit register.

    ,. o! !e need to generate -50ms delay by looping time period T 2delay

    time34cyclescloc" cycle.

    5. As to get toggling assign 000 to '1 register.

    6. o! apply the delay again to stabili7e logic 0 state of port.

    . )epeat the steps / to 6 !hole in a continuous loop.

    #ircuit $iagram!

  • 8/13/2019 m.tech Lab Manual JNTUH

    3/80

    %low chart!

    True

    Increment cycle i.e.&

    ycle4cycle1

    If2cycl

    e:-50

    ms3

    Start

    lear the available data

    in reg '1& 2'1403.

    Assigning #ogic 1 state

    to port '1 i.e.&2'140ff3

    Assigning #ogic 0

    state to port '1 i.e.&

    2'140003

    Increment cycle i.e.&

    ycle4cycle1

    If2cycl

    e:-50

    ms3

    True

    ;alse

    ;alse

  • 8/13/2019 m.tech Lab Manual JNTUH

    4/80

    Program!

    && '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    && Pro(ect! led interfacing to AT)*s51

    && odule descri"tion! led interfacing

    && '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    +include,reg51.h-

    oid clear/

    oid delay/unsigned int

    oid main/

  • 8/13/2019 m.tech Lab Manual JNTUH

    5/80

    clear/

    while/1 && infinite loo"

    P1304ff

    delay/600 &&250msec

    P230400

    delay/600 &&250msec

    7 && end of while loo"

    7 && end of main

    oid clear/ &&clearing all "orts

    P130400

    7

    oid delay/unsigned int c &&ma8ing c cycles delay

    unsigned int d

    for/d3cd930d::

    7

    2. Program to toggle only the bit P1.5 continuously with some delay. Use Timer 0,

    mode 1 to create delay.

    Aim!In this article !e are dealing ho! to use a timer of controller in order to perform delay.

    A""aratus!

    1. I%$ * +iel uvision ,.0&

  • 8/13/2019 m.tech Lab Manual JNTUH

    6/80

    -. Simulator* 'rofessional 'roteus ..

    Theory!

    Difference between software and hardware timer dela:

    First let us !now what the )i''erence *etween so'tware an) har)ware timer )ela(s. As so'tware

    timer is that$ a program which ma!es the controller not to )o an( tas!. ut 'irst o' all to run that

    )ela( program the processor ta!es some c(cles to eecute that )ela("& 'unction an) not surecompletes the eact )ela( we nee). Thus har)ware )ela( came into the picture.Here we are using

    in*uilt har)ware timers as we ha) two 1/ *it T%4E2$ T%4E1 timer to generate eact )ela(.

    This concept o' har)ware timers were use) mostl( in satellite launching$ uclear reactorsmonitoring$ etc.

    !sing T"#E$% in AT89S51:

    %n or)er to ma!e wor!ing o' Timers we nee) two registers6

    1& T7: "Timer count& 6

    TF1 Timer 1 oer 'low 'lag which sets *( har)ware on Timer 1 oer'low an) is cleare) *(

    har)ware i' processor ectors to interrupt routine.

    TR1Timer 1 run control *it which sets; cleare) *( so'tware to turn Timer 1 either

  • 8/13/2019 m.tech Lab Manual JNTUH

    7/80

    Gate: ,hen set$ timer;counter

  • 8/13/2019 m.tech Lab Manual JNTUH

    8/80

    #include// Out Pinsbit Out = P1^0; // Pin P2.0 is named as Out//Functin declaratins!id cct"init!id$;!id %nit&imer0!id$;unsigned int cunt=0;int main!id$' cct"init$; // (a)e all *rts +er Out=0; %nit&imer0$; // ,tart &imer0 -hile1$ // est is dne in &imer0 interru*t ' !id cct"init!id$

    ' P0 = 000;

    P1 = 000;P2 = 000;P = 000;

    !id %nit&imer0!id$'

    True

    ;alse

    TI>$)0?init23@

    $nd

    #$%?high23

    #$%?lo!23;lag4

    0

  • 8/13/2019 m.tech Lab Manual JNTUH

    9/80

    &(O 3= 0F0; // 4lear bit 6ield 6r timer0 &(O 7= 002; // ,et timer0 in mde 2

    &80 = 000; // 250 usec relading time &90 = 005; // First time !alue :&0 = 1; // :nable &imer0 interru*ts : = 1; // lbal interru*t enable

    &0 = 1; // ,tart &imer 0!id &imer0"%, !id$ interru*t 1 // %t is called a6ter e!er 250usec' cunt=cunt1; i6cunt==5000$ ' Out = ?Out; // &ggle Out *in cunt=0; &F0 = 0; // 4lear the interru*t 6lag

    %low chart!

    3). Program to interface a switch and a buer to two different !ins of a Port such

    that the buer should sound as long as the switch is !ressed.

    Aim!

    The basic program on a microcontroller is to operate the input and output functionality of the

    pins. AT89S51 is the controller having the 8051 architecture. In this proect !e program to use

  • 8/13/2019 m.tech Lab Manual JNTUH

    10/80

    controller using input device as s!itch. If controller obtains an input it should sho! an output

    !ith the help of a pin i.e.& bu77er attaching to a particular pin.

    A""aratus!

    /. I%$ * +iel uvision ,.0&

    ,. Simulator* 'rofessional 'roteus ..

    Theory!

    Here we are using AT89S51as a controller which is controlle) *( a toggle switch "which gies

    either *inar( 2 or1& an) respectie output accor)ing to the input. For this simple project we hae

    to !now the power "#$ %& o' an *u--er as to suppl( 'orm the controller an) power to suppl( 'romthe switch to the controller i.e.$ ,hat is # 'or logic high. %n eer( project 'irst o' all we hae to

    !now the operation o' each )eice in)ii)uall( an) then em*e) them accor)ingl(.

    Working of a switch:

    %nput 'or a controller using switches can *e )one in two wa(s.

    a&. @ull up$

    *&. @ull )own.

    Working of )*ll Down:

    From the a*oe circuit we consi)er LED as our controller pin. ,hen the switch is presse)$

    controller gets logic 1+which means 5,-.an) i' release) pin gets logic %+which means /0D

    thro*gh %ohms-2Thus @ull )own is nothing$ that the output will *e pull )own using a resistor i'no eternal e''ect.

    Working of )*ll Down:

    From the a*oe circuit we consi)er LED as our controller pin. ,hen the switch is presse)$

    controller gets logic %+which means /0D-.an) i' release) pin gets logic 1+which means 35,

    thro*gh %ohms-2Thus @ull up is nothing$ that the output will *e pulle) up using a resistor i' noeternal e''ect.

    Working of AT89451:

    AT89751 reuires a oltage o' 5.2# een programming the microcontroller. The current rating

    o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on11.2593 4H- 'reuenc(.

  • 8/13/2019 m.tech Lab Manual JNTUH

    11/80

    Working of *66er:

    ote6 %t is suggeste) to use 522mA an) 13# D7 power suppl(.

    Algorithm!

    . In this proect !e need to s!itch ( bu77er !hen user enters re

  • 8/13/2019 m.tech Lab Manual JNTUH

    12/80

    Program!

    && '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    && Pro(ect !;witch and bu

  • 8/13/2019 m.tech Lab Manual JNTUH

    13/80

    sbit bu

  • 8/13/2019 m.tech Lab Manual JNTUH

    14/80

    ". Program to interface #$% data !ins to !ort P1 and dis!lay a message on it.

    AI!

    In this proect !e !ill be dealing !ith 16B- #% display 2#> 016#3& and embedding it to our

    AT89S51. ;or !hich !e consider an application as to display a name on #%.

    A""aratus!

    1. I%$ * +iel uvision ,.0&

  • 8/13/2019 m.tech Lab Manual JNTUH

    15/80

    -. Simulator* 'rofessional 'roteus ..

    Theory!

    Here we are using AT89S51 to control the L4 21/L. For our application$ 'irst we want to !nowa*out the L421/L which wor!s on the principle o' piel matri that can *e controlle) using

    internal comman)s o' particular L7D.

    Working of a L4D:

    L7D "Liui) 7r(stal Displa(& screen is an electronic )ispla( mo)ule an) 'in) a wi)e range o'

    applications. A 1/?3 L7D )ispla( is er( *asic mo)ule an) is er( commonl( use) in arious

    )eices an) circuits. These mo)ules are pre'erre) oer seen segments an) other multi segment

    LEDs. The reasons *eing6 L7Ds are economical$ easil( programma*le$ hae no limitation o')ispla(ing special een custom characters "unli!e in seen segments&$ animations an) so on.

    A 162 LCDmeans it can )ispla( 1/ characters per line an) there are 3 such lines. %n this L7D

    each character is )ispla(e) in 5?B )ot matri. This L7D has two registers$ namel($ 7omman)an) Data. The comman) register stores the comman) instructions gien to the L7D. A comman)

    is an instruction gien to L7D to )o a pre)e'ine) tas! li!e initiali-ing it$ clearing its screen$

    setting the cursor position$ controlling )ispla( etc. The )ata register stores the )ata to *e

    )ispla(e) on the L7D. The )ata is the AS7%% alue o' the character to *e )ispla(e) on the L7D.

    As$ )ot matri haing negatie rows an) positie columns$ here in the a*oe 5?B )ot matri wesupplie) C5# to select 0r)column an) n) to 1st$ 0r)$ th$ 5th$/than) Bthrows. %n the same pattern

    L4 21/L ha) 03 5?8 )ot matrices *( which we can iew 03 characters at a time. All the

    characters are pre)e'ine) in the A4 memor( o' the L4 21/L.

    Working of AT89451:

    http://iblocks.in/wp-content/uploads/2012/09/lcd1.bmp
  • 8/13/2019 m.tech Lab Manual JNTUH

    16/80

    AT89751 reuires a oltage o' 5.2# een programming the microcontroller. The current rating

    o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on

    11.2593 4H- 'reuenc(.

    Algorithm!

    1. In this proect !e need to display a message on #%2#>016>3 using port '1 of

    AT89c51 as data port and port '- as configuration port .

    -. To provide output& first !e need to clear the storage or available data in port '1&'-

    register.

    /. ;rom the datasheet provided !ith #>016> to configure and display data on #% !e

    need to use configuration& data pins to get desired output on #% according to cloc"

    signals provided in datasheet.

    ,. According to #>016> datasheet of #% to get display !e need to use $nable2$3&

    readC!rite2)CD3& status register2)S3 and %0E%82data pins3.

    5. As #% !or"s on parallel communication !e are using !hole port '1 for data sharing to

    #%.

    ;chematic!

  • 8/13/2019 m.tech Lab Manual JNTUH

    17/80

    %low chart!

    True

    ;alse

    1

    Start

    lear the available datain reg '1& 2'1403.

    #cdinit23@

    !ritedata2FF3@

    CC!rite

    !ritedata2F)F3@

    !ritedata2FIF3@

    CC!rite

    $nd

    )eturn23@

  • 8/13/2019 m.tech Lab Manual JNTUH

    18/80

    Program:

    CC

    CC 'roect* #% 8bit

    CC Author* sudheer

    CC >odule description* (perate #% in 8bit mode

    CC

    GincludeHreg51.h:

    CC;unction declarations

    void cct?init2void3@

    void delay2int3@

    void lcdinit2void3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    19/80

    void !ritecmd2int3@

    void !ritedata2char3@

    void )eturnome2void3@

    CC

    CC'in description

    C

    '1 is data bus

    '-.0 is )S

    '-.1 is $

    C

    CC

    CC %efines 'ins

    sbit )S 4 '-=0@

    sbit $ 4 '-=1@

    sbit r! 4 '-=-@

    CC

    CC >ain program

    CC

    void main2void3

    J r!40@

    cct?init23@ CC>a"e all ports 7ero

    lcdinit23@ CCInitili7e #%

  • 8/13/2019 m.tech Lab Manual JNTUH

    20/80

    !ritedata2FiF3@ CC!rite

    !ritedata2F F3@

    !ritedata2FbF3@ CC!rite

    !ritedata2FlF3@

    !ritedata2FoF3@ CC!rite

    !ritedata2FcF3@ CC!rite

    !ritedata2F"F3@

    !ritedata2FKF3@ CC!rite

    !ritedata2FsF3@

    )eturnome23@ CC)eturn to 0 position

    !hile213

    J

    L

    L

    void cct?init2void3

    J

    '0 4 000@ CCnot used

    '1 4 000@ CCnot used

    '- 4 000@ CCused as data port

    '/ 4 000@ CCused for generating $ and )S

    L

    void delay2int a3

    J

  • 8/13/2019 m.tech Lab Manual JNTUH

    21/80

    int i@

    for2i40@iHa@i3@ CCnull statement

    L

    void !ritedata2char t3

    J

    )S 4 1@ CC 4: )S 4 1

    '1 4 t@ CC%ata transfer

    $ 4 1@ CC 4: $ 4 1

    delay21503@

    $ 4 0@ CC 4: $ 4 0

    delay21503@

    L

    void !ritecmd2int 73

    J

    )S 4 0@ CC 4: )S 4 0

    '1 4 7@ CC%ata transfer

    $ 4 1@ CC 4: $ 4 1

    delay21503@

    $ 4 0@ CC 4: $ 4 0

    delay21503@

    L

    void lcdinit2void3

  • 8/13/2019 m.tech Lab Manual JNTUH

    22/80

    J

    CCCCCCCCCCCCC )eset process from datasheet CCCCCCCCC

    delay2150003@

    !ritecmd20/03@

    delay2,5003@

    !ritecmd20/03@

    delay2/003@

    !ritecmd20/03@

    delay26503@

    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

    !ritecmd20/83@ CCfunction set

    !ritecmd200c3@ CCdisplay on&cursor off&blin" off

    !ritecmd20013@ CCclear display

    !ritecmd20063@ CCentry mode& set increment

    L

    void )eturnome2void3 CC)eturn to 0 location

    J

    !ritecmd200-3@

    delay215003@

    L

    5 Program to !nter"ace #e$%ad &hene'er a #e$ !( %re((ed) !t

    (ho*ld +e d!(%la$ed on LCD

  • 8/13/2019 m.tech Lab Manual JNTUH

    23/80

    AI!

    In this proect !e !ill be dealing !ith 44 keypad& and embedding it to our AT89S51. Mou are

    developing an embedded application using one or more members of the 8051 family of

    microcontrollers. The application has a timeEtriggered architecture& constructed using a

    scheduler. De are creating the user interface for your application. ;or !hich !e consider an

    application as to display the input "ey in the #%.

    A""aratus!

    1. I%$ * +iel uvision ,.0&

    -. Simulator* 'rofessional 'roteus ..

    Theory!

    Here we are using AT89S51 to control the 77 kead. For our application$ 'irst we want to

    !now a*out the 77 keadwhich wor!s on the principle o' switching concept.

    Working of a ead:

    ,e are concerne) here with !e(pa)s ma)e up o' a matri o' switches$ in anarrangement similar to that illustrate). The matri arrangement is use) to sae port pins. %' we

    hae rows an) 7 columns o' !e(s$ we nee) C 7 pins i' we use a matri arrangement an) ?

    7 pins i' we use in)ii)ual switches. %' (ou nee) si or more !e(s$ then the matri arrangementreuires 'ewer pins.

    4an( !e(pa)s hae 13 !e(s "

  • 8/13/2019 m.tech Lab Manual JNTUH

    24/80

    release). The )uration o' the !e( press will generall( *e at least 522 ms. The !e(s will not

    generall( *e allowe) to

  • 8/13/2019 m.tech Lab Manual JNTUH

    25/80

    AT89S51 reuires a oltage o' 5.2# een programming the microcontroller. The current rating

    o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on

    11.2593 4H- 'reuenc(.

    Algorithm!

    1. In this proect !e need to interface "eypad to the 8051 and produce scanned "ey on

    #%.

    -. ;irst !e need to clear the storage or available data in port register.

    /. To get scan !e need to use ro! of "eypad as input and column of "eypad as output.

    ,. Scan each ro! by interchanging output data of column and store the "ey in memory.

    5. o! !e need to generate -50ms delay by looping time period T 2delay

    time34cyclescloc" cycle.

    6. o! initiali7e the #% and push the data in memory to #% to display.

    . )epeat the steps , to 6 !hole in a continuous loop.

    -chemat!c:

  • 8/13/2019 m.tech Lab Manual JNTUH

    26/80

    Flow chart:

    True

    ;alse

    1

    Start

    lear the available datain reg '1& 2'1403.

    #cdinit23@

    NA)Tinitialise23@

    $nd

    >emory4read23@

    #cddata2memory3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    27/80

    Program!

    GincludeHreg51.h:

    Ginclude Klcd.hK

    sbit c,4 '1=,@

    sbit c/4 '1=5@

    sbit c-4 '1=6@

    sbit c14 '1=@

    sbit r14 '1=0@

    sbit r-4 '1=1@

    sbit r/4 '1=-@

    sbit r,4 '1=/@

    void delay2int3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    28/80

    void main23

    J

    lcdinit23@

    !hile213 CC infinite loop

    J

    c,41@

    c/41@

    c-40@

    c141@

    if2r14403

    J !ritecmd20013@

    !ritedata2F/F3@CC

    L

    else if2r-4403

    J !ritecmd20013@

    !ritedata2FF3@

    L

    else if2r/4403

    J

    !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F1F3@

    L

  • 8/13/2019 m.tech Lab Manual JNTUH

    29/80

    else if2r,4403

    J !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F5F3@

    L

    c,41@

    c/40@

    c-41@

    c141@

    if2r14403

    J !ritecmd20013@

    !ritedata2F-F3@ CC

    L

    else if2r-4403

    J !ritecmd20013@

    !ritedata2F6F3@

    L

    else if2r/4403

    J !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F0F3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    30/80

    L

    else if2r,4403

    J !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F,F3@

    L

    c,40@

    c/41@

    c-41@

    c141@

    if2r14403

    J !ritecmd20013@

    !ritedata2F1F3@CC

    L

    else if2r-4403

    J !ritecmd20013@

    !ritedata2F5F3@

    L

    else if2r/4403

    J!ritecmd20013@

    !ritedata2F9F3@

    L

  • 8/13/2019 m.tech Lab Manual JNTUH

    31/80

    else if2r,4403

    J!ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F/F3@

    L

    c,41@

    c/41@

    c-41@

    c140@

    if2r14403

    J !ritecmd20013@

    !ritedata2F,F3@CC

    L

    else if2r-4403

    J !ritecmd20013@

    !ritedata2F8F3@

    L

    else if2r/4403

    J !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F-F3@

    L

  • 8/13/2019 m.tech Lab Manual JNTUH

    32/80

    else if2r,4403

    J !ritecmd20013@

    !ritedata2F1F3@

    !ritedata2F6F3@

    L

    LCC end of !hile loop

    L CC end of main

    void delay2int i3

    J

    for2@i:0@iEE3@

    L

    &. Program to interface se'en segment dis!lay unit.

    Aim!

    A seven segment display is the most basic electronic display device that can displaydigits from 0E9. They find !ide application in devices that display numeric information li"e digitalcloc"s& radio& micro!ave ovens& electronic meters etc. The most common configuration has anarray of eight #$%s arranged in a special pattern to display these digits. They are laid out as as

  • 8/13/2019 m.tech Lab Manual JNTUH

    33/80

    Here we are using AT89S51 to control the B+segment )ispla(. For our application 'irst we nee)

    to !now a*out the B+segment )ispla( wor!ing.

    Working of a ;segment disla:

    Bsegment is generall( aaila*le in ten pin pac!age. ,hile eight pins correspon) to the eightLEDs$ the remaining two pins "at mi))le& are common an) internall( shorte).

    These segments come in two con'igurations$ namel($ 7ommon catho)e "77& an) 7ommon

    ano)e "7A&. %n 77 con'iguration$ the negatie terminals o' all LEDs are connecte) to the

    common pins. The common is connecte) to groun) an) a particular LED glows when itscorrespon)ing pin is gien high. %n 7A arrangement$ the common pin is gien a high logic an)

    the LED pins are gien low to )ispla( a num*er.

    Working of AT89451:

    AT89751 reuires a oltage o' 5.2# een programming the microcontroller. The current ratingo' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on

    11.2593 4H- 'reuenc(.

    The current supplie) to the B segment is also to *e consi)ere) as it is )rien *( the controller. %'

    su''icient current is not supplie) it e''ects *( thefano*t2

    Working of ;Segment:

    a-24ommon 4athode:

    http://iblocks.in/wp-content/uploads/2012/09/7seg-8051.png
  • 8/13/2019 m.tech Lab Manual JNTUH

    34/80

    As shown in the a*oe circuit B segment haing a$ *$ c$ )$ e$ '$ g pins can *e ena*le) using C5#

    high so that respectie regions will *e actiate). As this is a 77 "7ommon 7atho)e&$ the

    common pin is groun)e)$ an) to operate it we nee) to suppl( positie oltage.

    b-24ommon Anode:

    As shown in the a*oe circuit B segment haing a$ *$ c$ )$ e$ '$ g pins can *e ena*le) using n)i.e.$ logic %so that respectie regions will *e actiate). As this is a 7A "7ommon Ano)e&$ the

    common pin is gien a positie oltage C5#$ an) to operate it we nee) to suppl( n) or logic %.

    "nterfacing With AT89S51:

    %n the a*oe circuit we are using a 7ommon 7atho)e t(pe 'our B segment )ispla(. To operatethis )ispla( here we are using @ort3 pins 'rom which we proi)e C5# to the )ispla(. As our

    application is to )ispla( )ecimal )igits we 'irst hae to ma!e a co)e o' each )ecimal )igit.

    For eample$ in or)er to )ispla(

  • 8/13/2019 m.tech Lab Manual JNTUH

    35/80

    Program:

    #include// Functin declaratins!id clear!id$;!id delaint$;

    int ,egmentchar$;sbit s1=P1^0;// Pin descri*tin/@ P2 is used 6r A segmentP2.0 is attached -ith BB segmentP2.1 is attached -ith BCB segmentP2.2 is attached -ith B4B segmentP2. is attached -ith BB segmentP2. is attached -ith B:B segmentP2.5 is attached -ith BFB segmentP2.D is attached -ith BB segment@/// (ain 6unctinint main!id$' char h; // 4haracter t be dis*laed n Aseg clear$; // (a)e all *rts +er

    -hile1$'

    6rh=000;h

  • 8/13/2019 m.tech Lab Manual JNTUH

    36/80

    case 2 P = ?05C; brea); case P = ?0F; brea); case P = ?0DD; brea); case 5 P = ?0D; brea); case D P = ?0A; brea); case A P = ?00A; brea); case G P = ?0AF; brea); case E P = ?0DF; brea); /@case 00a P2 = 0AA; brea); case 00b P2 = 0A4; brea); case 00c P2 = 0E; brea); case 00d P2 = 05:; brea); case 00e P2 = 0AE; brea); case 006 P2 = 0A1; brea); @/

    de6ault P = 06; brea); return0$;

    Schematic:

  • 8/13/2019 m.tech Lab Manual JNTUH

    37/80

    Flowchart:

    Algorithm!

    1. In this proect !e need to interface seven segment display to at89c51.

    True

    ;alse

    1

    Start

    lear the available data

    in reg '1& 2'1403.

    Seven segment init23@

    $nd

    %isplay segment23@

  • 8/13/2019 m.tech Lab Manual JNTUH

    38/80

    -. ;irst !e need to clear the storage or available data in port register.

    /. o! !e need to generate -50ms delay by looping time period T 2delay

    time34cyclescloc" cycle.

    ,. As NA)T !or"s !ith some properties as baudrate& datalength& parity& stop and start bits&

    no! !e need to provide all.

    5. To get baudrate !e use internal TI>$)1& and remaining properties using respected

    registers.

    6. 'ush the data to NA)T data register !hich !ill send data to '.

    . )epeat the steps 6 in a continuous loop.

    . Program to tran(m!t a me((age "rom M!crocontroller to PC

    (er!all$ *(!ng R-22

    AI!

    In this part& !e !ill consider some "ey patterns suitable for assisting in the creation of user

    interfaces for a !ide range of embedded applications. De present P# ?I>@ /R;:22.This

    pattern considers ho!& using the universal O)SE-/-P standard& !e can transfer data bet!een anembedded device and a des"top& noteboo" or similar '. In addition to being a useful pattern in

    its o!n right& this pattern illustrates many of the features re

  • 8/13/2019 m.tech Lab Manual JNTUH

    39/80

    %n 199B the Telecommunications %n)ustr( Association release) what is 'ormall( !nown as T%A+

    303 #ersion F$ a serial communication protocol which has *een 0/3 THE ISE %TEFA7E.

    This 'ile ma( *e 'reel( re)istri*ute) proi)e) onl( that this 'ooter remains intact. uniersall(re'erre) to as

  • 8/13/2019 m.tech Lab Manual JNTUH

    40/80

    2 The receier is a*le to receie more )ata6 it )oes nothing.

    The transmitter sen)s another *(te o' )ata.

    3 Steps 10 continue until the receier cannot accept an( more )ata6 it then sen)s a

    $)1& and remaining properties using respected

    registers.

  • 8/13/2019 m.tech Lab Manual JNTUH

    41/80

    1/. 'ush the data to NA)T data register !hich !ill send data to '.

    1,. )epeat the steps 6 in a continuous loop.

    -chemat!c:

  • 8/13/2019 m.tech Lab Manual JNTUH

    42/80

    Program!

    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCC

    CC 'roect* Internet to serial port ontrol CC

    True

    ;alse

    1

    Start

    lear the available data

    in reg '1& 2'1403.

    #cdinit23@

    NA)Tinitialise23@

    $nd

    Tranmit2memory3

  • 8/13/2019 m.tech Lab Manual JNTUH

    43/80

    CC Author* )aghava )eddy CC

    CC %ate* 1,C11C-010 CC

    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

    Ginclude Hreg51.h:

    CC%$;I$ (STAT

    Gdefine aud?rate 0;d CC AN% )AT$ 9600

    CC%$;I$ ')(T(TM'$S

    void NSA)T?Init2void3@

    void NSA)T?Transmit2unsigned char3@

    void cct?init2void3@

    void delay2unsigned int t3@

    void main23

    J

    cct?init23@

    NSA)T?Init23@

    $A 4 1@

    $S 4 1@

    !hile213

    J

    NSA)T?Transmit2FF3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    44/80

    delay21003@

    NSA)T?Transmit2F)F3@

    delay21003@

    NSA)T?Transmit2FIF3@

    delay21003@

    NSA)T?Transmit2F F3@

    delay21003@

    L

    L

    void delay2unsigned int t3

    J

    unsigned int i&@

    for2i40@iHt@i3

    J

    for240@H50@3@

    L

    L

    void cct?init2void3 CCinitiali7e cct

    J

    '0 4 000@ CCnot used

    '1 4 000@ CCNsed for Appliances

    '- 4 000@ CCnot used

    '/ 4 00/@ CCused for serial

  • 8/13/2019 m.tech Lab Manual JNTUH

    45/80

    L

    void NSA)T?Init2void3 CC IITIA#IQ$ S$)IA# '()T

    J

    T>(% 4 00-@ CC Timer 1 I >(%$ - EANT( )$#(A% T( R$$)AT$

    AN% )AT$

    S( 4 050@ CC S$)IA# >(%$ 1& 8E%ATA IT 1ESTA)T IT& 1EST('

    IT& )$ $A#$%

    T0 4 aud?rate@ CC #(A% AN%)AT$ T( TI>$) )$RIST$)

    T)0 4 1@ CC STA)T TI>$)

    L

    void NSA)T?Transmit2unsigned char serialdata3

    J

    SN; 4 serialdata@ CC #(A% %ATA T( S$)IA# N;;$)

    )$RIST$)

    !hile2TI 44 03@ CC DAIT NTI# T)AS>ISSI( T((>'#$T$

    TI 4 0@ CC #$A) T)AS>ISSI( IT$))N'T

    ;#AR

    L

    4 Program to rece!'e a me((age "rom PC (er!all$ *(!ng R-22

  • 8/13/2019 m.tech Lab Manual JNTUH

    46/80

    !m:

    %n this part$ we will consi)er some !e( patterns suita*le 'or assisting in the creation o' user

    inter'aces 'or a wi)e range o' em*e))e) applications. ,e present PC L7, 8R-22.Thispattern consi)ers how$ using the uniersal

  • 8/13/2019 m.tech Lab Manual JNTUH

    47/80

    single 8+*it *loc!s o' )ata. To transmit a *(te o' )ata oer an S+303 lin!$ we generall(

    enco)e the in'ormation as 'ollows6

    ,e sen) a

  • 8/13/2019 m.tech Lab Manual JNTUH

    48/80

  • 8/13/2019 m.tech Lab Manual JNTUH

    49/80

    lgor!thm:

    1. In this proect !e need to interface ' to 8051 using NA)T protocol.

    -. ;irst !e need to clear the storage or available data in port register.

    /. o! !e need to generate -50ms delay by looping time period T 2delaytime34cyclescloc" cycle.

    ,. As NA)T !or"s !ith some properties as baudrate& datalength& parity& stop and start bits&

    no! !e need to provide all.

    5. To set baudrate !e use internal TI>$)1& and remaining properties using respected

    registers.

    6. o! read the data from ' using NA)T data register and store in a memory.

    . o! initiali7e the #% and push the data in memory to #% to display.

    8. )epeat the steps 6E in a continuous loop.

    -chemat!c:

  • 8/13/2019 m.tech Lab Manual JNTUH

    50/80

    True

    ;alse

    1

    Start

    lear the available datain reg '1& 2'1403.

    #cdinit23@

    NA)Tinitialise23@

    $nd

    >emory4read23@

    #cddata2memory3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    51/80

    Program:

    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCC

    CC 'roect* Internet to serial port ontrol CC

    CC Author* )aghava )eddy CC

    CC %ate* 1,C11C-010 CC

    CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

    Ginclude Hreg5-.h:

    G include Klcd.hK

    CC%$;I$ (STAT

    Gdefine aud?rate 0;% CC AN% )AT$ 9600

    void NSA)T?Init2void3@

  • 8/13/2019 m.tech Lab Manual JNTUH

    52/80

    void t2unsigned char3@

    unsigned char r23@

    unsigned char a1-@

    void clear2void3@

    int main2void3

    J

    unsigned char &i40@

    clear23@

    NSA)T?Init23@

    lcdinit23@

    CC$A 4 1@

    CC$S 4 1@

    CC !ritedata2F?F3 @

    !hile213

    J

    i4r23@

    !ritedata2i3@

    L

    L

    void clear2void3 CCinitiali7e cct

    J

    '0 4 000@ CCnot used

    '1 4 000@ CCNsed for Appliances

  • 8/13/2019 m.tech Lab Manual JNTUH

    53/80

    '- 4 000@ CCnot used

    '/ 4 00/@ CCused for serial

    L

    void NSA)T?Init2void3 CC IITIA#IQ$ S$)IA# '()T

    J

    T>(% 4 0-0@ CC Timer 1 I >(%$ - EANT( )$#(A% T( R$$)AT$

    AN% )AT$

    S( 4 050@ CC S$)IA# >(%$ 1& 8E%ATA IT 1ESTA)T IT&

    1EST(' IT

    T1 4 aud?rate@ CC #(A% AN%)AT$ T( TI>$) )$RIST$)

    T)1 4 1@ CC STA)T TI>$)

    L

    void t2unsigned char serialdata3

    J

    SN; 4 serialdata@ CC #(A% %ATA T( S$)IA# N;;$)

    )$RIST$)

    !hile2TI 44 03@ CC DAIT NTI# T)AS>ISSI( T(

    (>'#$T$

    TI 4 0@ CC #$A) T)AS>ISSI( IT$))N'T

    ;#AR

    L

    unsigned char r23

    J

    !hile2)I4403@

    )I40@

  • 8/13/2019 m.tech Lab Manual JNTUH

    54/80

    return2SN;3@

    L

    *.A$#!

    AT89s51 micrrocontroller doesnt have inbuilt A%. So !e need to interface an I called A%

    080, in order to perform A% !ith AT89S5.This proect deals !ith A% 080, by !hich !e can

    interface all electronic transducers& that acts as sensors.

    Working of AD4%8%7:

    Di''erential analog oltage inputs allow increasing the common+mo)e rejection an) o''settingthe analog -ero input oltage alue. %n a))ition$ the oltage re'erence input can *ea)juste) to

    allow enco)ing an( smaller analog oltage span to the 'ull 8 *its o' resolution.

    Feat*re(:

    logic nee)e) access time 105 ns

    Eas( inter'ace to all microprocessors$ or operates Mstan)aloneN

    Di''erential analog oltage inputs

    Logic inputs an) outputs meet *oth 4:S an) TTL oltage leel speci'ications

    ,or!s with 3.5# "L400/& oltage re'erence

    :n+chip cloc! generator

    2# to 5# analog input oltage range with single 5# suppl(

    o -ero a)just reuire)

    2.0O stan)ar) wi)th 32+pin D%@ pac!age

    32+pin mol)e) chip carrier or small outline pac!age

    :perates ratio metricall( or with 5 #D7$ 3.5 #D7$ or analog span a)juste) oltagere'erence.

  • 8/13/2019 m.tech Lab Manual JNTUH

    55/80

    .

    From a*oe timing )iagram we can anal(-e the 'low o' the AD7 conersion.

    For rea)ing the )ata 'rom AD7 we 'irst nee) to ena*le the AD7 to acuire )ata 'rom

    trans)ucer so that we nee) to )isa*le connection it to EAD$ then ,%TE the instructionto acuire )ata$ a'ter some time ena*le EAD comman) so that controller rea)s the

    conerte) )ata. ow ena*le it to interrupt to )isconnect controller )ata communication.

    Thus the programming woul) *e$

    r)>2J ;;ma!es controller to rea)

    wr>1J ;; ma!e AD7 to write into its *u''er a'ter certain )ela(

    )ela(J ;;proi)e some )ela(

    http://iblocks.in/wp-content/uploads/2012/09/8051-ADC2.jpghttp://iblocks.in/wp-content/uploads/2012/09/8051-ADC1.png
  • 8/13/2019 m.tech Lab Manual JNTUH

    56/80

    wr>2J ;;)isa*les the connection with trans)ucer in or)er not to oerwrite

    'irst )ata

    while"intr>>1&J ;;waits till whole *u''er to 'ill using interrupt

    r)>1J ;;rea)s )ata to the controller

    )ela(J ;; proi)e some )ela(

    intr>1J ;;ma!e interrupt high to )isconnect

    Working of AT89451:

    AT89751 reuires a oltage o' 5.2# een programming the microcontroller. The current rating

    o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on11.2593 4H- 'reuenc(.

    Here we are inter'acing AD7282 which rea)s )ata temperature 'rom L405 with AT89S51 an)

    )ispla(ing respectie )ata using L7D "L4 21/L& programming which we !nown inter'acing it

    earlier.

    http://iblocks.in/wp-content/uploads/2012/09/8051-ADC-LCD.png
  • 8/13/2019 m.tech Lab Manual JNTUH

    57/80

    ,e can implement the same technolog( 'or inter'acing trans)ucers li!e LD$ A@131B/2 "'ire

    sensor&$ SE+103B"gas sensor&

    7ote:

    @lease )on=t connect motors an) A7 loa)s )irectl( to controllers as the( operates athighwatt power.

    Don=t connect D7 5# motor )irectl( to controller as motors pro)uce back emfwhile

    running.

    Flow Chart:

    True

    ;alse

    1

    Start

    lear the available datain reg '1& 2'1403.

    #cdinit23@

    Adc?init23@

    >emory4)ead ?adc23@

    #%?data2memory3

  • 8/13/2019 m.tech Lab Manual JNTUH

    58/80

    Program:

    #include#de6ine *rt P#de6ine adc"in*ut P1#de6ine data*rt P0#de6ine sec 100sbit rs = *rt^0;sbit r- = *rt^1;sbit e = *rt^2;sbit -r= *rt^;sbit rd= *rt^;sbit intr= *rt^5;int test"intermediate=0Htest"6inal=0Htest"intermediate1I10JHtest"intermediate2IJ='0H0H0;!id delaunsigned int msec $

    ' int i HK ; 6ri=0;i

  • 8/13/2019 m.tech Lab Manual JNTUH

    59/80

    //dela100$; return;!id lcd"data"stringunsigned char @str$ // Functin t send string t 94' int i=0; -hilestrIiJL=BM0B$ ' lcd"datastrIiJ$; i; dela10$; return;!id sha*e$ // Functin t create the sha*e 6 degree' lcd"cmdD$; lcd"data2$; lcd"data5$; lcd"data2$;

    lcd"data0$; lcd"data0$; lcd"data0$; lcd"data0$; lcd"data0$;!id cn!ert$ // Functin t cn!ert the !alues 6 4 int numeric !aluet be sent t 94' int s; test"6inal=test"intermediate; lcd"cmd0c1$; dela2$; lcd"data"stringN&:(PN$; s=test"6inal/100; test"6inal=test"6inal100; lcd"cmd0cG$; i6sL=0$ lcd"datasG$; else lcd"cmd00D$; s=test"6inal/10; test"6inal=test"6inal10; lcd"datasG$; lcd"datatest"6inalG$; lcd"data0$; lcd"dataBcB$;

    lcd"dataB B$; dela2$;!id main$' int iHK; adc"in*ut=066; lcd"cmd0G$; lcd"cmd00c$; //is*la OnH 4ursr Clin)ing dela2$;

  • 8/13/2019 m.tech Lab Manual JNTUH

    60/80

    lcd"cmd001$; // 4lear ,creen dela2$; -hile1$ ' 6rK=0;K

  • 8/13/2019 m.tech Lab Manual JNTUH

    61/80

    10 Program to !nter"ace -te%%er Motor to rotate the motor !n

    cloc#w!(e and ant!cloc#w!(e d!rect!on(

    AI!

    In this part !e are interfacing a stepper motor to our AT89S51. As the electro mechanical

    devices emit bac" $>; !hile running and controller canPt provide high po!er to run& !e canPt

    drive them directly for !hich !e use $> 2electro mechanical3 drivers. In this application !e are

    moving a stepper motor step by step for!ard.

    A""aratus!

    1. I%$ * +iel uvision ,.0&

    -. Simulator* 'rofessional 'roteus ..

    Theory!

  • 8/13/2019 m.tech Lab Manual JNTUH

    62/80

    Here in this part we are controlling a D7 motor with AT89S51 using )rier li!e L390D.

    Working of steer motor: -te%%er Motor or a(te% motoris a *rushless$ s(nchronous

    motor which )ii)es a 'ull rotation into a num*er o' steps. Inli!e a *rushless D7 motor whichrotates continuousl( when a 'ie) D7 oltage is applie) to it$ a step motor rotates in )iscrete step

    angles. The -te%%er Motor(there'ore are manu'acture) with steps per reolution o' 13$ 3$ B3$1$ 182$ an) 322$ resulting in stepping angles o' 02$ 15$ 5$ 3.5$ 3$ an) 1.8 )egrees per step. The

    stepper motor can *e controlle) with or without 'ee)*ac!.

    Working of an L

  • 8/13/2019 m.tech Lab Manual JNTUH

    63/80

    ;chematic!

    Flow chart: True 1

    Start

    lear the available data

    in reg '1& 2'1403.

    Assigning #ogic 1 state

    to port '1 i.e.&2'140ff3

    Stepper23@

    %elay23@

    $nd

    ;alse

  • 8/13/2019 m.tech Lab Manual JNTUH

    64/80

    Program:

    9!ncl*dereg51h;

    'o!d clear80?012JiPaJiCC&J ;;null statement

    V

    oi) write)ata"char t&

    S > 1J ;; >Q S > 1 B

    @1 > tJ ;;Data trans'er

    E > 1J ;; >Q E > 1

    )ela("152&J

    E > 2J ;; >Q E > 2

  • 8/13/2019 m.tech Lab Manual JNTUH

    78/80

    )ela("152&J

    V

    oi) writecm)"int -&

    S > 2J ;; >Q S > 2

    @1 > -J ;;Data trans'er

    E > 1J ;; >Q E > 1

    )ela("152&J

    E > 2J ;; >Q E > 2

    )ela("152&J

    V

    oi) stepper'w)"&

    @0>221J

    )ela("B522&J

    @0>223J

    )ela("B522&J

    @0>22J

    )ela("B522&J

    @0>228J

    )ela("B522&J

  • 8/13/2019 m.tech Lab Manual JNTUH

    79/80

    V

    oi) stepperrws"&

    @0>228J

    )ela("B522&J

    @0>22J

    )ela("B522&J

    @0>223J

    )ela("B522&J

    @0>221J

    )ela("B522&J

    V

    oi) lc)init"oi)&

    ;;;;;;;;;;;;; eset process 'rom )atasheet ;;;;;;;;;

    )ela("15222&J

    writecm)"202&J

    )ela("522&J

    writecm)"202&J

    )ela("022&J

    writecm)"202&J

  • 8/13/2019 m.tech Lab Manual JNTUH

    80/80

    )ela("/52&J

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    writecm)"208&J ;;'unction set

    writecm)"22c&J ;;)ispla( on$cursor o''$*lin! o''

    writecm)"221&J ;;clear )ispla(

    writecm)"22/&J ;;entr( mo)e$ set increment

    V