anna university lab manual

Upload: natraj-rajan

Post on 04-Mar-2016

22 views

Category:

Documents


0 download

TRANSCRIPT

  • EXP NO: 1

    D A T E :

    8086 PROGRAMMING

    ADDITION & SUBTRACTION

    AIM: To write an Assembly Language Program (ALP) for performing the Addition and subtraction operation of 16-bit numbers. APPARATUS REQUIRED:

    SL.N O

    ITEM SPECIFICATION QUANTITY

    1. Microprocessor kit 2. Power Supply

    8086 kit +5 V dc

    1 1

  • ALGORITHM:

    16-bit addition i. Initialize the MSBs of sum to 0ii) Get the first number. iii) Add the second number to the first number. iv) If there is any carry, increment MSBs of sum by 1. v. Store LSBs of sum. vi) Store MSBs of sum.

    16-bit subtraction

    i. Initialize the MSBs of difference to 0 ii) Get the first number iii) Subtract the second number from the first number. iv) If there is any borrow, increment MSBs of difference by 1. v. Store LSBs of difference vi) Store MSBs of difference.

    1

  • FLOWCHART:

    2

  • 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 &

    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

    3

    3

  • OUTPUT:

    MEMORY

    DATA

    MEMORY

    DATA

    RESULT:

    ADDITION

    SUBTRACTION

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

    4

  • EXPT NO: 2

    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

    O ITEM SPECIFICATION QUANTITY

    1. Microprocessor kit 2. Power Supply

    8086 +5 V dc

    1 1

    ALGORITHM:

    Multiplication of 16-bit numbers:

    i. Get the multiplier. ii) Get the multiplicand iii) Initialize the product to 0. iv) Product= product + multiplicand v. Decrement the multiplier by 1 vi) If multiplicand is not equal to 0,repeat from step (d) otherwise store the product.

    Division of 16-bit numbers.

    i. Get the dividend ii) Get the divisor iii) Initialize the quotient to 0. iv) Dividend = dividend divisor v. If the divisor is greater, store the quotient. Go to step g. vi) If dividend is greater, quotient = quotient + 1. Repeat from step (d) vii) Store the dividend value as remainder.

    5

  • FLOWCHART:

    6

  • MULTIPLICATION PROGRAM COMMENTS

    MOV AX,[1200] Get the first data MOV BX, [1202]

    MUL BX

    MOV [1206],AX

    MOV AX,DX

    MOV [1208],AX

    HLT

    Get the second data

    Multiply both

    Store the lower order product

    Copy the higher order product to AX

    Store the higher order product

    Stop the program DIVISION

    PROGRAM COMMENTS MOV AX,[1200] Get the first data lower nibble MOV DX, [1202]

    MOV BX, [1204]

    DIV BX

    MOV [1206],AX

    MOV AX,DX

    MOV [1208],AX

    HLT

    Get the first data higher nibble

    Get the second data

    Divide the dividend by divisor

    Store the lower order product

    Copy the higher order product to AX

    Store the higher order product

    Stop the program

    7 7

  • OUTPUT:

    MULTIPLICATION

    MEMORY

    DATA

    DIVISON

    MEMORY

    DATA

    RESULT:

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

    8

  • EXPT NO: 3

    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 O

    ITEM SPECIFICATION QUANTITY

    1. Microprocessor kit 2. Power Supply

    8086 +5 V dc

    1 1

    ALGORITHM:

    Sorting in ascending order:

    i. Load the array count in two registers C ii) Get the first two numbers. 01 and C 2.iii) Compare the numbers and exchange if necessary so that the two numbers are in ascending order. iv) Decrement C 2. v. Get the third number from the array and repeat the process until C 2 is 0. vi) Decrement C1 and repeat the process until C 1 is 0.

    Sorting in descending order: i. Load the array count in two registers C ii) Get the first two numbers. 01 and C 2.iii) Compare the numbers and exchange if necessary so that the two numbers are in descending order. iv) Decrement C2. v. Get the third number from the array and repeat the process until C 2 is 0. vi) Decrement C 01 and repeat the process until C 1 is 0.

    9

  • FLOWCHART

    10

  • ASCENDING 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

    11

  • 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

    ASCENDING

    MEMORY

    DATA

    MEMORY

    DATA

    DESCENDING

    RESULT:

    Thus given array of numbers are sorted in ascending & descending order12

  • EX NO:4

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

    APPARATUS REQUIRED: SL.N

    O ITEM SPECIFICATION QUANTITY

    1. Microprocessor kit 2. Power Supply

    8086 +5 V dc

    1 1

    ALGORITHM:

    (i) Finding largest number: a. Load the array count in a register C bc. Compare the numbers and exchange if the number is small. d. Get the third number from the array and repeat the process until C

    (ii) Finding smallest number: e. Load the array count in a register C1. f. Get the first two numbers.

    g. Compare the

    h. Get the third number from the array and repeat the process until C1 is 0.

    13

  • FLOWCHART:

    14

  • 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

    15

  • 1

    LARGEST

    MEMORY DATA

    MEMORY

    DATA

    SMALLEST

    RESULT:

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

    16

  • EXPT NO: 5 DATE: 8086 PROGRAMMING

    APPARATUS REQUIRED: SL.N

    O ITEM SPECIFICATION QUANTITY

    1. Microprocessor kit 2. Power Supply

    8086 +5 V dc

    1 1

    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.

    17

  • FLOWCHART:

    18

  • COPYING A STRING PROGRAM COMMENTS

    MOV SI,1200H

    MOV DI,1300H

    MOV CX,0006H

    CLD

    REP MOVSB

    HLT

    MEMORY

    Initialize starting address

    Initialize destination address

    Initialize array size

    Clear direction flag

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

    INPUT

    DATA

    MEMORY

    DATA

    RESULT:

    OUTPUT

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

    19

  • EXPT NO: 6 SEARCHING A STRING

    DATE:

    AIM:To scan for a given byte in the string and find the relative address of the bytefrom 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.

    19

    20

  • FLOWCHART :

    21

  • MOV DI,1300H

    MOV SI, 1400H

    MOV CX, 0006H

    CLD

    MOV AL, 08H

    REPNE SCASB

    DEC DI

    MOV BL,[DI]

    MOV [SI],BL

    HLT

    OUTPUT:

    Initialize destination address

    Initialize starting address

    Initialize array size

    Clear direction flag

    Store the string to be searched

    Scan until the string is found

    Decrement the destination address

    Store the contents into BL reg

    Store content of BL in source address

    Stop INPUT

  • MEMORY

    DATA

    OUTPUT

    MEMORY LOCATION DATA

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

    22 EXNO: 7 8086 PROGRAMMING FIND AND REPLACE

    DATE:

    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 scannedbyte in BL register. f. Scan for the byte in ES. If the byte is not found, ZF?1 and repeatscanning. g. If the byte is found, ZF=1.Move the content of BL register to

    ES:DI.

    21

  • 23

  • FLOWCHART:

    24

  • FIND AND REPLACE A CHARACTER IN THE STRING PROGRAM COMMENTS

    MOV DI,1300H

    MOV SI,1400H

    Initialize destination address

    Initialize starting address MOV CX, 0006H

    CLD

    MOV AL, 08H

    MOV BH,30H

    REPNE SCASB

    DEC DI

    MOV BL,[DI]

    MOV [SI],BL

    MOV [DI],BH

    HLT

    Initialize array size

    Clear direction flag

    Store the string to be searched

    Store the string to be replaced

    Scan until the string is found

    Decrement the destination address

    Store the contents into BL reg

    Store content of BL in source address

    Replace the string

    Stop INPUT

  • MEMORY DATA

    MEMORY

    DATA

    RESULT:

    OUTPUT

    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.

    25 EXNO: 8 8086 INTERFACING

    INTERFACING ANALOG TO DIGITAL CONVERTER DATE: 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 QUANTITY1. Microprocessor kit 2. Power Supply 3. ADC Interface board

    8086 +5 V dc,+12 V dc -

    1 1 1

  • THEORY: An ADC usually has two additional control lines: the SOC input to tell theADC when to start the conversion and the EOC output to announce when theconversion is complete. The following program initiates the conversionprocess, checks the EOC pin of ADC 0809 as to whether the conversion is overand then inputs the data to the processor. It also instructs the processor to storethe 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.

    26

  • FLOW CHART:

    27

  • PROGRAM TABLE PROGRAM

    MOV AL,00

    COMMENTS

    Load accumulator with value for ALE high OUT 0D0H,AL

    MOV AL,00 MOV AL,00 MOV AL,00 MOV AL,00

    OUT 0D0H,AL

    Send through output port

    Introduce delay Store the value to make SOC low the accumulator

    Send through output port

    L1 : IN AL, 0D8H AND AL,01 CMP AL,01

    JNZ L1

    Read the EOC signal from port & check for end of conversion

    If the conversion is not yet completed, read EOC signal

    from port again

    IN AL,0C0H Read data from port ANALOG DIGITAL DATA ON LED HEX CODE IN MEMORY

    VOLTAGE DISPLAY LOCATION

    RESULT:

    Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its digital equivalent.

    28 EXNO: 9 8086 INTERFACING

    INTERFACING DIGITAL TO ANALOG CONVERTER DATE: AIM:

    1. To write an assembly language program for digital to analog conversion 2. To convert digital inputs into analog outputs & To generatedifferent waveforms.

    APPARATUS REQUIRED:

    SL.NO ITEM SPECIFICATION QUANTITY1. Microprocessor kit 2. Power Supply 3.

    DAC Interface board

    8086 Vi Microsystems +5 V, dc,+12 V dc -

    1 1 1

  • 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. 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 to00 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.

    29

  • 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. (vi) 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)

    30

  • FLOWCHART:

    31

  • PROGRAM COMMENTS

    MOV AL,7FH OUT C0,AL HLT

    Load digital value 00 in accumulator Send through output port Stop

    DIGITAL DATA ANALOG VOLTAGE

    PROGRAM TABLE: Square Wave PROGRAM COMMENTS

    PROGRAM TABLE: Saw tooth Wave PROGRAM COMMENTS

    L2 : MOV AL,00H L1 : OUT C0,AL INC AL JNZ L1 JMP L2

    Load 00 in accumulator Send through output port Increment contents of accumulator Send through output port until it reaches FF Go to starting location

    27

    32

  • PROGRAM TABLE: Triangular Wave PROGRAM COMMENTS

    L3 : MOV AL,00H L1 : OUT C0,AL INC AL JNZ L1 MOV AL,0FFH L2 : OUT C0,AL DEC AL JNZ L2 JMP L3

    WAVEFORM GENERATION:

    Load 00 in accumulator Send through output port Increment contents of accumulator Send through output port until it reaches FF Load FF in accumulator Send through output port Decrement contents of accumulator Send through output port until it reaches 00 Go to starting location

    WAVEFORMS AMPLITUDE TIMEPERIOD Square Waveform Saw-tooth waveform Triangular waveform

    MODEL GRAPH: Square Waveform

    33

  • Saw-tooth waveform

    Triangular waveform

    RESULT:

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

    34 EXNO: 10 STEPPER MOTOR INTERFACING

    DATE:

  • AIM:

    To write an assembly language program in 8086 to rotate the motor at differentspeeds.

    APPARATUS REQUIRED:

    SL.NO ITEM SPECIFICATION QUANTITY1. Microprocessor kit808612. Power Supply+5 V, dc,+12 V dc 13. Stepper Motor Interface board- 14. Stepper Motor - 1

    THEORY:

    A motor in which the rotor is able to assume only discrete stationary angularposition 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 theabove procedure both for backward and forward directions.

    SWITCHING SEQUENCE OF STEPPER MOTOR: MEMORY LOCATION 4500 4501 4502 4503

    A1 A2 B1 B2 HEX CODE

    01 0 0 0 09 H 00 1 0 1 05 H 10 1 1 0 06 H 01 0 1 0 0A H

    35

  • FLOWCHART:

    36

  • PROGRAM TABLE PROGRAM START : MOV DI, 1200H MOV CX, 0004H

    COMMENTS Initialize memory location to store the array ofnumber 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 JNZ L1 INC DI

    Introduce delay 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.

    37 EXNO: 11 INTERFACING PROGRAMMABLE 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 00 00 00 01 00 00 00 0 0

    DD

    0 0 D D

    K K

    K

    00- 8Bit character display left entry 1. - 16Bit character display left entry 2. 8Bit character display right entry 3. 16Bit character display right entry KKK- Key Board Mode 000-2Key lockout.

    38

  • 2.Clear Display: Control word-DC H 1 1

    1 1

    0 0

    1 CD

    1 CD

    1 CD

    0

    CF

    0 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)

    39

  • 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 andwrite operation of the display RAM.

    FLOWCHART:

    32

    40

  • PROGRAM TABLE: PROGRAM COMMENTS

    START : MOV SI,1200H MOV CX,000FH MOV AL,10 OUT C2,AL MOV AL,CC OUT C2,AL MOV AL,90 OUT C2,AL L1 : MOV AL,[SI] OUT C0,AL CALL DELAY INC SI LOOP L1 JMP START DELAY : MOV DX,0A0FFH LOOP1 : DEC DX JNZ LOOP1 RET

    LOOK-UP TABLE:

    1200 98 68 7C C8

    1204 FF 1C 29 FF

    Initialize array Initialize array size Store the control word for display mode Send through output port Store the control word to clear display Send through output port Store the control word to write display Send through output port Get the first data Send through output port Give delay Go & get next data Loop until all the data s have been taken Go to starting location Store 16bit count value Decrement count value Loop until count values becomes zero Return to main program

    41

  • OUTPUT: E 7-SEGMENT

    LED FORMAT

    HEX DATA

  • 1200H 1201H 1202H 1203H 1204H 1205H 1206H 1207H

    01 0 0 1 1 0 0 0 98 00 1 1 0 1 0 0 0 68 10 1 1 1 1 1 0 0 7C 01 1 0 0 1 0 0 0 C8 11 1 1 1 1 1 1 1 FF 00 0 0 0 1 1 0 0 1C 10 0 1 0 1 0 0 1 29 01 1 1 1 1 1 1 1 FF

    RESULT:

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

    42 EXNO: 12 INTERFACING PROGRAMMABLE TIMER-8253

    DATE: A IM:

    To study different modes of operation of programmable timer 8253.

    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 bythese 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 numberof 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.

    43

  • 34 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 REGISTER2. 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 00 1 0 0 Mode 2 = 34 H

    00 01 1 0 1 1 0 Mode 3 = 36 H

    SC1 SC0 CHANNEL SELECT RL1 RL0 READ/LOAD 0 0 1 1

    0 1 0 1

    CHANNEL 0 CHANNEL 1 CHANNEL 2 -----

    0 0 1 1

    0 1 0 1

    LATCH LSB MSB LSB FIRST, MSB NEXT

    BCD --0 BINARY COUNTER

    M2 M1 M0 MODE

    01 --BCD COUNTER

  • 0 0 0 0 1 1

    0 0 1 1 0 0

    0 1 0 1 0 1

    MODE 0

    MODE 1

    MODE 2

    MODE 3

    MODE 4

    MODE 5

  • PORT PIN ARRANGEMENT DEBOUNCE CIRCUIT CONNECTION

    1 CLK 0 2 CLK 1 3 CLK 2

    44

  • FLOW CHART:

    45

  • 04 OUT 0

    05 OUT 1

    06 OUT 2

    07 GATE 0

    08 GATE 1

    09 GATE 2

    10 GND

    MODE 2 RATE GENERATOR: PROGRAM COMMENTS

    MOV AL, 34H OUT 0BH MOV AL, 0AH OUT 08H MOV AL, 00H OUT 08H HLT

    Store the control word in accumulator Send through output port Copy lower order count value in accumulator Send through output port Copy higher order count value in accumulator Send through output port Stop

    MODE 3 SQUARE WAVE GENERATOR: PROGRAM COMMENTS

    MOV AL, 36H OUT 0BH MOV AL, 0AH OUT 08H MOV AL, 00H OUT 08H HLT

    Store the control word in accumulator Send through output port Copy lower order count value in accumulator Send through output port Copy higher order count value in accumulator Send through output port Stop

    6 46

  • MODEL GRAPH: RATE GENERATOR SQUARE WAVE GENERATOR

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

    47

  • EXNO: 13 DATE:

    AIM:

    INTERFACING USART 8251

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

    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 enable1... 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)

    48

  • 01 ransmitter ready1. 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)

  • 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 a9600 baud rate of 8251. 3. The command word and mode word is written to the 8251 to set up forsubsequent operations 4. The status word is read from the 8251 on completion of a serial I/O

    49

  • operation, or when the host CPU is checking the status of the device beforestarting the next I/O operation.

    FLOW CHART:

    50

  • PROGRAM: TRANSMITTER END PROGRAM COMMENTS

    MOV AL,36 OUT CE,AL MOV AL,10 OUT C8,AL MOV AL,00 OUT C8,AL MOV AL,4E OUT C2,AL MOV AL,37 OUT C2,AL

    Initialize 8253 in mode 3 square wave generator Send through port address Initialize AL with lower value of count (clock frequency 150KHz) Send through port address Initialize AL with higher value of count Send through port address Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) Send through port address Set command instruction(enables transmit enable & receive enable bits) Send through port address

    L1:IN AL,C2 Read status word AND AL,04 JZ L1 MOV AL,41 OUT C0,AL INT 2

    Check whether transmitter ready If not wait until transmitter becomes ready Set the data as 41 Send through port address Restart the system

    RECEIVER END PROGRAM COMMENTS

    MOV AL,36 OUT CE,AL MOV AL,10 OUT C8,AL MOV AL,00 OUT C8,AL MOV AL,4E OUT C2,AL MOV AL,37 OUT C2,AL

    Initialize 8253 in mode 3 square wave generator Send through port address Initialize AL with lower value of count (clock frequency 150KHz) Send through port address Initialize AL with higher value of count Send through port address Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) Send through port address Set command instruction(enables transmit enable & receive enable bits) Send through port address

    L1:IN AL,C2 Read status word 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.

    51 EXNO: 14 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.

    52

  • FLOWCHART:

    53

  • MODE 0 PROGRAM COMMENTS

    MOV AL,90H OUT C6,AL IN AL,C0 OUT C2,AL HLT

    MODE 1 PROGRAM

    MOV AL,0B0H OUT C6,AL MOV AL,09H OUT C6,AL MOV AL,13H OUT 30,AL MOV AL,0AH OUT 32,AL MOV AL,0FH OUT 32,AL MOV AL,00H OUT 32,AL STI HLT ISR: IN AL,C0 OUT C2,AL HLT MODE 2

    PROGRAM MOV AL,0C0H OUT C6,AL MOV AL,09H OUT C6,AL MOV AL,13H OUT 30,AL MOV AL,0AH OUT 32,AL

    Set the control word Send it to control port Get the contents of port A in AL Send the contents of port B to port address Stop

    COMMENTS Set the control word for mode 1 Send it to control port Control for BSR mode Send it to control port Interrupt generation Through 8259 Using IR2 interrupt(lower order count) Higher order count Set trap flag Stop Subroutine Read from Port A Send it to Port B Stop

    COMMENTS Set the control word for mode 2 Send it to control port Control for BSR mode Send it to control port Interrupt generation Through 8259

    54

  • MOV AL,0FH OUT 32,AL MOV AL,00H OUT 32,AL STI HLT ISR: IN AL,C0 OUT C2,AL HLT BSR mode

    Using IR2 interrupt(lower order count) Higher order count Set trap flag Stop Subroutine Read from Port A Send it to Port B Stop

  • Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word: D7 00 (0=BSR)

    D6 D5 D4 D3 D2 D1 D0 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) 00 0 0 0 0000 0001 = 01h 10 0 1 1 0000 0011 = 03h 00 1 0 2 0000 0101 = 05h 00 1 1 3 0000 0111 = 07h 01 0 0 4 0000 1001 = 09h 01 0 1 5 0000 1011 = 0Bh 11 1 0 6 0000 1101 = 0Dh 01 1 1 7 0000 1111 = 0Fh

    0000 0000 = 00h 0000 0010 = 02h 0000 0100 = 04h 0000 0110 = 06h 0000 1000 = 08h 0000 1010 = 0Ah 0000 1100 = 0Ch 0000 1110 = 0Eh

    I/O mode D7 D6 D5 D4 D3 D2 D1 D0 01 (1=I/O)

    GA mode select PA PCU GB mode

    select PB PCL

    0 D6, D5: GA mode select: o 00 = mode0 o

    01 = mode1 o1X = mode2

    0 D4(PA), D3(PCU): 1=input 0=output1 D2: GB mode select: 0=mode0, 1=mode12 D1(PB), D0(PCL): 1=input 0=output

    Result:Mode 0 Mode 1 Mode 2

    Input OutputInput OutputInput Output

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

    55 EXNO: 15 8051 PROGRAMMING

    8 BIT ADDITION DATE:

    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.

    with

  • t5. Add these two 8-bit numbers. 6. Store the result. 7. Stop the program.

    56

  • FLOW CHART:

    57

  • 08 Bit Addition (Immediate Addressing)ODE C

    OMMENTS

  • 4100 CLR C C3 Clear CY Flag 4101

    4103

    4105

    MOV A,# data1

    ADDC A. # data 2

    MOV DPTR, # 4500H

    74,data1 Get the data1 in Accumulator

    24,data2 Add the data1 with

    data2 90,45,00 Initialize the memory

    location 4108

    Store the result in

    MOVX 0@ DPTR, A F0 memory location 4109 L1 SJMP L1 80,FE Stop the program

    OUTPUT:

    OUTPUT MEMORY LOCATION DATA

    4500 RESULT:

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

    58 EXNO: 16 8051 PROGRAMMING 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.

    59

  • FLOWCHART: -

    60

  • 08 Bit Subtraction (Immediate Addressing)ADDRESS LABEL MNEMONIC

    OPERAND H COMMENTS

    4100 CLR C

    C3 Clear CY flag

    4101

    4103

    MOV

    SUBB

    A. # data1

    A. # data2

    74. data1 Store data1 in accumulator

    94,data2 Subtract data2 from

    data1

    4105

    4108

    MOV

    MOVX

    DPTR, # 4500 90,45,00 Initialize memory

    location Store the difference

    0@ DPTR, A

    F0 in memory location

    4109 L1 SJMP L1 80,FE Stop OUTPUT:

    OUTPUT RESULT:

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

    61

  • EXNO: 17 AIM:

    To perform division 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.

    62

  • FLOWCHART:

    63

  • 08 Bit MultiplicationADDRESS LABEL MNEMONIC

    OPERAND H COMMENTS

    4100 MOV A ,#data1

    74. data1 Store data1 in accumulator

    4102 MOV B, #data2 75,data2 Store data2 in B reg4104 MUL A,B F5,F0 Multiply both 4106

    4109

    401A

    410B

    410D

    MOV

    MOVX

    INC

    MOV

    MOV

    DPTR, # 4500H 0@ DPTR, A

    DPTR

    A,B

    0@ DPTR, A

    90,45,00 Initialize memory location Store lower order

    F0 result

    A3 Go to next memory location

    E5,F0

    Store higherorder result F0

    410E STOP SJMP STOP 80,FE Stop OUTPUT:

    INPUT OUTPUTMEMORY LOCATION DATA

    4500

    MEMORY LOCATION

    4502

    DATA

    RESULT:

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

    64 EXNO: 18 8051 PROGRAMMING 8 BIT DIVISION

    DATE:

    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.

    65

  • FLOWCHART:

    66

  • 08 Bit DivisionADDRESS LABEL MNEMONIC

    OPERAND HEX CODE

    COMMENTS

    4100

    MOV A. # data1 74,data1 Store data1 in

    accumulator

    4102 MOV B, # data2 75,data2 Store data2 in B reg4104 DIV A,B 84 Divide 4015

    MOV DPTR, # 4500H 90,45,00

    Initialize memory location

    4018

    4109

    410A

    410C

    410D

    MOVX

    INC

    MOV

    MOV

    STOP SJMP

    0@ DPTR, A

    DPTR

    A,B

    0@ DPTR, A

    STOP

    F0

    A3

    E5,F0

    F0

    80,FE

    Store remainder Go to

    next memory location

    Store quotient Stop

    OUTPUT:

    INPUT OUTPUTMEMORY LOCATION DATA MEMORY LOCATION DATA4500 (dividend) 4502 (remainder)

    4501 (divisor) 4503 (quotient) RESULT:

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

    67 EXNO: 19 8051 PROGRAMMING

    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.

    68

  • FLOWCHART:

    69

  • PROGRAM TABLE: A LABEL MNEMONICS OPERAND

    COMMENT 4100

    90,45,0

    0 Initialize memory

    MOV DPTR,#4500 location 4103

    74,FF

    Get the data in

    MOV A,#FF accumulator4105

    4016

    D3

    82,EF

    SETB

    ANL

    C

    C. ACC.7

    Set CY bit Perform AND with 7th

    bit of accumulator

    4018E5,D0 MOV A,DOH410A

    F0

    Store the result

    MOVX @DPTR,A 410B

    410C

    A3

    72,AA

    INC

    ORL

    DPTR

    C. IE.2

    Go to next location OR CY bit with 2nd bit

    if IE reg

    410E C2,D6 CLR PSW.6 Clear 6th bit of PSW4110 E5,D0 MOV A,DOH

    MOVX @DPTR,A 4113 4114 4116

    A3D2,90C2,99

    INC SETB CLR

    DPTR SCON.5

    SCON.1

    Go to next location Set 5th of SCON reg

    Clear 1st bit of SCON reg

    4118E5,98 MOV A,98H411A F0 MOVX @DPTR,A Store the result411B

    411C

    411E

    4120

    4122

    A3

    A2,99

    E5,D0

    F0

    80,FE

    L2

    INC

    MOV

    MOV

    MOVX

    SJMP

    70 DPTR

    C,SCON.1

    A,DOH

    @DPTR,A

    L2

    Go tonextlocation Co

  • py 1st bit of SCON

    regto

    CY

    flag

    Store the result

    Stop

  • OUTPUT: MEMORY BEFORE AFTER

    LOCATION SPECIAL FUNCTION REGISTER FORMAT

    EXECUTION EXECUTION

    4500H (PSW) CY AC FO RS1 RS0 OV - P 00H

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

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

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

    88H 88H 20H 09H

    RESULT:

    Thus the bit manipulation operation is done in 8051 microcontroller.

    71

  • 72