22EC502 MICROCONTROLLER-Model Ans Key
22EC502 MICROCONTROLLER-Model Ans Key
ANSWER KEY
Part A
1. Outline IN and OUT instruction of 8085
The IN instruction in the 8085 microprocessor reads data from an external I/O port into the
accumulator.
Syntax: IN Port_Address.
Example: IN 01H retrieves data from port 01H.
The OUT instruction sends data from the accumulator to an external I/O port.
Syntax: OUT Port_Address.
Example: OUT 02H transmits data to port 02H.
2. Differentiate Microprocessor and Microcontroller
The PSW.4 and PSW.3 specially named as RS1 and RS0 is used in selecting the register bank
as below,
• This instruction moves the contents of memory address 40H into register R0. 40H is an
address in the RAM, and the data stored at that address is copied into R0.
(ii) MOV R0, #40H:
• This instruction moves the immediate value 40H directly into register R0.
• The # symbol signifies that 40H is a literal (or immediate) value, not an address.
7. Write the use of IC M7211 in LCD interfacing
The IC M7211 is commonly used as an LCD driver in LCD interfacing applications. Here are
its primary functions and uses:
(i) Segment Driver: The M7211 is designed to drive multiple segments of an LCD, making it
ideal for interfacing with segment-based displays like those in simple alphanumeric and
graphic LCDs.
(ii) Simplifies Control: It reduces the complexity of driving an LCD directly from a
microcontroller by handling the segment voltages, timing, and multiplexing. This simplifies
the microcontroller’s workload and allows it to focus on other tasks.
(iii) Control Interface: The M7211 offers an interface that allows easy communication with
the microcontroller, enabling it to update display data easily.
8. Find the resolution of 10 bit ADC operating on 5V supply.
For a 10-bit ADC with a 5V supply, the resolution can be calculated as follows:
PART-B
Explanation: 6 Marks
Explanation: 6 marks
12.a. Analyze the special function registers involved in interrupt operation.
Introduction about 8051 interrupts, interrupt vector table, interrupt service routine – 5 marks
IE Register 4 marks
IP register 4 marks
13. Assuming Xtal = 11.0592 Mhz, write a program in 8051 to generate a square wave
of 50 KHz frequency in Mode1 on pin P2.3.
Calculation 6 marks
ORG 0000H
MAIN:
MOV TMOD, #01H ; Set Timer 0 to Mode 1 (16-bit timer mode)
MOV TH0, #0FFH ; Load high byte of Timer 0 for 10 μs delay
MOV TL0, #0F7H ; Load low byte of Timer 0 for 10 μs delay
SETB TR0 ; Start Timer 0
TOGGLE:
JNB TF0, TOGGLE ; Wait for Timer 0 overflow (TF0 = 1)
CLR TF0 ; Clear Timer 0 overflow flag
CPL P2.3 ; Toggle P2.3 to create square wave
MOV TH0, #0FFH ; Reload Timer 0 high byte for next cycle
MOV TL0, #0F7H ; Reload Timer 0 low byte for next cycle
SJMP TOGGLE ; Repeat the process
END
Explanation:
• JNB TF0, TOGGLE: Waits until Timer 0 overflows (when TF0 becomes 1).
• CLR TF0: Clears the overflow flag to prepare for the next cycle.
• Reload Timer: Reloads TH0 and TL0 with the calculated values for the next 10 μs
delay.
5. SJMP TOGGLE: Repeats the loop to maintain the square wave output.
13.b Write an 8051 assembly level program to exchange 10 bytes of data from location
30H to location 1000H
Algorithm 6 marks
Program 7 marks
ALGORITHM
Step 4: Store the byte from register B (original external RAM data) to internal RAM
PROGRAM
ORG 0000H
EXCHANGE_LOOP: MOV A, @R0 ; Load data from internal RAM (address in R0)
into accumulator
END
14.a Draw interfacing diagram of 8 bit ADC with 8051 and write program to read
binary output of ADC and make 8 leds to glow according to the digital value.
Diagram 6marks
PROGRAM
START_CONVERSION:
CLR P2.1 ; Start conversion (WR = 0)
NOP ; Small delay
SETB P2.1 ; WR = 1 to end the start pulse
WAIT_FOR_EOC:
JB P2.3, WAIT_FOR_EOC ; Wait until EOC goes low (conversion complete)
READ_ADC:
CLR P2.2 ; Output Enable (OE = 0) to read data
MOV A, P1 ; Read digital data from ADC (Port 1)
MOV P3, A ; Output data to LEDs (Port 3)
SETB P2.2 ; OE = 1 to complete read
END
14.b Design an 8051 based system to generate triangular wave in port 1 using DAC and
illustrate the working with assembly language code and interfacing diagram.
Diagram 8 mark
Explanation 5 mark
15.b Explain the memory organization of PIC microcontroller.
PART-C
16.a Write an 8051 assembly level program to count the number of positive numbers
and number of negative numbers in an array of ‘N’ bytes of data.
Algorithm 5 marks
Program 6 marks
Explanation 4 marks
ALGORITHM
o In 8-bit signed numbers, if the most significant bit (MSB) is 0, the number is
positive.
PROGRAM
MOV R0, #30H ; Assume array starts at internal RAM address 30H
MOV R1, N ; Load R1 with the number of elements, N
MOV R2, #00H ; Initialize positive count to 0
MOV R3, #00H ; Initialize negative count to 0
COUNT_LOOP:
MOV A, @R0 ; Load the next array element into accumulator
JNB ACC.7, POSITIVE ; Check the MSB (ACC.7); if 0, it's positive
NEGATIVE:
INC R3 ; Increment negative counter
SJMP NEXT ; Skip to next element
POSITIVE:
INC R2 ; Increment positive counter
NEXT:
INC R0 ; Move to the next element in the array
DJNZ R1, COUNT_LOOP ; Decrement R1; if not zero, repeat the loop
; After the loop ends, R2 contains the positive count, R3 contains the negative count
END
EXPLANATION
1. MOV R0, #30H: Initializes R0 to point to the start of the array at RAM location 30H.
2. MOV R1, N: Loads R1 with N, the number of elements in the array.
3. MOV R2, #00H and MOV R3, #00H: Initialize counters R2 and R3 for positive and
negative counts to zero.
4. COUNT_LOOP: Main loop to process each element.
o MOV A, @R0: Loads the current element into the accumulator.
o JNB ACC.7, POSITIVE: Checks if the MSB (ACC.7) is 0. If so, it’s positive,
and the program jumps to the POSITIVE label.
5. NEGATIVE:
o INC R3: Increments the negative count if the number is negative (MSB = 1).
6. POSITIVE:
o INC R2: Increments the positive count if the number is positive.
7. NEXT:
o INC R0: Moves to the next byte in the array.
o DJNZ R1, COUNT_LOOP: Decrements R1 (element counter) and loops back
if there are more elements to process.
8. END: At the end of the program, R2 holds the count of positive numbers, and R3 holds
the count of negative numbers.
16.b Write an 8051 assembly level program to count the number of even numbers and
number of odd numbers in an array of ‘N’ bytes of data.
Algorithm 5 marks
Program 6 marks
Explanation 4 marks
ALGORITHM
PROGRAM
MOV R0, #30H ; Assume array starts at internal RAM address 30H
MOV R1, N ; Load R1 with the number of elements, N
MOV R2, #00H ; Initialize even count to 0
MOV R3, #00H ; Initialize odd count to 0
COUNT_LOOP:
MOV A, @R0 ; Load the next array element into the accumulator
JNB ACC.0, EVEN ; Check the LSB (ACC.0); if 0, it's even
ODD:
INC R3 ; Increment odd counter
SJMP NEXT ; Skip to the next element
EVEN:
INC R2 ; Increment even counter
NEXT:
INC R0 ; Move to the next element in the array
DJNZ R1, COUNT_LOOP ; Decrement R1; if not zero, repeat the loop
; After the loop ends, R2 contains the even count, R3 contains the odd count
END
EXPLANATION
1. MOV R0, #30H: Initializes R0 to point to the start of the array at RAM location 30H.
3. MOV R2, #00H and MOV R3, #00H: Initialize counters R2 and R3 for even and odd
counts to zero.
• JNB ACC.0, EVEN: Checks if the least significant bit (ACC.0) is 0. If so, it’s even,
and the program jumps to the EVEN label.
5. ODD:
• INC R3: Increments the odd count if the number is odd (LSB = 1).
6. EVEN:
7. NEXT:
8. END: At the end of the program, R2 holds the count of even numbers, and R3 holds the
count of odd numbers.