






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Microcontrollers Program of 8051, 1. MULTIBYTE ADDITION 2. BIT MULTIPLICATION 3. BIT DIVISION 4. BIGGEST NUMBER 5. SMALLEST NUMBER 6. ASCENDING ORDER 7. DESCENDING ORDER 8. BCD TO ASCII CONVERSION 9. ASCII TO BINARY CONVERSION 10. ODD PARITY GENERATOR 11. EVEN PARITY GENERATOR 12. TIME DELAY ROUTINE
Typology: Lab Reports
1 / 12
This page cannot be seen from the preview
Don't miss anything!
Multi byte numbers like 8254h and 65f3h may be added.
i) Add f3 and 54 using ADD and store the result in memory location
ii) Add 82 and 65 using ADDC and store the result in another location
MOV DPTR,#8200H; memory address is loaded to store result MOV R1,#00H; R1 is initialized .It is used to store carry
MOV A,#F3H; LSB of second data is moved to A
ADD A,#54H; LSB of first data is added with A
MOVX @DPTR,A; added value in A is moved to memory
INC DPTR; DPTR is incremented
MOV A,#65H; MSB of second data is moved to A
ADDC A,#82H; MSB of first data is added with carry in A
MOVX @DPTR,A; added value is moved to memory
INC DPTR; DPTR is incremented to store 1 if carry
JNC NEXT; if carry, jump to labeled NEXT INC R1; R1 is incremented if carry available
NEXT: MOV A,R1; R1 value is moved to A
MOVX @DPTR,A; value in A is moved to memory
HLT: SJMP HLT
Assume that 8 bit data are available in memory address 8400h and 8401h
And the result is to be stored in 8402h,8403h
MOV DPTR,#8400H; DPTR is initialized
MOVX A,@DPTR; data in memory address 8400 is moved to A
MOV B,A; value in A is moved to B
INC DPTR; DPTR is incremented
MOVX A,@DPTR; next data in address 8401 is moved to A
MUL AB; both data are multiplied
INC DPTR; DPTR is incremented
MOVX @DPTR,A; low byte answer is moved to memory MOV A,B; high byte answer in B is moved to A
INC DPTR; DPTR incremented
MOVX @DPTR,A; high answer in A is moved to memory
HLT: SJMP HLT
Assume that the data to be arranged are available in array which starts from 8401h and the array length is available in 8400h.
The result is to be stored in 8500h
MOV B, #00H; to hold the biggest number, B is initialised MOV DPTR ,#8400H ;DPTR initialized with
MOVX A, @DPTR; array length in 8400 in moved to A
MOV R0,A; value (array length) in A is copied into R
AGAIN: INC DPTR; DPTR incremented
MOVX A, @DPTR; data in memory is moved to A
CJNE A,B, NEXT; A and B compared. Carry will be generated if B is bigger
NEXT: JC L1; if carry,jump to label L
MOV B,A; if no carry, move the value in A to B
L1: DJNZ R0, AGAIN; array length is decremented and jump to label AGAIN till array length is 0 MOV DPTR,#8500H; DPTR is initialized with 8500 to store bigger value in B MOV A,B; value in B (bigger value) is moved to A
MOVX @DPTR,A; this value (bigger value) is moved to memory addressed by DPTR(8500)
HLT: SJMP HLT
Assume that the data are available in array which starts from 8401h and the array length is available in 8400h.The result is to be stored in 8500h
MOV B, #00H; to hold the biggest number, B is initialised MOV DPTR ,#8400H ;DPTR initialized with
MOVX A, @DPTR; array length in 8400 in moved to A
MOV R0,A; value(array length) in A is copied into R
AGAIN: INC DPTR; DPTR incremented
MOVX A, @DPTR; data in memory is moved to A
CJNE A,B , NEXT; A and B compared. Carry will be generated ifB is bigger
NEXT: JC L1; if carry ,jump to label L
MOV B,A; if no carry, move the value in A to B
L1: DJNZ R0, AGAIN; array length is decremented and jump to label AGAIN till array length is 0 MOV DPTR,#8500H; DPTR is initialized with 8500 to store bigger value in B MOV A,B; value in B (bigger value) is moved to A
MOVX @DPTR,A; this value (bigger value) is moved to memory addressed by DPTR(8500) HLT: SJMP HLT
Assume that the data to be arranged are available in array which starts from 8401h and the array length is assumed as 09.
MOV R0, #08H; array length 08h(09-01) is stored
AGAIN: MOV A, R0; 08h is moved to R
MOV R1, A; Data moved to R
MOV DPTR, #8401H; DPTR is initialized with 8401h
BACK: PUSH DPH; 84 is saved in stack
PUSH DPL; 01 is saved in stack
MOVX A, @DPTR; first data is moved to A
MOV B, A; this data is copied into B INC DPTR; DPTR incremented
MOVX A, @DPTR; second data is moved to A
CJNE A,B, LOOP; first data in B and next data in A are compared. Carry will generate if B value is bigger LOOP: JC NEXT; if carry(second data is smaller)instruction labeled NEXT will be executed POP DPL; 01 from stack is moved to DPL POP DPH; 84 from stack is moved to DPH
MOVX @DPTR, A; second data is moved is moved to first location
INC DPTR; DPTR incremented
MOV A,B; first data in B is moved to A MOVX @DPTR,A; this first data is moved to second location
NEXT: DJNZ R1, BACK; jump for next two data comparison
DJNZ R0, AGAIN; jump for next scan
HLT: SJMP HLT; stay at here
To covert BCD number, each digit is separately considered and equivalent ASCII value is
generated. Ex. To convert 65 ,5 is converted into ASCII value 35 and 6 is converted into ASCII 36.+
The Assume that the BCD value 65 is stored in memory location 8400h and ASCII values are stored in 8401 ,8402.
MOV DPTR,#8400H; DPTR is initialized with 8400h
MOV XA, @DPTR; First Data Is Moved To A
MOV R1,A; Data moved to R
ANL A,#0FH; Get the Lower data ORL A,#30H; OR logic for 30h
INC DPTR; DPTR incremented
MOVX @DPTR,A; Second Data Is Moved To A
INC DPTR; DPTR incremented
MOV A,R1; Data moved to R
ANL A,#F0H; Get the Upper data
SWAP A; Move the lower value
ORL A,#30H; OR logic for 30h
MOVX @DPTR,A; Store the Result
HLT: SJMP HLT; stay at here
Odd parity means that the total number of 1โs in data as well as in parity bit is ODD.
Assume that the data 42H for which the parity is to be generated and the result is to be Stored in 8400h.
The data 42h has 2 nos. of โ1โ s. So one bit is generated to make ODD parity.
MOV DPTR, #8400H; memory address is loaded in DPTR
MOV R1,#08; to rotate the data 8times,R1 is initialised
MOV R2,#00; counter initialized to count no.of โ1โs
MOV A,#42h; the data 42h is stored in A
BACK: RRC A ; the data is rotated
JNC XXX; if not carry, jump to label XXX
INC R2; if carry, R2 is incremented
XXX: DJNZ R1, BACK; 8 rotation is checked
MOV A,R2; no. of 1 s in R2 is moved to A
MOV B,#02; to test the even ,that should be
DIV AB; divide by 02
MOV A,B; the remainder(it is 0 for even no of 1โs in data) is Move to A
CPL A; A value is complemented
MOVX @DPTR,A; Complemented value is stored in memory
HLT: SJMP HLT
Even parity means that the total number of 1โs in data as well as in parity bit is even. Assume that the data 42H for which the parity is to be generated and the result is to be Stored in 8400h.The data 42h has 2 nos. of โ1โ s. So NO need of one bit is generated to make even parity.
MOV DPTR, #8400H; memory address is loaded in DPTR
MOV R1,#08; to rotate the data 8times,R1 is initialised
MOV R2,#00; counter initialized to count no of โ1โs
MOV A,#42h; the data 42h is stored in A
BACK: RRC A; the data is rotated
JNC XXX; if not carry, jump to label XXX
INC R2; if carry, R2 is incremented
XXX: DJNZ R1, BACK; 8 rotation is checked
MOV A,R2; no. of 1 s in R2 is moved to A
MOV B,#02; to test the even ,that should be
DIV AB; divide by 02
MOV A,B; the remainder(it is 0 for even no.of 1โs in data) is moved to A
MOVX @DPTR,A, ; A value is stored in memory
HLT: SJMP HLT; stay at here