SlideShare a Scribd company logo
SMK FOMRA INSTITUTE OF TECHNOLOGY
     Old Mahabalipuram Road, (I.T.High Way),
     Kelambakkam,Chennai, Tamilnadu 603103




       DEPARTMENT ELECTRONICS AND
        COMMUNICATION ENGINEERING

       EC 2308 – MICROPROCESSOR AND
           MICROCONTROLLER LAB

                  V SEMSTER
                   2010-2011


NAME:___________________________________

YEAR/SEM: _______________BRANCH:_______

REG. NO.:________________________________
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                 DEPT OF ECE



EXPT NO:                     8086 PROGRAMMING            DATE:

                         ADDITION & SUBTRACTION


AIM:
       To write an Assembly Language Program (ALP) for performing the
addition and subtraction operation of two byte numbers.

APPARATUS REQUIRED:

SL.N            ITEM                SPECIFICATION              QUANTITY
 O
 1.     Microprocessor kit      8086 kit                          1
 2.     Power Supply            +5 V dc                           1

PROBLEM STATEMENT:
       Write an ALP in 8086 to add and subtract two byte numbers stored in the
memory location 1000H to 1003H and store the result in the memory location
1004H to 1005H.Also provide an instruction in the above program to consider
the carry also and store the carry in the memory location 1006H.
ALGORITHM:
(i) 16-bit addition
h)Initialize the MSBs of sum to 0
i)Get the first number.
j)Add the second number to the first number.
k)If there is any carry, increment MSBs of sum by 1.
l)Store LSBs of sum.
m)Store MSBs of sum.

(ii) 16-bit subtraction
f)Initialize the MSBs of difference to 0
g)Get the first number
h)Subtract the second number from the first number.
i)If there is any borrow, increment MSBs of difference by 1.
j)Store LSBs of difference
k)Store MSBs of difference.




                                                                            2
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB          DEPT OF ECE



  FLOWCHART

  ADDITION                                         SUBTRACTION

         START                                     START


SET UP COUNTER (CY)                       SET UP COUNTER (CARRY)


GET FIRST OPERAND                          GET FIRST
                                           OPERAND TO A



 GET SECOND OPERAND                               SUBTRACT
 TO    A                                       SECOND OPERAND
                                                FROM MEMORY



                                                                  YES
      A=A+B
                                               IS THERE
                                               ANY CY
                      YES
                                              NO              COUNTER =
      IS THERE
      ANY                                                     COUNTER + 1
                       COUNTER =
                       COUNTER + 1
                                              STORE THE
                                              DIFFERENCE
    NO

     STORE THE SUM
                                            STORE THE CARRY


   STORE THE CARRY                                   STOP


         STOP




                                                                        3
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB             DEPT OF ECE




ADDITION
            PROGRAM                          COMMENTS

MOV CX, 0000H                Initialize counter CX

MOV AX,[1200]                Get the first data in AX reg

MOV BX, [1202]               Get the second data in BX reg

ADD AX,BX                    Add the contents of both the regs AX & BX

JNC L1                       Check for carry

INC CX                       If carry exists, increment the CX

L1 : MOV [1206],CX           Store the carry

MOV [1204], AX               Store the sum

HLT                          Stop the program


SUBTRACTION
        PROGRAM                              COMMENTS

MOV CX, 0000H                Initialize counter CX

MOV AX,[1200]                Get the first data in AX reg

MOV BX, [1202]               Get the second data in BX reg

SUB AX,BX                    Subtract the contents of BX from AX

JNC L1                       Check for borrow

INC CX                       If borrow exists, increment the CX

L1 : MOV [1206],CX           Store the borrow

MOV [1204], AX               Store the difference

HLT                          Stop the program



RESULT:.


                                                                         4
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


                                        ADDITION



MEMORY

DATA




                                     SUBTRACTION




MEMORY


DATA




MANUAL CALCULATION




Thus addition & subtraction of two byte numbers are performed and the result is stored.




                                                                                          5
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                     DEPT OF ECE


EXPT NO:                      8086 PROGRAMMING              DATE:

                         MULTIPLICATION & DIVISION


AIM:
      To write an Assembly Language Program (ALP) for performing the
multiplication and division operation of 16-bit numbers .

APPARATUS REQUIRED:

SL.N             ITEM                 SPECIFICATION              QUANTITY
 O
 1.      Microprocessor kit       8086                                 1
 2.      Power Supply             +5 V dc                              1

PROBLEM STATEMENT:

       Write an ALP in 8086 MP to multiply two 16-bit binary numbers and
store the result in the memory location. Write instructions for dividing the data
and store the result.

ALGORITHM:
(i)Multiplication of 16-bit numbers:
a)Get the multiplier.
b)Get the multiplicand
c)Initialize the product to 0.
d)Product = product + multiplicand
e)Decrement the multiplier by 1
f)If multiplicand is not equal to 0,repeat from step (d) otherwise store the
product.

(ii)Division of 16-bit numbers.
a)Get the dividend
b)Get the divisor
c)Initialize the quotient to 0.
d)Dividend = dividend – divisor
e)If the divisor is greater, store the quotient. Go to step g.
f)If dividend is greater, quotient = quotient + 1. Repeat from step (d)
g)Store the dividend value as remainder.




                                                                               6
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB        DEPT OF ECE


     FLOWCHART

            MULTIPLICATION                              DIVISION

                                                           Start
                Start



                                                      Load Divisor &
     Get Multiplier & Multiplicand                    Dividend
          MULTIPLICAND



                                                      QUOTIENT = 0
             REGISTER=00


                                                       DIVIDEND =
                                                 DIVIDEND-DIVISOR
           REGISTER =
           REGISTER +
          MULTIPLICAND

                                              QUOTIENT = QUOTIENT+1

          Multiplier=MU
          LTIPLIER – 1


                                                            IS
                                            NO            DIVIDEN
                                                          D<
                                                          DIVISOR
NO               IS
                                                             ?
            MULTIPLIER
                =0?
                                                                   YES

                        YES                  STORE QUOTIENT
                                             STORE REMAINDER
       STORE THE RESULT                      = DIVIDEND NOW




                  STOP                                    STOP




                                                                         7
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB               DEPT OF ECE


MULTIPLICATION
         PROGRAM                             COMMENTS

MOV AX,[1200]                  Get the first data

MOV BX, [1202]                 Get the second data

MUL BX                         Multiply both

MOV [1206],AX                  Store the lower order product

MOV AX,DX                      Copy the higher order product to AX

MOV [1208],AX                  Store the higher order product

HLT                            Stop the program


DIVISION
            PROGRAM                          COMMENTS

MOV AX,[1200]                  Get the first data

MOV DX, [1202]                 Get the second data

MOV BX, [1204]                 Divide the dividend by divisor

DIV BX                         Store the lower order product

MOV [1206],AX                  Copy the higher order product to AX

MOV AX,DX                      Store the higher order product

MOV [1208],AX                  Stop the program

HLT                            Get the first data




                                                                         8
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


RESULT:.
MULTIPLICATION




MEMORY

DATA




DIVISON




MEMORY


DATA




MANUAL CALCULATION




Thus multiplication & division of two byte numbers are performed and the result is stored.




                                                                                             9
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                 DEPT OF ECE


EXPT NO:                      8086 PROGRAMMING          DATE:

                         ASCENDING & DESCENDING


AIM:
      To write an Assembly Language Program (ALP) to sort a given array in
ascending and descending order.

APPARATUS REQUIRED:

SL.N             ITEM                SPECIFICATION           QUANTITY
 O
 1.      Microprocessor kit      8086                              1
 2.      Power Supply            +5 V dc                           1

PROBLEM STATEMENT:

      An array of length 10 is given from the location. Sort it into descending
and ascending order and store the result.

ALGORITHM:
(i)Sorting in ascending order:
a.Load the array count in two registers C1 and C2.
b.Get the first two numbers.
c.Compare the numbers and exchange if necessary so that the two numbers are
in ascending order.
d.Decrement C2.
e.Get the third number from the array and repeat the process until C2 is 0.
f.Decrement C1 and repeat the process until C1 is 0.

(ii)Sorting in descending order:
a.Load the array count in two registers C1 and C2.
b.Get the first two numbers.
c.Compare the numbers and exchange if necessary so that the two numbers are
in descending order.
d.Decrement C2.
e.Get the third number from the array and repeat the process until C2 is 0.
f.Decrement C1 and repeat the process until C1 is 0.




                                                                            10
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB        DEPT OF ECE


FLOWCHART
ASCENDING ORDER                         DESCENDING ORDER


                                                START
          START



 INITIALIZE POINTER                       INITIALIZE POINTER

 COUNT = COUNT – 1                        COUNT = COUNT – 1


                                                               YES
                             YES                  IS
            IS
         POINTER                               POINTER

                                                          NO
                   NO

                                              TEMP = POINTER
        TEMP = POINTER                     POINTER = POINTER + 1
     POINTER = POINTER + 1                  POINTER + 1 = TEMP
      POINTER + 1 = TEMP



                                          POINTER = POINTER +1
     POINTER = POINTER +1                 COUNT = COUNT + 1
     COUNT = COUNT + 1


 NO                                      NO
                                               IS
          IS
                                               COUNT
          COUNT
                                                         YES
                   YES

NO
          IS                                   IS

          FLAG                                 FLAG
                                                         YES
                   YES

                                                STOP
          STOP




                                                                   11
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                DEPT OF ECE


ASCENDING

        PROGRAM                           COMMENTS
MOV SI,1200H            Initialize memory location for array size
MOV CL,[SI]             Number of comparisons in CL
L4 : MOV SI,1200H       Initialize memory location for array size
MOV DL,[SI]             Get the count in DL
INC SI                  Go to next memory location
MOV AL,[SI]             Get the first data in AL
L3 : INC SI             Go to next memory location
MOV BL,[SI]             Get the second data in BL
CMP AL,BL               Compare two data’s
JNB L1                  If AL < BL go to L1
DEC SI                  Else, Decrement the memory location
MOV [SI],AL             Store the smallest data
MOV AL,BL               Get the next data AL
JMP L2                  Jump to L2
L1 : DEC SI             Decrement the memory location
MOV [SI],BL             Store the greatest data in memory location
L2 : INC SI             Go to next memory location
DEC DL                  Decrement the count
JNZ L3                  Jump to L3, if the count is not reached zero
MOV [SI],AL             Store data in memory location
DEC CL                  Decrement the count
JNZ L4                  Jump to L4, if the count is not reached zero
HLT                     Stop

DESCENDING

        PROGRAM                           COMMENTS
MOV SI,1200H            Initialize memory location for array size
MOV CL,[SI]             Number of comparisons in CL
L4 : MOV SI,1200H       Initialize memory location for array size
MOV DL,[SI]             Get the count in DL
INC SI                  Go to next memory location
MOV AL,[SI]             Get the first data in AL
L3 : INC SI             Go to next memory location
MOV BL,[SI]             Get the second data in BL
CMP AL,BL               Compare two data’s



                                                                         12
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                          DEPT OF ECE


JB L1                             If AL > BL go to L1
DEC SI                            Else, Decrement the memory location
MOV [SI],AL                       Store the largest data
MOV AL,BL                         Get the next data AL
JMP L2                            Jump to L2
L1 : DEC SI                       Decrement the memory location
MOV [SI],BL                       Store the smallest data in memory location
L2 : INC SI                       Go to next memory location
DEC DL                            Decrement the count
JNZ L3                            Jump to L3, if the count is not reached zero
MOV [SI],AL                       Store data in memory location
DEC CL                            Decrement the count
JNZ L4                            Jump to L4, if the count is not reached zero
HLT                               Stop

RESULT:.
                                      ASCENDING



MEMORY

DATA




                                     DESCENDING




MEMORY


DATA




Thus given array of numbers are sorted in ascending & descending order.




                                                                                   13
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                     DEPT OF ECE




EXPT NO:                      8086 PROGRAMMING             DATE:

                              LARGEST& SMALLEST


AIM:
      To write an Assembly Language Program (ALP) to find the largest and
smallest number in a given array.

APPARATUS REQUIRED:

SL.N             ITEM                 SPECIFICATION             QUANTITY
 O
 1.      Microprocessor kit       8086                                1
 2.      Power Supply             +5 V dc                             1

PROBLEM STATEMENT:

      An array of length 10 is given from the location. Find the largest and
smallest number and store the result.

ALGORITHM:
(i)Finding largest number:

a.Load the array count in a register C1.
b.Get the first two numbers.
c.Compare the numbers and exchange if the number is small.
d.Get the third number from the array and repeat the process until C1 is 0.

(ii)Finding smallest number:

e.Load the array count in a register C1.
f.Get the first two numbers.
g.Compare the numbers and exchange if the number is large.
h.Get the third number from the array and repeat the process until C1 is 0.




                                                                              14
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB          DEPT OF ECE


FLOWCHART
LARGEST NUMBER IN AN ARRAY     SMALLEST NUMBER IN AN ARRAY

          START                                START


        INITIALIZE
                                               INITIALIZE
          COUNT
                                                 COUNT
      POINTER MAX =
                                            POINTER MIN = 0

        PONITER =                             PONITER =
       POINTER + 1                           POINTER + 1



                                      YES
         IS MAX                               IS MIN ≥
         ≥                                    POINTE
YES
                     NO                                     NO

      MAX = POINTER                         MIN = POINTER


      COUNT = COUNT-1                       COUNT = COUNT-1


NO                                     NO

        IS COUNT =                           IS COUNT =
             0                                    0
YES
                                    YES
       STORE MAXIMUM                        STORE MINIIMUM


           STOP                                    STOP




                                                                   15
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB               DEPT OF ECE


LARGEST

         PROGRAM                              COMMENTS

MOV SI,1200H           Initialize array size
MOV CL,[SI]            Initialize the count
INC SI                 Go to next memory location
MOV AL,[SI]            Move the first data in AL
DEC CL                 Reduce the count
L2 : INC SI            Move the SI pointer to next data
CMP AL,[SI]            Compare two data’s
JNB L1                 If AL > [SI] then go to L1 ( no swap)
MOV AL,[SI]            Else move the large number to AL
L1 : DEC CL            Decrement the count
JNZ L2                 If count is not zero go to L2
MOV DI,1300H           Initialize DI with 1300H
MOV [DI],AL            Else store the biggest number in 1300 location
HLT                    Stop

SMALLEST

         PROGRAM                              COMMENTS

MOV SI,1200H           Initialize array size
MOV CL,[SI]            Initialize the count
INC SI                 Go to next memory location
MOV AL,[SI]            Move the first data in AL
DEC CL                 Reduce the count
L2 : INC SI            Move the SI pointer to next data
CMP AL,[SI]            Compare two data’s
JB L1                  If AL < [SI] then go to L1 ( no swap)
MOV AL,[SI]            Else move the large number to AL
L1 : DEC CL            Decrement the count
JNZ L2                 If count is not zero go to L2
MOV DI,1300H           Initialize DI with 1300H
MOV [DI],AL            Else store the biggest number in 1300 location
HLT                    Stop




                                                                        16
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB              DEPT OF ECE



RESULT:.
                                        LARGEST




MEMORY

DATA




                                        SMALLEST




MEMORY


DATA




Thus largest and smallest number is found in a given array.




                                                                       17
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                   DEPT OF ECE


EXPT NO:                        8086 PROGRAMMING                           DATE:
                                 COPYING A STRING
AIM:
          To move a string of length FF from source to destination.

ALGORITHM:
  a. Initialize the data segment .(DS)
  b. Initialize the extra data segment .(ES)
  c. Initialize the start of string in the DS. (SI)
  d. Initialize the start of string in the ES. (DI)
  e. Move the length of the string(FF) in CX register.
  f. Move the byte from DS TO ES, till CX=0.


                                                      START




                                                     `
                                          Initialize DS,ES,SI,DI




                                           CX=length of string,
                                           DF=0.




                                          Move a byte from source string (DS)
                                          to destination string (ES)




                                                  Decrement CX




                                              `
                                                  NO      Check
                                                          for ZF=1




                                                   STOP




                                                                                            18
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


