EC2308 Lab Manual
EC2308 Lab Manual
LAB MANUAL
V SEMSTER 2010-2011
Under the Management of A.M. Kanniappa Mudaliar & A.M.K. Jambulinga Mudaliar Educational Trust # 122, Gengu Reddy Road, Near Hotel Dasaprakash , Opp. Blue Diamond Hotel, Egmore, Chennai - 600 008. Phone
Trust Off. : 28364541 28364542 College Off.
Phone
: 26810122 26810114
DEPT OF ECE
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
Programs for 16 bit Arithmetic operations (Using 8086). Programs for Sorting and Searching (Using 8086). Programs for String manipulation operations (Using 8086). Programs for Digital clock and Stop watch (Using 8086). Interfacing ADC and DAC. Parallel Communication between two MP Kits using Mode 1 and Mode 2 of 8255. Interfacing and Programming 8279, 8259, and 8253. Serial Communication between two MP Kits using 8251. Interfacing and Programming of Stepper Motor and DC Motor Speed control. Programming using Arithmetic, Logical and Bit Manipulation instructions of 8051 microcontroller. Programming and verifying Timer, Interrupts and UART operations in 8051 microcontroller.
12.
DEPT OF ECE
INDEX S.No. 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. Name of the Experiment 8086 PROGRAMS ADDITION & SUBTRACTION MULTIPLICATION & DIVISION ASCENDING & DESCENDING LARGEST & SMALLEST COPYING A STRING SEARCHING A STRING FIND & REPLACE INTERFACING EXPERIMENTS INTERFACING WITH ADC INTERFACING WITH DAC STEPPER MOTOR INTERFACE DC MOTOR INTERFACE INTERFACING WITH KEYBOARD/DISPLAY CONTROLLER INTERFACING WITH PROGRAMMABLE TIMER INTERFACING WITH 8251 INTERFACING WITH PPI 8255 INTERFACING WITH INTERRUPT CONTROLLER 8051 PROGRAMS 8 BIT ADDITION 8 BIT SUBTRACTION 8 BIT MULTIPLICATION 8 BIT DIVISION LOGICAL AND BIT MANIPULATION TIMER IN 8051 SERIAL COMMUNICATION USING 8051 DATA COMMUNICATIONS BETWEEN PC AND 8051 DIGITAL CLOCK DISPLAY STOP WATCH Page No. 2 7 12 16 19 22 24 26 28 32 34 37 40 44 47
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8086 PROGRAMMING ADDITION & SUBTRACTION DATE:
DEPT OF ECE
AIM: To write an Assembly Language Program (ALP) for performing the addition and subtraction operation of two byte numbers. APPARATUS REQUIRED: SL.N O 1. 2. ITEM Microprocessor kit Power Supply SPECIFICATION 8086 kit +5 V dc QUANTITY 1 1
PROBLEM STATEMENT: Write an ALP in 8086 to add and subtract two byte numbers stored in the memory location 1000H to 1003H and store the result in the memory location 1004H to 1005H.Also provide an instruction in the above program to consider the carry also and store the carry in the memory location 1006H. ALGORITHM: (i) 16-bit addition h) Initialize the MSBs of sum to 0 i) Get the first number. j) Add the second number to the first number. k) If there is any carry, increment MSBs of sum by 1. l) Store LSBs of sum. m) Store MSBs of sum. (ii) 16-bit subtraction f) Initialize the MSBs of difference to 0 g) Get the first number h) Subtract the second number from the first number. i) If there is any borrow, increment MSBs of difference by 1. j) Store LSBs of difference k) Store MSBs of difference.
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB FLOWCHART ADDITION START SET UP COUNTER (CY)
DEPT OF ECE
A=A+B IS THERE ANY CY YES IS THERE ANY CARRY COUNTER = COUNTER + 1 NO STORE THE SUM NO
YES
COUNTER = COUNTER + 1
STOP
STOP
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB ADDITION PROGRAM MOV CX, 0000H MOV AX,[1200] MOV BX, [1202] ADD AX,BX JNC L1 INC CX L1 : MOV [1206],CX MOV [1204], AX HLT COMMENTS Initialize counter CX Get the first data in AX reg Get the second data in BX reg
DEPT OF ECE
Add the contents of both the regs AX & BX Check for carry If carry exists, increment the CX Store the carry Store the sum Stop the program
SUBTRACTION PROGRAM MOV CX, 0000H MOV AX,[1200] MOV BX, [1202] SUB AX,BX JNC L1 INC CX L1 : MOV [1206],CX MOV [1204], AX HLT
COMMENTS Initialize counter CX Get the first data in AX reg Get the second data in BX reg Subtract the contents of BX from AX Check for borrow If borrow exists, increment the CX Store the borrow Store the difference Stop the program
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB PROGRAM USING TASM (ADDITION): data_here segment firstno dw 0202h secondno dw 0202h sum dw 2 dup(0) ends segment assume cs:code_here,ds:data_here mov ax,data_here mov ds,ax mov ax,firstno mov dx,0000h add ax,secondno jnc go inc dx mov sum,ax mov sum+2,dx int 3 ends end start
DEPT OF ECE
; Initialize data segment ; Get first No. ; Initialize dx for carry. ; Add second to it.
go:
code_here
PROGRAM USING TASM (SUBTRACTION): data_here segment minuend dw 2222h subtrahend dw 1111h result dw 2 dup(0) ends segment assume cs:code_here,ds:data_here mov ax,data_here mov ds,ax mov ax,minuend mov dx,subtrahend mov cx,0000h cmp ax,dx jnc ahead mov bx,dx mov dx,ax mov ax,bx mov cx,0001h sub ax,dx mov result,ax mov result+2,cx int 3 ends end start
; Initialize data segment. ; Get minuend & store in Acc. ; Get subtrahend & store in dx. ; Initialize cx for carry ; compare minuend & subtrahend if minuend smaller than subtrahend , interchange minuend & subtrahend.
ahead:
; Increment carry by one. ; subtract dx from ax ; store the result & carry.
code_here
DEPT OF ECE
RESULT:. ADDITION
MEMORY DATA
SUBTRACTION
MEMORY
DATA
MANUAL CALCULATION
Thus addition & subtraction of two byte numbers are performed and the result is stored.
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8086 PROGRAMMING MULTIPLICATION & DIVISION DATE:
DEPT OF ECE
AIM:
To write an Assembly Language Program (ALP) for performing the multiplication and division operation of 16-bit numbers . APPARATUS REQUIRED: SL.N O 1. 2. ITEM Microprocessor kit Power Supply SPECIFICATION 8086 +5 V dc QUANTITY 1 1
PROBLEM STATEMENT: Write an ALP in 8086 MP to multiply two 16-bit binary numbers and store the result in the memory location. Write instructions for dividing the data and store the result. ALGORITHM: (i) Multiplication of 16-bit numbers: a) Get the multiplier. b) Get the multiplicand c) Initialize the product to 0. d) Product = product + multiplicand e) Decrement the multiplier by 1 f) If multiplicand is not equal to 0, repeat from step (d) otherwise store the product. (ii) Division of 16-bit numbers. a) Get the dividend b) Get the divisor c) Initialize the quotient to 0. d) Dividend = dividend divisor e) If the divisor is greater, store the quotient. Go to step g. f) If dividend is greater, quotient = quotient + 1. Repeat from step (d) g) Store the dividend value as remainder.
DEPT OF ECE
DIVISION Start
REGISTER=00
QUOTIENT = 0
Multiplier=MULTIPLIER 1
QUOTIENT = QUOTIENT + 1
STOP
STOP
10
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB MULTIPLICATION PROGRAM MOV AX,[1200] MOV BX, [1202] MUL BX MOV [1206],AX MOV [1208],DX HLT
DEPT OF ECE
COMMENTS Get the first data Get the second data Multiply both Store the lower order product Store the higher order product Stop the program
DIVISION PROGRAM MOV AX,[1200] MOV DX, [1202] MOV BX, [1204] DIV BX MOV [1206],AX MOV AX,DX MOV [1208],AX HLT COMMENTS Get the first data (Dividend) Initialize DX register with 0000h Get the second data(Divisor) Divide the dividend by divisor Store the Quotient Move the remainder to AX Store the content of AX to memory location. Stop the program
11
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB PROGRAM USING TASM (MULTIPLICATION): data_here segment multiplicand dw 0202h multiplier dw 0202h product dw 2 dup(0) ends segment assume cs:code_here,ds:data_here mov ax,data_here mov ds,ax mov ax,multiplicand mul multiplier mov product,ax mov product+2,dx int 3 ends end start
DEPT OF ECE
; Initialize data segment. ; Get multiplicand ; multiply multiplier with it. ; Store the result.
code_here
PROGRAM USING TASM (DIVISION): data_here segment dividend divisor result ends
code_here
segment assume cs:code_here,ds:data_here mov ax,data_here mov ds,ax mov ax,dividend div divisor mov result,ax mov result+2,dx int 3 ends end start
12
DEPT OF ECE
RESULT:. MULTIPLICATION
MEMORY DATA
DIVISON
MEMORY
DATA
MANUAL CALCULATION
Thus multiplication & division of two byte numbers are performed and the result is stored.
13
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8086 PROGRAMMING ASCENDING & DESCENDING DATE:
DEPT OF ECE
AIM:
To write an Assembly Language Program (ALP) to sort a given array in ascending and descending order. APPARATUS REQUIRED: SL.N O 1. 2. ITEM Microprocessor kit Power Supply SPECIFICATION 8086 +5 V dc QUANTITY 1 1
PROBLEM STATEMENT: An array of length 10 is given from the location. Sort it into descending and ascending order and store the result. ALGORITHM: (i) Sorting in ascending order: a. Load the array count in two registers C1 and C2. b. Get the first two numbers. c. Compare the numbers and exchange if necessary so that the two numbers are in ascending order. d. Decrement C2. e. Get the third number from the array and repeat the process until C2 is 0. f. Decrement C1 and repeat the process until C1 is 0. (ii) Sorting in descending order:
a. Load the array count in two registers C1 and C2. b. Get the first two numbers. c. Compare the numbers and exchange if necessary so that the two numbers are in descending order. d. Decrement C2. e. Get the third number from the array and repeat the process until C2 is 0. f. Decrement C1 and repeat the process until C1 is 0.
14
DEPT OF ECE
START
YES IS POINTER POINTER +1 NO TEMP = POINTER POINTER = POINTER + 1 POINTER + 1 = TEMP YES IS POINTER POINTER NO TEMP = POINTER POINTER = POINTER + 1 POINTER + 1 = TEMP
NO NO IS COUNT = 0 YES YES IS FLAG NO IS FLAG =0 YES YES STOP STOP = 0 IS COUNT =0
15
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB ASCENDING PROGRAM MOV CL,COUNT L3: MOV DL,COUNT DEC DL MOV SI,1200 L2: MOV AL,[SI] INC SI MOV BL,[SI] CMP AL,BL JC /JNC DEC SI MOV [SI],BL INC SI MOV [SI],AL L1: DEC DL JNZ L2 DEC CL JNZ L3 HLT L1 COMMENTS Get the count in CL Get the count in DL Number of comparisons in DL Initialize memory location Get the first data in AL Go to next memory location Get the second data in BL Compare two datas
DEPT OF ECE
If AL < BL go to L1 (Ascending/Descending) Else, Decrement the memory location Store the smallest data Get the next data AL Get the next data AL Decrement the no of comparisons Jump to loop2 Decrement the count Jump to L3, if the count is not reached zero Stop
PROGRAM USING TASM(ASCENDING/DESCENDING) Dataseg datasegends codeseg start: segment assume cs:codeseg,ds:dataseg mov ax,dataseg mov ds,ax mov cl,04h mov bl,04h lea si,series mov al,[si] inc si cmp al,[si] jc loop mov dl,[si] mov [si],al dec si mov [si],dl segment series db
12h,23h,14h,25h,18h
; datas to be sorted
loop2: loop1:
; Compare first data with second data. If second data smaller than first one, interchange the datas
16
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB inc si dec bl jnz loop1 dec cl jnz loop2 int 3 ends end start
DEPT OF ECE
loop: other
codeseg
RESULT:. ASCENDING
MEMORY DATA
DESCENDING
MEMORY
DATA
Thus given array of numbers are sorted in ascending & descending order.
17
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8086 PROGRAMMING LARGEST& SMALLEST DATE:
DEPT OF ECE
AIM:
To write an Assembly Language Program (ALP) to find the largest and smallest number in a given array. APPARATUS REQUIRED: SL.NO ITEM 1. Microprocessor kit 2. Power Supply PROBLEM STATEMENT: An array of length 10 is given from the location. Find the largest and smallest number and store the result. ALGORITHM: (i) Finding largest number: a. b. c. d. (ii) e. f. g. h. Load the array count in a register C1. Get the first two numbers. Compare the numbers and exchange if the number is small. Get the third number from the array and repeat the process until C1 is 0. Finding smallest number: Load the array count in a register C1. Get the first two numbers. Compare the numbers and exchange if the number is large. Get the third number from the array and repeat the process until C1 is 0. SPECIFICATION 8086 +5 V dc QUANTITY 1 1
18
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB FLOWCHART LARGEST NUMBER IN AN ARRAY START
DEPT OF ECE
PONITER = POINTER + 1
PONITER = POINTER + 1
YES IS MAX POINTER? YES NO MAX = POINTER IS MIN POINTER NO MIN = POINTER
COUNT = COUNT-1
STOP
STOP
19
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB LARGEST PROGRAM MOV SI,1200H MOV CL,[SI] INC SI MOV AL,[SI] DEC CL L2 : INC SI CMP AL,[SI] JNC L1/JC L1 MOV AL,[SI] L1 : DEC CL JNZ L2 MOV DI,1300H MOV [DI],AL HLT RESULT:. LARGEST COMMENTS Initialize array size Initialize the count Go to next memory location Move the first data in AL Reduce the count Move the SI pointer to next data Compare two datas
DEPT OF ECE
If AL > [SI] then go to L1 ( Largest/Smallest) Else move the large number to AL Decrement the count If count is not zero go to L2 Initialize DI with 1300H store the biggest number in 1300 location Stop
MEMORY DATA
SMALLEST
MEMORY
DATA
20
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: AIM: To move a string of length FF from source to destination. ALGORITHM: a. Initialize the data segment .(DS) b. Initialize the extra data segment .(ES) c. Initialize the start of string in the DS. (SI) d. Initialize the start of string in the ES. (DI) e. Move the length of the string (FF) in CX register. f. Move the byte from DS TO ES, till CX=0. FLOWCHART: START 8086 PROGRAMMING COPYING A STRING DATE:
DEPT OF ECE
Move a byte from source string (DS) to destination string (ES) Decrement CX
NO
STOP
21
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB COPYING A STRING PROGRAM MOV SI,1200H MOV DI,1300H MOV CX,0006H CLD REP MOVSB HLT
DEPT OF ECE
COMMENTS Initialize destination address Initialize starting address Initialize array size Clear direction flag Copy the contents of source into destination until count reaches zero Stop
; data to move ; stationary block of data ; number of data to move ; data destination
data
code segment assume cs:code,ds:data,es:data start: mov ax,data mov ds,ax mov es,ax lea si,test_mess lea di,new_loc cld
; initialize data segment register ; initialize extra segment register ; Point si at source data ; Point di at destination data ; clear direction flag so pointers auto increment after each data element is moved
22
DEPT OF ECE
OUTPUT MEMORY
DATA
Thus a string of a particular length is moved from source segment to destination segment.
23
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8086 PROGRAMMING SEARCHING A STRING AIM: DATE:
DEPT OF ECE
To scan for a given byte in the string and find the relative address of the byte from the starting location of the string. ALGORITHM: a. Initialize the extra segment .(ES) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI to BX. START
Move DI to BX
STOP
24
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB SEARCHING FOR A CHARACTER IN THE STRING PROGRAM COMMENTS MOV DI,1300H MOV SI, 1400H MOV CX, 0006H MOV BL,00H CLD MOV AL, 08H LOOP2: NOP SCASB JNZ LOOP1 MOV [SI],BL INC SI LOOP1: INC BL LOOP LOOP2 HLT Initialize destination address Initialize starting address Initialize array size Initialize the relative address Clear direction flag
DEPT OF ECE
Store the string to be searched Delay Scan until the string is found Jump if the string is found Move the relative address to SI. Increment the memory pointer Increment the relative address Repeat until the count reaches zero Stop
Thus a given byte or word in a string of a particular length in the extra segment(destination) is found .
25
DEPT OF ECE
EXPT NO:
8086 PROGRAMMING
DATE:
FIND AND REPLACE AIM: To find a character in the string and replace it with another character. ALGORITHM: a. Initialize the extra segment .(E S) b. Initialize the start of string in the ES. (DI) c. Move the number of elements in the string in CX register. d. Move the byte to be searched in the AL register. e. Store the ASCII code of the character that has to replace the scanned byte in BL register. f. Scan for the byte in ES. If the byte is not found, ZF1 and repeat scanning. g. If the byte is found, ZF=1.Move the content of BL register to ES:DI. START
STOP 26
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB FIND AND REPLACE A CHARACTER IN THE STRING PROGRAM COMMENTS MOV DI,1300H MOV CX, 0006H CLD MOV AL, 08H MOV BH,30H BACK:SCASB JNZ LOOP1 DEC DI MOV [DI],BL LOOP1:LOOP BACK HLT RESULT: INPUT MEMORY DATA Initialize starting address Initialize array size Clear direction flag Store the string to be searched Store the string to be replaced Scan until the string is found Is the string found Decrement the destination address Replace the string Continue until count zero. Stop
DEPT OF ECE
OUTPUT MEMORY
DATA
Thus a given byte or word in a string of a particular length in the extra segment (destination) is found and is replaced with another character.
27
DEPT OF ECE
AIM: To write an assembly language program to convert an analog signal into a digital signal using an ADC interfacing. APPARATUS REQUIRED: ITEM SL.NO SPECIFICATION QUANTITY 1. 8086 1 Microprocessor kit 2. +5 V dc,+12 V dc 1 Power Supply 3. 1 ADC Interface board PROBLEM STATEMENT: The program is executed for various values of analog voltage which are set with the help of a potentiometer. The LED display is verified with the digital value that is stored in a memory location. THEORY: An ADC usually has two additional control lines: the SOC input to tell the ADC when to start the conversion and the EOC output to announce when the conversion is complete. The following program initiates the conversion process, checks the EOC pin of ADC 0809 as to whether the conversion is over and then inputs the data to the processor. It also instructs the processor to store the converted digital data at RAM location. ALGORITHM: (i) Select the channel and latch the address. (ii) Send the start conversion pulse. (iii) Read EOC signal. (iv) If EOC = 1 continue else go to step (iii) (v) Read the digital output. (vi) Store it in a memory location. FLOW CHART: START
SELECT THE CHANNEL AND LATCH SEND THE START CONVERSION PULSE NO IS EOC = 1? YES READ THE DIGITALOUTPUT STORE THE DIGITAL VALUE IN THE MEMORY LOCATION SPECIFIED
STOP
28
DEPT OF ECE
PROGRAM MOV AL,00 OUT 0C8H,AL MOV AL,08 OUT 0C8H,AL MOV AL,01 OUT 0D0H,AL MOV AL,00 MOV AL,00 MOV AL,00 MOV AL,00 OUT 0D0H,AL L1 : IN AL, 0D8H AND AL,01 CMP AL,01 JNZ L1 IN AL,0C0H MOV BX,1100 MOV [BX],AL HLT RESULT:
ANALOG VOLTAGE
COMMENTS Load accumulator with value for ALE high Send through output port Load accumulator with value for ALE low Send through output port Store the value to make SOC high in the accumulator Send through output port Introduce delay
Store the value to make SOC low the accumulator Send through output port Read the EOC signal from port & check for end of conversion If the conversion is not yet completed, read EOC signal from port again Read data from port Initialize the memory location to store data Store the data Stop
DIGITAL DATA ON LED DISPLAY HEX CODE IN MEMORY LOCATION
Thus the ADC was interfaced with 8086 and the given analog inputs were converted into its digital equivalent. 29
DEPT OF ECE
AIM : 1. To write an assembly language program for digital to analog conversion 2. To convert digital inputs into analog outputs & To generate different waveforms APPARATUS REQUIRED: SL.NO SPECIFICATION QUANTITY ITEM 1. 8086 Vi Microsystems 1 Microprocessor kit 2. +5 V, dc,+12 V dc 1 Power Supply 3. 1 DAC Interface board PROBLEM STATEMENT: The program is executed for various digital values and equivalent analog voltages are measured and also the waveforms are measured at the output ports using CRO. THEORY: Since DAC 0800 is an 8 bit DAC and the output voltage variation is between 5v and +5v. The output voltage varies in steps of 10/256 = 0.04 (approximately). The digital data input and the corresponding output voltages are presented in the table. The basic idea behind the generation of waveforms is the continuous generation of analog output of DAC. With 00 (Hex) as input to DAC2 the analog output is 5v. Similarly with FF H as input, the output is +5v. Outputting digital data 00 and FF at regular intervals, to DAC2, results in a square wave of amplitude 5v.Output digital data from 00 to FF in constant steps of 01 to DAC2. Repeat this sequence again and again. As a result a saw-tooth wave will be generated at DAC2 output. Output digital data from 00 to FF in constant steps of 01 to DAC2. Output digital data from FF to 00 in constant steps of 01 to DAC2. Repeat this sequence again and again. As a result a triangular wave will be generated at DAC2 output. ALGORITHM: Measurement of analog voltage: (i) Send the digital value of DAC. (ii) Read the corresponding analog value of its output. Waveform generation: Square Waveform: (i) Send low value (00) to the DAC. (ii) Introduce suitable delay. (iii) Send high value to DAC. (iv) Introduce delay. (v) Repeat the above procedure. Saw-tooth waveform: (i) Load low value (00) to accumulator. (ii) Send this value to DAC. (iii) Increment the accumulator. (iv) Repeat step (ii) and (iii) until accumulator value reaches FF. (v) Repeat the above procedure from step 1. Triangular waveform: (i) Load the low value (00) in accumulator. (ii) Send this accumulator content to DAC. (iii) Increment the accumulator. (iv) Repeat step 2 and 3 until the accumulator reaches FF, decrement the accumulator and send the accumulator contents to DAC. (v) Decrementing and sending the accumulator contents to DAC. (vi) The above procedure is repeated from step (i)
30
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB FLOWCHART: MEASUREMENT OF ANALOG VOLTAGE START
DEPT OF ECE
SQUARE WAVE FORM START INTIALISE THE ACCUMULATOR SEND ACC CONTENT TO DAC
DELAY TRANSFER THE ACCUMULATOR CONTENTS TO DAC LOAD THE ACC WITH MAX VALUE SEND ACC CONTENT DELAY
STOP TRIANGULAR WAVEFORM START SAWTOOTH WAVEFORM START INITIALIZE ACCUMULATOR SEND ACCUMULATOR CONTENT TO DAC INCREMENT ACCUMULATOR CONTENT YES
IS ACC FF NO
NO
IS ACC FF
YES
IS ACC 00
31
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB MEASUREMENT OF ANALOG VOLTAGE: PROGRAM MOV AL,7FH OUT C0,AL HLT COMMENTS
DEPT OF ECE
DIGITAL DATA
ANALOG VOLTAGE
32
DEPT OF ECE
WAVEFORMS
AMPLITUDE
TIMEPERIOD
Square Waveform
Saw-tooth waveform Triangular waveform
Triangular waveform
Thus the DAC was interfaced with 8085 and different waveforms have been generated. 33
AIM: To write an assembly language program in 8086 to rotate the motor at different speeds. APPARATUS REQUIRED: SL.NO 1. 2. 3. 4. ITEM Microprocessor kit Power Supply Stepper Motor Interface board Stepper Motor SPECIFICATION 8086 +5 V, dc,+12 V dc QUANTITY 1 1 1 1
PROBLEM STATEMENT: Write a code for achieving a specific angle of rotation in a given time and particular number of rotations in a specific time. THEORY: A motor in which the rotor is able to assume only discrete stationary angular position is a stepper motor. The rotary motion occurs in a stepwise manner from one equilibrium position to the next.Two-phase scheme: Any two adjacent stator windings are energized. There are two magnetic fields active in quadrature and none of the rotor pole faces can be in direct alignment with the stator poles. A partial but symmetric alignment of the rotor poles is of course possible. ALGORITHM: For running stepper motor clockwise and anticlockwise directions (i) Get the first data from the lookup table. (ii) Initialize the counter and move data into accumulator. (iii) Drive the stepper motor circuitry and introduce delay (iv) Decrement the counter is not zero repeat from step(iii) (v) Repeat the above procedure both for backward and forward directions. SWITCHING SEQUENCE OF STEPPER MOTOR: MEMORY LOCATION 4500 4501 4502 4503 A1 1 0 0 1 A2 0 1 1 0 B1 0 0 1 1 B2 0 1 0 0 HEX CODE 09 H 05 H 06 H 0A H
34
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB FLOWCHART: START INTIALIZE COUNTER FOR LOOK UP TABLE
DEPT OF ECE
GET THE FIRST DATA FROM THE ACCUMULATOR MOVE DATA INTO THE ACCUMULATOR DRIVE THE MOTOR CIRCUITARY DELAY DECREMENT COUNTER YES IS B = 0? NO GET THE DATA FROM LOOK UP TABLE
PROGRAM TABLE PROGRAM START : MOV DI, 1200H MOV CX, 0004H LOOP 1 : MOV AL, [DI] OUT 0C0, AL MOV DX, 1010H L1 : DEC DX JNZ L1 INC DI LOOP LOOP1 JMP START 1200 : 09,05,06,0A
COMMENTS Initialize memory location to store the array of number Initialize array size Copy the first data in AL Send it through port address Introduce delay Go to next memory location Loop until all the datas have been sent Go to start location for continuous rotation Array of datas
RESULT: Thus the assembly language program for rotating stepper motor in both clockwise and anticlockwise directions is written and verified.
35
AIM: To write an assembly language program in 8086 to control the speed of the motor. APPARATUS REQUIRED: SL.NO 1. 2. 3. 4. ITEM Microprocessor kit Power Supply DC Motor Interface board DC Motor SPECIFICATION 8086 +5 V, dc,+12 V dc QUANTITY 1 1 1 1
PROBLEM STATEMENT: Write a code for controlling the speed of the motor and measure the speed. THEORY: A motor in which the rotor is able to assume only discrete stationary angular position is a stepper motor. The rotary motion occurs in a stepwise manner from one equilibrium position to the next. Two-phase scheme: Any two adjacent stator windings are energized. There are two magnetic fields active in quadrature and none of the rotor pole faces can be in direct alignment with the stator poles. A partial but symmetric alignment of the rotor poles is of course possible. ALGORITHM: FLOWCHART:
36
DEPT OF ECE
37
DEPT OF ECE
38
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXP.NO: 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.
DEPT OF ECE
1. Display Mode Setup: Control word-10 H 0 0 DD 00- 8Bit character display left entry 01- 16Bit character display left entry 10- 8Bit character display right entry 11- 16Bit character display right entry KKK- Key Board Mode 000-2Key lockout. 2.Clear Display: Control word-DC H 1 1 1 1 0 0 1 CD 1 CD 1 CD 0 CF 0 CA 0 0 0 0 1 D 0 D 0 K 0 K 0 K
11
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
DEPT OF ECE
AI
Selects one of the 16 rows of display. Auto increment = 1, the row address selected will be incremented after each of read and write operation of the display RAM.
FLOWCHART:
SET 8279 FOR 8-DIGIT CHARACTER DISPLAY SET 8279 FOR CLEARING THE DISPLAY WRITE THE COMMAND TO DISPLAY LOAD THE CHARACTER INTO ACCUMULATOR AND DISPLAY DELAY
40
DEPT OF ECE
PROGRAM 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 1204 98 FF 68 1C 7C 29 C8 FF Initialize array
COMMENTS 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 datas have been taken Go to starting location Store 16bit count value Decrement count value Loop until count values becomes zero Return to main program
RESULT: MEMORY LOCATION 1200H 1201H 1202H 1203H 1204H 1205H 1206H 1207H 7-SEGMENT LED FORMAT c b a dp e g 0 0 1 1 0 0 1 1 0 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 1 1 1 HEX DATA f 0 0 0 0 1 0 1 1 98 68 7C C8 FF 1C 29 FF
d 1 0 0 1 1 0 0 1
Thus the rolling message HELP US is displayed using 8279 interface kit.
41
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXP. NO: AIM : To study different modes of operation of programmable timer 8253 APPARATUS REQUIRED: INTERFACING PROGRAMMABLE TIMER-8253
SL.NO 1. 2. 3. 4.
QUANTITY 1 1 1 1
THEORY: The main features of the timer are, Three independent 16-bit counters Input clock from DC to 2 MHz Programmable counter modes Count binary or BCD The control signals with which the 8253 interfaces with the CPU are CS, RD, WR, A1, A2. The basic operations performed by 8253 are determined by these control signals. It has six different modes of operation, viz, mode 0 to mode 5.
42
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB Mode 31. Initialize channel 0 in mode 3 2. Initialize the LSB of the count. 3. Initialize the MSB of the count. 4. Trigger the count 5. Read the corresponding output in CRO. PORT ADDRESS : 1. CONTROL REGISTER 2. COUNTER OF CHANNEL 0 3. COUNTER OF CHANNEL 1 4. COUNTER OF CHANNEL 2 5. O/P PORT OF CHANNEL 0 6. O/P PORT OF CHANNEL 1 7. O/P PORT OF CHANNEL 2 CONTROL WORD FORMAT: D7 SC1 0 0 D6 SC0 0 0 D5 RL1 1 1 D4 RL0 1 1 D3 M2 0 0 D2 M1 1 1 D1 M0 0 1 D0 BCD 0 Mode 2 = 34 H 0 Mode 3 = 36 H READ/LOAD
DEPT OF ECE
SC1 0 0 1 1 BCD M2 0 0 0 0 1 1
SC0
CHANNEL SELECT
RL1
RL0
0 CHANNEL 0 1 CHANNEL 1 0 CHANNEL 2 1 ------0 BINARY COUNTER M1 0 0 1 1 0 0 M0 0 1 0 1 0 1 MODE MODE 0 MODE 1 MODE 2 MODE 3 MODE 4 MODE 5
43
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB PORT PIN ARRANGEMENT 1 CLK 0 2 GATE 0 3 OUT 0 4 CLK 1 5 GATE1 6 OUT 1 7 CLK 2 8 GATE 2 9 OUT 2 10 GND
DEPT OF ECE
* *
44
DEPT OF ECE
STOP
RESULT: Thus an ALP for rate generator and square wave generator are written and executed.
45
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXP. NO: AIM: INTERFACING USART 8251
To study interfacing technique of 8251 (USART) with microprocessor 8086 and write an 8086 ALP to transmit and receive data between two serial ports with RS232 cable. APPARATUS REQUIRED: 8086 kit (2 Nos), RS232 cable. THEORY: The 8251 is used as a peripheral device for serial communication and is programmed by the CPU to operate using virtually any serial data transmission technique. The USART accepts data characters from the CPU in parallel format and then converts them into a continuous serial data stream for transmission. Simultaneously, it can receive serial data streams and convert them into parallel data characters for the CPU. The CPU can read the status of the USART at any time. These include data transmission errors and control signals. The control signals define the complete functional definition of the 8251. Control words should be written into the control register of 8251.These control words are split into two formats: 1) Mode instruction word & 2) Command instruction word. Status word format is used to examine the error during functional operation.
1...transmit enable 1...data terminal ready 1... receive enable 1... send break character 1.... reset error flags (pe,oe,fe) 1..... request to send (rts) 1...... internal reset 1....... enter hunt mode (enable search for sync characters)
1 ransmitter ready 1. receiver ready 1.. transmitter empty 1... parity error (pe) 1.... overrun error (oe) 1..... framing error (fe), async only 1...... sync detect, sync only 1....... data set ready (dsr)
46
DEPT OF ECE
ALGORITHM: 1. Initialize 8253 and 8251 to check the transmission and reception of a character 2. Initialize8253 to give an output of 150Khz at channel 0 which will give a 9600 baud rate of 8251. 3. The command word and mode word is written to the 8251 to set up for subsequent operations 4. The status word is read from the 8251 on completion of a serial I/O operation, or when the host CPU is checking the status of the device before starting the next I/O operation FLOW CHART: START
Is it High
Yes
STOP 47
DEPT OF ECE
PROGRAM: TRANSMITTER END PROGRAM COMMENTS MOV AL,36 Initialize 8253 in mode 3 square wave generator OUT CE,AL Send through port address MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz) OUT C8,AL Send through port address MOV AL,00 Initialize AL with higher value of count OUT C8,AL Send through port address MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) OUT C2,AL Send through port address MOV AL,37 Set command instruction(enables transmit enable & receive enable bits) OUT C2,AL Send through port address L1:IN AL,C2 Read status word AND AL,04 Check whether transmitter ready JZ L1 If not wait until transmitter becomes ready MOV AL,41 Set the data as 41 OUT C0,AL Send through port address INT 2 Restart the system RECEIVER END PROGRAM COMMENTS MOV AL,36 Initialize 8253 in mode 3 square wave generator OUT CE,AL Send through port address MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz) OUT C8,AL Send through port address MOV AL,00 Initialize AL with higher value of count OUT C8,AL Send through port address MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit) OUT C2,AL Send through port address MOV AL,37 Set command instruction(enables transmit enable & receive enable bits) OUT C2,AL Send through port address L1:IN AL,C2 Read status word AND AL,02 Check whether receiver ready JZ L1 If not wait until receiver becomes ready IN AL,C0 If it is ready, get the data MOV BX,1500 Initialize BX register with memory location to store the data MOV [BX],AL Store the data in the memory location INT 2 Restart the system RESULT: Thus ALP for serial data communication using USART 8251 is written and the equivalent ASCII 41 for character A is been transmitted & received.
48
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXP. NO: AIM: INTERFACING WITH PPI 8255
To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and mode 2 APPARATUS REQUIRED: 8086 kit, 8255 interface kit. ALGORITHM: Mode 0 1. Initialize accumulator to hold control word 2. store control word in control word register 3. Read data port A. 4. Store data from port A in memory 5. Place contents in port B Mode 1 & Mode 2 1. Initialize accumulator to hold control word (for port A) 2. Store control word in control word register 3. Initialize accumulator to hold control word (for port B) 4. Place contents in control word register. 5. Disable all maskable interrupts, enable RST 5.5 6. send interrupt mask for RST 6.5 & 7.5 7. Enable interrupt flag 8. Read data from port A, place contents in port B FLOWCHART Mode 0 START
Mode 1 & 2 START Store control word in control register Input to be read from port A
STOP
STOP
49
DEPT OF ECE
MODE 0
PROGRAM MOV AL,90H OUT C6,AL IN AL,C0 OUT C2,AL HLT 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
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 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 Higher order count Using IR2 interrupt(lower order count) Through 8259 COMMENTS Set the control word for mode 1 Send it to control port Control for BSR mode Send it to control port Interrupt generation
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
50
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB MOV AL,0FH OUT 32,AL MOV AL,00H OUT 32,AL STI HLT ISR: IN AL,C0 OUT C2,AL HLT BSR mode Set trap flag Stop Subroutine Read from Port A Send it to Port B Stop Higher order count Using IR2 interrupt(lower order count)
DEPT OF ECE
Bit set/reset, applicable to PC only. One bit is S/R at a time. Control word: D7 D6 D5 D4 D3 D2 D1 D0 0 (0=BSR) X X X Bit select: (Taking Don't care's as 0) 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 2 3 4 5 6 7 0000 0001 = 01h 0000 0011 = 03h 0000 0101 = 05h 0000 0111 = 07h 0000 1001 = 09h 0000 1011 = 0Bh 0000 1101 = 0Dh 0000 1111 = 0Fh B2 B1 B0 S/R (1=S,0=R)
B2 B1 B0 PC bit Control word (Set) Control word (reset) 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 1 (1=I/O) D6 D5 D4 PA D3 PCU D2 GB mode select D1 PB D0 PCL GA mode select
D6, D5: GA mode select: o 00 = mode0 o 01 = mode1 o 1X = mode2 D4(PA), D3(PCU): 1=input 0=output D2: GB mode select: 0=mode0, 1=mode1 D1(PB), D0(PCL): 1=input 0=output
Result: Input Mode 0 Output Mode 1 Input Output Mode 2 Input Output
The programs for interfacing 8255 with 8085 are executed & the output is obtained for modes 0, 1 & 2
51
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB Interfacing 8259 Programmable Interrupt Controller to 8085 p Aim:
DEPT OF ECE
To initialize 8259 with the following specifications: 1) ICW4 needed 2) single 8259 3) Interval of 4 4) Edge triggered mode 5) A7 A6 A5 = 0 0 0 6) Interrupt Service Routine address for IR0 = 5000 H 7) 8085 mode 8) Normal EOI 9) Non buffered mode 10) not special fully nested mode 11) mask all Interrupts except IR0 Apparatus Required: 8085p kit, 8259 Interface Board, Regulated Power supply, vxt parallel bus Theory: The 8259 is a programmable Interrupt Controller that can resolve eight levels of interrupt priorities in a variety of modes. It can vector an interrupt anywhere in the memory map. It is also capable of masking each interrupt request individually and read the status of pending interrupts, in_service interrupts and masked interrupts. The 8259 can be expanded to 64 priority levels by cascading network. Initialisation command words (ICW s): Before the normal operation can begin , each 8259 in the system must be initialised using 2 to 4 bytes of ICW s. Operation command words (OCW s): These are the command words which command the 8259 to operate in various interrupt modes. Program: MVI OUT MVI OUT MVI OUT MVI HLT ISR : MVI A,20 MVI MVI ADD STA HLT A,08 B,08 B 4500 ; Initialize OCW 2 for non specific EOI OUT C0H ; addition program A,17 C0H A,50 C2H A,00 C2H A,FE OUT C2H ; Initialize ICW 1 for ICW 4 needed , ; interval of 4 , single , edge triggered mode ; Initialize ICW 2 ; ; Initialize ICW 4 ; Initialize OCW 1 , set mask for all except ; IR0
Procedure: The program is entered in user RAM locations. On pressing IR0 , the CPU jumps to location 5000H. 8259 will not accept any more interrupt at IR0 since AEOI is not set. After it is set , the CPU goes back to main program after performing service addition subroutine. The result addition can be viewed at 4500H location.
52
DEPT OF ECE
Exercise: Program the 8259 in special mask mode. (In the special mask mode ,when the mask bit is set in 0CW1, it inhibits further interrupts at that level and enables interrupts from all other levels(lower as well as higher) that are not masked. Thus any interrupts may be selectively enabled by loading the mask register. Result: 1) Thus 8259 was initialized for the required specifications 2) All the LED s except one corresponding to IRO is seen glowing. 3) The result of addition subroutine was verified at memory location 4500H.
53
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8051 PROGRAMMING 8 BIT ADDITION
AIM: To write a program to add two 8-bit numbers using 8051 microcontroller.
ALGORITHM: 1. Clear Program Status Word. 2. Select Register bank by giving proper values to RS1 & RS0 of PSW. 3. Load accumulator A with any desired 8-bit data. 4. Load the register R 0 with the second 8- bit data. 5. Add these two 8-bit numbers. 6. Store the result. 7. Stop the program.
Load A and R 0 with 8- bit datas Add A & R 0 Store the sum STOP
54
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8 Bit Addition (Immediate Addressing) ADDRESS LABEL MNEMONIC OPERAND 4100 4101 4103 4105 4108 4109 L1 CLR MOV ADDC MOV MOVX SJMP C A, data1 A, # data 2 DPTR, # 4500H @ DPTR, A L1
DEPT OF ECE
COMMENTS Clear CY Flag Get the data1 in Accumulator Add the data1 with data2 Initialize the memory location Store the result in memory location Stop the program
RESULT:
DATA
Thus the 8051 ALP for addition of two 8 bit numbers is executed.
55
AIM: To perform subtraction of two 8 bit data and store the result in memory. ALGORITHM: a. Clear the carry flag. b. Initialize the register for borrow. c. Get the first operand into the accumulator. d. Subtract the second operand from the accumulator. e. If a borrow results increment the carry register. f. Store the result in memory. FLOWCHART:
START
IS CF=1
N Y
STOP
56
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8 Bit Subtraction (Immediate Addressing) ADDRESS LABEL MNEMONIC OPERAND 4100 4101 4103 4105 4108 4109 L1 CLR MOV SUBB MOV MOVX SJMP C A, # data1 A, # data2 DPTR, # 4500 @ DPTR, A L1
DEPT OF ECE
COMMENTS Clear CY flag Store data1 in accumulator Subtract data2 from data1 Initialize memory location Store the difference in memory location Stop
RESULT:
DATA
Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
57
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8051 PROGRAMMING 8 BIT MULTIPLICATION
AIM: To perform multiplication of two 8 bit data and store the result in memory.
ALGORITHM: a. Get the multiplier in the accumulator. b. Get the multiplicand in the B register. c. Multiply A with B. d. Store the product in memory. FLOWCHART:
START
MULTIPLY A WITH B
STOP
58
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8 Bit Multiplication ADDRESS LABEL 4100 4102 4104 4106 4109 401A 410B 410D 410E STOP
DEPT OF ECE
MNEMONIC MOV MOV MUL MOV MOVX INC MOV MOV SJMP
OPERAND A ,#data1 B, #data2 A,B DPTR, # 4500H @ DPTR, A DPTR A,B @ DPTR, A STOP
COMMENTS Store data1 in accumulator Store data2 in B reg Multiply both Initialize memory location Store lower order result Go to next memory location Store higher order result Stop
RESULT: INPUT MEMORY LOCATION 4500 4501 OUTPUT MEMORY LOCATION 4502 4503
DATA
DATA
Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
59
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXPT NO: 8051 PROGRAMMING 8 BIT DIVISION AIM: To perform division of two 8 bit data and store the result in memory.
ALGORITHM: 1. Get the Dividend in the accumulator. 2. Get the Divisor in the B register. 3. Divide A by B. 4. Store the Quotient and Remainder in memory.
FLOWCHART:
START
DIVIDE A BY B
STOP
60
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8 Bit Division ADDRESS LABEL MNEMONIC 4100 4102 4104 4015 4018 4109 410A 410C 410D STOP MOV MOV DIV MOV MOVX INC MOV MOV SJMP
DEPT OF ECE
OPERAND A, # data1 B, # data2 A,B DPTR, # 4500H @ DPTR, A DPTR A,B @ DPTR, A STOP
COMMENTS Store data1 in accumulator Store data2 in B reg Divide Initialize memory location Store remainder Go to next memory location Store quotient
F0 80,FE Stop
RESULT: INPUT MEMORY LOCATION 4500 (dividend) 4501 (divisor) OUTPUT MEMORY LOCATION 4502 (remainder) 4503 (quotient)
DATA
DATA
Thus the 8051 ALP for division of two 8 bit numbers is executed.
61
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB EXP. NO: AIM: LOGICAL AND BIT MANIPULATION
To write an ALP to perform logical and bit manipulation operations using 8051 microcontroller. APPARATUS REQUIRED: 8051 microcontroller kit ALGORITHM: 1. 2. 3. 4. 5. 6. 7. 8. Initialize content of accumulator as FFH Set carry flag (cy = 1). AND bit 7 of accumulator with cy and store PSW format. OR bit 6 of PSW and store the PSW format. Set bit 5 of SCON. Clear bit 1 of SCON. Move SCON.1 to carry register. Stop the execution of program.
FLOWCHART:
START
Set CY flag, AND CY with MSB of ACC Store the PSW format, OR CY with bit 2 IE reg
Clear bit 6 of PSW, Store PSW Set bit 5 of SCON, clear bit 1 and store SCON Move bit 1 of SCON to CY and store PSW STOP
62
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB PROGRAM TABLE ADDRESS HEX CODE 4100 90,45,00 4103 4105 4016 4018 410A 410B 410C 410E 4110 4112 4113 4114 4116 4118 411A 411B 411C 411E 4120 4122 74,FF D3 82,EF E5,D0 F0 A3 72,AA C2,D6 E5,D0 F0 A3 D2,90 C2,99 E5,98 F0 A3 A2,99 E5,D0 F0 80,FE L2 LABEL MNEMONICS MOV MOV SETB ANL MOV MOVX INC ORL CLR MOV MOVX INC SETB CLR MOV MOVX INC MOV MOV MOVX SJMP OPERAND DPTR,#4500 A,#FF C C, ACC.7 A,D0H @DPTR,A DPTR C, IE.2 PSW.6 A,DOH @DPTR,A DPTR SCON.5 SCON.1 A,98H @DPTR,A DPTR C,SCON.1 A,DOH
DEPT OF ECE
COMMENT Initialize memory location Get the data in accumulator Set CY bit Perform AND with 7th bit of accumulator Store the result Go to next location OR CY bit with 2 nd bit if IE reg Clear 6 th bit of PSW
Store the result Go to next location Set 5th of SCON reg Clear 1st bit of SCON reg Store the result Go to next location Copy 1st bit of SCON reg to CY flag Store the result
@DPTR,A L2 Stop
63
DEPT OF ECE
BEFORE
AFTER
4501H (PSW)
CY
AC
FO
RS1
RS0 OV
40H
88H
4502H (SCON)
20H
4503H (PSW)
CY
AC
FO
RS1
RS0 OV
FFH
09H
64
DEPT OF ECE
DATE : a) Program to generate a square wave of frequency --------. Steps to determine the count: Let the frequency of square wave to be generated be Fs KHz. And the time period of the square wave be Ts Sec. Oscillator Frequency = 11.0592MHz. One machine cycle = 12 clock periods Time taken to complete one machine cycle=12*(1/11.0592MHz)= 1.085microsec. Y(dec) = (Ts/2)/(1.085microsec) Count(dec) = 65536(dec) Y(dec) = Count(hexa)
MOV TL1,#LOWERORDER BYTE OF THE COUNT MOV TH1,#HIGHER ORDER BYTE OF THE COUNT SETB TR1 ; to start the timer (TCON.6) ; checking the status of timerflag1(TCON.7) for overflow CPL Px.x ; get the square wave through any of the portpins ; eg. P1.2 (second bit of Port 1) CLR TR1 CLR TF1 SJMP L1 b) Program to transfer a data serially from one kit to another. ; stop timer ; clear timer flag for the next cycle
BACK:
JNB TF1,BACK
Transmitter: MOV TMOD,#20H MOV TL1,#FDH MOV TH1,#FFH MOV SCON,#50H ; Control word for serial communication to to select serial mode1 SETB TR1 MOV A,#06h 65 ; Start timer1 ; Mode word to select timer1 & mode 2 ; Initialize timer1 with the count
DEPT OF ECE
LOOP:
Receiver: MOV TMOD,#20H MOV TL1,#FDH MOV TH1,#FFH MOV SCON,#50H SETB TR1 LOOP: JNB RI,LOOP MOV A,SBUF MOV DPTR,#4500H MOVX @DPTR,A CLR RI HERE: SJMP HERE
66
DEPT OF ECE
ALGORITHM:
1. Get an 8-bit number in accumulator. 2. The bit which is to be set is ORed by 1. 3. Store the answer at another memory location.
FLOW CHART:
START
67
DEPT OF ECE
STOP
PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 RESULT: OPCODE LABEL 74 START: 2F 44 45 90 45 00 F0 80 FE HERE: MNEMONICS MOV ORL OPERAND A, #DATA1 A, #DATA2 COMMENT Copy to A Register first number OR the A register with an immediate data 45h Store in Data Pointer the memory address Store the result in memory Halt here
MOV
DPTR, #4500
MOVX SJMP
@DPTR, A HERE
4500
CONCLUSION:
Thus the setting of bits in an 8-bit number has been done using 8051 C.
68
DEPT OF ECE
69
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB MASKING BITS IN AN 8-BIT NUMBER PROBLEM STATEMENT:
DEPT OF ECE
ALGORITHM: 1.Get an 8-bit number in accumulator. 2.The bit, which is to be masked, is ANDed by 1. 3.Store the result in memory.
FLOW CHART:
START
STOP
70
DEPT OF ECE
PROGRAM: ADDRESS 4100 4102 4102 4103 4104 4105 4106 4107 4108 4109 RESULT: OPCODE LABEL 74 START: 87 54 7E 90 45 00 F0 80 FE HERE: MNEMONICS MOV ANL MOV OPERAND A, #DATA1 A, #DATA2 DPTR, #4500 COMMENT Copy 1st Number to A register AND A register with 2nd number Copy the memory address to Data Pointer Store the result in memory Halt here
MOVX SJMP
@DPTR, A HERE
INPUT 1000 0111 (87h) DATA2 0111 1110 7Eh (to mask bits 0 and 7) DATA1
4500
CONCLUSION:
Thus the masking of bits in an 8-bit number has been done using 8051 C.
71
DEPT OF ECE
DATE :
SERIAL COMMUNICATION
D E S G B C F10 T : A Z
Display data, program, internal, bit memory or registers Edit data, program, internal, bit memory or registers Single step from specified address, press SP to terminate Execute the program till user break Set address till where the program is to be executed Clear break points Key followed by 4 key at the PC to upload data to a file (DOS) Test the onboard peripherals Download a file from PC mem to the SDA-SI-MEL kit (DOS) Assembler Disassembler
For SDA SI-MEL kit, following menu is displayed on pressing the option "T" 8051>T ALS-SDA SI-MEL Kit Test monitor
1. Test internal Data RAM 2. Test external Data Memory (U6) 3. Test external Data memory (U7) 4. 8255 loop test 5. Test 8253 6. Exit 72
DEPT OF ECE
Select (1-6):
Suppose the user presses the key '1', following message is displayed if the internal data RAM is OK.
After displaying the message, the menu is displayed once again waits for user to enter a key
8051>E EDIT (R,B,M,P,D)D - EXTERNAL DATA RAM Enter STA address = 0400 0400 = 0401 = 0402 = 0403 = 0404 = 0405 = 0406 = 0407 = 0408 = 0409 = 040A = 040B = 040C = 040D = 040E = 7F:55 Press 'N' key to go to the next address D5:66 D3:77 73:88 6F:12 CB:01 A7:02 Press 'P' key to go to the previous address 6F:03 7B:04 29:05 6F:06 73:07 FF:08 7D:09 Press 'CR' key to have the same address 09:90 Press 'ESC' Key to abort the command
73
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8051>E EDIT (R,B,M,P,D)B - BITS Enter STA address = 00 00 = 0:1 01= 0:1 02 = 0:0 03 = 0:1 03 = 1: 03 = 1: 02 = 0:
DEPT OF ECE
8051>E EDIT (R,B,M,P,D)R- REGISTERS ACC = 00:33 PSW = 00:44 DPH = 00:55 DPL = 00:00 DPL = 00:00
8051>E EDIT (R,B,M,P,D)-P = PROGRAM CODE 8000 = FF:78 8001 = FF:10 8002 = FF:79 8003 = FF:20 8004 = FF:7A 8005 = FF: 12 8007 = FF : 00 8008 = FF : 03 8009 = FF : 0F
74
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB 8051>E EDIT (R,B,M,P,D)-M - INTERNAL RAM 0000 = 00 : 12 0001 = 00 : 34 0002 = 00 : 00
DEPT OF ECE
DISPLAY COMMAND
0500 55 66 77 88 12 01 02 03 04 05 06 07 08 09 04 D7
8051>B BR _ NO: R BR_ADD 0000 ERROR! ONLY A BREAKS ALLOWED 8051>B BR _ NO: 0 ERROR! BREAK NUMBERS MUST BE BETWEEN 1 & 8 CLEAR BREAK COMMAND:
8051>C BR_N0:A Clears all the break point set by the user
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB PROGRAMME EXECUTION COMMAND: 8051>G PROGRAM EXECUTION
DEPT OF ECE
76
DEPT OF ECE
DATE:
Program that places a message on the screen every 10 seconds, using int 1ah;
CODE SEGMENT TIMEDELAY: MOV SP,1000H MOV DI,10XD TIME OUT: MOV AH,00H INT 1AH MOV BX,DX TIMER: MOV AH, 00H INT 1AH SUB DX, BX CMP DX, 182XD JC TIMER MOV AH, 09H CS MOV DX,MSG INT 21H DEC DI JNZ TIMEOUT MOV AX,4C00H INT 21H MSG: DB 'TEN MORE SECONDS HAVE PASSED $' CODE ENDS
77
DEPT OF ECE
Algorithm:
Main Program: 1. Initialize data segment to hold the clock data as hours, minutes and seconds 2. Display a message on screen for the user 3. Call the procedure to get the time from PCs real-time clock using BIOS interrupt 4. Call the procedure to convert the clock data into ASCII and display it on the screen 5. Check for user key press using BIOS interrupt service 6. If no key is pressed continue updating the clock on screen. 7. If a key is pressed terminate the program Procedure GetTime: 1. Use Function 02 in Interrupt 1Ah service to read the PCs real-time clock. This function returns hours in CH, minutes in CL and seconds in DH registers. 2. Divide each of these registers by 10h to separate the BCD digits 3. Convert each separated digit into ASCII by adding 30h with it. 4. Store each digit in the appropriate location in the memory. 5. Return from the procedure Procedure ShowTime: 1. Use BIOS interrupt 10h function 02h to set video cursor at desired location on the screen 2. Use DOS interrupt 21h function 09h to display the stored clock data from Data segment memory as a string terminated by $ 3. Call a procedure to delay for few milliseconds doing nothing 4. Return from the procedure
78
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB Procedure Delay: 1. Load a value in CX register 2. Do nothing 3. Decrement CX register by one. 4. loop until CX register is zero 5. Return from the procedure Flow chart: START
DEPT OF ECE
No
79
DEPT OF ECE
Return
Return
80
DEPT OF ECE
Assembly Listing:
.model small .stack .data message db 0ah, 0dh, "This program displays the time " message1 db 0ah, 0dh, "Press any key to quit...", '$', 0ah, 0dh prompt db "Time :: " hours1 db 0 hours2 db 0 separator1 db ':' minutes1 db 0 minutes2 db 0 separator2 db ':' seconds1 db 0 seconds2 db 0 last db '$' divisor db 10h .code mov ax, @data mov ds, ax ; initialize data segment mov ah, 09h ; display a friendly message lea dx, message int 21h again: call GetTime ; call the procedure to get the time call ShowTime ; show the time mov ah, 01h ; check for user key press int 16h jz again ; if no key pressed do again mov ah, 04ch int 21h ; terminate the program
GetTime proc mov ah, 02h ; BIOS function call to read real time clock int 1Ah mov al, ch ; resulting hours value in BCD is to be split div divisor ; into digits add al, 30h ; convert the digits into ASCII values add ah, 30h mov hours1, al ; store them in memory mov hours2, ah xor ax,ax ; clear AX register mov al, cl ; Now convert minutes in the same way and store div divisor add al, 30h add ah, 30h mov minutes1, al mov minutes2, ah
81
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB xor ax,ax ; clear AX register mov al, dh ; convert seconds in the same way and store div divisor add al, 30h add ah, 30h mov seconds1, al mov seconds2, ah ret GetTime endp
DEPT OF ECE
ShowTime proc mov ah, 02h ; set video cursor mov bh, 0 mov dh, 20d ; row and col position on screen mov dl, 10d int 10h mov ah, 09h ; display the time already stored in memory lea dx, prompt int 21h call delay ret ShowTime endp delay proc push cx mov cx, 0ffffh idleout: nop nop nop nop loop idleout pop cx ret delay endp end
Result:
The program should function as expected after assembling and linking into an executable .EXE program. It will display a clock on the screen. It will stop when the user presses a key.
82
DEPT OF ECE
Aim: To display a digital stopwatch on the PC screen allowing the user to start and stop the
watch.
Theory:
Every PC is equipped with BIOS that contains software to initialize the built in Timer IC to produce ticks with a periodicity of 18.2 ticks per every second. This does not rely on the real-time clock usually incorporated in the PC. The BIOS maintains the number of ticks elapsed since midnight or power-on of the machine. BIOS Interrupt 1Ah service provides the number of ticks elapsed at any time. One can use this service repeatedly to check for completion of 18 ticks, which would mean an approximate 1-second time gap. This can be used to update a memory variable to count seconds. After 60 seconds counting, the minute variable can be updated. Thus a stopwatch can be made to operate at the press of a key.
Algorithm:
Main Program: 1. Initialize Data Segment Register 2. Display a friendly message using DOS Int 21h function 09h 3. Call the procedure to show the watch with zero values 4. Check for user key press using BIOS Int 16h function 01h 5. If no key is pressed go to step 4 6. On key press, call the procedure to start the watch. 7. On return from the procedure terminate the program Procedure Show_watch: 1. Position the video cursor at the desired location on secreen using BIOS Int 10h function 02h 2. Display the watch data in memory using DOS Int 21h function 09h 3. Return from the procedure Procedure Start_Watch: 1. Get the current tick value using BIOS Int 1Ah function 00h 2. Store the last two digits of the returned value in DL into BL. This becomes the old value 3. Get the current tick value using BIOS Int 1Ah function 00h 4. Subtract the old value from the new value 5. Check whether it is 18 (which means 1 second) 6. If it is less than 18, goto step 3 7. If it is equal to 18, then increment LSD of seconds. 8. If LSD is greater than 9, proceed to increment MSD of seconds and make LSD of seconds equal to 0 9. Upon incrementing MSD of seconds if it is equal to 6, then make MSD equal to 0 and proceed to update minutes. 10. Increment LSD of minutes. 83
DEPT OF ECE
11. If LSD of minutes is greater than 9, increment MSD of minutes and make LSD equal to 0 12. If MSD of minutes is equal to 6, then make minutes and seconds equal to 0. 13. Call the procedure to Show the Watch. 14. Check for User key press using BIOS Int 16h function 01h. 15. If there is no key press proceed to step 1 16. If there is a key pressed, check whether that key is q. 17. If the key pressed is q, then return from the procedure. 18. Otherwise, go to step 1
Flow Chart:
Main Program: Start
Call Show_Watch
No
Stop
84
DEPT OF ECE
Show_watch Procedure:
Start
Return
Start_Watch Procedure:
Start B1 Get BIOS Timer Tick count and save it in another register Get BIOS Timer Tick count and compare it with previous value No Is the difference =18? Yes Update seconds LSD
A1
85
DEPT OF ECE
A2
86
DEPT OF ECE
A2
Show Timer
Is Key Pressed Y
N B1
Assembly Listing:
.model small .stack .data message db 0ah, 0dh, "This programs displays a stop watch" message1 db 0ah, 0dh, "Press a key to start and q to stop", '$', 0ah, 0dh prompt db "Timer :: " minutes1 db '0' minutes2 db '0' sep1 db ':' seconds1 db '0' seconds2 db '0' sep2 db '.' last db '$' divisor db 10h
87
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB .code mov ax, @data mov ds, ax ; initialize data segment mov ah, 09h ; display a friendly message lea dx, message int 21h call show_watch ; show the watch again: mov ah, 01h ; check for user key press int 16h jz again ; if no key pressed then wait for user key call start_watch ; then start the watch mov ah, 04ch int 21h ; terminate the program
DEPT OF ECE
start_watch proc doitagain: mov ah, 00h ; BIOS function call to read timer count int 1Ah ; BIOS Timer interrupt service mov bl, dl ; save current tick value in BL checkagain: mov ah, 00h ; Function to read system clock tick counter int 1Ah ; under BIOS interrupt service sub dl, bl ; find how many ticks have elapsed cmp dl, 18 ; is it equal to 1 second? jb checkagain ; if not, read the counter again mov al, seconds2 ; increment the last digit inc al cmp al, 39h ; check whether it exceeds 9 jbe update_seconds2 ; if not update Seconds2 mov al, 30h ; if so, change seconds2 to 0 mov seconds2, al mov al, seconds1 ; and then increment seconds1 inc al cmp al, 36h ; upon incrementing, is it 6? jb update_seconds1 ; if not update Seconds1 and go ahead mov al, 30h ; if so, change seconds1 to 0 first mov seconds1, al mov al, minutes2 ; then increment minutes2 inc al cmp al, 39h ; is it above 9 jbe update_minutes2 ; if not update this digit and go ahead mov al, 30h ; if so, change this digit to 0 mov minutes2, al ; mov al, minutes1 ; and affect the previous digit inc al ; cmp al, 36h jb update_minutes1 mov al, 0 update_minutes1: mov minutes1, al jmp done update_minutes2: mov minutes2, al
88
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB jmp done update_seconds1: mov seconds1, al jmp done update_seconds2: mov seconds2, al done: call show_watch mov ah, 01h int 16h jnz check_key jmp doitagain check_key: mov ah, 00h int 16h cmp al, 'q' jnz doitagain ret start_watch endp
DEPT OF ECE
show_watch proc mov dh, 10d ; desired row, col position mov dl, 10d mov ah, 02h ; set video cursor mov bh, 0 ; video page int 10h mov ah, 09h ; display the watch lea dx, prompt int 21h ret show_watch endp end
Result:
After assembling and linking into executable code, this program will display a timer as 00:00. When any key is pressed, it will start the watch and show the number of seconds and minutes. When the user presses the key q, the watch will stop and exit.
89