Professional Documents
Culture Documents
I. PROGRAMMING
II. INTERFACING:
a) Starting microvision 3
Click on keil Micro Vision icon on the desktop
d) Debugging
For memory display, select Memory window icon under View option
ALGORITHM:
OUTPUT:
Before Execution
X: 0X008035 : 01 02 03 04 05 00 00 00
X: 0X008041 : 00 00 00 00 00 00 00 00
After Execution
X: 0X008035 : 01 02 03 04 05 00 00 00
X: 0X008041 : 01 02 03 04 05 00 00 00
2.Write a program to exchange a block of data bytes from one
location to other location.
Algorithm:
OUTPUT:
Before Execution
X: 0027h : 10 20 30 40 50 00 00 00 00
X: 0041h : 60 70 80 90 75 00 00 00 00
After Execution
Address X : 0027h : 60 70 80 90 75 00 00 00 00
X : 0041h : 10 20 30 40 50 00 00 00 00
Algorithm
Descending Order
ORG 0000h
SJMP 30h
ORG 30h
MOV R0 , # 05h
DEC R0
BACK: MOV DPTR, #9000h
MOV A, R0
MOV R1,A
UP : MOVX A, @ DPTR
MOV B,A
INC DPTR
MOVX A, @ DPTR
CLR C
MOV R2,A
SUBB A,B
JC No exchange
MOV A,B
MOVX @ DPTR , A
DEC DPL
MOV A,R2
MOVX @ DPTR , A
INC DPTR
No exchange: DJNZ R1, UP
DJNZ R0, BACK
HERE : SJMP HERE
END
OUTPUT:
Before Execution
X: 9000h : 04 02 06 05 08
After Execution
X: 9000h : 08 06 05 04 02
Algorithm
ORG 0000h
SJMP 30h
ORG 30h
MOV R0 , # 05h
DEC R0
BACK: MOV DPTR, #9000h
MOV A, R0
MOV R1,A
UP : MOVX A, @ DPTR
MOV B,A
INC DPTR
MOVX A, @ DPTR
CLR C
MOV R2,A
SUBB A,B
JNC No exchange
MOV A,B
MOVX @ DPTR , A
DEC DPL
MOV A,R2
MOVX @ DPTR , A
INC DPTR
No exchange: DJNZ R1, UP
DJNZ R0, BACK
HERE : SJMP HERE
END
OUTPUT:
Before Execution
X: 9000h : 04 02 06 09 08
After Execution
X: 9000h : 02 04 06 08 09
Algorithm
ORG 0000H
SJMP 30H
ORG 30H
MOV R3,#05H
MOV DPTR,#4000H
MOVX A,@DPTR
MOV R1,A
BACK: INC DPTR
MOVX A,@DPTR
MOV R2,A
CLR C
SUBB A,R1
JC SKIP
MOV A,R2
MOV R1,A
SKIP: DJNZ R3,BACK
MOV DPL,#62H
MOV A,R1
MOVX @DPTR,A
HERE: SJMP HERE
END
RESULT:
BEFORE EXECUTION
X: 4000H: 23 21 24 28 03 18
AFTER EXECUTION
X:4062H: 28
Algorithm
ORG 0000H
SJMP 30H
ORG 30H
MOV R3,#05H
MOV DPTR,#4000H
MOVX A,@DPTR
MOV R1,A
BACK: INC DPTR
MOVX A,@DPTR
MOV R2,A
CLR C
SUBB A,R1
JNC SKIP
MOV A,R2
MOV R1,A
SKIP: DJNZ R3,BACK
MOV DPL,#62H
MOV A,R1
MOVX @DPTR,A
HERE: SJMP HERE
END
RESULT:
BEFORE EXECUTION
X: 4000H: 23 21 24 28 03 18
AFTER EXECUTION
X:4062H: 03
Algorithm
Algorithm
RESULT:
BEFORE EXECUTION
X: 8000H: EE 0A 0C 0B
X: 8020H: 21 22 23 24
AFTER EXECUTION
X: 8060H: 0F 2C 2F 2F
ALGORITHM
ALGORI THM.
RESULT:
BEFORE EXECUTION
X: 8000H: 10 20 30 40
X: 8020H: 50 60 70 80
AFTER EXECUTION
X: 8060H: 40 40 40 40
Algorithm
RESULT:
BEFORE EXECUTION
X: 8000H: FF 00 00 00
AFTER EXECUTION
X: 8000H: FF 01 FE 00
Algorithm.
ORG 00H
SJMP 30H
ORG 30H
MOV DPTR, # 8000H
MOVX A, @DPTR
MOV 0F0H , A
MOV R1, A
MUL AB
MOV R2, A
MOV R3, 0F0H
MOV 0F0H, R1
MUL AB
INC DPTR
MOVX @DPTR, A
MOV R4, 0F0H
MOV A, R3
MOV 0F0H , R1
MUL AB
ADD A, R4
INC DPTR
MOVX @DPTR, A
MOV A, #00H
ADDC A, 0F0H
INC DPTR
MOVX @DPTR, A
HERE: SJMP HERE
END
RESULT:
BEFORE EXECUTION
X: 0X008000H: FF 00 00 00 00 00
Algorithm
ORG 0000H
SJMP 30H
ORG 30H
MOV R0, # 05H
MOV R1, # 23H
MOV R2, #01H
MOV DPTR, # 8000H
UP : MOVX A, @DPTR
CJNE A, 01H, NEXT
SJMP SUCCESS
NEXT : INC R2
INC DPTR
DJNZ R0,UP
MOV R2, # 0FFH
SUCCESS: MOV A, R2
MOV DPTR, # 8050H
MOVX @DPTR,A
HERE: SJMP HERE
END
RESULT:
BEFORE EXECUTION
X: 8000H: 21 24 23 03 08
AFTER EXECUTION
X: 8050H: 03H
ALGORITHM
1. Store two 8 bit data at mem loc’s 8000h & 8001h & move data to reg
R0 & R1 respectively.
2. Get the data in reg R0 to reg A.
3. Complement the first data then AND it with the second data & store
the result in reg R2.
4. Get the second data from reg R1 into reg A.
5. Complement the second data & AND it with first data in reg R0.
6. Logically OR the content of reg A with content of reg R2.
7. Increment the memory location to 8002h & store the result.
8. End of code.
ORG 00H
SJMP 30H
ORG 30H
MOV DPTR, # 8000h
MOVX A, @DPTR
MOV R0, A
INC DPTR
MOVX A, @DPTR
MOV R1, A
MOV A, R0
CPL A
ANL A, R1
MOV R2, A
MOV A, R1
CPL A
ANL A, R0
ORL A, R2
INC DPTR
MOVX @DPTR , A
HERE: SJMP HERE
End
RESULT:
BEFORE EXECUTION:
X: 0X008000H: 22 25 00 00
AFTER EXECUTION:
X: 0X008000H: 22 25 07 00
Algorithm
RESULT:
BEFORE EXECUTION
X: 0X008000H: 0A 00 00 00
AFTER EXECUTION
X: 0X008000H: 0A FF 00 00
15 . WAP to find a number is positive or negative
Algorithm
RESULT:
BEFORE EXECUTION
X: 8000H: 34H
AFTER EXECUTION
X: 8001H: FFH
BEFORE EXECUTION
X: 8000H: A4H
AFTER EXECUTION
X: 8001H: AAH
16 .WAP to check the given data even or odd
Algorithm
RESULT:
BEFORE EXECUTION:
X: 8000H: 5AH
AFTER EXECUTION:
X: 8001H: EEH
BEFORE EXECUTION:
X: 8000H: FFH
AFTER EXECUTION;
X: 8001H: DDH
17. WAP to count the number of 1's & 0's
Algorithm
BEFORE EXECUTION:
X: 8000H: 6AH
AFTER EXECUTION:
X: 8000H: 6AH
X: 8001H: 04H
X: 8002H: 04H
Algorithm
RESULT:
Algorithm
1. Store the 8bit data at mem location 8000h & in reg R1.
2. Exchange the nibbles of input data in reg A.
3. Compare the data in reg A with the data in reg R1.
4. If equal , the 8 bit data is a palindrome & display 011h at mem loc
8001h.
5. Else the 8 bit data is not a palindrome & display 0FFh at mem loc
8001h.
6. End of code.
ORG 0000H
SJMP 30H
ORG 30H
MOV DPTR, #8000h
MOVX A, @DPTR
MOV R1,A
SWAP A
CJNE A , 01H,EXIT
MOV A, #11H
SJMP DOWN
EXIT : MOV A, #0FFH
DOWN: INC DPTR
MOVX @DPTR ,A
HERE: SJMP HERE
END
RESULT:
Before Execution : X : 8000h : 77h
After Execution: X : 8001h : 11h
Algorithm
ORG 0000H
SJMP 30H
ORG 30H
CLR C
MOV R0, #1Dh
MOV R1, #22h
MOV R2, #44h
MOV R3, #78h
MOV R4, #00h
MOV R5, #00h
MOV A, R1
MOV B, R3
MUL AB
MOV DPTR, # 8000h
MOVX @DPTR , A
MOV 16h, B
MOV A, R1
MOV B, R2
MUL AB
MOV 17H, A
MOV 18H, B
MOV A, R0
MOV B, R3
MUL AB
MOV 19h, B
ADD A, 17H
JNC DOWN
INC R4
DOWN: ADD A, 16h
JNC DOWN1
INC R4
DOWN1: INC DPTR
MOVX @DPTR, A
MOV A,R0
MOV B,R2
MUL AB
MOV 20h, B
ADD A, 19h
JNC DOWN2
INC R5
DOWN2: ADD A ,18h
JNC DOWN3
INC R5
DOWN3: ADD A,R4
JNC DOWN4
INC R5
DOWN4: INC DPTR
MOVX @DPTR , A
MOV A, 20h
ADD A, R5
INC DPTR
MOVX @DPTR , A
HERE: SJMP HERE
END
RESULT:
Before Execution: X : 8000h : F0
After Execution: X : 8001h : AF
X : 8002h : CA
X : 8003h : 07
ALGORITHM:
ORG 00H
SJMP 30H
ORG 30H
MOV R3, #00h
MOV R4,#00h
MOV R0, #44h
MOV R1,#78h
MOV A,R1
MOV B, A
MUL AB
MOV dptr, # 8000h
MOVX @dptr , A
MOV 16h,B
MOV A,R1
MOV B,R0
MUL AB
MOV 17h, A
MOV 18h, B
MOV 19h,A
MOV 20h,B
add A, 17h
JNC DOWN
INC R3
DOWN: add a, 16h
JNC down1
INC R3
DOWN1: INC DPTR
MOVX @dptr, a
MOV A,R0
MOV B,R0
MUL AB
MOV 21h , B
add A, 20h
JNC down2
INC R4
down2: add a, 18h
JNC DOWN4
INC R4
down 3: add a,R3
JNC down4
INC R4
down 4: INC dptr
MOVX @dptr,a
MOV A,21h
add A,R4
INC dptr
MOVX @dptr,a
HERE: Sjmp HERE
end
RESULT:
1. Store the 16 bit dividend in regs R0R1 and the 8 bit divisor in reg
R2
2. Initialize the regs R4,R5 & B with 00h to store the quotient & no of
shifts.
3. Incremenet the no of shifts
4. Rotate lower byte of divisor to left with carry & store as lower byte
of divisor in reg R2.
5. Rotate higher byte of divisor to left with carry & store as higher
byte of divisor in reg R3.
6. Check the carry flag
7. If cy=0 go to step 3.
8. If cy=1 , rotate lower byte of divisor right with carry & store in reg
R3.
9. Rotate higher byte of divisor right with carry & store in reg R2.
10.Subtract lower byte of dividend with data in reg R3 & store in reg
R0.
11.Subtract higher byte of dividend with data in reg R2 & store in reg
R1.
12.Check the carry flag.
13.If cy=0, compliment carry else get the original 16 bbit dividend &
then compliment carry.
14.Rotate lower byte of quotient in reg R4 with carry left & store in
reg R4.
15.Rotate higher byte of quotient in reg R5 with carry left & store in
reg R5.
16.Decrement the no of shifts in reg B
17.If no of shifta =0, store the data in reg’s R0,& R1 as remainder.
18.Else go to step 8.
19.end
ORG 00H
SJMP 30H
ORG 30H
MOV R0 #99h
MOV R1#99h
MOV R2 #15h
MOV R3,#00h
MOV R4, #00h
MOV R5,#00h
MOV B #00h
Div 1: INC B
MOV A,R2
RLC A
MUL AB
MOV R2,A
MOV A,R3
RLC A
MOV R3,A
JNC Div 1
Div 2 : MOV A,R3
RRC A
MOV R3,A
MOV A,R2
RRC A
MOV R2,A
CLR C
MOV 07h, R1
MOV 06h, R0
MOV A, R0
SUBB A,R2
MOV R0,A
MOV A,R1
SUBB A,R3
MOV R1,A
JNC Div 3
MOV R1, 07h
MOV R0,06h
Div 3 CPL C
MOV A, R4
RLC A
MOV R4,A
MOV A,R5
RLC A
MOV R5,A
DJNZ B, Div 2
MOV R3, 05h
MOV R2, 04h
HERE: Sjmp HERE
end
RESULT:
R0 = 09H R4 = 50H
R1 = 00H R5 = 07H
R2 = 50H R6 = 09H
R3 = 07H R7 = 00H
Algorithm
RESULT:
RESULT:
Before Execution : X : 8000h : 09h
After Execution: X : 8001h : 39h
X : 8002h : 30h
24. WAP to perform hexadecimal/binary to decimal conversion
RESULT:
Before Execution : X : 8000h : 44h
After Execution: X : 8001h : 2Ch
26. WAP to perform hexadecimal/binary to ASCII conversion
RESULT:
Before Execution : X : 8000h : 39h
After Execution: X : 8001h : 09h
ALGORITHM
1.Initialise the initial count = 00h
2. Call delay
3. Add 01h to initial count
4. Display the count at Port2
5.End of code
ORG 00H
SJMP 30H
ORG 30H
MOV A, #00H
L1: A CALL DELAY
ADD A, #01H
MOV P2,A
SJMP L1
DELAY: MOV R1,#0FFH
UP2: MOV R2,#0FFH
UP1: MOV R3,#20H
UP: DJNZ R3,UP
DJNZ R2,UP1
DJNZ R1,UP2
RET
END
RESULT
PORT 2 00H
01H
1FH
FFH
29 Write a Program DOWN counter using delay subroutine
(Hexadecimal)
ALGORITHM
1.Initialise the initial count = FFH
2. Call delay
3. Subtract 01h from initial count
4. Display the count at Port2
5.End of code
ORG 00H
SJMP 30H
ORG 30H
MOV A, #FFH
L1: A CALL DELAY
SUBB A, #01H
MOV P2,A
SJMP L1
DELAY: MOV R1,#0FFH
UP2: MOV R2,#0FFH
UP1: MOV R3,#20H
UP: DJNZ R3,UP
DJNZ R2,UP1
DJNZ R1,UP2
RET
END
RESULT
PORT 2 FFh
1Fh
00h
30.Write a Program to Perform Decimal UP counter using delay
subroutine
ALGORITHM
1.Initialise the initial value to 00h
2. Call delay
3. Add 01h to the initial value
4. Adjust the count value to decimal
5.Display the count value at port2
6.End of code
ORG 00H
SJMP 30H
ORG 30H
MOV A, #00H
L1: A CALL DELAY
ADD A, #01H
DAA
MOV P2,A
SJMP L1
DELAY: MOV R1,#0FFH
UP2: MOV R2,#0FFH
UP1: MOV R3,#20H
UP: DJNZ R3,UP
DJNZ R2,UP1
DJNZ R1,UP2
RET
END
RESULT
PORT 2 00
50
99
ALGORITHM
1.Initialise the initial value to 99h
2. Call delay
3. Add 99h to the initial count
4. Adjust the count value to decimal
5.Display the count value at port2
6.End of code
ORG 00H
SJMP 30H
ORG 30H
MOV A, #00H
L1: A CALL DELAY
ADD A, #99H
DAA
MOV P2,A
SJMP L1
DELAY: MOV R1,#0FFH
UP2: MOV R2,#0FFH
UP1: MOV R3,#20H
UP: DJNZ R3,UP
DJNZ R2,UP1
DJNZ R1,UP2
RET
END
RESULT
PORT 2 99
50
00
VIVA QUESTIONS
MICROCONTROLLER
1. What is microprocessor?
Ans. A general-purpose digital central processing unit.
8. Define Bus.
Ans. Conducting lines that carry information within MC & from MC
to external devices
Types of Buses
Ans. Address Bus: Carries address – 16 bits
Data bus: Carries data – 8 bits
13.Define CPU.
Ans. Heart of the processor that process the data.
15.Function of EA signal.
Ans. Enables the external memory.
28.Name two bits of SCON register that is used for selecting the serial
mode of communication.
Ans. SM0 & SM1
Importance of TI flags.
Ans. Monitors SBUF register to assure that it is not overloaded.
What is a Flag?
Ans. One bit register that indicates the result of the operation.
What is polling?
Ans. MC checks the devices in the round robin fashion.
What is an interrupt?
Ans. A signal that request the MC to give its attention.
Advantages of Interrupt.
Ans. MC can serve many devices.
Priority can be assigned to the devices.
What is ISR?
Ans. A small program associated with each interrupt is called ISR.
Priority of interrupts
Ans. IE0
TF0
IE1
TF1
RI or TI
TF2 or EXF2
What is subroutine?
Ans. A small program that is separately written and is being called
from the main program is called subroutine.
What is USART?
Ans. Universal synchronous – asynchronous receiver transmitter.
What is interfacing?
Ans. Connecting the MC to external devices is called as interfacing.
Connecting I/O chip to the CPU is called memory mapped I/O since
memory space is used to access I/O device
In I/O mapped I/O, I/O devices uses different address.