COPYING A STRING
       PROGRAM                                         COMMENTS

MOV SI,1200H                        Initialize destination address

MOV DI,1300H                        Initialize starting address

MOV CX,0006H                        Initialize array size

CLD                                 Clear direction flag

REP MOVSB                           Copy the contents of source into destination until
                                    count reaches zero
HLT                                 Stop



RESULT:

                                         INPUT

MEMORY

DATA




                                       OUTPUT

MEMORY


DATA




Thus a string of a particular length is moved from source segment to destination segment.




                                                                                            19
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                        DEPT OF ECE


EXPT NO:                          8086 PROGRAMMING                              DATE:

                                  SEARCHING A STRING
AIM:
       To scan for a given byte in the string and find the relative address of the byte from the
starting location of the string.

ALGORITHM:
  a. Initialize the extra segment .(ES)
  b. Initialize the start of string in the ES. (DI)
  c. Move the number of elements in the string in CX register.
  d. Move the byte to be searched in the AL register.
  e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI
     to BX.


                                                            START




                                                Initialize DS,ES ,SI,DI




                                              CX=length of the string,
                                              DF=0.




                                              Scan for a particular character
                                              specified in AL Register.




                                    NO
                                                    Check for
                                                    ZF=1




                                              Move DI to BX




                                                    STOP




                                                                                                 20
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                               DEPT OF ECE


SEARCHING FOR A CHARACTER IN THE STRING
         PROGRAM                        COMMENTS

MOV DI,1300H                                  Initialize destination address

MOV SI, 1400H                                 Initialize starting address

MOV CX, 0006H                                 Initialize array size

CLD                                           Clear direction flag

MOV AL, 08H                                   Store the string to be searched

REPNE SCASB                                   Scan until the string is found

DEC DI                                        Decrement the destination address

MOV BL,[DI]                                   Store the contents into BL reg

MOV [SI],BL                                   Store content of BL in source address

HLT                                           Stop


RESULT:

                                          INPUT

MEMORY

DATA




                                        OUTPUT

MEMORY LOCATION

DATA




Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found .




                                                                                            21
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                  DEPT OF ECE


EXPT NO:                         8086 PROGRAMMING                         DATE:


                                 FIND AND REPLACE
AIM:
       To find a character in the string and replace it with another character.

ALGORITHM:
    a. Initialize the extra segment .(E S)
    b. Initialize the start of string in the ES. (DI)
    c. Move the number of elements in the string in CX register.
    d. Move the byte to be searched in the AL register.
    e. Store the ASCII code of the character that has to replace the scanned byte in BL
       register.
    f. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning.
    g. If the byte is found, ZF=1.Move the content of BL register to ES:DI.


                                                   START




                                       Initialize DS, ES, SI, DI




                                         CX=length of the string in ES,
                                         DF=0.
                                         DF=0.




                                       Scan for a particular character
                                       specified in AL Register.



                                              NO

                                             Check for
                                             ZF=1


                                            YES

                                       Move the content of BL
                                       to ES:DI
                                                 ¿


                                            STOP




                                                                                           22
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                               DEPT OF ECE


FIND AND REPLACE A CHARACTER IN THE STRING
        PROGRAM                       COMMENTS

MOV DI,1300H                            Initialize destination address

MOV SI,1400H                            Initialize starting address

MOV CX, 0006H                           Initialize array size

CLD                                     Clear direction flag

MOV AL, 08H                             Store the string to be searched

MOV BH,30H                              Store the string to be replaced

REPNE SCASB                             Scan until the string is found

DEC DI                                  Decrement the destination address

MOV BL,[DI]                             Store the contents into BL reg

MOV [SI],BL                             Store content of BL in source address

MOV [DI],BH                             Replace the string

HLT                                     Stop


RESULT:

                                          INPUT

MEMORY

DATA



                                        OUTPUT

MEMORY


DATA



Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found and is replaced with another character.


                                                                                            23
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                               DEPT OF ECE


EXPT NO:                   8086 INTERFACING          DATE:
                INTERFACING ANALOG TO DIGITAL CONVERTER
AIM:
     To write an assembly language program to convert an analog signal into a digital signal
using an ADC interfacing.
APPARATUS REQUIRED:
 SL.NO                ITEM                    SPECIFICATION             QUANTITY
    1.      Microprocessor kit          8086                                   1
    2.      Power Supply                +5 V dc,+12 V dc                       1
    3.      ADC Interface board         -                                      1
PROBLEM STATEMENT:
         The program is executed for various values of analog voltage which are set with the
help of a potentiometer. The LED display is verified with the digital value that is stored in a
memory location.
THEORY:
       An ADC usually has two additional control lines: the SOC input to tell the ADC when
to start the conversion and the EOC output to announce when the conversion is complete. The
following program initiates the conversion process, checks the EOC pin of ADC 0809 as to
whether the conversion is over and then inputs the data to the processor. It also instructs the
processor to store the converted digital data at RAM location.
ALGORITHM:
    (i) Select the channel and latch the address.
    (ii) Send the start conversion pulse.
    (iii) Read EOC signal.
    (iv) If EOC = 1 continue else go to step (iii)
    (v) Read the digital output.
    (vi) Store it in a memory location.
FLOW CHART:
                                 STAR


                 SELECT THE CHANNEL AND LATCH
                            ADDRESS

                 SEND THE START CONVERSION PULSE


                                                  NO
                              IS EOC =
                                  1?
                                           YES

                      READ THE DIGITALOUTPUT


               STORE THE DIGITAL VALUE IN THE
                 MEMORY LOCATION SPECIFIED



                                STOP

                                                                                            24
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                              DEPT OF ECE

PROGRAM TABLE
        PROGRAM                                     COMMENTS

MOV AL,00                      Load accumulator with value for ALE high
OUT 0C8H,AL                    Send through output port
MOV AL,08                      Load accumulator with value for ALE low
OUT 0C8H,AL                    Send through output port
MOV AL,01                      Store the value to make SOC high in the accumulator
OUT 0D0H,AL                    Send through output port
MOV AL,00
MOV AL,00                      Introduce delay
MOV AL,00
MOV AL,00                      Store the value to make SOC low the accumulator
OUT 0D0H,AL                    Send through output port
L1 : IN AL, 0D8H
AND AL,01                      Read the EOC signal from port & check for end of
                               conversion
CMP AL,01
JNZ L1                         If the conversion is not yet completed, read EOC signal
                               from port again
IN AL,0C0H                     Read data from port
MOV BX,1100                    Initialize the memory location to store data
MOV [BX],AL                    Store the data
HLT                            Stop
RESULT:
    ANALOG              DIGITAL DATA ON LED               HEX CODE IN MEMORY
   VOLTAGE                      DISPLAY                         LOCATION




Thus the ADC was interfaced with 8086 and the given analog inputs were converted
into its digital equivalent.
EXPT NO:                    8086 INTERFACING            DATE:
                  INTERFACING DIGITAL – TO – ANALOG CONVERTER
AIM :


                                                                                         25
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


    1. To write an assembly language program for digital to analog conversion
    2. To convert digital inputs into analog outputs & To generate different waveforms
APPARATUS REQUIRED:
 SL.NO               ITEM                       SPECIFICATION             QUANTITY
   1.       Microprocessor kit           8086 Vi Microsystems                 1
   2.       Power Supply                 +5 V, dc,+12 V dc                    1
   3.       DAC Interface board          -                                    1
PROBLEM STATEMENT:
        The program is executed for various digital values and equivalent analog voltages are
measured and also the waveforms are measured at the output ports using CRO.
THEORY:
            Since DAC 0800 is an 8 bit DAC and the output voltage variation is between –5v
and +5v. The output voltage varies in steps of 10/256 = 0.04 (approximately). The digital
data input and the corresponding output voltages are presented in the table. The basic idea
behind the generation of waveforms is the continuous generation of analog output of DAC.
With 00 (Hex) as input to DAC2 the analog output is –5v. Similarly with FF H as input, the
output is +5v. Outputting digital data 00 and FF at regular intervals, to DAC2, results in a
square wave of amplitude 5v.Output digital data from 00 to FF in constant steps of 01 to
DAC2. Repeat this sequence again and again. As a result a saw-tooth wave will be generated
at DAC2 output. Output digital data from 00 to FF in constant steps of 01 to DAC2. Output
digital data from FF to 00 in constant steps of 01 to DAC2. Repeat this sequence again and
again. As a result a triangular wave will be generated at DAC2 output.
ALGORITHM:
        Measurement of analog voltage:
        (i) Send the digital value of DAC.
        (ii) Read the corresponding analog value of its output.
        Waveform generation:
        Square Waveform:
        (i) Send low value (00) to the DAC.
        (ii) Introduce suitable delay.
        (iii) Send high value to DAC.
        (iv) Introduce delay.
        (v) Repeat the above procedure.
        Saw-tooth waveform:
        (i) Load low value (00) to accumulator.
        (ii) Send this value to DAC.
        (iii) Increment the accumulator.
        (iv) Repeat step (ii) and (iii) until accumulator value reaches FF.
        (v) Repeat the above procedure from step 1.
        Triangular waveform:
        (i) Load the low value (00) in accumulator.
        (ii) Send this accumulator content to DAC.
        (iii) Increment the accumulator.
        (iv) Repeat step 2 and 3 until the accumulator reaches FF, decrement the
              accumulator and send the accumulator contents to DAC.
        (v) Decrementing and sending the accumulator contents to DAC.
        (vi) The above procedure is repeated from step (i)
FLOWCHART:
MEASUREMENT OF ANALOG VOLTAGE                                 SQUARE WAVE FORM
                                                                    START
       START

                                                                                          26
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB          DEPT OF ECE




                                        INTIALISE THE ACCUMULATOR
                                         SEND ACC CONTENT TO DAC
      SEND THE
  DIGITALVALUE TO
   ACCUMULATOR
                                                  DELAY

    TRANSFER THE
ACCUMULATOR CONTENTS                        LOAD THE ACC WITH MAX
                                           VALUE SEND ACC CONTENT
                                                   TO DAC

READ THE CORRESPONDING                          DELAY
     ANALOG VALUE


         STOP                        TRIANGULAR WAVEFORM
                                                  STAR
  SAWTOOTH WAVEFORM
         STAR                                    INITIALIZE
                                               ACCUMULATOR


        INITIALIZE                          SEND ACCUMULATOR
      ACCUMULATOR                             CONTENT TO DAC


 SEND ACCUMULATOR                              INCREMENT
                                              ACCUMULATOR
 CONTENT TO DAC
                                                                YES
       INCREMENT
                                                 IS ACC ≤
      ACCUMULATOR
                                                    FF
        CONTENT                                                  NO
 NO                  YES
                                                DECREMENT
          IS                               ACCUMULATOR CONTENT
         ACC ≤

                                             SEND
                                             ACCUMULATOR


  MEASUREMENT OF ANALOG VOLTAGE:               IS ACC ≤
                                     YES          00              NO
                 PROGRAM                    COMMENTS



                                                                       27
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                 DEPT OF ECE


MOV AL,7FH                         Load digital value 00 in accumulator
OUT C0,AL                          Send through output port
HLT                                Stop


 DIGITAL DATA       ANALOG VOLTAGE




PROGRAM TABLE: Square Wave
          PROGRAM                            COMMENTS

L2 : MOV AL,00H              Load 00 in accumulator
OUT C0,AL                    Send through output port
CALL L1                      Give a delay
MOV AL,FFH                   Load FF in accumulator
OUT C0,AL                    Send through output port
CALL L1                      Give a delay
JMP L2                       Go to starting location
L1 : MOV CX,05FFH            Load count value in CX register
L3 : LOOP L3                 Decrement until it reaches zero
RET                          Return to main program

PROGRAM TABLE: Saw tooth Wave
          PROGRAM                            COMMENTS

L2 : MOV AL,00H              Load 00 in accumulator
L1 : OUT C0,AL               Send through output port
INC AL                       Increment contents of accumulator
JNZ L1                       Send through output port until it reaches FF
JMP L2                       Go to starting location




                                                                            28
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                         DEPT OF ECE



PROGRAM TABLE: Triangular Wave
          PROGRAM                                    COMMENTS

L3 : MOV AL,00H                    Load 00 in accumulator
L1 : OUT C0,AL                     Send through output port
INC AL                             Increment contents of accumulator
JNZ L1                             Send through output port until it reaches FF
MOV AL,0FFH                        Load FF in accumulator
L2 : OUT C0,AL                     Send through output port
DEC AL                             Decrement contents of accumulator
JNZ L2                             Send through output port until it reaches 00
JMP L3                             Go to starting location

RESULT:WAVEFORM GENERATION:

         WAVEFORMS           AMPLITUDE         TIMEPERIOD

    Square Waveform
    Saw-tooth waveform

    Triangular waveform


MODEL GRAPH:

Square Waveform                                                Saw-tooth waveform




Triangular waveform




Thus the DAC was interfaced with 8085 and different waveforms have been generated.


                                                                                     29
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                              DEPT OF ECE


EXP.NO:               STEPPER MOTOR INTERFACING                                  DATE:

AIM:
  To write an assembly language program in 8086 to rotate the motor at different speeds.

APPARATUS REQUIRED:

SL.NO                ITEM                       SPECIFICATION           QUANTITY
  1.      Microprocessor kit                  8086                         1
  2.      Power Supply                        +5 V, dc,+12 V dc            1
  3.      Stepper Motor Interface board       -                            1
  4.      Stepper Motor                       -                            1

PROBLEM STATEMENT:

      Write a code for achieving a specific angle of rotation in a given time and particular
number of rotations in a specific time.

THEORY:

               A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a stepwise manner from one
equilibrium position to the next.Two-phase scheme: Any two adjacent stator windings are
energized. There are two magnetic fields active in quadrature and none of the rotor pole faces
can be in direct alignment with the stator poles. A partial but symmetric alignment of the
rotor poles is of course possible.

ALGORITHM:

    For running stepper motor clockwise and anticlockwise directions
   (i) Get the first data from the lookup table.
   (ii) Initialize the counter and move data into accumulator.
   (iii) Drive the stepper motor circuitry and introduce delay
   (iv) Decrement the counter is not zero repeat from step(iii)
   (v) Repeat the above procedure both for backward and forward directions.

SWITCHING SEQUENCE OF STEPPER MOTOR:

MEMORY         A1    A2    B1   B2    HEX
LOCATION                              CODE
4500           1     0     0    0     09 H
4501           0     1     0    1     05 H
4502           0     1     1    0     06 H
4503           1     0     1    0     0A H




                                                                                           30
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                           DEPT OF ECE


FLOWCHART:
                                    STAR
                                      T
                     INTIALIZE COUNTER FOR LOOK UP TABLE


            GET THE FIRST DATA FROM THE ACCUMULATOR


                      MOVE DATA INTO THE ACCUMULATOR


                                 DRIVE THE MOTOR
                                   CIRCUITARY

                                      DELAY


                              DECREMENT COUNTER

                                                           YES
                                     IS B = 0 ?
                           NO

                         GET THE DATA FROM LOOK UP
                                   TABLE

PROGRAM TABLE
PROGRAM                     COMMENTS
START : MOV DI, 1200H       Initialize memory location to store the array of
                            number
MOV CX, 0004H               Initialize array size
LOOP 1 : MOV AL,[DI]        Copy the first data in AL
OUT 0C0,AL                  Send it through port address
MOV DX, 1010H
L1 : DEC DX                 Introduce delay
JNZ L1
INC DI                      Go to next memory location
LOOP LOOP1                  Loop until all the data’s have been sent
JMP START                   Go to start location for continuous rotation
1200 : 09,05,06,0A          Array of data’s

