Microprocessor Lab Manual



Comments



Description

1MICROPROCESSORS LAB CODE NO: 05401 I. Microprocessor 8086 1. Introduction to MASM/TASM 2. Arithmetic operations – Multi byte addition and subtraction, multiplication and division-signed operation. 3. Logic operations- Shift and rotate-Converting packed BCD to Unpacked BCD, BCD to ASCII conversion. 4. By using string operation and instruction prefix: Move block, Reverse string, Sorting, Inserting, Deleting, and Length of the string, String comparison 5. DOS/BIOS Programming: Reading keyboard (Buffered with and with out echo) - Display characters, Strings. and unsigned Arithmetic operation, ASCIIarithmetic II.INTERFACING 1. 8259-Interuupt controller: Generate an interrupt using 8259 timer. 2. 8279-Keyboard display: Write a small program to display a string of Characters. 3. 8255-PPI: Write ALP to generate sinusoidal wave using PPI. 4. 8251-USART: Write a program in ALP establish communication between to processors. III.MICROCONTROLLER 8051 1. Reading and writing on a parallel port. 2. Timer in different modes. 3. Serial communication implementation. 2 MICROPROCESSORS LAB I. Microprocessor 8086 1. Introduction to MASM/TASM 2. Arithmetic operations – Multi byte addition and subtraction, multiplication and division-signed and unsigned Arithmetic operation, ASCII- arithmetic operation. 3. Logic operations- Shift and rotate-Converting packed BCD to Unpacked BCD, BCD to ASCII conversion. 4. By using string operation and instruction prefix: Move block, Reverse string, Sorting, Inserting, Deleting, and Length of the string, String comparison 5. DOS/BIOS Programming: Reading keyboard (Buffered with and with out echo) - Display characters, Strings. II. INTERFACING 1. 8259-Interuupt controller: 1. Pulse Counter 2. Frequency Counter 2. 8279-Keyboard display: Display String of Characters 3. 8255-PPI: Sine wave generation 4. 8251-USART: Write a program in ALP establish communication between to processors. III. MICROCONTROLLER 8051 1. Arithmatic operations. 2. Timer in different modes. a. Generate delay using timer 0 in mode 1 for square wave b. Generate delay using timer 0 in mode 2 for square wave EXPERIMENTS OTHER THAN JNTU SYLLABUS 1. 8279-Keyboard display: Write a small program to display a string of Characters. a. Display of Single Character b. Reading character from keyboard and displaying it 2. 8255-PPI: a. Square wave generation b. Stepper motor speed and direction control 3. Decimal counter display. 3 MICRO PROCESSOR 8086 1. INTRODUCTION TO MASM/TASM 4 INTRODUCTION TO MASM/TASM The assembler is a program that converts an assembly input file also called source file to an object file that can further be converted in to machine codes or an executable file using a linker. There are a number of assemblers available like MASM, TASM and DOS assembler.TASM is one of the popular assemblers used along with a link program to structure the codes generated By TASM in the form of executable files.TASM reads the source program as its input and provides an object file. The link accepts the object file produced by TASM as input and produces an EXE file. Before staring the process ensure that all the files namely, TASM, .EXE, LINK .EXE, DEBUG. EXE Are available in the same directory which is working .Start the procedure with the following command after boot the terminal and enter the directory containing all the files mentioned. D: Valid directory Cod: Change the directory with all files Edit: Edit the assembler to enter the program Save the files with. .ASM. ASSUME CS:CODE,DS:DATA DATA SEGMENT OPR1 DW 1234H OPR DW 0002H RESULT DW 01H DUP ? DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AX, OPR1 MOV BX, OPR2 CLC ADD AX, BX MOV DI, OFFSET RESULT MOV DI, AX MOV AH, 4CH INT 03H CODE ENDS. END START. The main task of any assembler program is to accept the text _assembly language program file as input and prepare an object file .the TASM accepts the file names only with the extension .ASM. The TASM linking program LINK.EXE .links the different object modules of a source program and function library routines to generate an integrated executable code of the source program. The main input to the linker is the .OBJ file that contains the object modules of the source program. Debug .Exe facilitates the debugging and trouble shooting of assembly language program. The debug utility enables to have the control these resources unto some extent. 5 TASM file name. ASM TLINK file name Debug file name.exe G- Execute current CS: IP. - Execute from offset in the current series U- Un assemble from the current CS: IP - Un assemble from the address SEG: OFFSET D- Display 128 memory locations of RAM starting from the current display pointer -Display memory contents SEG from offset1 to offset2 ASSEMBLER DIRECTIVES: An Assembler is a program used to convert an assembly language program in to equivalent machine code modules which may further be converted in to executable codes. The assembler decides the address of each label and substitutes the values for each of the constants and variables. It then forms the machine code for the mnemonics and data in assembly language program. While doing all these all these things, the assembler may find out Syntax errors. The logical errors or other programming errors are not find out by the assembler. For completing all these tasks, an assembler needs some hints from the programmer, i.e. the required storage for a particular constant or variable, logical names of the segments, types of the different routines and modules, end of file etc. These types of hints are given to assembler using some predefined alphabetical strings called “ASSEMBLER DIRECTIVES”. DB: This is used to reserve byte or bytes of memory locations in the available memory. While preparing the EXE file, this directive directs the assembler to allocate the specified number of memory bytes to the said data type that may be constant, variable or stringent. DW: This directive serves the same purposes as the DB directive, but it now makes the assembler Reserve the number of memory words instead of bytes. DQ: This directive is used to direct the assembler to reserve words of memory for the specified variable and may initialize it with the specified values. ASSUME: The ASSUME directive is used to inform the assemble, the names of the logical segments to be assumed for different segments used in the program. 6 END: The END directive marks the end of an assembly language program. When the assembler comes across this directive, it ignores the source lines available later on. ENDP: In assembly language programming, the subroutines are called procedures. Thus, procedures may be Independent program modules which return particular results or values to the calling programs. The ENDP Directive is used to indicate an end of procedures. A procedure is usually assigned a name, i.e. label. To mark The end of a particular procedure, the name of the procedure, i.e label appear as a prefix with the directive ENDP. ENDS: This directive marks the end of a logical segment. The logical segments are assigned with names Using the ASSUME directive. The names appear with the ENDS directive as prefixes to mark the end of Those particular segments. LABEL: This is used to assign a name to the current content of the location counter. At the start of the assembly process, the assembler initializes a location counter to keep track of memory Locations assigned to the program. As the program assembly proceeds, the contents of the Location counter are updated. LENGTH: This is used to refer the length of a data array or string. OFFSET: When the assembler comes across the offset operator along with a label, it first computes the 6-bit Displacement of the particular label, and replaces the string ‘offset label’ by the computed displacement. SEGMENT: This marks the staring of a logical segment .The started segment is also assigned a name i.e., label by this statement. The SEGMENT and ENDS directive must bracket each logical Segment of a program. 7 2. ARITHMETIC OPERATIONS  Multi byte addition  Multi byte Subtraction  Multi byte multiplication  Multi byte division  +Ve & -ve No.s of array  GCD of two numbers  0s &1s in 16-bit number  Prime number checking  Solving the equation 8 THIS PROGRAM PERFORMS MULTIBYTE ADDITION Turbo Assembler Version 2.51 add.asm /* the data segment in array1 and the data segment in array2 is added and the result Will be stored and displayed in data segment array3*/ 1 2 3 0000 4 5 6 7 8 9 10 11 12 13 14 15 16 17 assume cs: code,ds: data code segment start: move ax, data mov ds,ax mov cx,n1 ;initialise counter lea si,array1 ;initialise pointer lea bx,array2 lea di,array3 l1:mov al,[si] ;perform addition Of 1st byte ad al,[bx] mov [di], al ; store the result inc si ;update data pointers inc bx inc di dec cx ; repeat addition till The final byte jnz l1 int 03 code ends data segment 0004 n1 dw 0004h 01020304 array1 dd 01020304h ;specify inputs 01020304 array2 dd 01020304h ???????? array3 dd? ; store the result data ends end start 1st array: 01020304h 2nd array: 01020304h 0000 B8 0000s 0003 8E D8 0005 8B 0E 0000r 0009 BE 0002r 000C BB 0006r 000F BF 000Ar 0012 8A 04 0014 12 07 0016 88 05 0018 46 0019 43 001A 47 001B 49 18 001C 75 F4 19 001E CC 20 21 22 23 24 25 26 27 28 001F 0000 0000 0002 0006 000A 000E Input : 9 Output: 02040608h 10 THIS PROGRAM PERFORMS MULTIBYTE SUBTRACTION Turbo Assembler Version 2.51 sub.asm /* The data segment in array1 and the data segment in array2 is subtracted and the result Will be stored and displayed in data segment array3*/ 1 2 3 4 5 6 7 8 assume cs: code,ds: data 0000 0000 0003 0005 0009 B8 0000s 8E D8 8B 0E 0000r BE 0002r code segment start : mov ax,data mov ds,ax mov cx,n1 ;initialise counter lea si,array1 ;initialise array pointers lea bx,array2 lea di,array3 l1:mov al,[si] ;perform subtraction of ls byte sbb al,[bx] mov [di],ax ;store result inc si ;update data pointers inc bx inc di ;repeat subtraction till last byte dec cx jnz l1 int 03 code ends data segment 0004 n1 dw 0004h 0000000005060809 array1 dq 05060809h;specify input 0000000001020304 array2 dq 01020304h ???????????????? array3 dq ? ;store output data ends end start ;stop array1 :05060809h array2 :01020304h 04040505h 9 000C BB 000Ar 10 000F BF 0012r 11 0012 8A 04 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 0014 0016 0018 0019 001A 1A 07 89 05 46 43 47 001B 49 001C 75 F4 001E CC 001F 0000 0000 0002 000A 0012 001A Input: Output: 11 THIS PROGRAM PERFORMS MULTIBYTE MULTIPLICATION Turbo Assembler Version 2.51 mul.asm /* The data segment in data1 and the data segment in n2 is multiplied and the result Will be stored and displayed in data segment data2*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 assume cs: code,ds: data 0000 0000 0003 0005 0009 000D 0010 0013 0016 0018 001A 001C 001E code segment B8 0000s 8E D8 8B 0E 0000r 8A 1E 0002r BA 0000 BE 0003r BF 0007r 8A 04 F6 E3 03 C2 8A D4 88 05 start:mov ax,data mov ds,ax mov cx,n1 ;length of array mov bl,n2 ;multiplier mov dx,00h lea si,data1 ;array pointer lea di,data2 ;result pointer l1: mov al,[si] ;get 1st byte of multiplicand mul bl ;multiply add ax,dx mov dl,ah mov [di],al ;store result in result pointer inc si ;update data pointer inc di ;perform multiplication till the last multiplicand dec cx jnz l1 int 03 code ends 17 0020 46 18 0021 47 19 20 21 22 23 24 25 26 27 28 29 30 Input: 0022 49 0023 75 F1 0025 CC 0026 0000 0000 0002 0003 0007 000B 0004 05 01020304 ???????? data segment n1 dw 0004h n2 db 05h data1 dd 01020304h data2 dd ? data ends end start ;stop Multiplier: 05h Multiplicand: 01020304h Output: 050A0F14h 12 THIS PROGRAM PERFORMS MULTIBYTE DIVISION Turbo Assembler Version 2.51 div.asm /* The data segment in data1 and the data segment in n2 is divided and the result Will be stored and displayed in data segment data2*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Input: Output: assume cs: code,ds: data 0000 0000 0003 0005 0009 000D 0010 0013 0015 0017 0018 001A 001C 001E 0020 0021 0022 0023 0025 0026 0000 0000 0002 0003 0007 000B 0004 05 140F0A19 ???????? B8 0000s 8E D8 8B 0E 0000r 8A 1E 0002r BE 0003r BF 0007r B4 00 8A 04 98 F6 F3 1B C2 8A D4 88 05 46 47 49 75 F0 CC code segment start: mov ax, data mov ds,ax mov cx,n1 ;dividend length mov bl,n2 ;divisor lea si,data1 ;initialize data pointer lea di,data2 mov ah,00h l1:mov al,[si] ;get 1st byte of dividend cbw div bl ;perform division sbb ax,dx mov dl,ah mov [di],al ;store quotient inc si ;update dividend and result pointers inc di dec cx ;perform this till MSB jnz l1 int 03 ;stop code ends data segment n1 dw 0004h n2 db 05h data1 dd 140f0a19h data2 dd ? data ends end start Divisor: 05h Dividend; 140F0A19h 04030205h 13 THIS PROGRAM FINDS NO.OF +VE & -VE NO.S IN ARRAY Turbo Assembler Version 2.51 pos_neg.asm /*The data segment in the list finds whether it is a positive number or negative number if msb is 1 it is negative otherwise considered as positive*/ 1 2 3 0000 4 5 0000 33 DB 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Input: Output: 0002 0004 0007 0009 000D 0010 0012 0014 0016 0017 001A 001B 001E 0020 0022 0023 assume cs: code,ds: data code segment start: xor bx,bx ;initialise result pointer 33 D2 xor dx,dx B8 0000s mov ax,data 8E D8 mov ds,ax B1 05 90 90 mov cl,count ;declare length of array BE 0000r mov si,offset list 8B 04 again:mov ax,[si] ;get 1st no. D1 E0 shl ax,01h ;check whether msb is 1 72 04 jc nega ;if 1 the no.is -ve 43 inc bx ;if 0 the no.is +ve EB 02 90 jmp next 42 nega:inc dx 83 C6 02 next:add si,02h ;updte data pointer FE C9 dec cl ;decrement length counter 75 EE jnz again ;repeat untill final no. CC int 03 code ends ;store result 0000 data segment 0000 A500 C009 0159 B900 list dw 0a500h,0c009h,0159h,0b900h = 0005 count equ 05h 0008 data ends end start 0a500h,0c009h,0b900h,0159h no of positive nos :0159h no of negative nos:0a500h,0c009h,0b900h 14 THIS PROGRAM FINDS THE GCD OF TWO NUMBERS Turbo Assembler Version 2.51 gcd.asm /*This program calculates the GCD of two numbers stored at data segment num1 and num2 locations and gives the result at the data segment gcd offset address*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 assume cs: code,ds: data 0000 0000 0003 0005 0008 000A 000D 000F 0011 0013 0014 0016 0018 001A 001C 001F code segment B8 0000s 8E D8 BE 0000r 8B 04 BE 0002r 8B 1C 3B C3 7F 01 93 2B C3 3B C3 7F FA 7C F7 BE 0004r 89 04 start: mov ax,data mov ds,ax mov si,offset num1 ;get 1st no. mov ax,[si] mov si,offset num2 ;get 2nd no. mov bx,[si] cmp ax,bx ;get big no,asdividend jg go back : xchg ax,bx go : sub ax,bx ;get gcd using repeated cmp ax,bx jg go ;division jl back mov si,offset gcd ;store result mov [si],ax int 03 code ends data segment num1 dw 0018h ;the no.s in data segment ;stop 0021 CC 0022 0000 0000 0018 27 0002 0006 num2 dw 0006h 28 0004 ???? gcd dw ? 29 0006 data ends 30 31 end start Input : num1 is 0018h num2 is 0006h 0006h Output: 15 THIS PROGRAM FINDS NO.OF 0's AND 1's IN A 16-BIT NUMBER Turbo Assembler Version 2.51 zer_one.asm /*The data segment in the num finds no. of 1’s and no. of 0’s by converting the given number into binary */ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 assume cs: code,ds: data 0000 0000 0002 0004 0007 0009 000D 0010 0012 0014 0015 0018 0019 001B 001D 001E 33 DB 33 D2 B8 0000s 8E D8 B1 10 90 90 A1 0000r D1 C0 72 04 43 EB 02 90 42 FE C9 75 F3 CC code segment start: xor bx,bx ;clear result counters xor dx,dx mov ax,data mov ds,ax mov cl,count ;declare no. bit count mov ax,num ;get the no. again:rol ax,01h ;finds msb is 0 or 1 jc ones ;if 0 increment 0s count inc bx ;otherwise 1s count jmp next ;perform this until the 1st bit ones:inc dx next:dec cl jnz again int 03 ;stop code ends data segment num dw 0d759h count equ 10h data ends end start ;no. in data segment 0000 0000 D759 = 0010 0002 Input : Output: num is 0d759h number of 0’s :06 Number of 1’s:0A 16 THIS PROGRAM FINDS WHETHER GIVEN NUMBER IS PRIME OR NOT Turbo Assembler Version 2.51 prime.asm /*The data segment in num is prime the same data will be displayed at res otherwise zero will be displayed*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 assume cs: code,ds: data 0000 0000 0003 0005 0008 000A 000C 000F 0012 0013 0015 0017 code segment B8 0000s start: mov ax,data 8E D8 mov ds,ax BE 0000r mov si,offset num 8B 1C mov bx,[si] ;get the number 8B 04 loop1 :mov ax,[si] ;if no.is 1 B9 0001 mov cx,0001h BA 0000 4B 3B D9 74 0B F7 F3 mov dx,0000h ;no.is prime dec bx cmp bx,cx jz ahead2 ;otherwise perform div div bx ;if remainder 0 then no.is not prime 0019 83 FA 00 cmp dx,0000h 001C 74 02 jz ahead1 001E EB EA jmp loop1 ;no remainder no. is prime 0020 8B C2 ahead1: mov ax,dx ;perform div from -1to1 0022 BE 0002r ahead2: mov si,offset res 0025 89 04 mov [si],ax 0027 CC 0028 0000 0000 0012 0002 ???? 0004 int 03 code ends data segment num dw 0012h ;give the input no. res dw ? ;store result here data ends end start ;stop Input : Output: num=0012h result is 0000hi.e,num is not prime. 17 THIS PROGRAM SOLVES THE EQUATION (P+(Q*R)/S) Turbo Assembler Version 2.51 equ.asm /*The data segment in the P,Q,R and S substituted in the equation (P+(Q*R)/S) and the calculated result will be stored in res*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 assume cs: 0000 0000 0003 0005 0008 000C 000E 0012 0014 0018 001A 001D 001F 0020 0000 = = = = 0000 0002 0023 0012 0005 0009 ???? code segment code,ds: data B8 0000s start: mov ax,data 8E D8 mov ds,ax B8 0012 mov ax,q ;get no.q BB 0005 90 mov bx,r F7 E3 mul bx ;multiply with r B9 0009 90 mov cx,s F7 F1 div cx ;div the res by s BA 0023 90 mov dx,p ;add it to p 03 C2 add ax,dx BF 0000r mov di,offset res ;store the result 89 05 mov [di],ax CC int 03 code ends data segment p equ 0023h q equ 0012h r equ 0005h s equ 0009h res dw ? data ends end start ;no.s in datasegment ;result in data segment ;stop Input : Output: p=0023h , q=0012h , r= 0005h , s=0009h ax=002Dh 18 3.LOGICAL OPERATIONS  Conversion of ASCII no. to packed BCD  Conversion of packed BCD no. to ASCII  Conversion of BCD no. into binary 19 THIS PROGRAM CONVERTS ASCII NOS INTO PACKED BCD Turbo Assembler equa.asm Version 2.51 10/11/07 14:11:42 Page 1 /*The ASCII no’s directly store in the registers bl and al is converted into packed BCD and the result will be stored in the accumulator */ 1 2 3 4 5 6 7 8 9 10 11 12 assume cs:code code segment start: mov bl,'2' mov al,'4' and bl,0fh and al,0fh mov cl,04h rol bl,cl or al,bl int 03h code ends end start 0000 0000 0002 0004 0007 0009 000B 000D 000F 0010 B3 32 B0 34 80 E3 0F 24 0F B1 04 D2 C3 0A C3 CC ;GET 1ST ASCII no. ;get 2nd ASCII no. ;mask the upper nibble ;of 2 ASCII nos ;pack the 2 nos. ;BCD result in reg.AL. Input: bl=02h al=04h Output: BCD value is 24h in al register. 20 THIS PROGRAM CONVERTS PACKED BCD TO ITS EQUIVALENT ASCII NO. Turbo Assembler Version 2.51 bcd_asc.asm /*The packed BCD number 0095h is converted into its equivalent ASCII number and result will stored in res1 and res2*/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 assume cs: code,ds: data 0000 0000 0003 0005 0007 000A 000C 000E 0010 0013 0015 0017 001A 001D 0021 0022 code segment B8 0000s start: mov ax,data 8E D8 mov ds,ax 32 E4 xor ah,ah B0 95 90 mov al,bcd ;get the no. 8A E0 mov ah,al ;convert into unpacked bcd 24 0F and al,0fh 0C 30 or al,30h ;find res1 ascii 80 E4 F0 and ah,0f0h B1 04 mov cl,04h D2 C4 rol ah,cl 80 CC 30 and ah,30h ;find res2 ascii A2 0000r mov res1,al ;store result 88 26 0001r mov res2,ah CC int 03 code ends 0000 data segment = 0095 bcd equ 0095h ;BCD INPUT 0000 ?? res1 db ? ;result display 0001 ?? res2 db ? 0002 data ends end start Input : Output: 0095h ASCII value of 9 is 39h ASCII value of 5 is 35h 21 THIS PROGRAM IS FOR THE CONVERSION OF BCD TO BINARY Turbo Assembler Version 2.51 bcd2bin.asm /*The data segment in the bcd_input is converted into binary value and result will be displayed in bin_value*/ 1 assume cs: code,ds: data,ss:stack_seg 2 3 0000 code segment 4 5 0000 B8 0000s start:mov ax,data 6 0003 8E D8 mov ds,ax 7 0005 B8 0000s mov ax,stack_seg 8 0008 8E D0 mov ss,ax 9 000A B8 0000 mov ax,0000h 10 000D BC 00C8r lea sp,top_stack 11 0010 A0 0000r mov al,bcd_input ;get bcd input 12 0013 E8 0004 call bcd_bin ;call bin procedure 13 0016 A2 0001r mov bin_value,a ;store resultl 14 0019 CC int 03 ;stop 15 001A bcd_bin proc near ;save main program status 16 001A 9C pushf 17 001B 53 push bx 18 001C 51 push cx ;convert packed bcd input 19 001D 8A D8 mov bl,al 20 001F 80 E3 0F and bl,0fh ;unpacked bcd 21 0022 24 F0 and al,0f0h 22 0024 B1 04 mov cl,04h 23 0026 D2 C8 ror al,cl ;multiply each digit by its pos. 24 0028 B7 0A mov bh,0ah 25 002A F6 E7 mul bh 26 002C 02 C3 add al,bl ;add the resultants 27 002E 59 pop cx 28 002F 5B pop bx ;back to main program 29 0030 9D popf 30 0031 C3 ret 31 0032 bcd_bin endp 33 0032 code ends 35 0000 data segment 36 0000 11 bcd_input db 17 ;bcd input data segment 37 0001 ?? bin_value db ? ;result area 38 0002 data ends 39 40 0000 stack_seg segment ;reserve stack area 41 0000 64*(0000) dw 100 dup(0) 42 00C8 top_stack label word 43 00C8 stack_seg ends 44 end start Input: 17h Output: 11h 22 4.STRING OPERATIONS AND INSTRUCTION PREFIX  String transfer  Ascending order  Inserting character and spell checking  Deleting character  String comparision 23 THIS PROGRAM TRANSFERS A STRING OF CHARACTERS FROM ONE LOCATION TO ANOTHER Turbo Assembler Version 2.51 trfr_str.asm /*The data segment in the first_string is transferred to new location a and in between it leaves 100 locations*/ 1 2 3 4 5 6 7 8 assume cs: code,ds: data,es:data 0000 0000 0003 0005 0007 code segment B8 0000s 8E D8 8E C0 BE 0000r start:mov ax,data mov ds,ax mov es,ax lea si,first_string ;declare source & destination BF 0068r lea di,new_loc ;pointers B9 001E mov cx,30 ;specify string length FC cld ;move the string from source to destination F3> A4 rep movsb CC int 03 code ends ;stop 9 000A 10 000D 11 0010 12 13 14 15 16 17 18 0011 0013 0014 0000 data segment 0000 72 61 76 69 first_string db 'ravi' 0004 64*(??) db 100 dup(?) ; leave 100 locations 19 0068 1E*(00) new_loc db 30 dup(0) ;locations for destination 20 0086 data ends 21 end start Input : Output: String is ‘ravi’ at 0B7F:0000 String is ‘ravi’ at 0B7F:0071 24 THIS PROGRAM IS TO ARRANGE NUMBERS IN ASCENDING ORDER USING BUBBLE SORT Turbo Assembler Version 2.51 bubsrt.asm /*The data segment in the list are arranged in ascending order */ 1 2 3 4 5 6 7 8 9 10 11 12 assume cs: code,ds: data,es:data 0000 0000 0003 0005 0009 000B 000E 0010 0013 code segment B8 0000s start: mov ax,data 8E D8 mov ds,ax B2 04 90 90 mov dl,count-1 ;initialise counter 8A CA again1: mov cl,dl BE 0000r mov si,offset list ;get offset address 8A 04 again2: mov al,[si] ;getsmallno.in1stlocation 3A 44 01 cmp al,[si+1] 77 05 jb ahead ;compares till the end of array 13 0015 86 44 01 xchg [si+1],al 14 0018 86 04 xchg [si],al 15 001A 83 C6 01 ahead: add si,01 ;bring small no.s into 1st location 16 17 001D E2 EF loop again2 ;in each location 18 001F FE CA dec dl 19 0021 75 E6 jnz again1 ;perform untill no.s are arrange in order 20 21 0023 CC int 03h ; stop 22 23 0024 code ends 24 25 0000 data segment 26 0000 34 50 78 81 12 list db 34h,50h,78h,81h,12h 27 = 0005 count equ 05h 28 0005 data ends 29 30 end start Input : Output: 34h,50h,78h,81h,12h 12h,34h,50h,78h,81h 25 THIS PROGRAM INSERTS A MISSED CHARACTER IN A WORD / CORRECTS A MISSPELT WORD Turbo Assembler Version 2.51 miscr.asm /*The data segment in the array1 is compared with data segment array and correct the misspelt word*/ 1 assume cs: code,ds: data 2 3 0000 code segment 4 5 0000 B8 0000s start:mov ax,data 6 0003 8E D8 mov ds,ax 7 0005 8E C0 mov es,ax 8 0007 BE 0000r lea si,array ;get the right word 9 000A B9 0005 90 mov cx,num 10 000E BF 0005r lea di,array1 ;compare the right word 11 0011 FC l2: cld ;the word to be corrected 12 0012 F3> A6 repe cmpsb 13 0014 E3 05 jcxz l1 14 0016 E8 0003 call procedure ;call procedure 15 0019 EB F6 jmp l2 ;if mismatch found 16 001B CC l1: int 03h 17 001C 57 procedure: push di 18 001D 51 push cx ;insert the character 19 001E 56 push si 20 001F 4E dec si 21 0020 4F dec di 22 0021 8A 04 mov al,[si] 23 0023 86 05 l3: xchg al,[di] 24 0025 47 inc di 25 0026 49 dec cx 26 0027 75 FA jnz l3 27 0029 88 05 mov byte ptr[di],al ;make final byte 0 28 002B 5E pop si 29 002C 59 pop cx 30 002D 5F pop di 31 002E C3 ret 32 33 002F code ends 34 35 0000 data segment 36 0000 6B 69 72 61 6E array db 'kiran' 37 = 0005 num equ ($-array) 38 0005 6E 6B 72 69 array1 db 'nkri' 39 0009 data ends 40 41 end start ; stop Input: mispelt word is ‘nkri’ Output: Correct word is ‘kiran’ 26 THIS PROGRAM DELETES SPECIFIED CHARACTER FROM STRING Turbo Assembler Version 2.51 del_char.asm /*The data segment in the array1 and the specified character in accumulator al will be deleted*/ 1 assume cs: code,ds: data,es:data 2 3 0000 code segment 4 5 0000 B8 0000s start: mov ax,data 6 0003 8E D8 mov ds,ax 7 0005 8E C0 mov es,ax 8 0007 BE 0000r lea si,array1 ;get the string address 9 000A B9 0007 90 mov cx,num 10 000E B0 65 mov al,'e' ;get the character to be deleted 11 0010 3A 04 l2:cmp al,[si] ;find the character to be deleted 12 0012 75 06 jne l1 13 0014 E8 0008 call procedure ;call the delete procedure 14 0017 49 dec cx 15 0018 75 F6 jnz l2 16 001A 46 l1:inc si 17 001B 49 dec cx 18 001C 75 F2 jnz l2 ;stop 19 001E CC int 03 20 001F 51 procedure:push cx 21 0020 56 push si 22 0021 8B FE mov di,si ;initialise pointers 23 0023 49 dec cx 24 0024 46 inc si ;move the string 1 byte forth 25 0025 FC cld 26 0026 F3> rep 27 0027 A4 movsb 28 0028 C6 05 00 mov byte ptr[di],00h ;make final byte 0 29 002B 5E pop si 30 002C 59 pop cx 31 002D C3 ret 32 002E code ends ;back to main program 33 34 0000 data segment 35 0000 65 6C 65 6D 65 6E 74 array1 db 'element' ;string 36 = 0007 num equ ($-array1) 37 0007 data ends 38 end start Input : element Output: lmnt 27 THIS PROGRAM COMPARES 2 STRINGS & DISPLAY 0 IF NOT EQUAL AND DISPLAY 00 FF EQUAL Turbo Assembler Version 2.51 cmpr2str.asm /* The string stored in the second_string is if equal to the string in first_string then display 00 FF other wise 00*/ 1 assume cs: code,ds: data,es:data 2 3 0000 code segment 4 5 0000 B8 0000s start: mov ax,data ;initialise the segments needed 6 0003 8E D8 mov ds,ax 7 0005 8E C0 mov es,ax ;compare 2 strings 8 0007 BE 0000r lea si,first_string 9 000A BF 000Er lea di,second_string 10 000D B9 000E 90 mov cx,str_length 11 0011 FC cld 12 0012 F3> A6 repe cmpsb 13 0014 75 03 jne sound_alarm 14 0016 EB 05 90 jmp ok ;display 0 if not equal 15 0019 sound_alarm: 16 0019 B8 0000 mov ax,0000h 17 001C CC int 03 18 19 001D ok: 20 001D B8 00FF mov ax,00ffh ;display 00 if equal 21 0020 CC int 03h 22 0021 code ends 23 24 0000 data segment 25 0000 6D 69 63 72 6F 70 72+ first_string db'microprocessor';declare2 strings 26 6F 63 65 73 73 6F 72 27 = 000E str_length equ($first_string);specify length of string 28 000E 6D 69 63 72 6F 70 72+ second_string db 'microprocessor' 29 6F 63 65 73 73 6F 72 30 001C data ends 31 end start Input: first string’ MICROPROCESSOR' second string 'MICROPROCESSOR' Output: 00FF i.e, string is equal. 28 6.DOS/BIOS PROGRAMMING  Reading keyboard (Buffered with and with out echo) - Display characters 29 THIS PROGRAM READS CHARACTER FROM KEY BOARD AND DISPLAYS THE PRESSED KEY Turbo Assembler Version 2.51 10/11/07 14:09:15 Page 1 cons.asm /*The data segment in the mesg1rreads the character from the keyboard and the same character displayed on the mesg2*/ 1 assume cs:code,ds:data 2 0000 code segment 3 0000 B8 0000s start:mov ax,data ;initialize data segment 4 0003 8E D8 mov ds,ax 5 0005 B4 09 mov ah,09h ;prompt for key press 6 0007 BA 0000r mov dx,offset mesg1 7 000A CD 21 int 21h 8 000C B4 01 mov ah,01h ;read character 9 000E CD 21 int 21h 10 0010 A2 001Cr mov char,al 11 0013 BA 2000 mov dx,2000h ;wait for some time 12 0016 B9 FFFF again1:mov cx,0ffffh 13 0019 90 again2:nop 14 001A 90 nop 15 001B 49 dec cx 16 001C 75 FB jnz again2 17 001E 4A dec dx 18 001F 75 F5 jnz again1 19 0021 B4 09 mov ah,09h display msg2 &character 20 0023 BA 000Er mov dx,offset mesg2 21 0026 CD 21 int 21h 22 0028 B4 02 mov ah,02h 23 002A 8A 16 001Cr mov dl,char 24 002E CD 21 int 21h 25 0030 B4 4C mov ah,4ch 26 0032 CD 21 int 21h 27 0034 code ends 28 0000 data segment 29 0000 74 79 70 65 20 61 6E+ mesg1 db 'type any key:$';msgs in data seg. 30 79 20 6B 65 79 3A 24 31 000E 74 79 70 65 64 20 6B+ mesg2 db 'typed key is:$' 32 65 79 20 69 73 3A 24 33 001C 00 char db 0 34 001D data ends 35 end start Input: Output: ‘Type any key’: u ‘Type any key’: u 30 II.INTERFACING 31 1.8259-INTERRUPT CONTROLLER : GENERATE AN INTERRUPT USING 8259 INTERRUPT CONTROLLER AIM: a) To display the pulse counter. b) To derive the frequency counter. APPARATUS: 1. ESA 86/88-2 Microprocessor kit. 2. Function generator. 3. Connecting wires. THEORY: The Processor 8085 had five hardware interrupt pins. Out of these five interrupt pins, four pins were allotted fixed vector addresses but the pin INTR was not allotted any vector address, rather an external Device was supposed to hand over the type of the interrupt to the microprocessor. The microprocessor then gets this type and derives the interrupt vector address from that. Consider an application where a number of I/O devices connected with CPU desire to transfer data using interrupt driven data transfer mode. In this type of applications more number of interrupts are required than available in typical microprocessor. Moreover ,in this multiple interrupts systems the processor will have to take the care of priorities for the interrupts, simultaneously occurring at the interrupt request pins to overcome all this difficults ,we require a Programmable interrupt controller which is able to handle a number of interrupts at a time.8259A was operated with 8-bit as well as 16-bit processors. PORT ADDRESSES OF 8279 Control word register = FFF4 Data Port Address = FFF6 32 8259INTERFACING 33 PROGRAM: PULSE COUNTER Main program: Memor y address 2000 2006 200C 2012 2015 2017 2018 201B 201D 201E 2020 2021 2023 2024 2025 Op codes C7,06,00,30,00,0 0 C7,06,20,01,50,2 0 C7,06,22,01,00,0 0 BA,F4,FF B0,13 EE BA,F6,FF B0,48 EE B0,03 EE B0,FE EE FB EB,FE labels Mnemonics Operands MOV MOV MOV MOV MOV OUT MOV MOV OUT MOV OUT MOV OUT STI JMP [3000],0000H [0120],2050H [0122],0000H DX,FFF4H AL,13H DX,AL DX,FFF6H AL,48H DX,AL AL,03H DX,AL AL,FEH DX,AL L1 Comments ;Initial cnt.0 ; ISR addr .in INT vector location. ;Initialize 8259 in edge triggered interrupt , 8086 processor, automatic end of interrupt , interrupt no. 0 ; Keep monitoring the interrupt. Delay subroutine: Memory address 2050 2053 2055 2056 2059 205E Op codes A1,00,30 04,01 27 A3,00,30 9A,0A,0B,00,FF CF labels Mnemonics Operands MOV ADD DAA MOV CALL IRET AX,[3000] AL,01H [3000],AX FF00:0B0A ;Display count ; Back main. to Comments ; Increment the counter by 1. L1: 34 35 FREQUENCY COUNTER Main program: Memor y address 2000 2006 200C 2012 2015 2017 2018 201B 201D 201E 2020 2021 2023 2024 2025 2028 202B 202C 202D 202F 2030 2032 2037 Op codes C7,06,00,30,00,0 0 C7,06,20,01,50,2 0 C7,06,22,01,00,0 0 BA,F4,FF B0,13 EE BA,F6,FF B0,48 EE B0,03 EE B0,FE EE FB BB,0C,00 B9,02,63 90 49 75,FC 4B 75,F6 9A,0A,0B,00,FF EB,FE labels Mnemonics Operands MOV MOV MOV MOV MOV OUT MOV MOV OUT MOV OUT MOV OUT STI MOV MOV NOP DEC JNZ DEC JNZ CALL JMP [3000],0000H [0120],2050H [0122],0000H DX,FFF4H AL,13H DX,AL DX,FFF6H AL,48H DX,AL AL,03H DX,AL AL,FEH DX,AL BX,000CH CX,6302H CX L1 BX L2 FF00:0B0A L3 Comments ;Initial cnt.0 ; ISR adder .in INT vector location. ;Initialize 8259 in edge triggered interrupt , 8086 processor, automatic end of interrupt , interrupt no. 0 ;Activate interrupt ; Initialize counters for 1 sec delay. ; Wait for 1sec. ; Display the frequency value. Interrupt service subroutine: Memory address 2050 2053 2055 2056 Op codes A1,00,30 04,01 27 A3,00,30 labels Mnemonics Operands MOV ADD DAA MOV AX,[3000] AL,01H [3000],AX Comments ;Count pulses the L2: L1: L3: 36 2059 CF IRET ; Back to main. RESULT: The count of the pulses is displayed on the microprocessor data field. The frequency is measured and displayed. VIVA QUESTIONS: 1. Which initialisation command word indicates whether PIC is being used in single or cascaded mode? 2. What is meant by handshaking? 3. Explain IRET instruction? 4. In the PIC which registers is used to mask the interrupts? 5. What are the total numbers of interrupts available if all the 8-inputs of PIC are having slave? 6. What is MACRO? 7. What are the flags of 8086? 8. Which pin is used to distinguish the minimum mode and maximum mode? 37 38 2.8279-KEYBOARD DISPLAY : WRITE A SMALL PROGRAM TO DISPLAY A STRING OF CHARACETRS. AIM: To display string of characters. APPARATUS: ESA 86/88-2 Microprocessor kit. THEORY: Intel’s 8279 is a general purpose keyboard display controller that simultaneously drives the display of a system and interfaces a key board with the CPU, leaving it free for its routine task .The keyboard display interface scans the keyboard to identify if any key has been pressed and sense the code of the pressed key to Performed by the controller in repetitive fashion with out involving the Cup-Tie keyboard is interfaced either in interrupt mode or polled mode. In the interrupt mode the processor is requested service only if any key is pressed otherwise the CPU can proceed with its main task. In the polled mode the CPU periodically reads an internal flag of 8279 to check for a key pressure. The keyboard section can interface an array of a maximum of 64 keys with the CPU.The keyboard entries are debounced and stored in 8-byte FIFO RAM that is further accessed by the CPU to read the key codes. If more than 8-characters are entered in the FIFO. Before any FIFO read operation the overrun status is set. The 8279 is normally provides maximum of sixteen 7 segment Display interface with CPU. PORT ADDRESSES OF 8279 Control word register = FFEB Data Port Address = FFE9 8279A Interfacing: 8086 8279 7-seg display 39 8279 INTERNAL ARCHITECTURE PROGRAM: To display string of characters Memory address 2000 2003 2005 2006 2008 2009 200B 200C 200F 2012 2015 2017 2018 2019 201A 201C Op codes BA,EB,FF B0,00 EE B0,38 EE B0,90 EE BE,00,30 B9,LENGTH BA,E9,FF 8A,04 EE 46 49 75,F9 EB,FE labels Mnemonics Operands MOV MOV OUT MOV OUT MOV OUT MOV MOV MOV MOV OUT INC DEC JNZ JMP DX,FFEBH AL,00H DX,AL AL,38H DX,AL AL,90H DX,AL SI,3000H CX,LENGTH DX,FFE9H AL,[SI] DX,AL SI CX L1 L2 Comments ; Initialize 8279 in encoded scan keypad 2key lock out,8char display left entry. ;Select display position 0 ;Display the string of characters L1: L2: 40 RESULT: A character is displayed at 0 position of the display. A string characters is displayed on left entry basis. A character is read from the keyboard and displayed the key no on the display using look-up table method. VIVA QUESTIONS: 1. What is the value in AH perform input from keyboard? 2. A keyboard is made using 12 keys connected not as a matrix. How many pins of the I/O port are used? 3. Write a 7–segment code for ‘B’? 4. In the single character display using interrupt 21H, DL is the register contains character to display. If DL contains 41H, which character is displayed? 5. What is the difference between CALL and JMP? 6. What is the purpose of ALE? 7. What are the difference between microprocessor and micro controller? 41 42 3.8255- PROGRAMMABLE PERIPHERAL INTERFACE (PPI) AIM: To generate sine wave. APPARATUS: 1. 2. 3. 4. 5. THEORY: The parallel input-output port chip 8255 is also called as Programmable peripheral input-output Port. The Intel’s 8255 are designed for use with Intel’s 8-bit, 16-bit and higher capability microprocessors. It has 24 input/output lines which may be individually programmed in 2-groups of 12 lines each, or 3 groups of 8 lines .The two groups of I/O pins are named as GROUP A and GROUP B. Each of these two groups contain a sub group of 8 I/O lines called as 8bit Port and other sub group of 4 I/O lines are a 4-bit port. Thus GROUP A Contains an 8-bit port A along with a 4-bit port, C upper. Port lines are identified by symbols PAO-PA7, While the port C lines are identified as PC4-PC7 .Similarly group B contains an 8-bit port B, containing lines PB0-PB7 and a 4-bit port C with lower bits PC0-PC3 .The port C upper and port C lower can be used in recombination as an 8-bit port-C .Both the port Cs are assigned the same address. Thus one may have either Three 8-bit I/O ports are two 8-bit and two 4-bit I/O ports from 8255.All of these ports can function independently either as input or as output ports. This can be achieved by programming the bits of an internal register of 8255 called as Control word register. (CWR). PORT ADDRESSES OF 8255 Control word register Port A Port B Port AC = FFE7 = FFE1 = FFE3 = FFE5 ESA 86/88-2 Microprocessor kit. C.R.O. Stepper motor interface module with stepper motor. F R C Cable. Power supply- +15v. Block diagram of 8255 Interfacing Micro processor 8086 8255 PPI Stepper motor inter face 43 Block diagram of 8255 programmable peripheral interface: POWER SUPPLIES +5V GND Group A control Group A Port A (8) I/O PA7-PA0 BIDIRECTIOAL DATA BUS BUFFER 8 bit internal bus DATA BUS BUFFER Group A Port C upper (4) I/O PC7-PC4 D7--D0 Group B Port C lower (4) I/O PC3-PC0 __ RD __ WR A1 A0 RESET Read/ write Control logic Group B control Group B Port B (8) I/O PB7-PB0 __ CS Generation of a Sine Waveform: 8086 MICRO PROCESSOR 8255 PPI 8-BIT DAC CRO 44 Program: Memory address 2000 2002 2005 2006 2009 200C 2010 2012 2013 2014 2015 2017 Lookup table: Memory address 3000 Corresponding values 7F,80,82,83,84,86, 87,88,89,8A,8B,8C,8C, 8D,8E,8E,8F,8F,8F, Op codes B0,80 BA,E7,FF EE BA,E1,FF B9, 22,00 8B,36,00,30 8A,04 EE 46 49 75,F9 EB,F0 labels Mnemonics Operands AL,80H DX,FFE7H DX DX,FFE1H CX,22H SI,[3000H] AL,[SI] DX SI CX L1 BACK Comments ;Initialize 8255 all ports o/p ;Keep on writing the sine wave co ordinate data values to port A MOV MOV OUT MOV BACK: MOV MOV L1: MOV OUT INC DEC JNZ JMP RESULT: Amplitude and time period of the square wave are measured. Stepper motor is rotated. VIVA QUESTIONS: 1. Give the BSR format? 2. What is the angle of a stepper motor in full step mode? 3. 8255 has how many pins? 4. If the Control word 09bH is given to control register of the 8255 ppi then explain what is the condition of ports? 5. If the 8255 is selected for addresses 0F800H-0F806H what is the address of port C? 6. Mode 1 of 8255 is used for which of the I/O methods? 7. 8255 has how many ports? 8. What are the applications of the ports? 9. Why we need interfacing devices? 45 46 4.8251- UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART) AIM: To transfer a block of data. To receive a block of data. APPARATUS: ESA 86/88-2 Microprocessor kits—2n0s. R S 232 Cable. THEORY: Intel’s 8251A is a Universal Asynchronous receiver and transmitter compatible with Intel’s processors. This may be programmed to operate in any of the serial communication modes built in to it. This chip converts the parallel data in to serial stream of bits suitable for serial transmission. It is able to receive a serial stream of bits and convert in to parallel data bytes to be read by a microprocessor. The data transmission between two points involves unidirectional or bidirectional transmission of meaningful digital data through a media. There are basically three modes of data transmission. a) Simplex b) Duplex c) Half-duplex In simplex mode data is transmitted only in one direction over a Single communication channel. In Duplex mode data may be transferred between two transreceivers.In both Directions simultaneously. In half-duplex mode data transmission may take place in either direction, but at a time data may be transmitted only in one direction. PORT ADDRESSES OF 8279 Control word register = FFF2 Data Port Address 8251A Interfacing = FFF0 47 D7-D0 DATA BUS BUFFER I N RESET CLK C/D __ RD __ WR __ CS ___ DSR __ DTR __ CTS __ RTS READ/ WRITE CONTROL LOGIC T E R N A L B U MODEM CONTROL S TRANSMIT BUFFER (P—S) TxD TxRdy TRANSMIT CONTROL TxEMPT TxC RECEIVER BUFFER (S—P) RxD RECEIVE CONTROL RxRdy ___ RxC SYNDET/ BRKDET FUNCTIONAL BLOCK DIAGRAM OF 8251 USART 48 PROGRAM: Transmitter Memory address 2000 2003 2005 2006 2009 200B 200C 200F 2011 2012 2015 2017 2019 201A 201D 201F 2021 2022 2025 2027 2029 202A 202D 2030 2033 2034 2036 2028 203A 203D 203F 2040 2041 2042 2044 Op codes BA,F2,FF B0,00 EE B9,02,00 E2,FE EE B9,02,00 E2,FE EE B9,02,00 E2,FE B0,40 EE B9,02,00 E2,FE B0,CE EE B9,02,00 E2,FE B0,37 EE B9,0A,00 BE,00,30 BA,F2,FF EC 24,81 3C,81 75,F9 BA,F0,FF 8A,04 EE 46 49 75,EC CC labels Mnemonics Operands MOV MOV OUT MOV LOOP OUT MOV LOOP OUT MOV LOOP MOV OUT MOV LOOP MOV OUT MOV LOOP MOV OUT MOV MOV MOV IN AND CMP JNZ MOV MOV OUT INC DEC JNZ INT DX,FFF2H AL,00H DX,AL CX,0002H L1 DX,AL CX,0002H L2 DX,AL CX,0002H L3 AL,40H DX,AL CX,0002H L4 AL,CEH DX,AL CX,0002H L5 AL,37H EE CX,000AH SI,3000H DX,FFF2H AL,DX AL,81H AL,81H L6 DX,FFF0H AL,[SI] DX,AL SI CX L7 03 Comments ; Soft ware reset 8251. L1: L2: L3: L4: L5: ;activate both Txer and Rxer with communication parameters b.r.f 16,char length 8,no stop bits,2 start bits, no parity. ;transmitting block length 10, start addr.3000 ;wait for Txer ready ;transmit the total block on polling basis L7: L6: 49 Receiver Memory address 2000 2003 2005 2006 2009 200B 200C 200F 2011 2012 2015 2017 2019 201A 201D 201F 2021 2022 2025 2027 2029 202A 202D 2030 2033 2034 2036 2038 203B 203D 203F 2040 2041 2042 Op codes BA,F2,FF B0,00 EE B9,02,00 E2,FE EE B9,02,00 E2,FE EE B9,02,00 E2,FE B0,40 EE B9,02,00 E2,FE B0,CE EE B9,02,00 E2,FE B0,37 EE B9,0A,00 BE,00,30 BA,F2,FF EC 24,81 75,FB BA,F0,FF 8A,04 EE 46 49 75,EE CC labels Mnemonics Operands MOV MOV OUT MOV LOOP OUT MOV LOOP OUT MOV LOOP MOV OUT MOV LOOP MOV OUT MOV LOOP MOV OUT MOV MOV MOV IN AND JNZ MOV MOV OUT INC DEC JNZ INT DX,FFF2H AL,00H DX,AL CX,0002H L1 DX,AL CX,0002H L2 DX,AL CX,0002H L3 AL,40H DX,AL CX,0002H L4 AL,CEH DX,AL CX,0002H L5 AL,37H EE CX,000AH SI,3000H DX,FFF2H AL,DX AL,02H L6 DX,FFF0H AL,[SI] DX,AL SI CX L7 03 Comments ;software reset 8251. L1: L2: L3: L4: L5: ; activate both Txer and Rxer with communication parameters b.r.f 16, char length 8, no stop bits, 2 start bits, no parity. ;receiving block length 10, start addr.3000 ;wait for Rear ready ;receive the total block on polling basis L7: L6: 50 RESULT: A block of 10 bytes is transmitted from the location 3000. A block of 10 bytes is received and stored at location 3000. VIVA QUESTIONS: 1. 2. 3. 4. 5. 6. 7. 8. What signal is used to receive serial data by the DTE from the DCE? What is device from which data originate s or terminates? What are the data transmission techniques? What is the difference between simplex and duplex? What is baud rate factor? The L2 and L1 bits in mode word are used for setting which parameter? What is the full form of USART? Which parameter is set by using bits S1 and S2? 51 52 III.MICRO CONTROLLER 8051 53 INTRODUCTION TO 8051 MICROCONTROLLER: Feature of 8051 Microcontroller: 1. ESA 51e operates on single +5v power supply either in stand alone mode using PC keyboard and LCD or with host PC through its RS-232C interface in serial mode implemented using the On-chip serial port of Microcontroller. 2. Stand alone and serial monitor programs support the entry of user programs editing and debugging facilities like single stepping and full speed execution of user programs. 3. Total On-board memory is 128Kbytes of which 88K bytes RAM has back-up provision. 4. I/O lines and four programmable interval timers. 5. INTERRUPTS: EXTERNAL: INTERNAL: INT is used for implementing single stepping and user’s break switching is available to user. Internal timer and serial interrupts are used by the system monitor. COMMANDS: A Assembler: ESA 5E provides the powerful, PROM resident one-line assembler to enhance development work. This assembler supports the entire standard mnemonics and addressing modes of Intel /5 microcontrollers. FUNCTION: The assembler generates the actual machine and stores them in the memory locations defined by the program.Also, the system will display the codes generated as well as the source statements. Any error detected is also displayed on the screen. C Compare a block of memory with destination block Function: Compare command can be used to compare the contents of one memory block with The content of another memory block. F Fill memory Fill a block of memory with a constant or search a string of data in program memory, external data memory and internal data memory. Function: This command is used to fill a block of memory with specified constant. G Go command Transfer the processor control from the monitor to user program. 54 Function: The GO command is used to transfer the control of the system from monitor to the users Program. H Help command List all the commands supported by serial monitor. Function: The help command is used to list all the commands supported by the monitor. J Jump to address: Function: The J command is used to change the program counter value to the desired address Before executing a program by either GO command or SINGLE STEP command. Modify/Display/Move memory Modify/Display/Move memory contents in program memory, external data memory ands internal Data memory with all combinations Function: The M Modify memory command is used to examine the contents of specified memory locations. Further if location are in RAM their contents can be altered if desired and block move contents of memory from program, data or internal memory to program or data or internal memory for all combinations. The M Display memory command is used to display the contents of the program memory, external or internal data memory. The M Move memory command is used to move a block of data from one area of the memory to another area. P Programmer: S Single step command: The command is used to execute a program one instruction at a time. With each instruction Executed, control is returned to the monitor. Thus this command is an extremely useful debugging tool. Provision has been made for single stepping with disassembly. S Single step command with disassembly: Function: This command is used to single step a program with disassembly. The register content Will not be displayed. Z Disassemble: Disassembly is an extremely useful feature, often employed during debugging Function: A disassemble converts machine language codes in to assembly language mnemonics, making it easy for user to understand the/verify the program. M 55 PORT0 DRIVER PORT2 DRIVER RAM ADDR REGISTER RAM PORT0 LATCH PORT2 LATCH ROM B REGISTER ACC C TMP1 ALU TMP2 STACK POINTER PROGRAM ADDR REGISTER BUFFER PC INCREMENT PSW INTERRUPT, SERIEL PORTAND TIMER BLOCKS PROGRAM COUNTER DPTR TIMING AND CONTROL INSTRUCTIO N REGISTER PORT1 OSCILLAT OR PORT1 DRIVERS PORT3 LATCH PORT3 DRIVERS DRIVER 56 1. ARITHMATIC OPERATIONS AIM: To execute the program in stand alone mode and print ESA PVT LTD APPARATUS: 1.ESA-51 microcontroller kit 2. Power supply 3. Key board THEORY: 8051 is an 8 bit Microcontroller which a Microprocessor with integrated peripherals. The accumulator register act as an operand register in case of some instructions. The accumulator has been allotted an address in the on chip special for register bank. Data pointer register is a 16-bit register and contains a high byte and positive lower byte Of a 16-bit register external RAM address. It is accessed as a 16-bit register or 28-bit register as a specified above. It has allotted to address as a specified also in the special function register bank for its two bytes DPH and DPL .SWAP is an instruction which interchanges the upper and lower nibble of a register for example SWAPS means it interchanges the upper and lower nibble of the contents of accumulator register. Memor Op codes y address 8000 8003 8005 8008 800B 800E 8013 8018 12,03,BB C2,D5 90,80,0E 12,03,2A 02,80,0B 45,53,41,20,50 56,54,20,4C,54 44,2E,00 labels Mnemonics Operands Comments LCALL CLR MOV LCALL LJMP STG DB ‘ESA PVT LTD’ 03BB D5 DPTR,#800E 0348h 800B To select the Program memory Out routine to display string of characters INPUT: 45,53,41,20,50,56,54,20,4C,54,44,2E,00 OUTPUT: ’ESA PVT LTD’ RESULT:’ESA PVT LTD’ is displayed on the LCD in stand alone mod 57 AIM: By using 8051 microcontroller a) To perform addition of two numbers b) To perform subtraction of two numbers c) To perform multiplication of two numbers d) To perform division of two numbers APPARATUS: 1.ESA-51 microcontroller kit 2. Power supply 3. Key board THEORY: The 8051 is an 8-bit Microcontroller designed by Intel. It was optimized for 8-bit Mathematics and single bit Boolean operations. Microcontroller consists of Cutworm kinds of memory Sections I/O ports, special function registers and control logic needed foe a variety of peripheral functions. These elements communicate through an 8-bit data bus which runs through out the chip referred to as internal Data bus. This bus if buffered to the outside world through an I/O port when memory or I/O expansion is desired ADDITION Memory address 8000 8003 8004 8006 8007 8008 800A 800B 800C Op codes 90,90,00 E0 E5,0B A3 A0 25,0B A3 F0 02,00,00 labels Mnemonics Operands MOV MOVX MOV INC MOVX ADD INC MOVX LJMP Comments DPTR,#9000H Keep data in 9000h and A,@DPTR 9001h;data memory B,A DPTR A,@DPTR A,B DPTR @DPTR,A 0 Perform addition operation Store the result in 9002h and 9003h of data memory. INPUT: 9000-05H 9001-02H OUTPUT: 9002-0AH 58 SUBTRACTION Memory address 8000 8003 8004 8006 8007 8008 800A 800B 800C Op codes 90,90,00 E0 E5,0B A3 A0 95,0B A3 F0 02,00,00 labels Mnemonics Operands MOV MOVX MOV INC MOVX SUBB INC MOVX LJMP Comments DPTR,#9000H Keep data in 9000h and A,@DPTR 9001h;data memory B,A DPTR A,@DPTR A,B DPTR @DPTR,A 0 Perform subtraction operation Store the result in 9002h and 9003h of data memory. INPUT: 9000-06H 9001-02H OUT PUT: 04H 59 MULTIPLICATION Memory Op codes address 8000 8003 8004 8006 8009 800A 800B 800E 800F 8010 8012 8013 90,90,01 E0 F5,F0 90,90,00 E0 A4 90,90,02 F0 A3 E6,F0 F0 02,00,00 labels Mnemonics Operands MOV MOVX MOV MOV MOVX MUL MOV MOVX INC MOV MOVX LJMP Comments DPTR,#90001H Keep data in 9000h and A,@DPTR 9001h;data memory 0F0H,A DPTR,#9000H A,@DPTR AB DPTR,#9002H @DPTR,A DPTR A,OFOH @DPTR,A 0 Perform multiplication operation Store the result in 9002h and 9003h of data memory. INPUT: 9000- 05 H 9001- 04 H OUTPUT: 9002-09H 60 DIVISION Memory Op codes address 8000 8003 8004 8006 8008 8009 800A 800D 800E 800F 8011 8012 INPUT: OUTPUT: 90,90,01 E0 F5,F0 16,82 E0 84 90,90,02 F0 A3 E6,F0 F0 02,00,00 9000-04H 9001-05H 9002-01H labels Mnemonics Operands MOV . MOVX MOV DEC MOVX DIV MOV MOVX INC MOV MOVX LJMP Comments DPTR,#90001H Keep data in 9000h and 9001h;data A,@DPTR memory 0F0H,A 82H A,@DPTR AB DPTR,#9002H @DPTR,A DPTR A,OFOH @DPTR,A 0 Perform division operation Store the result in 9002h and 9003h of data memory. RESULT: Hence arithmetic operations like addition, subtraction, multiplication and division are performed on 8051 Microcontroller. 61 2. TIMER IN DIFFERENT MODES AIM: To generate a square wave with frequency using Timer 0 and Interrupts APPARATUS: 1. 2. 3. 4. THEORY: 8051 has two 8-bit register A and B, which can be used to store operands, as allowed by the instruction set. 8051 has a family of special function registers called a special function registers including A and B registers. There is total number of 21-bit addressable 8-bit registers. The registers TH0-TL0 from 16-bit counter or timer registers, with H indicating the upper byte and L indicating the lower byte of 16-bit timer registers.TMOD is ca be used for programming the modes of Times/Counters .TCON is called Timer/Counter control register. Some of the bits of this registers are used to turn the Timers on or off. This registers are also contains interrupt control flags for external interrupts INT1 or INT0. MAIN PROGRAM: Memory address 8000 8003 8004 8006 8007 8008 Op codes 75,89,01 75,8C,F0 75,8A,FF 11,20 80,FE 53,41,20 labels Mnemonics Operands MOV MOV MOV ACALL CPL SJMP TH1 8C,#0FF Introduce delay 8020 95 8003 Keep complimenting port 1,5-bit To get square wave Comments Microcontroller kit Cathode ray oscilloscope Keyboard CRO probes TMOD Initialize timer 0 89,#01 In mode 1,16bit count TL1 8A,#0F0 reg.mode 62 DELAY PROGRAM: Memory address 8020 800 8004 8006 8007 C2,8C C2, 8D 22 Op codes D2,8C labels Mnemonics Operands SETB JNB CLR CLR RET 8C 8D,8022 8C 8D Comments Start the timer Wait for delay time Reset timer Reset timer over flow flag MAIN PROGRAM: Memory address 8000 800 8004 8006 8007 Op codes 75,89,02 75,A8,82 75,8C,F0 D2,8C 80,0B labels Mnemonics Operands MOV MOV MOV SETB SJMP 89,#02 0A8,#82 8C,#0F0 8C 800B Comments Initialize timer 0 in mode 2, Declare TF 0 as an interrupt Load timer count reg.TL1 Start the timer Keep monitoring the interrupt INTERRUPT SERVICE ROUTINE: Memory address FFF1 FFF2 Op codes B2,95 32 labels Mnemonics Operands CPL RETI 95 Comments Generate a square wave on interrupt basis 63 OBSERVATIONS: Time period calculations for Timer0 mode1 16-bit counter =FOFFH Number of clock cycles = FFFF – FOFF=F00H Clock period =11.095 µSec/12=0.925µSec Delay= Clock period* Number of clock cycles=0.925µSec* F00H=3.78msec. Therefore ON time=3.78msec OFF time=3.78msec Time period=ON time OFF time= 7.56msec Frequency=1/Time period=1/7.56msec=132Hz Time period calculations for Timer0 mode2 16-bit counter =FFH Number of clock cycles = FF – FO=0FH Clock period =11.095 µSec/12=0.925µSec Delay= Clock period* Number of clock cycles=0.925µSec* 0F=13.875µSec. Therefore ON time=13.875µSec. OFF time=13.875µSec. Time period=ON time OFF time= 27.75 µSec Frequency=1/Time period=1/27.75 µSec =36.04 KHz. RESULT: Hence square wave in Timer0 mode1 with a frequency 132Hz and in timer0 mode2 with a frequency 36.04 KHz was generated. 64 EXPERIMENTS OTHER THAN JNTU SYLLABUS 65 1.8279-KEYBOARD DISPLAY : PROGRAM TO DISPLAY A CHARACETR & READING KEYBOARD AND DISPLAY CHARACTER AIM: To display single character. To read the character from the keyboard and display. APPARATUS: ESA 86/88-2 Microprocessor kit. THEORY: Intel’s 8279 is a general purpose keyboard display controller that simultaneously drives the display of a system and interfaces a key board with the CPU, leaving it free for its routine task .The keyboard display interface scans the keyboard to identify if any key has been pressed and sense the code of the pressed key to Performed by the controller in repetitive fashion with out involving the Cup-Tie keyboard is interfaced either in interrupt mode or polled mode. In the interrupt mode the processor is requested service only if any key is pressed otherwise the CPU can proceed with its main task. In the polled mode the CPU periodically reads an internal flag of 8279 to check for a key pressure. The keyboard section can interface an array of a maximum of 64 keys with the CPU.The keyboard entries are debounced and stored in 8-byte FIFO RAM that is further accessed by the CPU to read the key codes. If more than 8-characters are entered in the FIFO. Before any FIFO read operation the overrun status is set. The 8279 is normally provides maximum of sixteen 7 segment Display interface with CPU. PORT ADDRESSES OF 8279 Control word register = FFEB Data Port Address = FFE9 8279A Interfacing: 8086 8279 7-seg display 66 8279 INTERNAL ARCHITECTURE PROGRAM: To display single character Memory address 2000 2003 2005 2006 2008 2009 200B 200C 200F 2011 2012 Op codes BA,EB,FF B0,00 EE B0,38 EE B0,90 EE BA,E9,FF B0,CHAR EE EB,FE labels Mnemonics Operands MOV MOV OUT MOV OUT MOV OUT MOV MOV OUT JMP DX,FFEBH AL,00H DX,AL AL,38H DX,AL AL,90H DX,AL DX,FFE9H AL,CHAR DX,AL L1 Comments ; Initialize 8279 in encoded scan keypad 2key lock out, 8char display left entry. ;Select display position 0 ;Display character the L1: 67 To read the character and display Memory address 2000 2003 2005 2006 2008 2009 200C 200D 200F 2011 2013 2014 2017 2018 201B 201D 201F 2022 2024 2025 2028 202A 202B Op codes BA,EB,FF B0,00 EE B0,38 EE BA,EB,FF EC 24,07 74,F8 B0,40 EE BA,E9,FF EC BE,00,40 B4,00 0B,F0 BA,EB,FF B0,90 EE BA,E9,FF 8A,04 EE EB,DC labels Mnemonics Operands MOV MOV OUT MOV OUT MOV IN AND JZ MOV OUT MOV IN MOV MOV OR MOV MOV OUT MOV MOV OUT JMP DX,FFEBH AL,00H DX,AL AL,38H DX,AL DX,FFEBH AL,DX AL,07 L1 AL,40H DX,AL DX,FFE9H EC SI,4000H AH,00H SI,AX DX,FFEBH AL,90H DX,AL DX,FFE9H AL,[SI] DX,AL L1 Comments ;Initialize 8279 in encoded scan keypad 2key lock out,8char display left entry. ; scan the key board for key press. ;read character the L1: ; get the address of the character code. ;Select display position 0 ;Display the key no. pressed ; wait for next key. RESULT: A character is displayed at 0 position of the display. A string characters is displayed on left entry basis. A character is read from the keyboard and displayed the key no on the display using look-up table method. VIVA QUESTIONS: 8. What is the value in AH perform input from keyboard? 9. A keyboard is made using 12 keys connected not as a matrix. How many pins of the I/O port are used? 10. Write a 7–segment code for ‘B’? 11. In the single character display using interrupt 21H, DL is the register contains character to display. If DL contains 41H, which character is displayed? 12. What is the difference between CALL and JMP? 13. What is the purpose of ALE? What are the difference between microprocessor and micro controller? 68 69 2.8255- PROGRAMMABLE PERIPHERAL INTERFACE (PPI) AIM: To generate square wave. To control the speed & direction of stepper motor. APPARATUS: ESA 86/88-2 Microprocessor kit. C.R.O. Stepper motor interface module with stepper motor. F R C Cable. Power supply- +15v. THEORY: The parallel input-output port chip 8255 is also called as Programmable peripheral input-output Port. The Intel’s 8255 are designed for use with Intel’s 8-bit, 16-bit and higher capability microprocessors. It has 24 input/output lines which may be individually programmed in 2-groups of 12 lines each, or 3 groups of 8 lines .The two groups of I/O pins are named as GROUP A and GROUP B. Each of these two groups contain a sub group of 8 I/O lines called as 8bit Port and other sub group of 4 I/O lines are a 4-bit port. Thus GROUP A Contains an 8-bit port A along with a 4-bit port, C upper. Port lines are identified by symbols PAO-PA7, While the port C lines are identified as PC4-PC7 .Similarly group B contains an 8-bit port B, containing lines PB0-PB7 and a 4-bit port C with lower bits PC0-PC3 .The port C upper and port C lower can be used in recombination as an 8-bit port-C .Both the port Cs are assigned the same address. Thus one may have either Three 8-bit I/O ports are two 8-bit and two 4-bit I/O ports from 8255.All of these ports can function independently either as input or as output ports. This can be achieved by programming the bits of an internal register of 8255 called as Control word register. (CWR). PORT ADDRESSES OF 8255 Control word register Port A Port B Port AC = FFE7 = FFE1 = FFE3 = FFE5 Block diagram of 8255 Interfacing Micro processor 8086 8255 PPI Stepper motor inter face 70 Block diagram of 8255 programmable peripheral interface: POWER SUPPLIES +5V GND Group A control Group A Port A (8) I/O PA7-PA0 BIDIRECTIOAL DATA BUS BUFFER 8 bit internal bus DATA BUS BUFFER Group A Port C upper (4) I/O PC7-PC4 D7--D0 Group B Port C lower (4) I/O PC3-PC0 __ RD __ WR A1 A0 RESET Read/ write Control logic Group B control Group B Port B (8) I/O PB7-PB0 __ CS 71 SQUARE WAVE GENERATION PROGRAM: Main program: Memory address 2000 2003 2005 2006 2009 200B 200C 200F 2011 Op codes BA,E7,FF B0,80 EE BA,E1,FF B0,FF EE E8,11,00 F6,D0 EB,F8 labels Mnemonics Operands MOV MOV OUT MOV MOV OUT CALL NOT JMP DX,FFE7H AL,80H DX,AL DX,FFE1H AL,FFH DX,AL DELAY AL L1 Comments ;Initialize 8255 all ports o/p ;Make port a high ;Wait for on/off Compliment port A continuously L1: Delay subroutine: Memory address 2020 2023 2026 2027 2028 202A 202B 202D Op codes BB,01,00 B9,99,00 90 49 75,FC 4B 75,F6 C3 labels Mnemonics Operands L3: L2: MOV MOV NOP DEC JNZ DEC JNZ RET BX,0001H CX,0099H CX L2 BX L3 Comments ;Initialize counters delay the for ;Wait for 0.5 ms. 72 STEPPER MOTOR PROGRAM: Main program: Memory address 2000 2003 2005 2006 2009 200B 200C 200F 2011 Op codes BA,E7,FF B0,80 EE BA,E1,FF B0,FF EE E8,11,00 D0,C8/C0 EB,F8 labels Mnemonics Operands MOV MOV OUT MOV MOV OUT CALL ROR/ROL JMP DX,FFE7H AL,80H DX,AL DX,FFE1H AL,88H DX,AL DELAY AL L1 Comments ;Initialize 8255 all ports o/p ; Start stepper motor in half step mode. ;Wait for step time ;Rotate the stepper motor continuously L1: Delay subroutine: Memory address 2020 2023 2026 2027 2028 202A 202B 202D Op codes BB,0A,00 B9,02,5D 90 49 75,FC 4B 75,F6 C3 labels Mnemonics Operands L3: L2: MOV MOV NOP DEC JNZ DEC JNZ RET BX,000AH CX,5D02H CX L2 BX L3 Comments ;Initialize counters delay the for ;Wait for 1 sec. RESULT: Amplitude and time period of the square wave are measured. Stepper motor is rotated. VIVA QUESTIONS: 1. Give the BSR format? 2. What is the angle of a stepper motor in full step mode? 3. 8255 has how many pins? 4. If the Control word 09bH is given to control register of the 8255 ppi then explain what is the condition of ports? 5. If the 8255 is selected for addresses 0F800H-0F806H what is the address of port C? 6. Mode 1 of 8255 is used for which of the I/O methods? 7. 8255 has how many ports? 8. What are the applications of the ports? 9. Why we need interfacing devices? 73 74 3.DECIMAL COUNTER AIM: To display decimal counter on the data field of ESA-86/88-2 kit. APPARATUS: ESA 86/88-2 Microprocessor kit. PROGRAM: Main program: Memory address 2000 2003 2004 2009 200C 200D 200F 2010 Op codes B8,00,00 50 9A,0A,0B,00,FF E8,14,00 58 04,01 27 EB,F1 labels Mnemonics Operands L1: MOV PUSH CALL CALL POP ADD DAA JMP AX,0000H AX FF00:0B0A DELAY AX AL,01H L1 Comments ; Get the 1st no. ; Display the no. ; Add 1 to previous no. ;Jump back Delay subroutine: Memory address 2020 2023 2026 2027 2028 202A 202B 202D Op codes BB,0A,00 B9,02,5D 90 49 75,FC 4B 75,F6 C3 labels Mnemonics Operands L3: L2: MOV MOV NOP DEC JNZ DEC JNZ RET BX,000AH CX,5D02H CX L2 BX L3 Comments ;Initialize counters delay the for ;Wait for 1 sec. RESULT: The decimal counter is displayed on the data field of the microprocessor display.
Copyright © 2024 DOKUMEN.SITE Inc.