RESULT: Thus the assembly language program for rotating stepper motor in both clockwise
and anticlockwise directions is written and verified.


                                                                                    31
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


EXP.NO:        INTERFACING PRGRAMMABLE KEYBOARD AND DISPLAY
                    CONTROLLER- 8279
DATE:

AIM :
        To display the rolling message “ HELP US “ in the display.

APPARATUS REQUIRED:
    8086 Microprocessor kit, Power supply, Interfacing board.

ALGORITHM :
    Display of rolling message “ HELP US “
               1. Initialize the counter
               2. Set 8279 for 8 digit character display, right entry
               3. Set 8279 for clearing the display
               4. Write the command to display
               5. Load the character into accumulator and display it
               6. Introduce the delay
               7. Repeat from step 1.


1. Display Mode Setup: Control word-10 H

0          0           0          1             0        0           0           0
0          0           0           D            D        K           K           K

DD
     00- 8Bit character display left entry
     01- 16Bit character display left entry
     10- 8Bit character display right entry
      11- 16Bit character display right entry
KKK- Key Board Mode
        000-2Key lockout.
2.Clear Display: Control word-DC H

1          1           0           1              1      1           0           0
1          1           0           CD            CD      CD          CF          CA




                                            11        A0-3; B0-3 =FF

               1-Enables Clear display
               0-Contents of RAM will be displayed
                                                      1-FIFO Status is cleared


                                                                       1-Clear all bits
                                                                       (Combined effect of CD)

                                                                                         32
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                DEPT OF ECE


3. Write Display: Control word-90H

1           0        0         1            0          0          0     0
    1           0         0
                                   AI           A       A         A         A




                                           Selects one of the 16 rows of display.

Auto increment = 1, the row address selected will be incremented after each of read and
write operation of the display RAM.


FLOWCHART:


                                SET UP
                               POINTER

                         INITIALIZE THE COUNTER


                    SET 8279 FOR 8-DIGIT CHARACTER
                                DISPLAY

                         SET 8279 FOR CLEARING THE
                                   DISPLAY

                    WRITE THE COMMAND TO DISPLAY

                         LOAD THE CHARACTER INTO
                         ACCUMULATOR AND DISPLAY


                                   DELAY




                                                                                          33
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                           DEPT OF ECE

PROGRAM TABLE


              PROGRAM                                       COMMENTS
START : MOV SI,1200H                 Initialize array
MOV CX,000FH                         Initialize array size
MOV AL,10                            Store the control word for display mode
OUT C2,AL                            Send through output port
MOV AL,CC                            Store the control word to clear display
OUT C2,AL                            Send through output port
MOV AL,90                            Store the control word to write display
OUT C2,AL                            Send through output port
L1 : MOV AL,[SI]                     Get the first data
OUT C0,AL                            Send through output port
CALL DELAY                           Give delay
INC SI                               Go & get next data
LOOP L1                              Loop until all the data’s have been taken
JMP START                            Go to starting location
DELAY : MOV DX,0A0FFH                Store 16bit count value
LOOP1 : DEC DX                       Decrement count value
JNZ LOOP1                            Loop until count values becomes zero
RET                                  Return to main program

LOOK-UP TABLE:

1200     98     68    7C     C8
1204     FF     1C    29     FF

RESULT:

 MEMORY              7-SEGMENT LED FORMAT                          HEX DATA
LOCATION        d    c   b  a   dp e   g                f
1200H           1    0   0  1   1   0  0                0     98
1201H           0    1   1  0   1   0  0                0     68
1202H           0    1   1  1   1   1  0                0     7C
1203H           1    1   0  0   1   0  0                0     C8
1204H           1    1   1  1   1   1  1                1     FF
1205H           0    0   0  0   1   1  0                0     1C
1206H           0    0   1  0   1   0  0                1     29
1207H           1    1   1  1   1   1  1                1     FF



       Thus the rolling message “HELP US” is displayed using 8279 interface kit.


                                                                                    34
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                    DEPT OF ECE


EXP. NO:           INTERFACING PROGRAMMABLE TIMER-8253                                  DATE:

AIM :
            To study different modes of operation of programmable timer 8253

APPARATUS REQUIRED:


SL.NO                      ITEM                    SPECIFICATION              QUANTITY
       1.      Microprocessor kit               8086 Vi Microsystems                1
       2.      Power Supply                     +5V dc                              1
       3.      8253 interfacing kit             -                                   1
       4.      CRO                              -                                   1


THEORY:

            The main features of the timer are,
i.          Three independent 16-bit counters
ii.         Input clock from DC to 2 MHz
iii.        Programmable counter modes
iv.         Count binary or BCD
                    The control signals with which the 8253 interfaces with the CPU are CS, RD,
                    WR, A1, A2.The basic operations performed by 8253 are determined by these
                    control signals. It has six different modes of operation, viz, mode 0 to mode 5.


MODE 2 – RATE GENERATOR
        It is a simple divide - by – N counter. The output will be low for one input clock
period. The period from one output pulse to the next equals the number of input counts in the
count register. If the count register is reloaded between output pulses, the present period will
not be affected, but the subsequent period will reflect the new value.

MODE 3 – SQUARE WAVE GENERATOR
       It is similar to mode 2, except that the output will remain high until one half for even
number count, If the count is odd, the output will be high for (count+1)/2 counts and low for
(count-1)/2 counts

ALGORITHM:

Mode 2-
1. Initialize channel 0 in mode 2
2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.




                                                                                                 35
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                         DEPT OF ECE


Mode 3-
1. Initialize channel 0 in mode 3
2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.

PORT ADDRESS :
1. CONTROL REGISTER               –
2. COUNTER OF CHANNEL 0           -
3. COUNTER OF CHANNEL 1           -
4. COUNTER OF CHANNEL 2           -
5. O/P PORT OF CHANNEL 0          -
6. O/P PORT OF CHANNEL 1          -
7. O/P PORT OF CHANNEL 2          -

CONTROL WORD FORMAT:

 D7    D6     D5      D4     D3   D2       D1    D0
SC1    SC0    RL1     RL0    M2   M1       M0    BCD

 0      0      1       1      0    1       0      0
                                                         Mode 2 = 34 H
 0      0      1       1      0    1       1      0
                                                         Mode 3 = 36 H

SC1    SC0    CHANNEL SELECT           RL1      RL0    READ/LOAD

0      0      CHANNEL 0                 0      0   LATCH
0      1      CHANNEL 1                 0      1   LSB
1      0      CHANNEL 2                 1      0   MSB
1      1      -----                     1      1   LSB FIRST, MSB NEXT
BCD   --0 –BINARY COUNTER             1 --BCD COUNTER

 M2    M1      M0      MODE
         1 CLK 0
 0     0    0          MODE 0
 0     0 2 CLK 1
            1          MODE 1
 0     1    0          MODE 2
 0     1 3 CLK 2
            1          MODE 3
 1     0    0          MODE 4
 1     0 4 OUT 0
            1          MODE 5

            5 OUT 1         PORT PIN ARRANGEMENT             DEBOUNCE CIRCUIT
                            CONNECTION
            6 OUT 2
                                                                             *   *        *
            7 GATE 0

            8 GATE 1

            9 GATE 2                                                                 36
            10 GND
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                DEPT OF ECE




MODE 2 – RATE GENERATOR:

      PROGRAM                   COMMENTS
MOV AL, 34H      Store the control word in accumulator
OUT 0BH          Send through output port
MOV AL, 0AH      Copy lower order count value in accumulator
OUT 08H          Send through output port
MOV AL, 00H      Copy higher order count value in accumulator
OUT 08H          Send through output port
HLT              Stop

MODE 3 – SQUARE WAVE GENERATOR:

      PROGRAM                   COMMENTS
MOV AL, 36H      Store the control word in accumulator
OUT 0BH          Send through output port
MOV AL, 0AH      Copy lower order count value in accumulator
OUT 08H          Send through output port
MOV AL, 00H      Copy higher order count value in accumulator
OUT 08H          Send through output port
HLT              Stop




                                                                         37
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                         DEPT OF ECE


MODEL GRAPH:

RATE GENERATOR                                   SQUARE WAVE GENERATOR




FLOW CHART

      START


INITIALIZE ACCUMULATOR
WITH MODE SET WORD


 INITIALIZE LSB OF COUNT




INITIALIZE MSB OF COUNT



 TRIGGER THE COUNT


        STOP




RESULT: Thus an ALP for rate generator and square wave generator are written and
executed.




                                                                                   38
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                       DEPT OF ECE


EXP. NO:                        INTERFACING USART 8251                                    DATE:

AIM:
          To study interfacing technique of 8251 (USART) with microprocessor 8086 and
write an 8086 ALP to transmit and receive data between two serial ports with RS232 cable.

APPARATUS REQUIRED:
          8086 kit (2 Nos), RS232 cable.
THEORY:
          The 8251 is used as a peripheral device for serial communication and is
programmed by the CPU to operate using virtually any serial data transmission technique.
The USART accepts data characters from the CPU in parallel format and then converts them
into a continuous serial data stream for transmission. Simultaneously, it can receive serial
data streams and convert them into parallel data characters for the CPU. The CPU can read
the status of the USART at any time. These include data transmission errors and control
signals. The control signals define the complete functional definition of the 8251. Control
words should be written into the control register of 8251.These control words are split into
two formats: 1) Mode instruction word & 2) Command instruction word. Status word format
is used to examine the error during functional operation.




                                                                                 1...transmit enable
                                                                         1...data terminal ready
                                                                     1... receive enable
                                                         1... send break character
                                              1.... reset error flags (pe,oe,fe)
                             1..... request to send (rts)
                  1...... internal reset
     1....... enter hunt mode (enable search for sync characters)




                                                                             1 ransmitter ready
                                                                          1. receiver ready
                                                                 1.. transmitter empty
                                                     1... parity error (pe)
                                          1.... overrun error (oe)
                              1..... framing error (fe), async only
                    1...... sync detect, sync only
       1....... data set ready (dsr)




                                                                                                       39
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE




ALGORITHM:
1.Initialize 8253 and 8251 to check the transmission and reception of a character
2.Initialize8253 to give an output of 150Khz at channel 0 which will give a 9600 baud rate of
8251.
3.The command word and mode word is written to the 8251 to set up for subsequent
operations
4.The status word is read from the 8251 on completion of a serial I/O operation, or when the
host CPU is checking the status of the device before starting the next I/O operation
FLOW CHART:
                                STAR




                           Check TX/RX Ready

                                                 No

                             Is it High
                                           Yes


                        Write Data into data register


                               STOP

                                                                                          40
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                         DEPT OF ECE


PROGRAM: TRANSMITTER END
  PROGRAM                                   COMMENTS
MOV AL,36   Initialize 8253 in mode 3 square wave generator
OUT CE,AL   Send through port address
MOV AL,10   Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL   Send through port address
MOV AL,00   Initialize AL with higher value of count
OUT C8,AL   Send through port address
MOV AL,4E   Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL   Send through port address
MOV AL,37   Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL   Send through port address
L1:IN AL,C2 Read status word
AND AL,04   Check whether transmitter ready
JZ L1       If not wait until transmitter becomes ready
MOV AL,41   Set the data as 41
OUT C0,AL   Send through port address
INT 2       Restart the system

RECEIVER END
  PROGRAM                                  COMMENTS
MOV AL,36   Initialize 8253 in mode 3 square wave generator
OUT CE,AL   Send through port address
MOV AL,10   Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL   Send through port address
MOV AL,00   Initialize AL with higher value of count
OUT C8,AL   Send through port address
MOV AL,4E   Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL   Send through port address
MOV AL,37   Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL   Send through port address
L1:IN AL,C2 Read status word
AND AL,02   Check whether receiver ready
JZ L1       If not wait until receiver becomes ready
IN AL,C0    If it is ready, get the data
MOV BX,1500 Initialize BX register with memory location to store the data
MOV [BX],AL Store the data in the memory location
INT 2       Restart the system

RESULT:

Thus ALP for serial data communication using USART 8251 is written and the equivalent
ASCII 41 for character ‘A’ is been transmitted & received.



                                                                                        41
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                               DEPT OF ECE


 EXP. NO:                      INTERFACING PPI 8255                            DATE:

 AIM:
          To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and mode 2

 APPARATUS REQUIRED:
       8086 kit, 8255 interface kit.

 ALGORITHM:
 Mode 0
 1. Initialize accumulator to hold control word
 2. store control word in control word register
 3. Read data port A.
 4. Store data from port A in memory
 5. Place contents in port B
 Mode 1 & Mode 2
 1. Initialize accumulator to hold control word (for port A)
 2. Store control word in control word register
 3. Initialize accumulator to hold control word (for port B)
 4. Place contents in control word register.
 5. Disable all maskable interrupts, enable RST 5.5
 6. send interrupt mask for RST 6.5 & 7.5
 7. Enable interrupt flag
 8. Read data from port A, place contents in port B

 FLOWCHART
 Mode 0                                                Mode 1 & 2
                                                                         STAR
        STAR
                                                         Store control word in control register

  Store control word in
     control register
                                                               Input to be read from port A

Input to be read from port A
                                                           Disable all interrupts except RST
                                                                           6.5
   Store into accumulator
                                                                  Store output to port B
  Output written on port B

                                                                        STOP
         STOP




                                                                                              42
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                DEPT OF ECE


MODE 0
       PROGRAM                           COMMENTS
MOV AL,90H        Set the control word
OUT C6,AL         Send it to control port
IN AL,C0          Get the contents of port A in AL
OUT C2,AL         Send the contents of port B to port address
HLT               Stop

MODE 1
       PROGRAM                           COMMENTS
MOV AL,0B0H       Set the control word for mode 1
OUT C6,AL         Send it to control port
MOV AL,09H        Control for BSR mode
OUT C6,AL         Send it to control port
MOV AL,13H        Interrupt generation
OUT 30,AL
MOV AL,0AH        Through 8259
OUT 32,AL
MOV AL,0FH        Using IR2 interrupt(lower order count)
OUT 32,AL
MOV AL,00H        Higher order count
OUT 32,AL
STI               Set trap flag
HLT               Stop
ISR:              Subroutine
IN AL,C0          Read from Port A
OUT C2,AL         Send it to Port B
HLT               Stop
MODE 2
       PROGRAM                           COMMENTS
MOV AL,0C0H       Set the control word for mode 2
OUT C6,AL         Send it to control port
MOV AL,09H        Control for BSR mode
OUT C6,AL         Send it to control port
MOV AL,13H        Interrupt generation
OUT 30,AL
MOV AL,0AH        Through 8259
OUT 32,AL



                                                                         43
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                            DEPT OF ECE


MOV AL,0FH                   Using IR2 interrupt(lower order count)
OUT 32,AL
MOV AL,00H                   Higher order count
OUT 32,AL
STI                          Set trap flag
HLT                          Stop
ISR:                         Subroutine
IN AL,C0                     Read from Port A
OUT C2,AL                    Send it to Port B
HLT                          Stop
BSR mode
Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word:
D7                      D6    D5     D4      D3    D2    D1     D0
0 (0=BSR)               X     X      X       B2    B1    B0     S/R (1=S,0=R)
Bit   select: (Taking Don't care's as 0)
B2    B1 B0 PC bit Control word (Set) Control word (reset)
 0     0 0      0    0000 0001 = 01h 0000 0000 = 00h
 0     0 1      1    0000 0011 = 03h 0000 0010 = 02h
 0     1 0      2    0000 0101 = 05h 0000 0100 = 04h
 0     1 1      3    0000 0111 = 07h 0000 0110 = 06h
 1     0 0      4    0000 1001 = 09h 0000 1000 = 08h
 1     0 1      5    0000 1011 = 0Bh 0000 1010 = 0Ah
 1     1 0      6   0000 1101 = 0Dh 0000 1100 = 0Ch
 1     1 1      7    0000 1111 = 0Fh     0000 1110 = 0Eh

I/O mode
D7                 D6          D5            D4   D3    D2                      D1   D0
1 (1=I/O)          GA mode select            PA   PCU   GB mode select          PB   PCL


      •    D6, D5: GA mode select:
              o 00 = mode0
              o 01 = mode1
              o 1X = mode2
      •    D4(PA), D3(PCU): 1=input 0=output
      •    D2: GB mode select: 0=mode0, 1=mode1
      •    D1(PB), D0(PCL): 1=input 0=output

Result:
                  Mode 0                 Mode 1                 Mode 2
          Input      Output           Input         Output        Input         Output


The programs for interfacing 8255 with 8085 are executed & the output is obtained for modes
0,1 & 2




                                                                                           44
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                           DEPT OF ECE


EXPT NO:                       8051 PROGRAMMING                          DATE:

                                    8 BIT ADDITION


AIM:
       To write a program to add two 8-bit numbers using 8051 microcontroller.


ALGORITHM:

       1. Clear Program Status Word.
       2. Select Register bank by giving proper values to RS1 & RS0 of PSW.
       3. Load accumulator A with any desired 8-bit data.
       4. Load the register R 0 with the second 8- bit data.
       5. Add these two 8-bit numbers.
       6. Store the result.
       7. Stop the program.




FLOW CHART:

                          START


                         Clear PSW

                       Select Register
                       Bank

                       Load A and R 0
                       with 8- bit datas

                       Add A & R 0

                       Store the sum


                           STOP




                                                                                    45
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                         DEPT OF ECE


8 Bit Addition (Immediate Addressing)
ADDRESS LABEL MNEMONIC OPERAND                           HEX        COMMENTS
                                                         CODE
4100                    CLR              C               C3         Clear CY Flag

4101                    MOV              A,# data1       74,data1   Get the data1 in
                                                                    Accumulator
4103                    ADDC             A, # data 2     24,data2   Add the data1 with
                                                                    data2
4105                    MOV              DPTR, #         90,45,00   Initialize the memory
                                         4500H                      location
4108                    MOVX             @ DPTR, A       F0         Store the result in
                                                                    memory location
4109         L1         SJMP             L1              80,FE      Stop the program




RESULT:


              OUTPUT
MEMORY LOCATION                              DATA

             4500




Thus the 8051 ALP for addition of two 8 bit numbers is executed.




                                                                                     46
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                              DEPT OF ECE


EXPT NO:             8 BIT SUBTRACTION                                        DATE:

AIM:
   To perform subtraction of two 8 bit data and store the result in memory.

ALGORITHM:
  a. Clear the carry flag.
  b. Initialize the register for borrow.
  c. Get the first operand into the accumulator.
  d. Subtract the second operand from the accumulator.
  e. If a borrow results increment the carry register.
  f. Store the result in memory.

FLOWCHART:
                              START




                            CLEAR CARRY
                            FLAG




                            GET I’ST
                            OPERAND IN
                            ACCR




                            SUBTRACT THE
                            2’ND OPERAND
                            FROM ACCR



                                                N
                               IS CF=1


                    Y
                            INCREMENT
                            THE BORROW
                            REGISTER




                            STORE
                            RESULT IN
                            MEMORY




                            STOP




                                                                                       47
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                            DEPT OF ECE


8 Bit Subtraction (Immediate Addressing)
ADDRESS LABEL           MNEMONIC OPERAND                      HEX         COMMENTS
                                                              CODE
4100                      CLR              C                  C3          Clear CY flag

4101                      MOV              A, # data1         74, data1   Store data1 in
                                                                          accumulator
4103                      SUBB             A, # data2         94,data2    Subtract data2 from
                                                                          data1
4105                      MOV              DPTR, # 4500       90,45,00    Initialize memory
                                                                          location
4108                      MOVX             @ DPTR, A          F0          Store the difference
                                                                          in memory location
4109         L1           SJMP             L1                 80,FE       Stop




RESULT:


                                OUTPUT
                  MEMORY LOCATION                            DATA

                               4500




Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.




                                                                                          48
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                            DEPT OF ECE


EXPT NO:                        8051 PROGRAMMING                             DATE:

                                8 BIT MULTIPLICATION

AIM:
   To perform multiplication of two 8 bit data and store the result in memory.


ALGORITHM:
  a. Get the multiplier in the accumulator.
  b. Get the multiplicand in the B register.
  c. Multiply A with B.
  d. Store the product in memory.

FLOWCHART:



                      START




                   GET
                   MULTIPLIER
                   IN ACCR




                   GET
                   MULTIPLICAND
                   IN B REG




                   MULTIPLY A
                   WITH B




                   STORE
                   RESULT IN
                   MEMORY




                    STOP




                                                                                     49
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                            DEPT OF ECE


8 Bit Multiplication
ADDRESS LABEL            MNEMONIC         OPERAND           HEX          COMMENTS
                                                            CODE
4100                     MOV              A ,#data1         74, data1    Store data1 in
                                                                         accumulator
4102                     MOV              B, #data2         75,data2     Store data2 in B reg

4104                     MUL              A,B               F5,F0        Multiply both

4106                     MOV              DPTR, #           90,45,00     Initialize memory
                                          4500H                          location
4109                     MOVX             @ DPTR, A         F0           Store lower order
                                                                         result
401A                     INC              DPTR              A3           Go to next memory
                                                                         location
410B                     MOV              A,B               E5,F0
                                                                         Store higher order
410D                     MOV              @ DPTR, A         F0           result

410E          STOP       SJMP             STOP              80,FE        Stop




RESULT:

          INPUT                                       OUTPUT
MEMORY LOCATION             DATA            MEMORY LOCATION                DATA

4500                                        4502

4501                                        4503




Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.




                                                                                         50
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                            DEPT OF ECE


EXPT NO:                        8051 PROGRAMMING                           DATE:

                                    8 BIT DIVISION

AIM:
   To perform division of two 8 bit data and store the result in memory.


ALGORITHM:
    1. Get the Dividend in the accumulator.
    2. Get the Divisor in the B register.
    3. Divide A by B.
    4. Store the Quotient and Remainder in memory.


FLOWCHART:


                      START




                   GET DIVIDEND
                   IN ACCR




                   GET DIVISOR IN
                   B REG




                   DIVIDE A BY B




                   STORE
                   QUOTIENT &
                   REMAINDER
                   IN MEMORY




                   STOP




                                                                                     51
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


8 Bit Division
ADDRESS LABEL MNEMONIC                   OPERAND           HEX        COMMENTS
                                                           CODE
4100                    MOV              A, # data1        74,data1   Store data1 in
                                                                      accumulator
4102                    MOV              B, # data2        75,data2   Store data2 in B reg

4104                    DIV              A,B               84         Divide

4015                    MOV              DPTR, # 4500H     90,45,00   Initialize memory
                                                                      location
4018                    MOVX             @ DPTR, A         F0         Store remainder

4109                    INC              DPTR              A3         Go to next memory
                                                                      location
410A                    MOV              A,B               E5,F0
                                                                      Store quotient
410C                    MOV              @ DPTR, A         F0

410D         STOP       SJMP             STOP              80,FE      Stop




RESULT:

             INPUT                                    OUTPUT
MEMORY LOCATION             DATA            MEMORY LOCATION               DATA
4500 (dividend)                             4502 (remainder)

4501     (divisor)                          4503       (quotient)




Thus the 8051 ALP for division of two 8 bit numbers is executed.




                                                                                       52
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                     DEPT OF ECE


EXP. NO:              LOGICAL AND BIT MANIPULATION                      DATE:

AIM:

      To write an ALP to perform logical and bit manipulation operations using 8051
microcontroller.

APPARATUS REQUIRED:
    8051 microcontroller kit

ALGORITHM:

   1.   Initialize content of accumulator as FFH
   2.   Set carry flag (cy = 1).
   3.   AND bit 7 of accumulator with cy and store PSW format.
   4.   OR bit 6 of PSW and store the PSW format.
   5.   Set bit 5 of SCON.
   6.   Clear bit 1 of SCON.
   7.   Move SCON.1 to carry register.
   8.   Stop the execution of program.


FLOWCHART:


                           START


                 Set CY flag, AND CY with MSB of
                 ACC
            Store the PSW format, OR CY with bit 2 IE reg


                 Clear bit 6 of PSW, Store PSW


                Set bit 5 of SCON , clear bit 1 and store
                SCON

               Move bit 1 of SCON to CY and store PSW


                            STOP




                                                                                53
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB           DEPT OF ECE


PROGRAM TABLE

ADDRESS HEX        LABEL   MNEMONICS   OPERAND      COMMENT
        CODE
4100    90,45,00           MOV         DPTR,#4500   Initialize   memory
                                                    location
4103     74,FF             MOV         A,#FF        Get     the data in
                                                    accumulator
4105     D3                SETB        C            Set CY bit

4016     82,EF             ANL         C, ACC.7     Perform AND with 7th
                                                    bit of accumulator
4018     E5,D0             MOV         A,DOH
410A     F0                MOVX        @DPTR,A      Store the result

410B     A3                INC         DPTR         Go to next location

410C     72,AA             ORL         C, IE.2      OR CY bit with 2nd bit
                                                    if IE reg
410E     C2,D6             CLR         PSW.6        Clear 6th bit of PSW

4110     E5,D0             MOV         A,DOH
4112     F0                MOVX        @DPTR,A      Store the result

4113     A3                INC         DPTR         Go to next location

4114     D2,90             SETB        SCON.5       Set 5th of SCON reg
4116     C2,99             CLR         SCON.1       Clear 1st bit of SCON
                                                    reg
4118     E5,98             MOV         A,98H
411A     F0                MOVX        @DPTR,A      Store the result

411B     A3                INC         DPTR         Go to next location

411C     A2,99             MOV         C,SCON.1     Copy 1st bit of SCON
                                                    reg to CY flag
411E     E5,D0             MOV         A,DOH
                                                    Store the result
4120     F0                MOVX        @DPTR,A

4122     80,FE     L2      SJMP        L2           Stop




                                                                       54
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                       DEPT OF ECE


    RESULT:


  MEMORY        SPECIAL FUNCTION REGISTER FORMAT                   BEFORE        AFTER
  LOCATION                                                       EXECUTION EXECUTION
4500H (PSW)     CY    AC     FO     RS1    RS0 OV       -   P    00H       88H


4501H (PSW)     CY    AC     FO     RS1    RS0 OV       -   P    40H          88H


4502H (SCON)    SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH                             20H


4503H (PSW)     CY    AC     FO     RS1    RS0 OV       -   P    FFH          09H




    Thus the bit manipulation operation is done in 8051 microcontroller.




                                                                                    55
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                                  DEPT OF ECE


EX.NO           PROGRAMS TO VERIFY TIMER, INTERRUPTS & UART
                OPERATIONS IN 8031 MICROCONTROLLER
DATE :
      a) Program to generate a square wave of frequency --------.
Steps to determine the count:
         Let the frequency of sqaurewave to be generated be Fs KHz.
         And the time period of the squarewave be Ts Sec.
         Oscillator Frequency = 11.0592MHz.
         One machine cycle = 12 clock periods
         Time taken to complete one machine cycle=12*(1/11.0592MHz)= 1.085microsec.
         Y(dec) = (Ts/2)/(1.085microsec)
         Count(dec) = 65536(dec) – Y(dec)
                    = Count(hexa)


                MOV TMOD,#10h        ; To select timer1 & mode1 operation
L1:             MOV TL1,#LOWERORDER BYTE OF THE COUNT
                MOV TH1,#HIGHER ORDER BYTE OF THE COUNT
                SETB TR1             ; to start the timer (TCON.6)
BACK:           JNB TF1,BACK         ; checking the status of timerflag1(TCON.7) for
                                      overflow
                CPL Px.x             ; get the square wave through any of the portpins
                                     ; eg. P1.2 (second bit of Port 1)
                CLR TR1              ; stop timer
                CLR TF1              ; clear timer flag for the next cycle
                SJMP L1
      b) Program to transfer a data serially from one kit to another.
Transmitter:
                MOV TMOD,#20H                ; Mode word to select timer1 & mode 2
                MOV TL1,#FDH                 ; Initialize timer1 with the count
                MOV TH1,#FFH
                MOV SCON,#50H                ; Control word for serial communication to
                                              to select serial mode1
                SETB TR1                     ; Start timer1
                MOV A,#06h


                                                                                           56
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                 DEPT OF ECE


            MOV SBUF,A        ; Transfer the byte to be transmitted to serial
                              Buffer register.
LOOP:       JNB TI, LOOP      ; checking the status of Transmit interrupt
                              flag
            CLR TI
HERE:       SJMP HERE


Receiver:
            MOV TMOD,#20H
            MOV TL1,#FDH
            MOV TH1,#FFH
            MOV SCON,#50H
            SETB TR1
LOOP:       JNB RI,LOOP
            MOV A,SBUF
            MOV DPTR,#4500H
            MOVX @DPTR,A
            CLR RI
HERE:       SJMP HERE




                                                                                57
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


EX.NO.         COMMUNICATION BETWEEN 8051 MICROCONTROLLER
               KIT & PC
DATE :


SERIAL COMMUNICATION


8051>H
HELP MENU


D      Display data, program, internal, bit memory or registers
E      Edit data, program, internal, bit memory or registers
S      Single step from specified address, press SP to terminate
G      Execute the program till user break
B      Set address till where the program is to be executed
C      Clear break points
F10    Key followed by 4 key at the PC to upload data to a file (DOS)
T      Test the onboard peripherals
:      Download a file from PC mem to the SDA-SI-MEL kit (DOS)
A      Assembler
Z      Disassembler




TEST FOR ONBOARD PERIPHERALS


For SDA SI-MEL kit, following menu is displayed on pressing the option "T"


8051>T
ALS-SDA SI-MEL Kit Test monitor


1. Test internal Data RAM
2. Test external Data Memory (U6)
3. Test external Data memory (U7)
4. 8255 loop test
5. Test 8253


                                                                                      58
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                              DEPT OF ECE


6. Exit


Select (1-6):


Suppose the user presses the key '1', following message is displayed if the internal data RAM
is OK.


Testing internal data RAM: Pass


After displaying the message, the menu is displayed once again waits for user to enter a key


EDITING MEMORY COMMAND:


8051>E
EDIT (R,B,M,P,D)…D - EXTERNAL DATA RAM
Enter STA address = 0400
0400 =          7F:55 Press 'N' key to go to the next address
0401 =          D5:66
0402 =          D3:77
0403 =          73:88
0404 =          6F:12
0405 =          CB:01
0406 =          A7:02 Press 'P' key to go to the previous address
0407 =          6F:03
0408 =          7B:04
0409 =          29:05
040A =          6F:06
040B =          73:07
040C =          FF:08
040D =          7D:09 Press 'CR' key to have the same address
040E =          09:90 Press 'ESC' Key to abort the command


8051>E
EDIT (R,B,M,P,D)…B - BITS


                                                                                           59
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB   DEPT OF ECE


Enter STA address = 00
00 = 0:1
01= 0:1
02 = 0:0
03 = 0:1
03 = 1:
03 = 1:
02 = 0:


8051>E
EDIT (R,B,M,P,D)…R- REGISTERS
ACC = 00:33
PSW = 00:44
DPH = 00:55
DPL = 00:00
DPL = 00:00


8051>E
EDIT (R,B,M,P,D)…-P = PROGRAM CODE
8000 = FF:78
8001 = FF:10
8002 = FF:79
8003 = FF:20
8004 = FF:7A
8005 = FF: 12
8007 = FF : 00
8008 = FF : 03
8009 = FF : 0F




8051>E
EDIT (R,B,M,P,D)…-M - INTERNAL RAM
0000 = 00 : 12
0001 = 00 : 34


                                                            60
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB              DEPT OF ECE


0002 = 00 : 00




DISPLAY COMMAND


8051>D
EDIT (R,B,M,P,D)…-EXTERNAL DATA RAM


Enter STA address = 0400


Enter END address = 040F


0500 55 66 77 88 12 01 02 03 04 05 06 07 08 09 04 D7


SETTING BREAK COMMAND :


8051>B
BR _ NO: R
BR_ADD 0000
ERROR! ONLY A BREAKS ALLOWED


8051>B
BR _ NO: 0
ERROR! BREAK NUMBERS MUST BE BETWEEN 1 & 8


CLEAR BREAK COMMAND:


8051>C
BR_N0:A          Clears all the break point set by the user


8051>C
BR_N0:1          Clears the break point number 1




                                                                       61
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB          DEPT OF ECE


PROGRAMME EXECUTION COMMAND:
8051>G
PROGRAM EXECUTION


ENTER START ADDRESS = 8000


ACC PSW DPH DPL PCH PCL SP B R0 R1 R2 R3 R3 R4 R5 R6 R7
33 44 55 00 10 34 00 00 00 00 00 00


ASSEMBLE MEMORY COMMAND


8051>A
ENTER START ADDRESS = 8000


DISASSEMBLE MEMORY COMMAND
8051>Z




                                                                   62
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                      DEPT OF ECE


EX. NO.    PROGRAMS FOR DIGITAL CLOCK AND STOP WATCH (USING
           8086)
DATE:


     Program that places a message on the screen every 10 seconds, using int 1ah;


           CODE SEGMENT
           TIMEDELAY:
                   MOV SP,1000H
                   MOV DI,10XD
           TIME OUT:
                   MOV AH,00H
                   INT 1AH
                   MOV BX,DX
           TIMER:
                   MOV AH, 00H
                   INT 1AH
                   SUB DX, BX
                   CMP DX, 182XD
                   JC TIMER
                   MOV AH, 09H
           CS      MOV DX,MSG
                   INT 21H
                   DEC DI
                   JNZ TIMEOUT
                   MOV AX,4C00H
                   INT 21H
           MSG:
                   DB 'TEN MORE SECONDS HAVE PASSED $'
           CODE ENDS




                                                                                    63
EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB                             DEPT OF ECE


EX.NO.                    Interfacing 8259 with 8085 microprocessor           DATE:


Initialize 8259 with the following specifications:
ICW4 needed, single 8259, Interval of ------(8085), Edge triggered mode, Vector
address(8085)/ Type number(8086) of IR0 ------, ------- mode, Normal EOI, Non-buffered
mode, Not special fully nested mode, Mask all interrupts except ---------.


       A0 – Address with A0 = 0
       A1 – Address with A0 = 1
Using 8086:


       MOV AL,ICW1
       OUT A0,AL
       MOV AL,ICW2
       OUT A1,AL
       MOV AL,ICW4
       OUT A1,AL
       MOV AL,OCW1
       OUT A1,AL
       STI
       HLT


Vector Table: offset address -        Interrupt type * 4
       0000: offsetaddress    -       Segment Address : Offset address of the ISR


ISR:   MOV AL,OCW2
       OUT A0,AL
       HLT




                                                                                         64

More Related Content

PPTX
3.programmable interrupt controller 8259
PPTX
8086 memory interface.pptx
PPTX
8086 Microprocessor powerpoint
PPT
1326 Introduction To 8086 Microprocessor
PPS
Addressing modes of 8085
PPTX
5.programmable interval timer 8253
PPTX
Introduction to 8085 Microprocessor
PPT
Parallel adder
3.programmable interrupt controller 8259
8086 memory interface.pptx
8086 Microprocessor powerpoint
1326 Introduction To 8086 Microprocessor
Addressing modes of 8085
5.programmable interval timer 8253
Introduction to 8085 Microprocessor
Parallel adder

What's hot (20)

PPT
PIC 16F877A by PARTHIBAN. S.
PPT
8086 microprocessor
PDF
Intel 80486 Microprocessor
PPTX
Verilog HDL
PPTX
3.codes( binary code ,excess 3, gray code )
PDF
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
PPTX
Microprocessor architecture-I
PPTX
8257 DMA Controller
PPTX
486 or 80486 DX Architecture
PPTX
Registers-shift register
PPTX
Branching instructions in 8086 microprocessor
PPT
80486 microprocessor
PPT
8251 communication interface
PPTX
Advanced Pipelining in ARM Processors.pptx
PPTX
Pentium ii
PPTX
8051 Microcontroller
PDF
ARM Architecture
PPTX
Clock-8086 bus cycle
PPTX
PIC 16F877A by PARTHIBAN. S.
8086 microprocessor
Intel 80486 Microprocessor
Verilog HDL
3.codes( binary code ,excess 3, gray code )
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
Microprocessor architecture-I
8257 DMA Controller
486 or 80486 DX Architecture
Registers-shift register
Branching instructions in 8086 microprocessor
80486 microprocessor
8251 communication interface
Advanced Pipelining in ARM Processors.pptx
Pentium ii
8051 Microcontroller
ARM Architecture
Clock-8086 bus cycle
Ad

Similar to Ec2308 microprocessor and_microcontroller__lab1 (20)

PPT
ARITHMETIC LOGIC UNIT.ppt
PDF
15CS44 MP & MC Module 2
DOC
180410227 ae2406-lab-manual-doc
PPTX
CA UNIT II.pptx
PDF
Microprocessor lab
PDF
Microprocessor lab
PDF
Microprocessor lab
PDF
Microprocessor lab
PDF
Arithmetic Unit Addition Subtraction Multiplication and Division
PPT
Addition and subtraction with signed magnitude data (mano
PPT
Arithmetic & logical operations in 8051
PPTX
Datapath design
PDF
DPCO-Unit 2-Combinational Circuit.pdf
PPTX
Arithmetic and logical instructions 8051 microcontroller
PPTX
Ee2356 lab manual
PPTX
Arithmetic micro operations
PPT
Parallel Prefix Adders Presentation
PPTX
Module 2 (1).pptx
PDF
My Report on adders
ARITHMETIC LOGIC UNIT.ppt
15CS44 MP & MC Module 2
180410227 ae2406-lab-manual-doc
CA UNIT II.pptx
Microprocessor lab
Microprocessor lab
Microprocessor lab
Microprocessor lab
Arithmetic Unit Addition Subtraction Multiplication and Division
Addition and subtraction with signed magnitude data (mano
Arithmetic & logical operations in 8051
Datapath design
DPCO-Unit 2-Combinational Circuit.pdf
Arithmetic and logical instructions 8051 microcontroller
Ee2356 lab manual
Arithmetic micro operations
Parallel Prefix Adders Presentation
Module 2 (1).pptx
My Report on adders
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Institutional Correction lecture only . . .
PDF
Classroom Observation Tools for Teachers
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Computing-Curriculum for Schools in Ghana
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Module 4: Burden of Disease Tutorial Slides S2 2025
FourierSeries-QuestionsWithAnswers(Part-A).pdf
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
Institutional Correction lecture only . . .
Classroom Observation Tools for Teachers
Pharma ospi slides which help in ospi learning
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Computing-Curriculum for Schools in Ghana
VCE English Exam - Section C Student Revision Booklet
Supply Chain Operations Speaking Notes -ICLT Program

Ec2308 microprocessor and_microcontroller__lab1

  • 1. SMK FOMRA INSTITUTE OF TECHNOLOGY Old Mahabalipuram Road, (I.T.High Way), Kelambakkam,Chennai, Tamilnadu 603103 DEPARTMENT ELECTRONICS AND COMMUNICATION ENGINEERING EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB V SEMSTER 2010-2011 NAME:___________________________________ YEAR/SEM: _______________BRANCH:_______ REG. NO.:________________________________
  • 2. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: ADDITION & SUBTRACTION AIM: To write an Assembly Language Program (ALP) for performing the addition and subtraction operation of two byte numbers. APPARATUS REQUIRED: SL.N ITEM SPECIFICATION QUANTITY O 1. Microprocessor kit 8086 kit 1 2. Power Supply +5 V dc 1 PROBLEM STATEMENT: Write an ALP in 8086 to add and subtract two byte numbers stored in the memory location 1000H to 1003H and store the result in the memory location 1004H to 1005H.Also provide an instruction in the above program to consider the carry also and store the carry in the memory location 1006H. ALGORITHM: (i) 16-bit addition h)Initialize the MSBs of sum to 0 i)Get the first number. j)Add the second number to the first number. k)If there is any carry, increment MSBs of sum by 1. l)Store LSBs of sum. m)Store MSBs of sum. (ii) 16-bit subtraction f)Initialize the MSBs of difference to 0 g)Get the first number h)Subtract the second number from the first number. i)If there is any borrow, increment MSBs of difference by 1. j)Store LSBs of difference k)Store MSBs of difference. 2
  • 3. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FLOWCHART ADDITION SUBTRACTION START START SET UP COUNTER (CY) SET UP COUNTER (CARRY) GET FIRST OPERAND GET FIRST OPERAND TO A GET SECOND OPERAND SUBTRACT TO A SECOND OPERAND FROM MEMORY YES A=A+B IS THERE ANY CY YES NO COUNTER = IS THERE ANY COUNTER + 1 COUNTER = COUNTER + 1 STORE THE DIFFERENCE NO STORE THE SUM STORE THE CARRY STORE THE CARRY STOP STOP 3
  • 4. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE ADDITION PROGRAM COMMENTS MOV CX, 0000H Initialize counter CX MOV AX,[1200] Get the first data in AX reg MOV BX, [1202] Get the second data in BX reg ADD AX,BX Add the contents of both the regs AX & BX JNC L1 Check for carry INC CX If carry exists, increment the CX L1 : MOV [1206],CX Store the carry MOV [1204], AX Store the sum HLT Stop the program SUBTRACTION PROGRAM COMMENTS MOV CX, 0000H Initialize counter CX MOV AX,[1200] Get the first data in AX reg MOV BX, [1202] Get the second data in BX reg SUB AX,BX Subtract the contents of BX from AX JNC L1 Check for borrow INC CX If borrow exists, increment the CX L1 : MOV [1206],CX Store the borrow MOV [1204], AX Store the difference HLT Stop the program RESULT:. 4
  • 5. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE ADDITION MEMORY DATA SUBTRACTION MEMORY DATA MANUAL CALCULATION Thus addition & subtraction of two byte numbers are performed and the result is stored. 5
  • 6. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: MULTIPLICATION & DIVISION AIM: To write an Assembly Language Program (ALP) for performing the multiplication and division operation of 16-bit numbers . APPARATUS REQUIRED: SL.N ITEM SPECIFICATION QUANTITY O 1. Microprocessor kit 8086 1 2. Power Supply +5 V dc 1 PROBLEM STATEMENT: Write an ALP in 8086 MP to multiply two 16-bit binary numbers and store the result in the memory location. Write instructions for dividing the data and store the result. ALGORITHM: (i)Multiplication of 16-bit numbers: a)Get the multiplier. b)Get the multiplicand c)Initialize the product to 0. d)Product = product + multiplicand e)Decrement the multiplier by 1 f)If multiplicand is not equal to 0,repeat from step (d) otherwise store the product. (ii)Division of 16-bit numbers. a)Get the dividend b)Get the divisor c)Initialize the quotient to 0. d)Dividend = dividend – divisor e)If the divisor is greater, store the quotient. Go to step g. f)If dividend is greater, quotient = quotient + 1. Repeat from step (d) g)Store the dividend value as remainder. 6
  • 7. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FLOWCHART MULTIPLICATION DIVISION Start Start Load Divisor & Get Multiplier & Multiplicand Dividend MULTIPLICAND QUOTIENT = 0 REGISTER=00 DIVIDEND = DIVIDEND-DIVISOR REGISTER = REGISTER + MULTIPLICAND QUOTIENT = QUOTIENT+1 Multiplier=MU LTIPLIER – 1 IS NO DIVIDEN D< DIVISOR NO IS ? MULTIPLIER =0? YES YES STORE QUOTIENT STORE REMAINDER STORE THE RESULT = DIVIDEND NOW STOP STOP 7
  • 8. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MULTIPLICATION PROGRAM COMMENTS MOV AX,[1200] Get the first data MOV BX, [1202] Get the second data MUL BX Multiply both MOV [1206],AX Store the lower order product MOV AX,DX Copy the higher order product to AX MOV [1208],AX Store the higher order product HLT Stop the program DIVISION PROGRAM COMMENTS MOV AX,[1200] Get the first data MOV DX, [1202] Get the second data MOV BX, [1204] Divide the dividend by divisor DIV BX Store the lower order product MOV [1206],AX Copy the higher order product to AX MOV AX,DX Store the higher order product MOV [1208],AX Stop the program HLT Get the first data 8
  • 9. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE RESULT:. MULTIPLICATION MEMORY DATA DIVISON MEMORY DATA MANUAL CALCULATION Thus multiplication & division of two byte numbers are performed and the result is stored. 9
  • 10. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: ASCENDING & DESCENDING AIM: To write an Assembly Language Program (ALP) to sort a given array in ascending and descending order. APPARATUS REQUIRED: SL.N ITEM SPECIFICATION QUANTITY O 1. Microprocessor kit 8086 1 2. Power Supply +5 V dc 1 PROBLEM STATEMENT: An array of length 10 is given from the location. Sort it into descending and ascending order and store the result. ALGORITHM: (i)Sorting in ascending order: a.Load the array count in two registers C1 and C2. b.Get the first two numbers. c.Compare the numbers and exchange if necessary so that the two numbers are in ascending order. d.Decrement C2. e.Get the third number from the array and repeat the process until C2 is 0. f.Decrement C1 and repeat the process until C1 is 0. (ii)Sorting in descending order: a.Load the array count in two registers C1 and C2. b.Get the first two numbers. c.Compare the numbers and exchange if necessary so that the two numbers are in descending order. d.Decrement C2. e.Get the third number from the array and repeat the process until C2 is 0. f.Decrement C1 and repeat the process until C1 is 0. 10
  • 11. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FLOWCHART ASCENDING ORDER DESCENDING ORDER START START INITIALIZE POINTER INITIALIZE POINTER COUNT = COUNT – 1 COUNT = COUNT – 1 YES YES IS IS POINTER POINTER NO NO TEMP = POINTER TEMP = POINTER POINTER = POINTER + 1 POINTER = POINTER + 1 POINTER + 1 = TEMP POINTER + 1 = TEMP POINTER = POINTER +1 POINTER = POINTER +1 COUNT = COUNT + 1 COUNT = COUNT + 1 NO NO IS IS COUNT COUNT YES YES NO IS IS FLAG FLAG YES YES STOP STOP 11
  • 12. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE ASCENDING PROGRAM COMMENTS MOV SI,1200H Initialize memory location for array size MOV CL,[SI] Number of comparisons in CL L4 : MOV SI,1200H Initialize memory location for array size MOV DL,[SI] Get the count in DL INC SI Go to next memory location MOV AL,[SI] Get the first data in AL L3 : INC SI Go to next memory location MOV BL,[SI] Get the second data in BL CMP AL,BL Compare two data’s JNB L1 If AL < BL go to L1 DEC SI Else, Decrement the memory location MOV [SI],AL Store the smallest data MOV AL,BL Get the next data AL JMP L2 Jump to L2 L1 : DEC SI Decrement the memory location MOV [SI],BL Store the greatest data in memory location L2 : INC SI Go to next memory location DEC DL Decrement the count JNZ L3 Jump to L3, if the count is not reached zero MOV [SI],AL Store data in memory location DEC CL Decrement the count JNZ L4 Jump to L4, if the count is not reached zero HLT Stop DESCENDING PROGRAM COMMENTS MOV SI,1200H Initialize memory location for array size MOV CL,[SI] Number of comparisons in CL L4 : MOV SI,1200H Initialize memory location for array size MOV DL,[SI] Get the count in DL INC SI Go to next memory location MOV AL,[SI] Get the first data in AL L3 : INC SI Go to next memory location MOV BL,[SI] Get the second data in BL CMP AL,BL Compare two data’s 12
  • 13. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE JB L1 If AL > BL go to L1 DEC SI Else, Decrement the memory location MOV [SI],AL Store the largest data MOV AL,BL Get the next data AL JMP L2 Jump to L2 L1 : DEC SI Decrement the memory location MOV [SI],BL Store the smallest data in memory location L2 : INC SI Go to next memory location DEC DL Decrement the count JNZ L3 Jump to L3, if the count is not reached zero MOV [SI],AL Store data in memory location DEC CL Decrement the count JNZ L4 Jump to L4, if the count is not reached zero HLT Stop RESULT:. ASCENDING MEMORY DATA DESCENDING MEMORY DATA Thus given array of numbers are sorted in ascending & descending order. 13
  • 14. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: LARGEST& SMALLEST AIM: To write an Assembly Language Program (ALP) to find the largest and smallest number in a given array. APPARATUS REQUIRED: SL.N ITEM SPECIFICATION QUANTITY O 1. Microprocessor kit 8086 1 2. Power Supply +5 V dc 1 PROBLEM STATEMENT: An array of length 10 is given from the location. Find the largest and smallest number and store the result. ALGORITHM: (i)Finding largest number: a.Load the array count in a register C1. b.Get the first two numbers. c.Compare the numbers and exchange if the number is small. d.Get the third number from the array and repeat the process until C1 is 0. (ii)Finding smallest number: e.Load the array count in a register C1. f.Get the first two numbers. g.Compare the numbers and exchange if the number is large. h.Get the third number from the array and repeat the process until C1 is 0. 14
  • 15. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FLOWCHART LARGEST NUMBER IN AN ARRAY SMALLEST NUMBER IN AN ARRAY START START INITIALIZE INITIALIZE COUNT COUNT POINTER MAX = POINTER MIN = 0 PONITER = PONITER = POINTER + 1 POINTER + 1 YES IS MAX IS MIN ≥ ≥ POINTE YES NO NO MAX = POINTER MIN = POINTER COUNT = COUNT-1 COUNT = COUNT-1 NO NO IS COUNT = IS COUNT = 0 0 YES YES STORE MAXIMUM STORE MINIIMUM STOP STOP 15
  • 16. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE LARGEST PROGRAM COMMENTS MOV SI,1200H Initialize array size MOV CL,[SI] Initialize the count INC SI Go to next memory location MOV AL,[SI] Move the first data in AL DEC CL Reduce the count L2 : INC SI Move the SI pointer to next data CMP AL,[SI] Compare two data’s JNB L1 If AL > [SI] then go to L1 ( no swap) MOV AL,[SI] Else move the large number to AL L1 : DEC CL Decrement the count JNZ L2 If count is not zero go to L2 MOV DI,1300H Initialize DI with 1300H MOV [DI],AL Else store the biggest number in 1300 location HLT Stop SMALLEST PROGRAM COMMENTS MOV SI,1200H Initialize array size MOV CL,[SI] Initialize the count INC SI Go to next memory location MOV AL,[SI] Move the first data in AL DEC CL Reduce the count L2 : INC SI Move the SI pointer to next data CMP AL,[SI] Compare two data’s JB L1 If AL < [SI] then go to L1 ( no swap) MOV AL,[SI] Else move the large number to AL L1 : DEC CL Decrement the count JNZ L2 If count is not zero go to L2 MOV DI,1300H Initialize DI with 1300H MOV [DI],AL Else store the biggest number in 1300 location HLT Stop 16
  • 17. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE RESULT:. LARGEST MEMORY DATA SMALLEST MEMORY DATA Thus largest and smallest number is found in a given array. 17
  • 18. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: COPYING A STRING AIM: To move a string of length FF from source to destination. ALGORITHM: a. Initialize the data segment .(DS) b. Initialize the extra data segment .(ES) c. Initialize the start of string in the DS. (SI) d. Initialize the start of string in the ES. (DI) e. Move the length of the string(FF) in CX register. f. Move the byte from DS TO ES, till CX=0. START ` Initialize DS,ES,SI,DI CX=length of string, DF=0. Move a byte from source string (DS) to destination string (ES) Decrement CX ` NO Check for ZF=1 STOP 18
  • 19. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE COPYING A STRING PROGRAM COMMENTS MOV SI,1200H Initialize destination address MOV DI,1300H Initialize starting address MOV CX,0006H Initialize array size CLD Clear direction flag REP MOVSB Copy the contents of source into destination until count reaches zero HLT Stop RESULT: INPUT MEMORY DATA OUTPUT MEMORY DATA Thus a string of a particular length is moved from source segment to destination segment. 19
  • 20. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: SEARCHING A STRING AIM: To scan for a given byte in the string and find the relative address of the byte from the starting location of the string. ALGORITHM: a. Initialize the extra segment .(ES) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI to BX. START Initialize DS,ES ,SI,DI CX=length of the string, DF=0. Scan for a particular character specified in AL Register. NO Check for ZF=1 Move DI to BX STOP 20
  • 21. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE SEARCHING FOR A CHARACTER IN THE STRING PROGRAM COMMENTS MOV DI,1300H Initialize destination address MOV SI, 1400H Initialize starting address MOV CX, 0006H Initialize array size CLD Clear direction flag MOV AL, 08H Store the string to be searched REPNE SCASB Scan until the string is found DEC DI Decrement the destination address MOV BL,[DI] Store the contents into BL reg MOV [SI],BL Store content of BL in source address HLT Stop RESULT: INPUT MEMORY DATA OUTPUT MEMORY LOCATION DATA Thus a given byte or word in a string of a particular length in the extra segment(destination) is found . 21
  • 22. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 PROGRAMMING DATE: FIND AND REPLACE AIM: To find a character in the string and replace it with another character. ALGORITHM: a. Initialize the extra segment .(E S) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Store the ASCII code of the character that has to replace the scanned byte in BL register. f. Scan for the byte in ES. If the byte is not found, ZF≠1 and repeat scanning. g. If the byte is found, ZF=1.Move the content of BL register to ES:DI. START Initialize DS, ES, SI, DI CX=length of the string in ES, DF=0. DF=0. Scan for a particular character specified in AL Register. NO Check for ZF=1 YES Move the content of BL to ES:DI ¿ STOP 22
  • 23. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FIND AND REPLACE A CHARACTER IN THE STRING PROGRAM COMMENTS MOV DI,1300H Initialize destination address MOV SI,1400H Initialize starting address MOV CX, 0006H Initialize array size CLD Clear direction flag MOV AL, 08H Store the string to be searched MOV BH,30H Store the string to be replaced REPNE SCASB Scan until the string is found DEC DI Decrement the destination address MOV BL,[DI] Store the contents into BL reg MOV [SI],BL Store content of BL in source address MOV [DI],BH Replace the string HLT Stop RESULT: INPUT MEMORY DATA OUTPUT MEMORY DATA Thus a given byte or word in a string of a particular length in the extra segment(destination) is found and is replaced with another character. 23
  • 24. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8086 INTERFACING DATE: INTERFACING ANALOG TO DIGITAL CONVERTER AIM: To write an assembly language program to convert an analog signal into a digital signal using an ADC interfacing. APPARATUS REQUIRED: SL.NO ITEM SPECIFICATION QUANTITY 1. Microprocessor kit 8086 1 2. Power Supply +5 V dc,+12 V dc 1 3. ADC Interface board - 1 PROBLEM STATEMENT: The program is executed for various values of analog voltage which are set with the help of a potentiometer. The LED display is verified with the digital value that is stored in a memory location. THEORY: An ADC usually has two additional control lines: the SOC input to tell the ADC when to start the conversion and the EOC output to announce when the conversion is complete. The following program initiates the conversion process, checks the EOC pin of ADC 0809 as to whether the conversion is over and then inputs the data to the processor. It also instructs the processor to store the converted digital data at RAM location. ALGORITHM: (i) Select the channel and latch the address. (ii) Send the start conversion pulse. (iii) Read EOC signal. (iv) If EOC = 1 continue else go to step (iii) (v) Read the digital output. (vi) Store it in a memory location. FLOW CHART: STAR SELECT THE CHANNEL AND LATCH ADDRESS SEND THE START CONVERSION PULSE NO IS EOC = 1? YES READ THE DIGITALOUTPUT STORE THE DIGITAL VALUE IN THE MEMORY LOCATION SPECIFIED STOP 24
  • 25. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAM TABLE PROGRAM COMMENTS MOV AL,00 Load accumulator with value for ALE high OUT 0C8H,AL Send through output port MOV AL,08 Load accumulator with value for ALE low OUT 0C8H,AL Send through output port MOV AL,01 Store the value to make SOC high in the accumulator OUT 0D0H,AL Send through output port MOV AL,00 MOV AL,00 Introduce delay MOV AL,00 MOV AL,00 Store the value to make SOC low the accumulator OUT 0D0H,AL Send through output port L1 : IN AL, 0D8H AND AL,01 Read the EOC signal from port & check for end of conversion CMP AL,01 JNZ L1 If the conversion is not yet completed, read EOC signal from port again IN AL,0C0H Read data from port MOV BX,1100 Initialize the memory location to store data MOV [BX],AL Store the data HLT Stop RESULT: ANALOG DIGITAL DATA ON LED HEX CODE IN MEMORY VOLTAGE DISPLAY LOCATION Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its digital equivalent. EXPT NO: 8086 INTERFACING DATE: INTERFACING DIGITAL – TO – ANALOG CONVERTER AIM : 25
  • 26. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 1. To write an assembly language program for digital to analog conversion 2. To convert digital inputs into analog outputs & To generate different waveforms APPARATUS REQUIRED: SL.NO ITEM SPECIFICATION QUANTITY 1. Microprocessor kit 8086 Vi Microsystems 1 2. Power Supply +5 V, dc,+12 V dc 1 3. DAC Interface board - 1 PROBLEM STATEMENT: The program is executed for various digital values and equivalent analog voltages are measured and also the waveforms are measured at the output ports using CRO. THEORY: Since DAC 0800 is an 8 bit DAC and the output voltage variation is between –5v and +5v. The output voltage varies in steps of 10/256 = 0.04 (approximately). The digital data input and the corresponding output voltages are presented in the table. The basic idea behind the generation of waveforms is the continuous generation of analog output of DAC. With 00 (Hex) as input to DAC2 the analog output is –5v. Similarly with FF H as input, the output is +5v. Outputting digital data 00 and FF at regular intervals, to DAC2, results in a square wave of amplitude 5v.Output digital data from 00 to FF in constant steps of 01 to DAC2. Repeat this sequence again and again. As a result a saw-tooth wave will be generated at DAC2 output. Output digital data from 00 to FF in constant steps of 01 to DAC2. Output digital data from FF to 00 in constant steps of 01 to DAC2. Repeat this sequence again and again. As a result a triangular wave will be generated at DAC2 output. ALGORITHM: Measurement of analog voltage: (i) Send the digital value of DAC. (ii) Read the corresponding analog value of its output. Waveform generation: Square Waveform: (i) Send low value (00) to the DAC. (ii) Introduce suitable delay. (iii) Send high value to DAC. (iv) Introduce delay. (v) Repeat the above procedure. Saw-tooth waveform: (i) Load low value (00) to accumulator. (ii) Send this value to DAC. (iii) Increment the accumulator. (iv) Repeat step (ii) and (iii) until accumulator value reaches FF. (v) Repeat the above procedure from step 1. Triangular waveform: (i) Load the low value (00) in accumulator. (ii) Send this accumulator content to DAC. (iii) Increment the accumulator. (iv) Repeat step 2 and 3 until the accumulator reaches FF, decrement the accumulator and send the accumulator contents to DAC. (v) Decrementing and sending the accumulator contents to DAC. (vi) The above procedure is repeated from step (i) FLOWCHART: MEASUREMENT OF ANALOG VOLTAGE SQUARE WAVE FORM START START 26
  • 27. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE INTIALISE THE ACCUMULATOR SEND ACC CONTENT TO DAC SEND THE DIGITALVALUE TO ACCUMULATOR DELAY TRANSFER THE ACCUMULATOR CONTENTS LOAD THE ACC WITH MAX VALUE SEND ACC CONTENT TO DAC READ THE CORRESPONDING DELAY ANALOG VALUE STOP TRIANGULAR WAVEFORM STAR SAWTOOTH WAVEFORM STAR INITIALIZE ACCUMULATOR INITIALIZE SEND ACCUMULATOR ACCUMULATOR CONTENT TO DAC SEND ACCUMULATOR INCREMENT ACCUMULATOR CONTENT TO DAC YES INCREMENT IS ACC ≤ ACCUMULATOR FF CONTENT NO NO YES DECREMENT IS ACCUMULATOR CONTENT ACC ≤ SEND ACCUMULATOR MEASUREMENT OF ANALOG VOLTAGE: IS ACC ≤ YES 00 NO PROGRAM COMMENTS 27
  • 28. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MOV AL,7FH Load digital value 00 in accumulator OUT C0,AL Send through output port HLT Stop DIGITAL DATA ANALOG VOLTAGE PROGRAM TABLE: Square Wave PROGRAM COMMENTS L2 : MOV AL,00H Load 00 in accumulator OUT C0,AL Send through output port CALL L1 Give a delay MOV AL,FFH Load FF in accumulator OUT C0,AL Send through output port CALL L1 Give a delay JMP L2 Go to starting location L1 : MOV CX,05FFH Load count value in CX register L3 : LOOP L3 Decrement until it reaches zero RET Return to main program PROGRAM TABLE: Saw tooth Wave PROGRAM COMMENTS L2 : MOV AL,00H Load 00 in accumulator L1 : OUT C0,AL Send through output port INC AL Increment contents of accumulator JNZ L1 Send through output port until it reaches FF JMP L2 Go to starting location 28
  • 29. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAM TABLE: Triangular Wave PROGRAM COMMENTS L3 : MOV AL,00H Load 00 in accumulator L1 : OUT C0,AL Send through output port INC AL Increment contents of accumulator JNZ L1 Send through output port until it reaches FF MOV AL,0FFH Load FF in accumulator L2 : OUT C0,AL Send through output port DEC AL Decrement contents of accumulator JNZ L2 Send through output port until it reaches 00 JMP L3 Go to starting location RESULT:WAVEFORM GENERATION: WAVEFORMS AMPLITUDE TIMEPERIOD Square Waveform Saw-tooth waveform Triangular waveform MODEL GRAPH: Square Waveform Saw-tooth waveform Triangular waveform Thus the DAC was interfaced with 8085 and different waveforms have been generated. 29
  • 30. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP.NO: STEPPER MOTOR INTERFACING DATE: AIM: To write an assembly language program in 8086 to rotate the motor at different speeds. APPARATUS REQUIRED: SL.NO ITEM SPECIFICATION QUANTITY 1. Microprocessor kit 8086 1 2. Power Supply +5 V, dc,+12 V dc 1 3. Stepper Motor Interface board - 1 4. Stepper Motor - 1 PROBLEM STATEMENT: Write a code for achieving a specific angle of rotation in a given time and particular number of rotations in a specific time. THEORY: A motor in which the rotor is able to assume only discrete stationary angular position is a stepper motor. The rotary motion occurs in a stepwise manner from one equilibrium position to the next.Two-phase scheme: Any two adjacent stator windings are energized. There are two magnetic fields active in quadrature and none of the rotor pole faces can be in direct alignment with the stator poles. A partial but symmetric alignment of the rotor poles is of course possible. ALGORITHM: For running stepper motor clockwise and anticlockwise directions (i) Get the first data from the lookup table. (ii) Initialize the counter and move data into accumulator. (iii) Drive the stepper motor circuitry and introduce delay (iv) Decrement the counter is not zero repeat from step(iii) (v) Repeat the above procedure both for backward and forward directions. SWITCHING SEQUENCE OF STEPPER MOTOR: MEMORY A1 A2 B1 B2 HEX LOCATION CODE 4500 1 0 0 0 09 H 4501 0 1 0 1 05 H 4502 0 1 1 0 06 H 4503 1 0 1 0 0A H 30
  • 31. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE FLOWCHART: STAR T INTIALIZE COUNTER FOR LOOK UP TABLE GET THE FIRST DATA FROM THE ACCUMULATOR MOVE DATA INTO THE ACCUMULATOR DRIVE THE MOTOR CIRCUITARY DELAY DECREMENT COUNTER YES IS B = 0 ? NO GET THE DATA FROM LOOK UP TABLE PROGRAM TABLE PROGRAM COMMENTS START : MOV DI, 1200H Initialize memory location to store the array of number MOV CX, 0004H Initialize array size LOOP 1 : MOV AL,[DI] Copy the first data in AL OUT 0C0,AL Send it through port address MOV DX, 1010H L1 : DEC DX Introduce delay JNZ L1 INC DI Go to next memory location LOOP LOOP1 Loop until all the data’s have been sent JMP START Go to start location for continuous rotation 1200 : 09,05,06,0A Array of data’s RESULT: Thus the assembly language program for rotating stepper motor in both clockwise and anticlockwise directions is written and verified. 31
  • 32. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP.NO: INTERFACING PRGRAMMABLE KEYBOARD AND DISPLAY CONTROLLER- 8279 DATE: AIM : To display the rolling message “ HELP US “ in the display. APPARATUS REQUIRED: 8086 Microprocessor kit, Power supply, Interfacing board. ALGORITHM : Display of rolling message “ HELP US “ 1. Initialize the counter 2. Set 8279 for 8 digit character display, right entry 3. Set 8279 for clearing the display 4. Write the command to display 5. Load the character into accumulator and display it 6. Introduce the delay 7. Repeat from step 1. 1. Display Mode Setup: Control word-10 H 0 0 0 1 0 0 0 0 0 0 0 D D K K K DD 00- 8Bit character display left entry 01- 16Bit character display left entry 10- 8Bit character display right entry 11- 16Bit character display right entry KKK- Key Board Mode 000-2Key lockout. 2.Clear Display: Control word-DC H 1 1 0 1 1 1 0 0 1 1 0 CD CD CD CF CA 11 A0-3; B0-3 =FF 1-Enables Clear display 0-Contents of RAM will be displayed 1-FIFO Status is cleared 1-Clear all bits (Combined effect of CD) 32
  • 33. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 3. Write Display: Control word-90H 1 0 0 1 0 0 0 0 1 0 0 AI A A A A Selects one of the 16 rows of display. Auto increment = 1, the row address selected will be incremented after each of read and write operation of the display RAM. FLOWCHART: SET UP POINTER INITIALIZE THE COUNTER SET 8279 FOR 8-DIGIT CHARACTER DISPLAY SET 8279 FOR CLEARING THE DISPLAY WRITE THE COMMAND TO DISPLAY LOAD THE CHARACTER INTO ACCUMULATOR AND DISPLAY DELAY 33
  • 34. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAM TABLE PROGRAM COMMENTS START : MOV SI,1200H Initialize array MOV CX,000FH Initialize array size MOV AL,10 Store the control word for display mode OUT C2,AL Send through output port MOV AL,CC Store the control word to clear display OUT C2,AL Send through output port MOV AL,90 Store the control word to write display OUT C2,AL Send through output port L1 : MOV AL,[SI] Get the first data OUT C0,AL Send through output port CALL DELAY Give delay INC SI Go & get next data LOOP L1 Loop until all the data’s have been taken JMP START Go to starting location DELAY : MOV DX,0A0FFH Store 16bit count value LOOP1 : DEC DX Decrement count value JNZ LOOP1 Loop until count values becomes zero RET Return to main program LOOK-UP TABLE: 1200 98 68 7C C8 1204 FF 1C 29 FF RESULT: MEMORY 7-SEGMENT LED FORMAT HEX DATA LOCATION d c b a dp e g f 1200H 1 0 0 1 1 0 0 0 98 1201H 0 1 1 0 1 0 0 0 68 1202H 0 1 1 1 1 1 0 0 7C 1203H 1 1 0 0 1 0 0 0 C8 1204H 1 1 1 1 1 1 1 1 FF 1205H 0 0 0 0 1 1 0 0 1C 1206H 0 0 1 0 1 0 0 1 29 1207H 1 1 1 1 1 1 1 1 FF Thus the rolling message “HELP US” is displayed using 8279 interface kit. 34
  • 35. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP. NO: INTERFACING PROGRAMMABLE TIMER-8253 DATE: AIM : To study different modes of operation of programmable timer 8253 APPARATUS REQUIRED: SL.NO ITEM SPECIFICATION QUANTITY 1. Microprocessor kit 8086 Vi Microsystems 1 2. Power Supply +5V dc 1 3. 8253 interfacing kit - 1 4. CRO - 1 THEORY: The main features of the timer are, i. Three independent 16-bit counters ii. Input clock from DC to 2 MHz iii. Programmable counter modes iv. Count binary or BCD The control signals with which the 8253 interfaces with the CPU are CS, RD, WR, A1, A2.The basic operations performed by 8253 are determined by these control signals. It has six different modes of operation, viz, mode 0 to mode 5. MODE 2 – RATE GENERATOR It is a simple divide - by – N counter. The output will be low for one input clock period. The period from one output pulse to the next equals the number of input counts in the count register. If the count register is reloaded between output pulses, the present period will not be affected, but the subsequent period will reflect the new value. MODE 3 – SQUARE WAVE GENERATOR It is similar to mode 2, except that the output will remain high until one half for even number count, If the count is odd, the output will be high for (count+1)/2 counts and low for (count-1)/2 counts ALGORITHM: Mode 2- 1. Initialize channel 0 in mode 2 2. Initialize the LSB of the count. 3. Initialize the MSB of the count. 4. Trigger the count 5. Read the corresponding output in CRO. 35
  • 36. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE Mode 3- 1. Initialize channel 0 in mode 3 2. Initialize the LSB of the count. 3. Initialize the MSB of the count. 4. Trigger the count 5. Read the corresponding output in CRO. PORT ADDRESS : 1. CONTROL REGISTER – 2. COUNTER OF CHANNEL 0 - 3. COUNTER OF CHANNEL 1 - 4. COUNTER OF CHANNEL 2 - 5. O/P PORT OF CHANNEL 0 - 6. O/P PORT OF CHANNEL 1 - 7. O/P PORT OF CHANNEL 2 - CONTROL WORD FORMAT: D7 D6 D5 D4 D3 D2 D1 D0 SC1 SC0 RL1 RL0 M2 M1 M0 BCD 0 0 1 1 0 1 0 0 Mode 2 = 34 H 0 0 1 1 0 1 1 0 Mode 3 = 36 H SC1 SC0 CHANNEL SELECT RL1 RL0 READ/LOAD 0 0 CHANNEL 0 0 0 LATCH 0 1 CHANNEL 1 0 1 LSB 1 0 CHANNEL 2 1 0 MSB 1 1 ----- 1 1 LSB FIRST, MSB NEXT BCD --0 –BINARY COUNTER 1 --BCD COUNTER M2 M1 M0 MODE 1 CLK 0 0 0 0 MODE 0 0 0 2 CLK 1 1 MODE 1 0 1 0 MODE 2 0 1 3 CLK 2 1 MODE 3 1 0 0 MODE 4 1 0 4 OUT 0 1 MODE 5 5 OUT 1 PORT PIN ARRANGEMENT DEBOUNCE CIRCUIT CONNECTION 6 OUT 2 * * * 7 GATE 0 8 GATE 1 9 GATE 2 36 10 GND
  • 37. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MODE 2 – RATE GENERATOR: PROGRAM COMMENTS MOV AL, 34H Store the control word in accumulator OUT 0BH Send through output port MOV AL, 0AH Copy lower order count value in accumulator OUT 08H Send through output port MOV AL, 00H Copy higher order count value in accumulator OUT 08H Send through output port HLT Stop MODE 3 – SQUARE WAVE GENERATOR: PROGRAM COMMENTS MOV AL, 36H Store the control word in accumulator OUT 0BH Send through output port MOV AL, 0AH Copy lower order count value in accumulator OUT 08H Send through output port MOV AL, 00H Copy higher order count value in accumulator OUT 08H Send through output port HLT Stop 37
  • 38. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MODEL GRAPH: RATE GENERATOR SQUARE WAVE GENERATOR FLOW CHART START INITIALIZE ACCUMULATOR WITH MODE SET WORD INITIALIZE LSB OF COUNT INITIALIZE MSB OF COUNT TRIGGER THE COUNT STOP RESULT: Thus an ALP for rate generator and square wave generator are written and executed. 38
  • 39. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP. NO: INTERFACING USART 8251 DATE: AIM: To study interfacing technique of 8251 (USART) with microprocessor 8086 and write an 8086 ALP to transmit and receive data between two serial ports with RS232 cable. APPARATUS REQUIRED: 8086 kit (2 Nos), RS232 cable. THEORY: The 8251 is used as a peripheral device for serial communication and is programmed by the CPU to operate using virtually any serial data transmission technique. The USART accepts data characters from the CPU in parallel format and then converts them into a continuous serial data stream for transmission. Simultaneously, it can receive serial data streams and convert them into parallel data characters for the CPU. The CPU can read the status of the USART at any time. These include data transmission errors and control signals. The control signals define the complete functional definition of the 8251. Control words should be written into the control register of 8251.These control words are split into two formats: 1) Mode instruction word & 2) Command instruction word. Status word format is used to examine the error during functional operation. 1...transmit enable 1...data terminal ready 1... receive enable 1... send break character 1.... reset error flags (pe,oe,fe) 1..... request to send (rts) 1...... internal reset 1....... enter hunt mode (enable search for sync characters) 1 ransmitter ready 1. receiver ready 1.. transmitter empty 1... parity error (pe) 1.... overrun error (oe) 1..... framing error (fe), async only 1...... sync detect, sync only 1....... data set ready (dsr) 39
  • 40. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE ALGORITHM: 1.Initialize 8253 and 8251 to check the transmission and reception of a character 2.Initialize8253 to give an output of 150Khz at channel 0 which will give a 9600 baud rate of 8251. 3.The command word and mode word is written to the 8251 to set up for subsequent operations 4.The status word is read from the 8251 on completion of a serial I/O operation, or when the host CPU is checking the status of the device before starting the next I/O operation FLOW CHART: STAR Check TX/RX Ready No Is it High Yes Write Data into data register STOP 40
  • 41. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAM: TRANSMITTER END PROGRAM COMMENTS MOV AL,36 Initialize 8253 in mode 3 square wave generator OUT CE,AL Send through port address MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz) OUT C8,AL Send through port address MOV AL,00 Initialize AL with higher value of count OUT C8,AL Send through port address MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) OUT C2,AL Send through port address MOV AL,37 Set command instruction(enables transmit enable & receive enable bits) OUT C2,AL Send through port address L1:IN AL,C2 Read status word AND AL,04 Check whether transmitter ready JZ L1 If not wait until transmitter becomes ready MOV AL,41 Set the data as 41 OUT C0,AL Send through port address INT 2 Restart the system RECEIVER END PROGRAM COMMENTS MOV AL,36 Initialize 8253 in mode 3 square wave generator OUT CE,AL Send through port address MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz) OUT C8,AL Send through port address MOV AL,00 Initialize AL with higher value of count OUT C8,AL Send through port address MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) OUT C2,AL Send through port address MOV AL,37 Set command instruction(enables transmit enable & receive enable bits) OUT C2,AL Send through port address L1:IN AL,C2 Read status word AND AL,02 Check whether receiver ready JZ L1 If not wait until receiver becomes ready IN AL,C0 If it is ready, get the data MOV BX,1500 Initialize BX register with memory location to store the data MOV [BX],AL Store the data in the memory location INT 2 Restart the system RESULT: Thus ALP for serial data communication using USART 8251 is written and the equivalent ASCII 41 for character ‘A’ is been transmitted & received. 41
  • 42. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP. NO: INTERFACING PPI 8255 DATE: AIM: To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and mode 2 APPARATUS REQUIRED: 8086 kit, 8255 interface kit. ALGORITHM: Mode 0 1. Initialize accumulator to hold control word 2. store control word in control word register 3. Read data port A. 4. Store data from port A in memory 5. Place contents in port B Mode 1 & Mode 2 1. Initialize accumulator to hold control word (for port A) 2. Store control word in control word register 3. Initialize accumulator to hold control word (for port B) 4. Place contents in control word register. 5. Disable all maskable interrupts, enable RST 5.5 6. send interrupt mask for RST 6.5 & 7.5 7. Enable interrupt flag 8. Read data from port A, place contents in port B FLOWCHART Mode 0 Mode 1 & 2 STAR STAR Store control word in control register Store control word in control register Input to be read from port A Input to be read from port A Disable all interrupts except RST 6.5 Store into accumulator Store output to port B Output written on port B STOP STOP 42
  • 43. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MODE 0 PROGRAM COMMENTS MOV AL,90H Set the control word OUT C6,AL Send it to control port IN AL,C0 Get the contents of port A in AL OUT C2,AL Send the contents of port B to port address HLT Stop MODE 1 PROGRAM COMMENTS MOV AL,0B0H Set the control word for mode 1 OUT C6,AL Send it to control port MOV AL,09H Control for BSR mode OUT C6,AL Send it to control port MOV AL,13H Interrupt generation OUT 30,AL MOV AL,0AH Through 8259 OUT 32,AL MOV AL,0FH Using IR2 interrupt(lower order count) OUT 32,AL MOV AL,00H Higher order count OUT 32,AL STI Set trap flag HLT Stop ISR: Subroutine IN AL,C0 Read from Port A OUT C2,AL Send it to Port B HLT Stop MODE 2 PROGRAM COMMENTS MOV AL,0C0H Set the control word for mode 2 OUT C6,AL Send it to control port MOV AL,09H Control for BSR mode OUT C6,AL Send it to control port MOV AL,13H Interrupt generation OUT 30,AL MOV AL,0AH Through 8259 OUT 32,AL 43
  • 44. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MOV AL,0FH Using IR2 interrupt(lower order count) OUT 32,AL MOV AL,00H Higher order count OUT 32,AL STI Set trap flag HLT Stop ISR: Subroutine IN AL,C0 Read from Port A OUT C2,AL Send it to Port B HLT Stop BSR mode Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word: D7 D6 D5 D4 D3 D2 D1 D0 0 (0=BSR) X X X B2 B1 B0 S/R (1=S,0=R) Bit select: (Taking Don't care's as 0) B2 B1 B0 PC bit Control word (Set) Control word (reset) 0 0 0 0 0000 0001 = 01h 0000 0000 = 00h 0 0 1 1 0000 0011 = 03h 0000 0010 = 02h 0 1 0 2 0000 0101 = 05h 0000 0100 = 04h 0 1 1 3 0000 0111 = 07h 0000 0110 = 06h 1 0 0 4 0000 1001 = 09h 0000 1000 = 08h 1 0 1 5 0000 1011 = 0Bh 0000 1010 = 0Ah 1 1 0 6 0000 1101 = 0Dh 0000 1100 = 0Ch 1 1 1 7 0000 1111 = 0Fh 0000 1110 = 0Eh I/O mode D7 D6 D5 D4 D3 D2 D1 D0 1 (1=I/O) GA mode select PA PCU GB mode select PB PCL • D6, D5: GA mode select: o 00 = mode0 o 01 = mode1 o 1X = mode2 • D4(PA), D3(PCU): 1=input 0=output • D2: GB mode select: 0=mode0, 1=mode1 • D1(PB), D0(PCL): 1=input 0=output Result: Mode 0 Mode 1 Mode 2 Input Output Input Output Input Output The programs for interfacing 8255 with 8085 are executed & the output is obtained for modes 0,1 & 2 44
  • 45. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8051 PROGRAMMING DATE: 8 BIT ADDITION AIM: To write a program to add two 8-bit numbers using 8051 microcontroller. ALGORITHM: 1. Clear Program Status Word. 2. Select Register bank by giving proper values to RS1 & RS0 of PSW. 3. Load accumulator A with any desired 8-bit data. 4. Load the register R 0 with the second 8- bit data. 5. Add these two 8-bit numbers. 6. Store the result. 7. Stop the program. FLOW CHART: START Clear PSW Select Register Bank Load A and R 0 with 8- bit datas Add A & R 0 Store the sum STOP 45
  • 46. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 8 Bit Addition (Immediate Addressing) ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS CODE 4100 CLR C C3 Clear CY Flag 4101 MOV A,# data1 74,data1 Get the data1 in Accumulator 4103 ADDC A, # data 2 24,data2 Add the data1 with data2 4105 MOV DPTR, # 90,45,00 Initialize the memory 4500H location 4108 MOVX @ DPTR, A F0 Store the result in memory location 4109 L1 SJMP L1 80,FE Stop the program RESULT: OUTPUT MEMORY LOCATION DATA 4500 Thus the 8051 ALP for addition of two 8 bit numbers is executed. 46
  • 47. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8 BIT SUBTRACTION DATE: AIM: To perform subtraction of two 8 bit data and store the result in memory. ALGORITHM: a. Clear the carry flag. b. Initialize the register for borrow. c. Get the first operand into the accumulator. d. Subtract the second operand from the accumulator. e. If a borrow results increment the carry register. f. Store the result in memory. FLOWCHART: START CLEAR CARRY FLAG GET I’ST OPERAND IN ACCR SUBTRACT THE 2’ND OPERAND FROM ACCR N IS CF=1 Y INCREMENT THE BORROW REGISTER STORE RESULT IN MEMORY STOP 47
  • 48. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 8 Bit Subtraction (Immediate Addressing) ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS CODE 4100 CLR C C3 Clear CY flag 4101 MOV A, # data1 74, data1 Store data1 in accumulator 4103 SUBB A, # data2 94,data2 Subtract data2 from data1 4105 MOV DPTR, # 4500 90,45,00 Initialize memory location 4108 MOVX @ DPTR, A F0 Store the difference in memory location 4109 L1 SJMP L1 80,FE Stop RESULT: OUTPUT MEMORY LOCATION DATA 4500 Thus the 8051 ALP for subtraction of two 8 bit numbers is executed. 48
  • 49. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8051 PROGRAMMING DATE: 8 BIT MULTIPLICATION AIM: To perform multiplication of two 8 bit data and store the result in memory. ALGORITHM: a. Get the multiplier in the accumulator. b. Get the multiplicand in the B register. c. Multiply A with B. d. Store the product in memory. FLOWCHART: START GET MULTIPLIER IN ACCR GET MULTIPLICAND IN B REG MULTIPLY A WITH B STORE RESULT IN MEMORY STOP 49
  • 50. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 8 Bit Multiplication ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS CODE 4100 MOV A ,#data1 74, data1 Store data1 in accumulator 4102 MOV B, #data2 75,data2 Store data2 in B reg 4104 MUL A,B F5,F0 Multiply both 4106 MOV DPTR, # 90,45,00 Initialize memory 4500H location 4109 MOVX @ DPTR, A F0 Store lower order result 401A INC DPTR A3 Go to next memory location 410B MOV A,B E5,F0 Store higher order 410D MOV @ DPTR, A F0 result 410E STOP SJMP STOP 80,FE Stop RESULT: INPUT OUTPUT MEMORY LOCATION DATA MEMORY LOCATION DATA 4500 4502 4501 4503 Thus the 8051 ALP for multiplication of two 8 bit numbers is executed. 50
  • 51. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXPT NO: 8051 PROGRAMMING DATE: 8 BIT DIVISION AIM: To perform division of two 8 bit data and store the result in memory. ALGORITHM: 1. Get the Dividend in the accumulator. 2. Get the Divisor in the B register. 3. Divide A by B. 4. Store the Quotient and Remainder in memory. FLOWCHART: START GET DIVIDEND IN ACCR GET DIVISOR IN B REG DIVIDE A BY B STORE QUOTIENT & REMAINDER IN MEMORY STOP 51
  • 52. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 8 Bit Division ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS CODE 4100 MOV A, # data1 74,data1 Store data1 in accumulator 4102 MOV B, # data2 75,data2 Store data2 in B reg 4104 DIV A,B 84 Divide 4015 MOV DPTR, # 4500H 90,45,00 Initialize memory location 4018 MOVX @ DPTR, A F0 Store remainder 4109 INC DPTR A3 Go to next memory location 410A MOV A,B E5,F0 Store quotient 410C MOV @ DPTR, A F0 410D STOP SJMP STOP 80,FE Stop RESULT: INPUT OUTPUT MEMORY LOCATION DATA MEMORY LOCATION DATA 4500 (dividend) 4502 (remainder) 4501 (divisor) 4503 (quotient) Thus the 8051 ALP for division of two 8 bit numbers is executed. 52
  • 53. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EXP. NO: LOGICAL AND BIT MANIPULATION DATE: AIM: To write an ALP to perform logical and bit manipulation operations using 8051 microcontroller. APPARATUS REQUIRED: 8051 microcontroller kit ALGORITHM: 1. Initialize content of accumulator as FFH 2. Set carry flag (cy = 1). 3. AND bit 7 of accumulator with cy and store PSW format. 4. OR bit 6 of PSW and store the PSW format. 5. Set bit 5 of SCON. 6. Clear bit 1 of SCON. 7. Move SCON.1 to carry register. 8. Stop the execution of program. FLOWCHART: START Set CY flag, AND CY with MSB of ACC Store the PSW format, OR CY with bit 2 IE reg Clear bit 6 of PSW, Store PSW Set bit 5 of SCON , clear bit 1 and store SCON Move bit 1 of SCON to CY and store PSW STOP 53
  • 54. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAM TABLE ADDRESS HEX LABEL MNEMONICS OPERAND COMMENT CODE 4100 90,45,00 MOV DPTR,#4500 Initialize memory location 4103 74,FF MOV A,#FF Get the data in accumulator 4105 D3 SETB C Set CY bit 4016 82,EF ANL C, ACC.7 Perform AND with 7th bit of accumulator 4018 E5,D0 MOV A,DOH 410A F0 MOVX @DPTR,A Store the result 410B A3 INC DPTR Go to next location 410C 72,AA ORL C, IE.2 OR CY bit with 2nd bit if IE reg 410E C2,D6 CLR PSW.6 Clear 6th bit of PSW 4110 E5,D0 MOV A,DOH 4112 F0 MOVX @DPTR,A Store the result 4113 A3 INC DPTR Go to next location 4114 D2,90 SETB SCON.5 Set 5th of SCON reg 4116 C2,99 CLR SCON.1 Clear 1st bit of SCON reg 4118 E5,98 MOV A,98H 411A F0 MOVX @DPTR,A Store the result 411B A3 INC DPTR Go to next location 411C A2,99 MOV C,SCON.1 Copy 1st bit of SCON reg to CY flag 411E E5,D0 MOV A,DOH Store the result 4120 F0 MOVX @DPTR,A 4122 80,FE L2 SJMP L2 Stop 54
  • 55. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE RESULT: MEMORY SPECIAL FUNCTION REGISTER FORMAT BEFORE AFTER LOCATION EXECUTION EXECUTION 4500H (PSW) CY AC FO RS1 RS0 OV - P 00H 88H 4501H (PSW) CY AC FO RS1 RS0 OV - P 40H 88H 4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H 4503H (PSW) CY AC FO RS1 RS0 OV - P FFH 09H Thus the bit manipulation operation is done in 8051 microcontroller. 55
  • 56. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EX.NO PROGRAMS TO VERIFY TIMER, INTERRUPTS & UART OPERATIONS IN 8031 MICROCONTROLLER DATE : a) Program to generate a square wave of frequency --------. Steps to determine the count: Let the frequency of sqaurewave to be generated be Fs KHz. And the time period of the squarewave be Ts Sec. Oscillator Frequency = 11.0592MHz. One machine cycle = 12 clock periods Time taken to complete one machine cycle=12*(1/11.0592MHz)= 1.085microsec. Y(dec) = (Ts/2)/(1.085microsec) Count(dec) = 65536(dec) – Y(dec) = Count(hexa) MOV TMOD,#10h ; To select timer1 & mode1 operation L1: MOV TL1,#LOWERORDER BYTE OF THE COUNT MOV TH1,#HIGHER ORDER BYTE OF THE COUNT SETB TR1 ; to start the timer (TCON.6) BACK: JNB TF1,BACK ; checking the status of timerflag1(TCON.7) for overflow CPL Px.x ; get the square wave through any of the portpins ; eg. P1.2 (second bit of Port 1) CLR TR1 ; stop timer CLR TF1 ; clear timer flag for the next cycle SJMP L1 b) Program to transfer a data serially from one kit to another. Transmitter: MOV TMOD,#20H ; Mode word to select timer1 & mode 2 MOV TL1,#FDH ; Initialize timer1 with the count MOV TH1,#FFH MOV SCON,#50H ; Control word for serial communication to to select serial mode1 SETB TR1 ; Start timer1 MOV A,#06h 56
  • 57. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE MOV SBUF,A ; Transfer the byte to be transmitted to serial Buffer register. LOOP: JNB TI, LOOP ; checking the status of Transmit interrupt flag CLR TI HERE: SJMP HERE Receiver: MOV TMOD,#20H MOV TL1,#FDH MOV TH1,#FFH MOV SCON,#50H SETB TR1 LOOP: JNB RI,LOOP MOV A,SBUF MOV DPTR,#4500H MOVX @DPTR,A CLR RI HERE: SJMP HERE 57
  • 58. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EX.NO. COMMUNICATION BETWEEN 8051 MICROCONTROLLER KIT & PC DATE : SERIAL COMMUNICATION 8051>H HELP MENU D Display data, program, internal, bit memory or registers E Edit data, program, internal, bit memory or registers S Single step from specified address, press SP to terminate G Execute the program till user break B Set address till where the program is to be executed C Clear break points F10 Key followed by 4 key at the PC to upload data to a file (DOS) T Test the onboard peripherals : Download a file from PC mem to the SDA-SI-MEL kit (DOS) A Assembler Z Disassembler TEST FOR ONBOARD PERIPHERALS For SDA SI-MEL kit, following menu is displayed on pressing the option "T" 8051>T ALS-SDA SI-MEL Kit Test monitor 1. Test internal Data RAM 2. Test external Data Memory (U6) 3. Test external Data memory (U7) 4. 8255 loop test 5. Test 8253 58
  • 59. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 6. Exit Select (1-6): Suppose the user presses the key '1', following message is displayed if the internal data RAM is OK. Testing internal data RAM: Pass After displaying the message, the menu is displayed once again waits for user to enter a key EDITING MEMORY COMMAND: 8051>E EDIT (R,B,M,P,D)…D - EXTERNAL DATA RAM Enter STA address = 0400 0400 = 7F:55 Press 'N' key to go to the next address 0401 = D5:66 0402 = D3:77 0403 = 73:88 0404 = 6F:12 0405 = CB:01 0406 = A7:02 Press 'P' key to go to the previous address 0407 = 6F:03 0408 = 7B:04 0409 = 29:05 040A = 6F:06 040B = 73:07 040C = FF:08 040D = 7D:09 Press 'CR' key to have the same address 040E = 09:90 Press 'ESC' Key to abort the command 8051>E EDIT (R,B,M,P,D)…B - BITS 59
  • 60. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE Enter STA address = 00 00 = 0:1 01= 0:1 02 = 0:0 03 = 0:1 03 = 1: 03 = 1: 02 = 0: 8051>E EDIT (R,B,M,P,D)…R- REGISTERS ACC = 00:33 PSW = 00:44 DPH = 00:55 DPL = 00:00 DPL = 00:00 8051>E EDIT (R,B,M,P,D)…-P = PROGRAM CODE 8000 = FF:78 8001 = FF:10 8002 = FF:79 8003 = FF:20 8004 = FF:7A 8005 = FF: 12 8007 = FF : 00 8008 = FF : 03 8009 = FF : 0F 8051>E EDIT (R,B,M,P,D)…-M - INTERNAL RAM 0000 = 00 : 12 0001 = 00 : 34 60
  • 61. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE 0002 = 00 : 00 DISPLAY COMMAND 8051>D EDIT (R,B,M,P,D)…-EXTERNAL DATA RAM Enter STA address = 0400 Enter END address = 040F 0500 55 66 77 88 12 01 02 03 04 05 06 07 08 09 04 D7 SETTING BREAK COMMAND : 8051>B BR _ NO: R BR_ADD 0000 ERROR! ONLY A BREAKS ALLOWED 8051>B BR _ NO: 0 ERROR! BREAK NUMBERS MUST BE BETWEEN 1 & 8 CLEAR BREAK COMMAND: 8051>C BR_N0:A Clears all the break point set by the user 8051>C BR_N0:1 Clears the break point number 1 61
  • 62. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE PROGRAMME EXECUTION COMMAND: 8051>G PROGRAM EXECUTION ENTER START ADDRESS = 8000 ACC PSW DPH DPL PCH PCL SP B R0 R1 R2 R3 R3 R4 R5 R6 R7 33 44 55 00 10 34 00 00 00 00 00 00 ASSEMBLE MEMORY COMMAND 8051>A ENTER START ADDRESS = 8000 DISASSEMBLE MEMORY COMMAND 8051>Z 62
  • 63. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EX. NO. PROGRAMS FOR DIGITAL CLOCK AND STOP WATCH (USING 8086) DATE: Program that places a message on the screen every 10 seconds, using int 1ah; CODE SEGMENT TIMEDELAY: MOV SP,1000H MOV DI,10XD TIME OUT: MOV AH,00H INT 1AH MOV BX,DX TIMER: MOV AH, 00H INT 1AH SUB DX, BX CMP DX, 182XD JC TIMER MOV AH, 09H CS MOV DX,MSG INT 21H DEC DI JNZ TIMEOUT MOV AX,4C00H INT 21H MSG: DB 'TEN MORE SECONDS HAVE PASSED $' CODE ENDS 63
  • 64. EC 2308 – MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE EX.NO. Interfacing 8259 with 8085 microprocessor DATE: Initialize 8259 with the following specifications: ICW4 needed, single 8259, Interval of ------(8085), Edge triggered mode, Vector address(8085)/ Type number(8086) of IR0 ------, ------- mode, Normal EOI, Non-buffered mode, Not special fully nested mode, Mask all interrupts except ---------. A0 – Address with A0 = 0 A1 – Address with A0 = 1 Using 8086: MOV AL,ICW1 OUT A0,AL MOV AL,ICW2 OUT A1,AL MOV AL,ICW4 OUT A1,AL MOV AL,OCW1 OUT A1,AL STI HLT Vector Table: offset address - Interrupt type * 4 0000: offsetaddress - Segment Address : Offset address of the ISR ISR: MOV AL,OCW2 OUT A0,AL HLT 64