0% found this document useful (0 votes)
2 views

Microcontroller Lab Manual

This document is a lab manual for Microcontrollers (10ESL47) prepared by faculty at Sri Venkateshwara College of Engineering. It includes a comprehensive syllabus covering programming and interfacing with 8051 and MSP 430 microcontrollers, along with detailed lab experiments and outcomes. The manual outlines various programming tasks, algorithms, and expected results for students to complete during their lab sessions.

Uploaded by

Manjunath M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Microcontroller Lab Manual

This document is a lab manual for Microcontrollers (10ESL47) prepared by faculty at Sri Venkateshwara College of Engineering. It includes a comprehensive syllabus covering programming and interfacing with 8051 and MSP 430 microcontrollers, along with detailed lab experiments and outcomes. The manual outlines various programming tasks, algorithms, and expected results for students to complete during their lab sessions.

Uploaded by

Manjunath M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 85

SVCE/ECE/MNL.

/Microcontroller/Ver-02

SRI VENKATESHWARA COLLEGE OF ENGINEERING


VIDYANAGAR, BENGALURU-562157

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING

LAB MANUAL
FOR
MICROCONTROLLERS
(10ESL47)
(IV SEMESTER E&CE)

Prepared by

Prof. POORNIMA G R
Mr. DILEEP REDDY BOLLA
Ms. ARPITA KULKARNI

Approved By:
Dr. SHIVSHANKAR
HoD, E&CE
INDEX

Sl. No. Description Page No.


Data Transfer - Block move, Exchange, Sorting, Finding largest element
1
in an array.
. Arithmetic Instructions - Addition/subtraction, multiplication and
2 division, square, Cube– (16 bits Arithmetic operations –
bitaddressable).
3 Counters.
4 Boolean & Logical Instructions (Bit manipulations).
5 Conditional CALL & RETURN.
Code conversion: BCD – ASCII; ASCII – Decimal; Decimal - HEX and
6
HEX - Decimal.
Programs to generate delay, Programs using serial port and on-Chip
7
timer / Counter
Write C programs to interface 8051 chip to Interfacing modules to
8
develop single chip solutions.
Simple Calculator using 6 digit seven segment displays and Hex
9
Keyboard interface to 8051
10 Alphanumeric LCD panel and Hex keypad input interface to 8051
11 External ADC and Temperature control interface to 8051.
Generate different waveforms Sine, Square, Triangular, Ramp etc. using
12
DAC interface to 8051; change the frequency and amplitude.
13 Stepper and DC motor control interface to 8051.
14 Elevator interface to 8051.
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Course Syllabus
I. PROGRAMMING (On both 8051 & MSP 430)
1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array.
2. Arithmetic Instructions - Addition/subtraction, multiplication and division, square, Cube – (16
bits Arithmetic operations – bit addressable).
3. Counters.
4. Boolean & Logical Instructions (Bit manipulations).
5. Conditional CALL & RETURN.
6. Code conversion: BCD – ASCII; ASCII – Decimal; Decimal - HEX and HEX - Decimal.
7. Programs to generate delay, Programs using serial port and on-Chip timer /Counter.
II. INTERFACING:
8. Write C programs to interface 8051 chip to Interfacing modules to develop single chip
solutions.
9. Simple Calculator using 6 digit seven segment displays and Hex Keyboard interface to 8051.
10. Alphanumeric LCD panel and Hex keypad input interface to 8051.
11. External ADC and Temperature control interface to 8051.
12. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC interface to
8051; Change the frequency and amplitude.
13. Stepper and DC motor control interface to 8051.
14. Elevator interface to 8051.

Course Outcomes:
Level of
CO. No After the completion of the course the student will be able to Blooms
Taxonomy
Implement, demonstrate and design hardware and software for
C247.1 small digital systems involving microcontrollers of 8051 & L3,L4,L5
MSP 430.
Write assembly language & C program in 8051 & MSP 430 for
C247.2 various embedded system applications. L3,L4
Mapping of Course Outcomes with Program Outcomes :
Program Outcomes
Course outcomes a b c d e f g h i j k l
(After completion of the course the student
will be able to)
Implement, demonstrate and design
hardware and software for small x x x x x x x x x x
C247.1 digital systems involving
microcontrollers of 8051 & MSP 430.
Write assembly language & C program
C247.2 in 8051 & MSP 430 for various x x x x x x x xx
embedded system applications.

Use the 8051 microcontroller and its x x x x x x x x x x x


C247.3 standard peripherals.
Microcontrollers Lab Question Bank

1. Write a program to transfer a block of data from a given source to destination


2. Write a program to interchange n bytes of data starting from location x with n bytes of data
starting from location y
3. Write a program to arrange a set of 8 bit numbers at location x in ascending order using
bubble sort
4. Write a program to arrange a set of 8 bit numbers at location x in descending order using
bubble sort
5. Write a program to find the largest element in a given string of n bytes at location 4000h. Sort
the largest element at location 4062h.
6. Write a program to find the largest element in a given string of n bytes at location
7. 4000h. Sort the smallest element at location 4062h.
8. Write a program to transfer block of data from source to destination locations with
overlap.
9. Write a program to add 2 multi byte numbers
10. Write a program to subtract 2 multi byte numbers
11. Write a program to multiply 16 bit number by 8 bit number
12. Write a program to divide two 8 bit numbers
13. Write a program to find square of a number
14. Write a program to find cube of a number
15. Write an ALP for Decimal down counter.
16. Write an ALP for Decimal up counter
17. Write an ALP for Hexadecimal down counter
18. Write an ALP for Hexadecimal up counter
19. Write an ALP to realize the following Boolean expression.
_ _ _
Y = ABC + ABC + ABC
20. Write an ALP to convert BCD to ASCII
21. Write an ALP to convert ASCII to BCD.
22. Write an ALP to convert Decimal to Hexadecimal
23. Write an ALP to convert Hexadecimal to Decimal.
24. Write an ALP to convert ASCII to Hexadecimal.
25. Write an ALP to generate a software delay
MSP 430 PROGRAMS
1. Write an ALP to transfer 16bit data from location from 20h to 40h(without overlap)
2. Write an ALP to transfer 16bit data from location from 20h to 40h(with overlap)
3. Write an ALP to Exchange n=5bytes of data at location 35h and 41h
4. Write an ALP to sort an array n=16 bytes of data in Ascending order
5. Write an ALP to convert ASCII code to HEXADECIMAL code
6. Write an ALP to implement an 8 bit up binary (HEX) counter on port P2
7. Write an ALP to illustrate arithmetic operations and logical operations(AND, OR, XOR)
C PROGRAMS
1. Write a C program to interface SEVEN SEGMENT DISPLAY(FOUR UNITS) to display
message SVCE
2. Write a C program to interface 8051 chip to DAC to generate SINE, square, triangle, ramp
3. Write a C program to interface 8051 chip to ELEVATER
4. Write a C program to interface 8051 chip to HEX KEYPAD
5. Write a C program to interface 8051 chip to STEPPER MOTOR
EXPT. NO: 1a. Data Transfer - Block move(without overlap)

Aim: To write and execute an assembly language program to transfer a block of data from source
to destination.

Apparatus Required:

No Name Quantity
1 8051 microcontroller Keil Simulator kit 1

Algorithm:
1. Initialize the source and destination memory pointers to address external memory.
2. Initialize the counter.
3. Read data from source location.
4. Write data to destination location.
5. Decrement the counter and check for 0, if not go to repeat from step 3, otherwise terminate
the program.
Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address
ORG 0x00
SJMP 0x30
ORG 0x30
MOV R0,#01h; holds the higher order byte of source
MOVR1,#02h; holds the higher order byte of destination
MOVR2,#00h; holds the lower order byte of source & destination
MOVR7,#05h; initialize counter
L1: MOV DPH,R0; DPH loaded with value of r0
MOV DPL,R2; DPL loaded with value of r2
MOVX A,@DPTR; accumulator loaded with the value of dptr
MOVDPH,R1; DPH loaded with value of r1
MOVX@DPTR,A; content of acc. loaded to address pointed to dptr (dest)
INC R2; increment r2
DJNZR7,L1; decrement r7, jump to loop if not equal to 0
HERE: SJMP HERE
END
RESULT:

BEFORE EXECUTION : AFTER EXECUTION :


EXPT. NO: 1b. Data Transfer - Interchange
Aim: To write and execute an assembly language program to interchange N bytes of data starting
from location x with N bytes of data starting from location y.

Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1

Algorithm:
1. Initialize the memory pointers to address two blocks x and y in external memory.
2. Initialize the counter with N value.
3. Read data from location X to temporary memory location.
4. Readdata from Y location and write into X memory location.
5. Write data from temporary memory location to Y memory location.
6. Increment memory pointers of x and y locations.
7. Decrement the counter and check for 0, if not, repeat from step 3, otherwise terminate the
program.
Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address
ORG 0x00
SJMP 0x30
ORG 0x30
MOV r1,#0x01 ; holds the higher order byte
MOV r2,#0x02
MOV r3,#0x03
MOV r4,#0x00 ; lower order byte
MOV r7,#0x05
L1: MOV DPH,R1 ; DPH loaded with 0x01
MOV DPL,R4 ; DPL loaded with 0x00
MOVX A,@DPTR ; accumulator loaded with 0x00
MOV DPH,R3 ; DPH loaded with 0x03
MOVX @DPTR,A ; content of accumulator loaded to0x0100
MOV DPH,R2 ; DPH loaded with value of r2
MOVX A,@DPTR ; acc. loaded with data pointed by dptr
MOV DPH,R1 ; DPH loaded with value of r1
MOVX @DPTR,A; content of acc. loaded to address pointed to dptr
MOV DPH,R3; DPH loaded with value in r3
MOVX A,@DPTR; accumulator loaded with data pointed to dptr
MOV DPH,R2; dpl loaded with value of r2
MOVX @DPTR,A;content of acc. loaded to address pointed to dptr
INC R4; increment r4
DJNZ R7,L1; decrement r7, jump to loop if not equal to 0
HERE: SJMP HERE
END
RESULT:

BEFORE EXECUTION : AFTER EXECUTION :

EXPT. NO: 1c. Ascending order- Bubble sort

Aim: Write a program to arrange a set of 8 bit numbers at location x in ascending order using
bubble sort technique.

Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:

Algorithm:
1. Store the elements of the array from the address 100h.
2. Initialize a pass counter with array size – 1 count (for number of passes) on R1.
3. Load compare counter with pass counter contents and initialize a register (say DPTR to
point to the start address of the array (100h).
4. Compare the next element with the current element, if smaller skip the exchange(go to step
6)
5. Exchange the two numbers in the array.
6. Decrement the exchange counter and repeat through step 5 until the counter becomes zero.
7. Decrement the pass counter and repeat through step 4 until the counter becomes 0.
8. Endless loop to terminate the program.
Program:
Memory Hex Label – Mnemonics - Operand(s) – Comments
address code(s)
ORG00H
SJMP0X030
ORG0X030
MOVR1,#03H; enter the number of data (n-1)
L5: MOV R2,#03H
MOVDPTR,#0X0100; dptr loaded with contents of 0x0100
MOVX A,@DPTR; acc. is loaded with contents of 0x0100
MOVB,A; contents of a loaded to b
L2:INCDPTR; increment dptr
MOVX A,@DPTR; acc. loaded with data pointed by dptr
CJNEA,B,L1; compare a & b, if not equal jump to l1
DJNZR2,L2; decrement r2 if not zero jump to l2
L1:JC L3
XCHA,B; exchange b & a
L3:DECDPL; decrement dpl
MOVX @DPTR, A; content of acc. loaded to address pointed to dptr
INC DPL; increment dpl
DJNZ R2,L2; decrement r2 if not zero jump TO L2
MOV A,B; accumulator is loaded with b
MOVX @DPTR,A;content of acc. loaded to address pointed to dptr
DJNZ R1,L5; decrement r1 if not zero jump to l5
HERE: SJMP HERE
END

BEFORE EXECUTION : AFTER EXECUTION :

RESULT:

Result:
Thus an assembly language program was written to arrange 8 bit array of data in
descending order and it was executed successfully.

EXPT. NO: 1d. Sorting - Descending order

Aim: Write a program to arrange a set of 8 bit numbers at location x in Descending order using
bubble sort

Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1

Algorithm:
1. Store the elements of the array from the address 100h.
2. Initialize a pass counter with array size – 1 count (for number of passes) on R1.
3. Load compare counter with pass counter contents and initialize a register (say DPTR to
point to the start address of the array (100h).
4. Compare the next element with the current element, if smaller skip the exchange(go to step
6)
5. Exchange the two numbers in the array.
6. Decrement the exchange counter and repeat through step 5 until the counter becomes zero.
7. Decrement the pass counter and repeat through step 4 until the counter becomes 0.
8. Endless loop to terminate the program.
Program:
Memory Hex Label – Mnemonics - Operand(s) – Comments
address code(s)
ORG 00H
SJMP 0X030
ORG 0X030
MOV R1,#03H; enter the number of data (n-1)
L5:MOV R2,#03H
MOV DPTR,#0X0100; dptr loaded with contents of
0x0100
MOVX A,@DPTR; acc. is loaded with contents of 0x0100
MOV B,A; contents of a loaded to b
L2:INC DPTR; increment dptr
MOVXA,@DPTR; acc. loaded with data pointed by dptr
CJNE A,B,L1; compare a & b, if not equal jump to l1
DJNZ R2,L2; decrement r2 if not zero jump to l2
L1:JNC L3
XCH A,B; exchange b & a
L3:DEC DPL; decrement dpl
MOVX @DPTR, A; content of acc. loaded to address pointed
to dptr
INC DPL; increment dpl
DJNZ R2,L2; decrement r2 if not zero jump TO L2
MOV A,B; accumulator is loaded with b
MOVX @DPTR,A;content of acc. loaded to address pointed to dptr
DJNZ R1,L5; decrement r1 if not zero jump to l5
HERE: SJMP HERE
END

BEFORE EXECUTION : AFTER EXECUTION :

Result:
EXPT. NO : 1e. Largest Element
Aim: Write
a program to find the largest element in a given string of n bytes at location 4000h.
Sort the largest element at location 4062h.

Objective:To find the largest number in a given 8bit set of numbers


Apparatus Required
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Program
Memory Hex code(s) Label – Mnemonics - Operand(s) – Comments
address
ORG 00H
SJMP 0X030
ORG 0X030
MOV R3, #04H; array length
MOV DPTR, #0X4000
MOVX A, @DPTR ; first byte
MOV R1, A
NEXTBYTE: INC DPTR
MOVX A, @DPTR; get next byte
CLR C
MOV R2, A
SUBB A, R1
JC SKIP
MOV A, R2; keep present large no in acc
MOV R1, A; keep present large no in r1
SKIP : DJNZ R3, NEXTBYTE; if r3 # 0 goto nextbyte
MOV DPL, #62H
MOV A, R1
MOVX @DPTR, A
HERE : SJMP HERE
END

Result:

BEFORE EXECUTION : AFTER EXECUTION :


EXPT. NO : 1f. Smallest Element
Aim: Write
a program to find the smallest element in a given string of n bytes at location 4000h.
Sort the largest element at location 4062h.

Objective:To find the smallest number in a given 8bit set of numbers


Apparatus Required
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1

Algorithm:
1. Initialize counter and pointer
2. Read data in temporary location
3. Compare first and second data
4. Store the smaller value in destination address location
5. Decrement counter and goto step 2
6. When counter equal to zero end the program

Program
Memory Hex code(s) Label – Mnemonics - Operand(s) – Comments
address
ORG 00H
SJMP 0X030
ORG 0X030
MOV R3, #04H; array length
MOV DPTR, #0X4000
MOVX A, @DPTR ; first byte
MOV R1, A
NEXTBYTE: INC DPTR
MOVX A, @DPTR; get next byte
CLR C
MOV R2, A
SUBB A, R1
JNC SKIP
MOV A, R2; keep present large no in acc
MOV R1, A; keep present large no in r1
SKIP : DJNZ R3, NEXTBYTE; if r3 # 0 goto nextbyte
MOV DPL, #62H
MOV A, R1
MOVX @DPTR, A
HERE : SJMP HERE
END

Result:
BEFORE EXECUTION : AFTER EXECUTION :
EXPT. NO : 1g. Block Transfer-With Overlap

Aim:write a program to transfer block of data from source to destination locations


with overlap.

Objective: To move the 8 bit block of data with overlap.

Apparatus required: No Name Quantity


1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Initialize counter and pointer
2. Read data in temporary location
3. Compare first and second data
4. Store the larger value in destination address location
5. Decrement counter and goto step 2
6. When counter equal to zero end the program

Program:
Memory Hex Label – Mnemonics - Operand(s) – Comments
address code(s)
ORG 0X00
SJMP 0X30
ORG 0X30
MOV R1,#0X29; source block higher order address
MOV R2,#0X30; destination block higher order address
MOV R3,#0X40; higher order address of block1 & block 2
MOV R4,#0X0A ; initialized counter
MOV DPH,R3; dph loaded with r3
LOOP1 :MOV DPL, R1; dpl loaded with r1
MOVX A, @DPTR; accumulator loaded with 4029 address
MOV DPL, R2; dpl loaded with r2
MOVX @DPTR, A
MOV R2, DPL; r2 is loaded with dpl
DEC R2; decrement r2
DEC R1; decrement r1
DJNZ R4, LOOP1; decrement r0, if not equal to zero then jump to loop1
HERE : SJMP HERE
END

Result:
BEFORE EXECUTION :
AFTER EXECUTION:
EXPT. NO : 2a. Multibyte-Addition

Aim:Write an assembly language program to add 2 multi byte numbers.

Objective:To perform addition of two 16bit(2bytes) numbers.

Apparatus required: No Name Quantity


1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Initialize the counter.
2. Initialize source and destination memory location for operand 1 and 2.
3. Perform addition and write in destination memory location.
4. Decrement the counter and increment pointer and goto step 3.
5. Increment the pointer to display the carry, if generated.
6. End the program.

Program:
Memory Hex code(s) Label – Mnemonics - Operand(s) – Comments
address
ORG 00H
SJMP 0X30
ORG 0X30
MOV R1,#40H
MOV R2,#00H; operand 1
MOV R3,#20H; operand 2
MOV R4,#50H; result
MOV R5,#02H; number of bytes
MOV DPH,R1; move dph with r1 contents
L2: MOV DPL,R2; move dpl with r2 contents
MOVX A,@DPTR; move the 1st byte of the1st no to acc
MOV B,A; move to b
MOV DPL,R3;move dpl with r3 contents
MOVX A,@DPTR; move the 1st byte of the 2nd no to acc
ADDC A,B; add a and b with carry
MOV DPL,R4; load dpl with contents of r4
MOVX @DPTR,A; move 1st byte of the sum to dptr address
INC R2; increment r2
INC R3; increment r3
INC R4; increment r4
DJNZ R5,L2; decrement r5 jump to l2 if not 0
INC DPTR; increment dptr
JC L3;jump to l3 if carry=1
MOV A,#00H;mov 00 to acc
MOVX @DPTR,A; mov 00 to dptr
SJMP HERE
L3: MOV A,#01H; move 01 to acc
MOVX @DPTR,A ;move 01 to dptr address
HERE: SJMP HERE
END
BEFORE EXECUTION : AFTER EXECUTION :
EXPT. NO : 2b. Subtraction-8bit

Aim: Write an assembly language program to subtract 2 multi byte numbers.

Objective:To perform subtraction of two 8bit(1byte) numbers.

Apparatus required: No Name Quantity


1 8051 microcontroller Keil Simulator kit 1

Algorithm:
1. Initialize the counter.
2. Initialize source and destination address in external memory.
3. Subtract and read the result in destination address location.
4. Increment data pointer decrement counter.
5. If carry is generated take 2’s compliment of the subtrahend and add with minuend.
6. Write the result in the destination memory location.
Program:

Memory Hex Label – Mnemonics - Operand(s) – Comments


address code(s)
ORG 00H
SJMP 0X30
ORG 0X30
MOV R1,#81H
MOV R2,#00H; operand 1
MOV R3,#20H; operand 2
MOV R4,#50H; result
MOV A, R4;move the contents of r4(result) to a
MOV R6, A; move the contents of a to r6
MOV R5, #03H; counter to r5
MOV A, R5; move the contents of r5 to a
MOV R0, A; move the contents of a to r0
MOV DPH,R1; move higher address of the operand to dph
L2: MOV DPL, R2; move the lower address to dpl
MOVX A,@DPTR; move the1st byte of the 1st no to a
MOV B,A; move the contents of a to b
MOV DPL,R3; move the lower address of the operand2 to dpl
MOVX A,@DPTR; move the1st byte of the 2ndt no to a
SUBB A,B; subtract a and b with barrow
MOV DPL,R4; move the lower address of the result to dpl
MOVX @DPTR,A; move the lower byte of the result to dptr address
INC R2; increment r2
INC R3; increment r3
INC R4; increment r4
DJNZ R5,L2; decrement r5 jump to l2 if not zero
JC L3; jump to l3 if carry=1
INC DPTR; increment dptr
MOV A,#00H
MOVX @DPTR,A; move 00 to dptr location
SJMP HERE
L3: MOV DPL, R6; move the result address to dpl
MOVX @DPTR,A; move 00 to dptr location;
CPL A ; complement acc
ADDC A, #00H; add acc with zero with carry
MOVX @DPTR, A ; move the sum to dptr address
INC R6 ;increment r6
DJNZ R0, L3 ; ; decrement r0 jump to l3 if not zero
INC DPTR ; increment dptr
MOV A, #01H ; move 01 to a
MOVX @DPTR, A ; move 01 to dptr address
HERE: SJMP HERE
END

BEFORE EXECUTION : AFTER EXECUTION :


EXPT. NO : 2c. Multiplication-16bit with 8bit

Aim:Write an assembly language program to multiply 16 bit number by 8 bit


number.

Objective: To perform multiplication of 2bytes and 1byte number.

Apparatus required: No Name Quantity


8051 microcontroller Keil Simulator
1 kit 1
Algorithm:
1. Initialize the data pointer for source and destination memory.
2. Read the multiplicand from the pointer.
3. Store the MSB of multiplicand in temporary memory location.
4. Multiply the multiplier with the LSB of multiplicand and store the result in register.
5. Increment pointer and multiply the multiplier with the MSB of multiplicand and store the
result in register.
6. Add the intermediate results of higher and lower byte multiplication.
7. Add the carry, if generated to MSB of the sum result
8. Increment the pointer and display the result in destination address location.
9. End the program

Program:
Memory Hex Label – Mnemonics - Operand(s) – Comments
address code(s)
ORG 00H
SJMP 0X30
ORG 0X30
MOV DPTR, #4050H ; load dptr with address 4050
MOVX A, @DPTR ; move the 8bit no to a
MOV B,A ; move to b
PUSH B ; push the contents of b to stack
INC DPTR; increment dptr (1st byte of the 2nd no)
MOVX A,@DPTR; move 1st byte of the 2nd no to a
MUL AB ; multiply a and b
MOV R1, A ;move the 1st byte of the ans1 to r1
MOV R2, B; move the 2nd byte of the ans1 to r2
INC DPTR; increment dptr (2nd byte of the 2nd no)
MOVX A,@DPTR; move 2nd byte of the 2nd no to a
POP B;retrieve the 1st 8bit no from the stack
MUL AB ; multiply a and b
ADD A, R2; add a with 2nd byte of the ans1 to R2
PUSH 0E0H ; push the contents of a to stack
MOV DPTR, #4055H ; ; load dptr with address 4055
MOV A, R1 ; move the 1st byte of the ans1(r1) to a
MOVX @DPTR, A ;move the ans to the dptr address
INC DPTR ; increment dptr
POP 0E0H; retrieve the 2nd byte of the ans to a from the stack
MOVX @DPTR, A; move the 2nd byte of the ans to dptr adsress
MOV A,B ;move the 3rd byte of the ans to a
ADDC A, #00H ; add acc with carry with 00
INC DPTR ; increment dptr
MOVX @DPTR, A; move the 3rd byte of the ans to dptr adsress
HERE: SJMP HERE
END

Result:
BEFORE EXECUTION :

AFTER EXECUTION :

EXPT. NO : 2 d) write a program to divide two 8 bit numbers


Aim: To write and execute an assembly language program to divide two 8-bit numbers.
Objective:
To divide an 8 bit number with other 8-bit number and store it to desired destination
location in memory locations.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
6. Load DPTR with desired memory location.
7. Move the contents of that memory into B register through A and increment memory
location
8. Move the contents of the next memory into A register
9. Perform DIV operation and load Quotient to dptr and Remainder to dptr again by
incrementing it
10. Store the same in desired memory location

Program:
Memor Hex Label – Mnemonics - Operand(s) – Comments
y code(s)
address
org 00h
sjmp 0x030
org 0x030
mov dptr, #4000h
movx a, @dptr ; divisor
mov b, a ; move the content from A to B
inc dptr
movx a, @dptr
div ab ; Q-> a , Rem-> b
inc dptr
movx @dptr, a
inc dptr
mov a, b
movx @dptr, a
here : sjmp here
end
RESULT:

BEFORE EXECUTION : AFTER EXECUTION :

INPUT : INPUT :

0x4000 : 05 0x4000 : 05
0x4001 : 15 0x4001 : 15

OUTPUT : OUTPUT :

0x4002 : XX 0x4002 : 04
0x4003 : XX 0x4003 : 01

EX. NO: 2 e) Write a program to find square of a number

Aim: To write and execute an assembly language program to find the Square of a number

Objective:To find the square of an 8 bit number and store it to desired destination location in
memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1

Algorithm:

1. Initialize the program counter with 0x00,Store the program from 0x30h to avoid interrupt area.
2. Move DPTR content with B through A.
3. After multiply load A (LSB) to Port A.
4. After multiply load B (MSB) to Port B.

Program:
Memor Hex Label – Mnemonics - Operand(s) – Comments
y code(s)
address
org 00h
sjmp 030h
org 030h
mov dptr,#4000h
movx a, @dptr
mov b, a
mul ab
mov 80h, a ;value of accumulator sent to port 0(80h)
mov 90h, b ; value of register b sent to port 1(90h)
here : sjmp here
end

RESULT :

BEFORE EXECUTION : AFTER EXECUTION :


INPUT : INPUT :
0x4000 : 40 0x4000 : 40

OUTPUT : OUTPUT :
Port 0 : XX Port 0 : 0x00
Port 1 : XX Port 1 : 0x10
EXPT. NO : 2 f) Write a program to find cube of a number

Aim: To write and execute an assembly language program to find the Cube of a number

Objective:To find the Cube of an 8 bit number and store it to desired destination location in
memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:

1. Store the eight bit number x in A, B , & any Register-Rx.


2. Multiply A and B registers to obtain the square (say SQH:SQL) of thenumber x.
3. The high part of the square result (SQH) is stored on the stack.
4. Multiply the low part of the square result (SQL) with x (partial cuberesult).
5. Store the low part of the above result at desired location & the high part in Rx.
6. Retrieve the high part of the square result (SQH) stored on the stack &
multiply with x.
7. Add the low part of the above result (SQH*X) with R1 and store in Memory
location .
8. Add the high part (SQH*X) with the resulting carry and store in Memory location
Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address
org 00h
sjmp 030h
org 030h
mov dptr,#4100h ; load dptr with address 4100
movx a, @dptr ; move the no to A
mov b, a ; move to B
mov r3, a ; move to r3
mul ab ; multiply A and B
mov r4, b ; move the higher byte of the square to r4
mov b, r3 ; move the 8bit no to B
mul ab ;multiply lower byte of the square with the 8bit no
mov r1, a ; move the lower byte of the cube to r1
mov r2, b ; move the higher byte of the partial cube to r2
mov a, r4 ; move the higher byte of the square A from r4
mov b, r3 ; move the 8bit no to B
mul ab ; multiply A and B
add a, r2 ; ADD A with of the partial cube r2
push 0e0h ; Push the contents of A to the stack
mov dptr, #4055h ; load dptr with address 4055
mov a, r1 ; move the lower byte of the cube (r1) to A
movx @dptr, a ; move to dptr address from A
inc dptr ;increment dptr
pop 0e0h ;POP the contents of the stack to A
movx @dptr, a ; move to dptr address from A
mov a, #00h ; load A with 00
addc a,b ; add A with B with Carry
inc dptr ; increment dptr
movx @dptr, a ; move to dptr address from A
here : sjmp here

end

RESULT :
BEFORE EXECUTION : AFTER EXECUTION :
INPUT : INPUT :
0x4100 : AA 0x4000 : 40

OUTPUT : OUTPUT :
0x4055 : XX 0x4055 : 68
0x4056 : XX 0x4056 : F7
0x4057 : XX 0x4057 : 4A

EX. NO: 3a) Write an ALP for Decimal down counter


3
Aim: To write and execute an assembly language program to count down the Decimal numbers

Objective:To Initialize down counter for Decimal numbers and show the count using ports .
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Move 00H to A register
2. Call the delay subroutine for , in delay program move FFH to any three registers ,
loop and decrement until 0.
3. Increment A registers Add 99H to A register.
4. Increment A register(decrement for down counter)
Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address

org 00h
sjmp 030h
org 030h
mov a,#00h load A with 00h
back: acall delay ; call the delay subroutine
add a, #99h ; add A with 99h
da a ; adjust the A with decimal equivalent
mov 80h, a ; move the contents of A to the port P0
jnz back ; if P0is not zero, go back
here : sjmp here ;if P0=0 be here
delay: mov r1, #0ffh ; delay routine
loop2 : mov r2, #0ffh
loop1 : mov r3, #0ffh
loop3 : djnz r3, loop3
djnz r2, loop1
djnz r1, loop2
ret
end

RESULT :
EXPT. NO :
3 b)
Write an ALP for Decimal up counter
Aim: To
write and execute an assembly language program to count up the Decimal numbers

Objective:To Initialize up counter for Decimal numbers and show the count using ports.
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Move 00H to A register
2. Call the delay subroutine for , in delay program move FFH to register r1, r2 and r3,
loop and decrement until 0.
3. Increment A register Add 01h to A register .
4. Increment A register (Increment for Up counter)
Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address

org 00h
sjmp 0x30
org 0x30
mov a, #00h ;load A with 00h
back: acall delay ;Call the delay routine
add a, #01h ;ADD Acc with 01h
da a ;adjust the A with decimal equivalent
mov 80h, a ;move the contents of A to the port P0
jnz back ;if P0is not zero, go back
here : sjmp here ;if P0=0 be here
delay: mov r1, #0ffh ;delay routine
loop2 : mov r2, #0ffh
loop1 : mov r3, #0ffh
loop3 : djnz r3, loop3
djnz r2, loop1
djnz r1, loop2
ret ;return from the subroutine
end

RESULT :
EXPT. NO :
3 c)
Write an ALP for Hexadecimal down counter
Aim: To
write and execute an assembly language program to count down the Hexadecimal numbers

Objective:To Initialize down counter for Hexadecimal numbers and show the count using ports.
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Move 00H to A register
2. Call the delay subroutine for , in delay program move FFH to register r1, r2 and r3,
loop and decrement until 0.
3. Increment A register Add 0FFh to A register.
4. Increment A register(decrement for down counter)

Program
Memor Hex Label – Mnemonics - Operand(s) – Comments
y code(s)
address

org 00h
sjmp 030h
org 030h
mov a,#00h ;load A with 00
back: acall delay ;call delay routine
add a, #0FFh ;ADD A with FFh
mov 80h, a ;move the contents of A to the port P0
jnz back ;if P0is not zero, go back
here : sjmp here ;if P0=0 be here
delay : mov r1, #0FFh ;delay subroutine
loop2 : mov r2, #0FFh
loop1 : mov r3, #0FFh
loop3 : djnz r3, loop3
djnz r2, loop1
djnz r1, loop2
ret ;return from the sub routine
end

RESULT :

EXPT. NO :
3 d)
Write an ALP for Hexadecimal up counter

Aim: To write and execute an assembly language program to count up the Hexadecimal numbers

Objective:To Initialize up counter for Hexadecimal numbers and show the count using ports.
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Move 00H to A register
2. Call the delay subroutine for , in delay program move FFH to register r1, r2 and r3,
loop and decrement until 0.
3. Increment A register Add 01H to A register.
4. Increment A register (Increment for Up counter)

Program :

Memor Hex Label – Mnemonics - Operand(s) – Comments


y
address code(s)

org 00h
sjmp 030h
org 030h
mov a,#00h ;load A with 00
back: acall delay ;call delay routine
add a, #01h ;ADD A with 01h
mov 80h, a ;move the contents of A to the port P0
jnz back ;if P0is not zero, go back
here : sjmp here ;if P0=0 be here
delay : mov r1, #0FFh ;delay subroutine
loop2 : mov r2, #0FFh
loop1 : mov r3, #0FFh
loop3 : djnz r3, loop3
djnz r2, loop1
djnz r1, loop2
ret ;return from the sub routine
end

RESULT :

Write an ALP to realize the following Boolean


EXPT. NO :
4
expression _ _ _
Y = ABC + ABC + ABC
Aim: To write and execute an assembly language program to find the value of Y for the given
Boolean expression

Objective: To find the output value of Y for the given expression and store it to desired
destination location in bit level memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm:
1. Store the condition x in R1
2. Store the result present in A and B registers to the appropriate memory
Locations
3. Compute the operations using ANL ,ORL operators using c(carry bit register )
4. Increment the memory and store the result

Program:

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address

org 00h
ljmp 8000h
org 8000h
setb 00h ; set the 00 bit as 1
clr 01h ; clear the 01 bit as 0
setb 02h ; set the 02 bit as 1
mov c, 01h ;1st bit i.e. B is taken as c; c=0
anl c, 02h ; 2nd bit i.e. c is given 0 by anding
anl c, /00h ; 00th bit is anded with c
mov 03h, c ; c is moved to 03h
mov c, 00h ; c gets values as 1
anl c, /01h ; c gets values as 11
anl c, 02h ;c gets values as 1
mov 04h, c ;move 1 to4th location
mov c, 00h ; first for ab/c take c as i.e. c=1
anl c, 01h ; c is given 0
anl c, /02h ;0 anding with c bar i.e. c=0
orl c, 04h ;0 is given to 04h
orl c, 03h
mov 08h, c
here: sjmp here
end

RESULT :
BEFORE EXECUTION : AFTER EXECUTION :

D: 0x0020 : XX D: 0x0020 : 15
D: 0x0021 : XX D: 0x0021 : 01
EX. NO: 5 a) Write an ALP to convert BCD to ASCII

Aim: To write and execute an assembly language program to convert the given BCD number to
ASCII number

Objective: To know the conversion process involved in BCD number to ASCII number
And store it to desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm
1. Move the BCD data to be converted to accumulator.
2. Get the lower nibble(BCD digit) & ADD (or ORL) with 30h
3. Store the converted ASCII value
4. Get the higher nibble(tens BCD digit) & ADD (or ORL) with 30h
Program :

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address

org 00h
sjmp 030h
org 030h
mov dptr,#8100h ;load the data pointer
movx a, @dptr ;move the content in data pointer to accumulator
mov r2, a ;move the content in accumulator to r2 register
anl a, #0fh ;do logical AND operation for accumulator and 0fh
orl a, #30h ;do logical OR operation for accumulator with 30h
mov r6, a ;move the content in accumulator to r6 register
mov a, r2 ;then move the content from r2 to accumulator
anl a, #0f0h ;do logical AND operation for accumulator and 0f0h
swap a ;swap the contents in accumulator
orl a, #30h ;do logical OR operation for accumulator with 30h
inc dptr ;increment the data pointer
movx@dptr, a ;move the content in accumulator to data pointer
address
inc dptr ;increment data pointer
mov a, r6 ;move the content from r6 register to accumulator
movx@dptr, a ;move the content in accumulator to data pointer
address
here : sjmp here
end
RESULT :

BEFORE EXECUTION : AFTER EXECUTION :

EX. NO: 5 b) Write an ALP to convert ASCII to BCD


5 b)
Aim: To write and execute an assembly language program to convert the given ASCII number to
BCD number

Objective: To know the conversion process involved in ASCII number to BCD number
And store it to desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm
1. Move the ASCII data to be converted to Accumulator
2. do logical AND operation for accumulator with 0Fh
3. Swap the contents of the accumulator and move the data to B register
4. Take another ASCII data and do logical AND operation for accumulator and 0fh
5. do logical OR operation for accumulator and b
6. move the content in accumulator to 60h address
Program :

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s
address )

org 00h
sjmp 030h
org 030h
mov a, #'4' ;move 4 to accumulator
anl a, #0Fh ; do logical AND operation for accumulator and 0fh
swap a ;swap the content an accumulator
mov b, a ;move the data from accumulator to b register
mov a, #'7' ;move 7 to accumulator
anl a, #0Fh ; do logical AND operation for accumulator and 0fh
orl a, b ;do logical OR operation for accumulator and b
mov 60h, a ;move the content in accumulator to 60h address
here: sjmp here
end

RESULT :

BEFORE EXECUTION : AFTER EXECUTION :

EX. NO: 5 c) Write an ALP to convert Decimal to Hexadecimal

Aim: To write and execute an assembly language program to convert the given decimal number
to hexadecimal number

Objective: To know the conversion process involved in decimal number to hexadecimal number,
and store it to desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm
1. Move the decimal data to be converted from external memory 40h to accumulator
2. AND A reg with 0f0h and obtain the upper MSB of the decimal digit and swapth
e LSB and MSB of accumulator to bring the same to units place
3. Move 0Ah to B register and multiply with A reg to convert to hex value, storethe
converted tens value in r1
4. Get the LSB of the decimal number and add to the converted tens value
5. Point to the next memory location and store the result (hexadecimal).
Program :

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s
address )

org 00h
sjmp 0x30
org 0x30
mov ;initiate the data pointer with 8100h address location
dptr,#8100h
movx a, @dptr ;move the content in data pointer to accumulator
mov b, a ;move the data from a to b
anl a, # 0x0F ;do logical AND operation for accumulator with 0Fh
mov r1, a ;move the content from accumulator to R1 register
mov a, b ;move the content in b to accumulator
anl a, # 0xF0 ;do logical AND operation for accumulator with F0h
swap a
mov b, #0Ah ;move 0Ah to b register
mul ab ;multiply a and b registers
add a, r1 ;add the content in accumulator with R1 register
inc dptr ;increment data pointer
movx @dptr, a ;move the data from accumulator to data pointer
here : sjmp here
end

RESULT :
BEFORE EXECUTION : AFTER EXECUTION :

EX. NO: 5 d) Write an ALP to convert Hexadecimal to Decimal

Aim: To write and execute an assembly language program to convert the given hexadecimal
number to decimal number

Objective: To know the conversion process involved in hexadecimal number to decimal number,
and store it to desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm

1. Move the hex data to be converted to accumulator.


2. Move 10 to B register and divide with A reg to convert to ASCII value
3. Store the converted LSB value in r7
4. Repeat the step 2 to obtain the converted MSB value
5. Store the same in r6

Program :
Memor Hex Label – Mnemonics - Operand(s) – Comments
y code(s)
address

org 00h
sjmp 0x30
org 0x30
mov dptr,#8100h ;initiate the data pointer with 8100h address
location
movx a, @dptr ;move the content in data pointer to accumulator
mov dpl, #50h ;move 50h to lower byte of the data pointer
mov b, #0ah ;move 0ah to b register
div ab ;divide a and b registers
mov r1, a ;move the content in a to r1 register
mov r2, b ;move the content in b to r2 register
mov a, r2 ;move the content in r2 to accumulator
movx @dptr, a ;move the data from accumulator to data pointer
mov r3, a ;move data from accumulator to r3 register
inc dptr ;increment the data pointer
mov b, #0ah ;move 0ah to b register
mov a, r1 ;copy the content of r0 to accumulator
div ab ;divide a and b
mov r1, a ;copy the contents of A into r1
mov r2, b ;copy the contents of b into r2
mov a, r2 contents of r2 into a
movx @dptr, a
inc dptr ;increment the data pointer
mov a, r1 ;copy the content of r0 to accumulator
movx @dptr, a
mov a, r2 ;copy the contents of r2 into a
swap a ;swap the content in a
orl a, r3 ; do the OR logic for and r3 register
mov 60h, a ;save content of A in RAM location 60h
mov 61h, r1 ;save content in r1 register in RAM location 61h
here : sjmp here
end
RESULT :

BEFORE EXECUTION : AFTER EXECUTION :


Write an ALP to convert ASCII to Hexadecimal
EX. NO: 5 e)
program to find cube of a number

Aim: To write and execute an assembly language program to convert the given ASCII number to
Hex decimal number

Objective: To know the conversion process involved ASCII number to Hex decimal number
, and store it to desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm
1. Move the ASCII character to be converted to accumulator.
2. If character is greater than 41h,(for A-F), then subtract 07h & 30h
3. Else (i.e., for 0-9) subtract only 30h
4. Store the converted hexadecimal number

Program :
Memor Hex Label – Mnemonics - Operand(s) – Comments
y code(s)
address

org 00h
sjmp 0x30
org 0x30
mov r1, #50h ;load 50H into R1
mov a, @r1 ;get a byte from R1 register
clr c ;clear carry
subb a, #0Ah ;subtract Accumulator ,0Ah
mov a, @r1 ; get a byte from R1 register
jc skip ;jump with carry to skip location
clr c ;clear the carry
subb a, #07h ;subtract Accumulator ,07h
skip: clr c
subb a, #30h ;subtract Accumulator ,30h
inc r1 ;increment r1 register
mov @r1, a ;get a byte from accumulator to r1 register
here: sjmp here
end
Result :

BEFORE EXECUTION : AFTER EXECUTION :

EX. NO: 6 Write an ALP to generate a software delay

Aim: To write and execute an assembly language program to convert the given Hexadecimal to
ASCII
Objective: To know the conversion process involved Hexadecimal to ASCII , and store it to
desired destination location in memory locations
.
Apparatus Required:
No Name Quantity
1 8051 microcontroller Keil Simulator kit 1
Algorithm
1. Move the hexadecimal data to be converted to accumulator.
2. Get the lower nibble & call ASCII routine
3. Store the converted ASCII value
4. Get the higher nibble & call ASCII routine
5. Store the converted ASCII value
6. If digit greater than 09,(for A-F) add 07h & 30h
7. Else (i.e., for 0-9) add only 30h
8. Return

Memor Hex Label – Mnemonics - Operand(s) – Comments


y code(s)
address

org 00h
sjmp 0x30
org 0x30
mov r1, #50h ; move r1 as 50 h
mov a, @r1 ; move the content of r1 to a
mov r2, a ; move the content of A to r2 register
anl a, #0Fh ; and logic A with 0Fh
acall ASCII ; call the ASCII subroutine
inc r1 ; increment r1 register
mov @r1, a
mov a, r2
swap a
anl a, #0Fh ; and logic A with 0Fh
acall ASCII ; call the ASCII subroutine
inc r1
mov @r1, a
here : sjmp here
ASCII : mov r4, a ;subroutine of ASCII
clr c
subb a, #0Ah
mov a, r4
jc skip
add a, #07
skip : add a, #30
ret
RESULT :

BEFORE EXECUTION : AFTER EXECUTION :


MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Program -07 SERIAL COMMUNICATION

Aim:
To transfer the data serially between two 8051 microcontroller kit and IBM PC
using serial port (RS232).
Apparatus Required:

No Name Quantity

1 8051 microcontroller kit & Simulator 1


2 RS232C Interfacing kit and wire 1

Theory:

Programming the 8051 to transfer data serially

1. The TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2
(8-bit auto-reload) to set the baud rate.
2. The TH1 is loaded with -3H to set the baud rate of 9600 for serial data transfer
3. The SCON register is loaded with the value 50 H, indicating serial mode 1, where an 8-
bit data is framed with start and stop bits.
4. TRI is set to l to start timer l.
5. TI is cleared by the “CLR TI” instruction.
6. The character byte to be transferred serially is written into the SBUF register.
7. The TI flag bit is monitored with the use of the instruction “JNB TI, $” to see if the
character has been transferred completely.
8. To transfer the next character, go to Step 5.

Programming the 8051 to receive date serially

1. The TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2
(8-bit auto-reload) to set the baud rate.
2. The TH1 is loaded with -3H to set the baud rate of 9600 for serial data transfer
3. The SCON register is loaded with the value 50 H, indicating serial mode 1, where an 8-
bit data is framed with start and stop bits.

DEPT. OF E&CE 49
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

4. TRI is set to l to start timer l.


5. RI is cleared with the “CLR RI” Instruction.
6. The RI flag bit is monitored with the use of the Instruction” JNC RI, $” to see if an
entire character has been received yet.
7. When RI is raised, SBUF has the byte. Its contents are moved into a safe place.
8. To receive the next character, go to Step 5.

Procedure:

1. Connect the 8051 microcontroller kit and IBM PC using RS232 kit.
2. Enter and run the program in 8051 microcontroller kit to transmit GTU serially.
3. Enter and run the program in 8051 microcontroller kit to receive data from PC
terminal program window.
4. Enter and run the program in 8051 microcontroller kit to receive data from PC
terminal program window and sent it to P2 port of 8051 where relay is connected.

Program: Transmitter Program


Memory address Hex code(s) Label – Mnemonics - Operend(s) - Comments
ORG 0000H
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#-3
SETB TR1

HOME:
MOV A,#'G'
ACALL SEND
MOV A,#'T'
ACALL SEND
MOV A,#'U'
ACALL SEND
AJMP HOME

SEND:
MOV SBUF,A
JNB TI,$
CLR TI
RET

END

DEPT. OF E&CE 50
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Program: Receiver Program


Memory address Hex code(s) Label – Mnemonics - Operend(s) - Comments
ORG 0000H
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#-3
SETB TR1
HOME:
JNB RI,HOME
CLR RI
MOV P2,SBUF
AJMP HOME
END

Program: Receiver Program-relay interfaced


Memory address Hex code(s) Label – Mnemonics - Operend(s) - Comments
ORG 0000H
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#-3
SETB TR1
HOME:
JNB RI,HOME
CLR RI
CPL P2.2
AJMP HOME
END

Result:
Thus the assembly language was written to transfer the data serially between micro
controller kit and IBM PC using RS232 cable and it was executed.

DEPT. OF E&CE 51
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

MSP 430 PROGRAMS


EX. NO: 1a. Data Transfer - Block move
Aim: To write and execute an MSP 430 assembly language program to transfer 16bit data from
location from 20h to 40h(without overlap)
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize the source and destination memory pointers.
3. Initialize counter.
4. Move a word of data from source to destination.
5. Increment source and destination pointers twice.
6. Decrement counter and check for 0, if not, go to step 4, otherwise endless loop to
terminate the program.
Program:
Memor
Hex Label - Mnemonics - Operand(s) – Comments
y
code(s)
address
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL; stop watch dog timer
MOV #0X20,R4;initialize source pointer
MOV #0X40,R5;initialize destination pointer
MOV.B #0X10,R6;initialize counter
NEXT:MOV.W0(R4), 0(R5);move byte from source to destination
INCD R4 ;Increment source pointer twice
INCD R5 ;Increment destination pointer twice
DEC.B R6;decrement counter
JNZ NEXT;repeat till counter is zero
JMP $;jump to current location
END

RESULT:

BEFORE EXECUTION AFTER EXECUTION


SOURCE DESTINATION SOURCE DESTINATION
Memory Data Memory Data Memory Data Memory Data
address address address address
0x20 1111h 0x40 xx 0x20 1111h 0x40 1111h
0x22 2222h 0x42 xx 0x22 2222h 0x42 2222h
0x24 3333h 0x44 xx 0x24 3333h 0x44 3333h

DEPT. OF E&CE 52
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

0x26 4444h 0x46 xx 0x26 4444h 0x46 4444h


0x28 5555h 0x48 xx 0x28 5555h 0x48 5555h

EX. NO: 1b. Data Transfer - Block move


Aim: To write and execute an MSP 430 assembly language program to transfer 8 bit data from
location20h to 40h (with overlap).
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize the source and destination memory pointers.
3. Initialize counter.
4. Move a word of data from source to destination.
5. Decrement source and destination pointers.
6. Decrement counter and check for 0, if not, go to step 4, otherwise endless loop to
terminate the program.
Program:
Memor
Hex Label - Mnemonics - Operand(s) – Comments
y
code(s)
address
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV #0X29,R4 ;initialize source pointer
MOV #0X2E,R5 ;initialize destination pointer
MOV.B #0X10,R6 ;initialize counter
NEXT: MOV.B 0(R4),0(R5);move byte from source to destination
DEC R4 ;decrement source pointer twice
DEC R5 ;decrement destination pointer twice
DEC.B R6 ;decrement counter
JNZ NEXT ;repeat till counter is zero
JMP $;jump to current location
END

DEPT. OF E&CE 53
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

RESULT:

BEFORE EXECUTION AFTER EXECUTION


SOURCE DESTINATION SOURCE DESTINATION
Memory Data Memory Data Memory Data Memory Data
address address address address
0x20 11h 0x25 xx 0x20 11h 0x25 11h
0x21 22h 0x26 xx 0x21 22h 0x26 22h
0x22 33h 0x27 xx 0x22 33h 0x27 33h
0x23 44h 0x28 xx 0x23 44h 0x28 44h
0x24 55h 0x29 xx 0x24 55h 0x29 55h
0x25 66h 0x2A xx 0x25 66h 0x2A 66h
0x26 77h 0x2B xx 0x26 77h 0x2B 77h
0x27 88h 0x2C xx 0x27 88h 0x2C 88h
0x28 99h 0x2D xx 0x28 99h 0x2D 99h
0x29 0aah 0x2E xx 0x29 0aah 0x2E 0aah

DEPT. OF E&CE 54
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

EX. NO: 1c. Data Transfer - Exchange


Aim: To write and execute an MSP 430 assembly language program to Exchange n=5bytes of
data starting at location 35h and 41h.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize the array1 and array2 memory pointers.
3. Initialize counter.
4. Move data byte from array1 to temporary Register.
5. Move data byte from array2 to array1.
6. Move data byte from temporary Register to array1.
7. Incrementarray1 and array2 pointers.
8. Decrement counter and check for 0, if not, go to step 4, otherwise endless loop to
terminate the program.
Program:
Memor
Hex Label - Mnemonics - Operand(s) – Comments
y
code(s)
address
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV #0X35,R4;initialize source pointer
MOV #0X41,R5;initialize destination pointer
MOV #0X05,R6;initialize counter
NEXT:MOV.B @R4, R7 ; move byte from array1 to temp. reg.
MOV.B @R5, 0(R4) ; move byte from array2 to array1.
MOV.B R7, 0(R5) ; move byte from temp.reg. to array1
INC R4 ; Incrementarray1 pointer.
INC R5 ; Incrementarray2 pointer.
DEC.B R6;decrement counter
JNZ NEXT;repeat till counter is zero
JMP $;jump to current location
END

DEPT. OF E&CE 55
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

RESULT:

BEFORE EXECUTION AFTER EXECUTION


SOURCE DESTINATION SOURCE DESTINATION
Memory Memory Memory Memory
Data Data Data Data
address address address address
0x35 11h 0x41 0aah 0x35 0aah 0x41 11h
0x36 22h 0x42 0bbh 0x36 0bbh 0x42 22h
0x37 33h 0x43 0cch 0x37 0cch 0x43 33h
0x38 44h 0x44 0ddh 0x38 0ddh 0x44 44h
0x39 55h 0x45 0eeh 0x39 0eeh 0x45 55h

DEPT. OF E&CE 56
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

EX. NO: 1d. Sorting- Ascending


Aim: To write and execute an MSP 430 assembly language program to sort an array n=16 bytes
of data in Ascending order
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1.Stop the watch dog timer.
2.Store the elements of the array from the address 20h.
3.Initialize a pass counter with array size – 1 count (for number of passes).
4.Load compare counter with pass counter contents and initialize a register (say R4) to point to the
start address of the array (20h).
5.Compare the next element with the current element, if smaller skip the exchange(go to step 7)
6.Exchange the two numbers in the array.
7.Decrement the exchange counter and repeat through step 5 until the counter becomes zero.
8. Decrement the pass counter and repeat through step 4 until the counter becomes 0.
9. Endless loop to terminate the program.
Program:
Memory Hex Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV.B#05, R5; initialize pass counter to n-1=5.
OUTER:MOV #0X20,R4; starting address of array
MOV.B R5,R6; load exchange counter or inner pass
INNER: MOV.B @R4+,R7;current no. into R7 and array pointer update
;to next number

DEPT. OF E&CE 57
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

CMP.B @R4,R7; compare the consecutive numbers


JNC SKIP; if current number less than next number skip
exchange
;code below exchanges the two numbers in the array
MOV.B @R4,R8
MOV.B R7,0(R4)
DEC R4
MOV.B R8,0(R4)
INC R4
SKIP: DEC.B R6;decrement the exchange counter in the inner pass
JNZ INNER
DEC.B R5;decrement number of passes
JNZ OUTER
JMP $;jump to current location
END

RESULT:

BEFORE EXECUTION AFTER EXECUTION


SOURCE DESTINATION
Memory Memory
Data Data
address address
0x20 23h 0x20 15h
0x21 44h 0x21 19h
0x22 19h 0x22 23h
0x23 78h 0x23 44h
0x24 66h 0x24 66h
0x25 15h 0x25 78h

DEPT. OF E&CE 58
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

EX. NO: 2a. CODE CONVERSION – ASCII to HEXADECIMAL


Aim: To write and execute an MSP 430 assembly language program toconvert ASCII code to
HEXADECIMAL code.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Load the ASCII character to be converted to a register (R6) from memory location.
3. If character is greater than 41h,(i.e., for A to F), then subtract 07h and 30h.
4. Else, (i.e., for 0 to 9) subtract only 30h
5. Store the converted hexadecimal number.
6. Endless loop to terminate the program.
Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV #0X50,R4 ; store ASCII number
MOV.B @R4+,R6 ; get data on to R6
SUB.B #0X30,R6 ;subtract 30h from R6
CMP #0X0A,R6 ; check if contents of R6 are greater than 0Ah
JNC SKIP ;jump to skip if R6 contents < 0A
SUB.B #0X07,R6 ; if R6 >0A,subtract 07 h further
SKIP: MOV.B R6,0(R4) ; store the converted data in memory location
pointed by R4.
JMP $;jump to current location
END

DEPT. OF E&CE 59
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

RESULT:

BEFORE EXECUTION AFTER EXECUTION


SOURCE DESTINATION
Memory Memory
Data Data
address address
0x50 45h 0x50 45h
0x51 xxh 0x51 0eh

EX. NO: 3a. COUNTERS – Hexadecimal UP Counter


Aim: To write and execute an MSP 430 assembly language program to implement 8 bit
HEXADECIMAL counter on port 2.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize port P2 as output port by writing 0xFF into P2DIR.
3. Move 00h to R4 register.
4. Implement a small delay.
5. Send R4 contents to P2OUT register.
6. Increment R4 register.
7. Repeat from step 4 continuously.
Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV.B #0XFF,&P2DIR ; set up port 2 as out put port.
MOV.B #0X00,R4 ; initialize counter as 00h for up count
NEXT: INC.B R4 ;increment next count
MOV.W #0X02,R5 ; set up for small delay.
DELAY: DEC.W R5
JNZ DELAY
MOV.B R4,&P2OUT ;send the count on port2
JMP NEXT; loop

DEPT. OF E&CE 60
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

END

RESULT:

P2DIR=0XFF

Observe at

P2OUT=0X00, 0X01, 0X02,……………….0XFF

EX. NO: 3b. COUNTERS – Hexadecimal DOWN Counter


Aim: To write and execute an MSP 430 assembly language program to implement 8 bit
HEXADECIMAL counter on port 2.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize port P2 as output port by writing 0xFF into P2DIR.
3. Move 00h to R4 register.
4. Implement a small delay.
5. Send R4 contents to P2OUT register.
6. Decrement R4 register.
7. Repeat from step 4 continuously.
Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV.B #0XFF,&P2DIR; set up port 2 as output port
MOV.B #0X00,R4; initialize counter as 00h for up count
NEXT: DEC.B R4;decrement next count
MOV.W #0X02, R5; set up for small delay.
DELAY: DEC.W R5
JNZ DELAY
MOV.B R4,&P2OUT;send the count on port2

DEPT. OF E&CE 61
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

JMP NEXT; loop


END

RESULT:

P2DIR=0XFF

Observe at

P2OUT=0X0FF, 0X0FE, 0X0FD,……………….0X00.

EX. NO: 3c. COUNTERS – BCD Up Counter


Aim: To write and execute an MSP 430 assembly language program to implement 8 bit
BCDcounter on port 2.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize port P2 as output port by writing 0xFF into P2DIR.
3. Move 00h to R4 register.
4. Adjust for BCD.
5. Implement a small delay.
6. Send R4 contents to P2OUT register.
7. Increment R4 register.
8. Repeat from step 4 continuously.
Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV.B #0XFF,&P2DIR ; set up port 2 as output port
MOV.B #0X00,R4 ; initialize counter as 00h for up count
NEXT: CLRC ;clear carry

DEPT. OF E&CE 62
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

DADD.B #0x01,R4 ;Adjust for decimal value


MOV.W #0X02, R5 ;set up for small delay.
DELAY: DEC.W R5
JNZ DELAY
MOV.B R4,&P2OUT ;send the count on port2
JMP NEXT ; loop
END

RESULT:
P2DIR=0XFF
Observe at
P2OUT=00, 01, 02,………………. 99.

EX. NO: 3d. COUNTERS – BCD Down Counter


Aim: To write and execute an MSP 430 assembly language program to implement 8 bit
BCDcounter on port 2.
Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize port P2 as output port by writing 0xFF into P2DIR.
3. Move 00h to R4 register.
4. Adjust for BCD.
5. Implement a small delay.
6. Send R4 contents to P2OUT register.
7. decrement R4 register.
8. Repeat from step 4 continuously.
Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer
MOV.B #0XFF,&P2DIR ; set up port 2 as output port
MOV.B #0X00,R4 ; initialize counter as 00h for up count
NEXT: CLRC ;clear carry
DADD.B #0x99,R4 ;Adjust for decimal value

DEPT. OF E&CE 63
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

MOV.W #0X02, R5 ;set up for small delay.


DELAY: DEC.W R5
JNZ DELAY
MOV.B R4,&P2OUT ;send the count on port2
JMP NEXT ; loop
END

RESULT:
P2DIR=0XFF
Observe at
P2OUT=99, 98, 97,………………. 00.

EX. NO: 4. Arithmetic and Logical Operations


Aim: To write and execute an MSP 430 assembly language program to illustrate arithmetic
operations (Addition binary, decimal, subtraction) and logical operations (AND, OR, EXOR)

Apparatus Required:
No Name Quantity
1 IAR Embedded Workbench KickStart for MSP430 1
Algorithm:
1. Stop the watch dog timer.
2. Initialize source & destination locations
3. Add the operands and store the result.
4. Perform RCD addition and store the result in nest location.
5. Perform subtractionand store the result in nest location
6. Perform logical AND operationand store the result in nest location
7. Perform logical OR operationand store the result in nest location
8. Perform logical XOR operationand store the result in nest location
9. Endless loop

Program:
Memory Hex
Label - Mnemonics - Operand(s) – Comments
address code(s)
MAIN: NOP ;main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watch dog timer

DEPT. OF E&CE 64
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

MOV #0X20,R4
MOV.B @R4+,R5
MOV.B @R4+,R6
MOV.B R6,0(R4)
ADD.B R5,0(R4)
INC R4
MOV.B R6,0(R4)
DADD.B R5,0(R4)
INC R4
MOV.B R6,0(R4)
SUB.B R5,0(R4)
INC R4
MOV.B R6,0(R4)
AND.B R5,0(R4)
INC R4
MOV.B R6,0(R4)
BIS.B R5,0(R4)
INC R4
MOV.B R6,0(R4)
XOR.B R5,0(R4)
INC R4
JMP $;endless loop
END

OUT PUT

Before Execution After Execution

0x20 =32 0x20=32


0x21=59 0x21=59
0x22=xx 0x22=8b
0x23=xx 0x23=91
0x24=xx 0x24=27
0x25=xx 0x25=10
0x26=xx 0x26=7b
0x27=xx 0x27=6b

DEPT. OF E&CE 65
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

INTERFACING

Program -8 INTERFACING OF SEVEN SEGMENT LED DISPLAY


Aim:
To interface two seven segment LED display in 89C51 microcontroller
and to verify data on LED display.

Objective:
Interface one common cathode type seven segment display with port 1.then write a
program that displays pattern 'SVCE' continuously.

Apparatus Required:

No Name Quantity
1 8051 microcontroller kit & Simulator 1
2 SEVEN SEGMENT display interface 1

Procedure:

1. Connect the display interface board as per required.


2. Enter the program.
3. The output would be displayed on two seven segment LED.
Program:

DEPT. OF E&CE 66
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

# include <stdio.h>
# include <reg51.h>
//sfr P0=0x80;
//sfr P1=0x90;
void delay (int g);
int port [20] = {0xff, 0xff, 0xff, 0xff, 0x06, 0xC6, 0xC1, 0x92},i;
int i;
void main ()
{
char d,b,j,k,s;
while (1)
{
i=0; P2=0;
for (d=0; d<2; d++)
{
for (b=0; b<4; b++)
{
k = port [i++];
for (j=0; j<8; j++)
{

s=k;
s=s&0x80;
if (s==0x00)
P1=0x00;
else
P1=0x01;
P2=0x01;
P2=0x00;
s=k;
s=s<<1;
k=s;
}
}
delay (10000);
delay (10000);
}
}
}
void delay (int g)
{ int h;
for (h=0; h<=g; h++)
{ ;}
}

DEPT. OF E&CE 67
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

----------------------ooooo--------------------
Write a C program to interface 8051 chip to develop SINE, square, triangle, ramp using
DAC interface

Sine wave Generation

#include<reg51.h>

sfr p0=0x80;

sfr p1=0x90;

void main()

unsigned char
i,m[]={0x7F,0x9F,0xAA,0xBE,0XD0,0XE0,0XEC,0XF6,0XEF,0XFC,0XF6,0XE5,0XE0,0XB0
,0XBE,0XAA,0X95,0X7F,0X68,0X83,0X3F,0X3D,0X2D,0X3F,0X53,0X68,0X7F};

while(1)

for(i=0;i<36;i++)

p0=m[i];

p1=m[i];

Triangle wave Generation

#include<reg51.h>

sfr p0=0x80;

sfr p1=0x90;

DEPT. OF E&CE 68
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

void main()

unsigned char i,j;

while(1)

for(i=0;i<0xff;i++)

p0=i;

p1=i;

for(j=0xff;j>0;j--)

p0=j;

p1=j;

Square Wave Generation

#include<reg51.h>

sfr p0=0x80;

sfr p1=0x90;

void delay(unsigned char);

void main()

DEPT. OF E&CE 69
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

unsigned char k;

while(1)

p0=0xff;

p1=0xff;

delay(50);

p0=0x00;

p1=0x00;

delay(50);

void delay(unsigned char i)

unsigned char j;

for( ; i>0; i--)

for(j=0;j<111;j++);

RAMP wave Generation

#include <reg51.h>

sfrP0=0x80;

DEPT. OF E&CE 70
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

sfrP1=0x90;

void main ()

unsigned char i;

while (1)

for (i=0; i<0xff; i++)

P0=i;

P1=i;

ELEVATER Interface

#include<reg51.h>

void delay(unsigned int);

void main()

unsigned char flr [9]={0XFF,0X00,0X03,0XFF,0X06,0XFF,0XFF,0XFF,0X09};

unsigned char fclr[9]={0XFF,0XE0,0XD3,0XFF,0XB6,0XFF,0XFF,0XFF,0X79};

unsigned char regflr,curflr=0x01,i,j;

P0=0x00;

P0=0xF0;

DEPT. OF E&CE 71
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

while(1)

P1=0x0F;

regflr=P1|0xf0;

while(regflr==0x0ff)

regflr=P1|0xf0;

regflr=~regflr;

if(curflr==regflr)

P0=fclr[curflr];

continue;

else if(curflr>regflr)

i=flr[curflr]-flr[regflr];

j=flr[curflr];

for(; i>0; i--)

P0=0xf0|j; j--;

delay(2500);

else

DEPT. OF E&CE 72
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

i=flr[regflr]-flr[curflr];

j=flr[curflr];

for(; i>0;i--)

P0=0xf0|j;

j++;

delay(2500);

curflr=regflr;

P0=fclr[curflr];

void delay(unsigned int x)

for(; x>0; x--);

-----------ooooooo----------

HEX KEYPAD Interface

#include<reg51.h>

#include<stdio.h>

sbit en =P3^5;

sbit rs =P3^7;

sbit rw =P3^6;

DEPT. OF E&CE 73
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

void delay (void);

unsigned char cmd [5] = {0x38,0x06,0x01,0x0f,0x80};

unsigned char key [16] = {"048C159D26AE37BF"};

unsigned char data_byte[14]={" key pressed= "},x,l;

void data_write(unsigned char);

void lcd_setup(void);

void main ()

unsigned char b,c,d,e,f;

while(1)

c=0x0e;

x=0;

for(e=0;e<4;e++)

P0=c;

d=0x0e;

for(b=0;b<4;b++)

f=P1;

f=f&0x0f;

if(f==d)

lcd_setup();

DEPT. OF E&CE 74
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

b=4;

e=4;

else

x=x+1;

d=d<<1;

d=d|0x01;

d=d&0x0f;

c=c<<1;

c=c|0x01;

c=c&0x0f;

void lcd_setup(void)

unsigned char l,i;

rs=0;

rw=0;

en=0;

for(l=0;l<5;l++)

DEPT. OF E&CE 75
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

i=cmd[l];

data_write(i);

delay();

rs=1;

for(l=1;l<14;l++)

i=data_byte[l];

data_write(i);

delay();

i=key[x];

data_write(i);

delay();

void data_write(unsigned char db)

P2=db;

en=1;

en=0;

void delay(void)

DEPT. OF E&CE 76
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

unsigned int j;

for(j=0;j<111;j++); }

STEPPER MOTOR

#include<reg51.h>

bit dir=0;

void delay(unsigned int x)

for(; x>0;x--);

void changedir(void) interrupt 0

dir=~dir;

delay(32000);

void main()

unsigned char val,i;

EA=0x1;

EX0=0x1;

P0=0x00;

while(1)

if(dir)

DEPT. OF E&CE 77
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

val=0x88;

for(i=0;i<4;i++)

P0=val;

val=val>>1;

delay(575);

else

val=0x11;

for(i=0;i<4;i++)

P0=val;

val=val<<1;

delay(575);

DEPT. OF E&CE 78
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Q1. What is difference between microcontroller and microproccessor?

Ans:

Microproccessor Microcontroller
Memory, ports, timers, interrupts and controllers Memory, ports, interrupts and controllers are
are external to the chip. internal to the chip.
Based on Von-Neumann architecture. Based on Harvard architecture.
Have many instructions for data transfer b/w the Have limited instructions for data transfer b/w
microprocessor and external memory. the microcontroller and external memory.
The instruction sets contains limited number of
It performs large number of bit level operation.
instructions for bit operation.

Q2. What are flags and Program status word (PSW)?

Ans: Flags are 1-bit registers provided to store the result of certain program instructions.
PSW: The PSW contains the math flags, user program flag F0, and the register select bits that
identify which of the four general purpose register banks is currently in use by the program.
CY AC F0 RS1 RS0 OV -- P

Q3. What is stack?

Ans: The stack refers to an area of internal RAM that is used in conjugation with certain opcodes
to store and retrieve data quickly.

Q4. What is counter and timer?

Ans; Counter is the process of counting the pulses generated by any system.

Q5. Explain the TCON special function register?

Ans: TCON special function register


TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

DEPT. OF E&CE 79
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Explain the above table based on your microcontroller knowledge of flags1 and 0’s and others.

Q6. Explain TMOD special function register.

Ans: TMOD special function register


Gate C/Tbar M1 M0 Gate C/Tbar M1 M0

Q7. Draw the special function register for SCON and PCON.

Ans: SCON
SM0 SM1 SM2 REN TB8 RB8 TI RI
PCON:
SM0D -- -- -- GF1 GF0 PD IDL

Q8. What do you mean by timer flag interrupt?

Ans: When a timer/counter overflows, the corresponding timer flag, TF0 or TF1, is set to 1. The
flag is cleared to 0 when the resulting interrupt generates a program call to the appropriate timer
subroutine in memory.

Q9. Draw and explain the Interrupt enable (IE) and Interrupt Priority (IP) special function
register.

Ans: IE special function register:


EA -- ET2 ES ET1 EX1 ET0 EX0
IP special function registers:
-- -- PT2 PS PT1 PX1 PT0 PX0
- not implemented
PT2: Reserved for future use.
PS: Priority of serial port interrupt.
PT1: Priority of timer of 1 overflow interrupt. Set cleared by program.
PX1: Priority of external int 1.
PT0: Priority of timer 0 overflow interrupt.

DEPT. OF E&CE 80
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

PX0: Priority of external int 0.

Q10. What are different addressing modes in microcontroller? Give one example for each.

Ans: 1. Immediate addressing mode. (ADD A, #77)


2. Register addressing mode. (ADD A, R0)
3. Direct addressing mode. (MOV A, 088H)
4. Indirect addressing mode. (MOV A,@R0)

Q11. What are different instruction sets?

Ans: 1. Data transfer instruction.


2. Arithmetic instruction.
3. Logical Instruction.
4. Boolean variable manipulation instruction.
5. Program branching instructions.

Q12. For the given set of instruction name the operation and addressing modes.
i) MOV A,#n
ii) MOV A, addr
iii) MOVX A,@DPTR
iv) MOVC A,@A+DPTR
v) XCH A,Rn
Ans: i) Operation: Copy the immediate 8 bit data into the accumulator.
Addressing mode: Immediate add mode.
It is a 2 byte instruction.
ii) Operation: Copy the contents of the internal RAM address (addr) into the accumulator.
Addressing mode: Direct addressing mode.
It is a 2 byte instruction.
iii) Operation: Copy the contents of the external RAM address stored in DPTR into the
accumulator.
Addressing mode: Indirect addressing mode.
It is a 1 byte instruction.
iv) Operation: Copy the code byte, found at the ROM address formed by adding A and the
DPTR, into the accumulator.

DEPT. OF E&CE 81
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

It is a 1 byte instruction.
v) Operation: Exchange data bytes between the accumulator and the register Rn.
Addressing: Register Addressing mode.
It is a 1 byte instruction.

Q13. What are the various jump instructions in microcontroller?

Ans: It is of two types- conditional jump and unconditional jump. Conditional jump is of two
types byte level instruction an bit level instruction. Similarly unconditional jump is also divided
into 3 sub-jump and these are- Short jump, Absolute jump, Long jump.

Q14. What do you mean by subroutine?

Ans: A subroutine is a program that may be used many times in the execution of a larger
program.

Q15.What are the various criteria to choose the microcontroller?


The important criteria to be considered in choosing micro controllers are:
(1) Availability of software development tools like compilers, debuggers, assemblers
(2) Meeting the computing needs of the task at hand efficiently at low-cost.
(3) Wide availability
(4) Reliable sources/manufacturers
(5) The amount of RAM and ROM on chip
(6) The number of I/O pins and the timer on the chip
(7) Power consumption
(8) Speed of the device
(9) Packaging
(10) Cost per unit.

DEPT. OF E&CE 82
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Q16.List some of the 8051 microcontroller manufacturers?


Intel
Philips
Infineon
Maxim/Dellas semiconductor
Atmel

Q17. What is difference between microprocessor and microcontroller?


The microprocessor has no ROM, RAM and no I/O ports on the chip itself.
Whereas the microcontroller has a CPU in addition to a fixed amount of RAM,ROM, I/O ports
and a timer all on a single chip.
Q18.List out some of the features of the 8051?
ROM – 4K bytes
RAM – 128 bytes
Timer – 2 no
I/O Pins – 32
Serial Port – 1
Interrupt sources – 6

Q19. What are the various types of memories used in microcontroller/microprocessor?


ROM – Read Only Memory
RAM – Random Access Memory
PROM – Programmable Read Only Memory
EPROM – Erasable Programmable Read Only Memory
EEROM – Electrically Erasable Programmable Read Only Memory.

Q20.What is meant by Flipflop?


A Flip-flop is a basic electronic circuit used for storing information in a digital machine.
It is a bistable device. It means it has two stable states.
It has one or more inputs and two complement outputs.

Q21.Intel 8051 follows which architecture?

DEPT. OF E&CE 83
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

Intel 8051 is Harvard Architecture

Q22.What is the difference between Harvard Architecture and von Neumann


Architecture?

The name Harvard Architecture comes from the Harvard Mark. The most obvious
characteristic of the Harvard Architecture is that it has physically separate signals and storage for
code and data memory. It is possible to access program memory and data memory
simultaneously. Typically, code (or program) memory is read-only and data memory is read-
write. Therefore, it is impossible for program contents to be modified by the program itself.

The von Neumann Architecture is named after the mathematician and early computer scientist
John von Neumann. Von Neumann machines have shared signals and memory for code and data.
Thus, the program can be easily modified by itself since it is stored in read-write memory.

Q23.8051 was developed using which technology?

Intel’s original MCS-51 family was developed using NMOS technology, but later versions,
identified by a letter C in their name (e.g., 80C51) used CMOS technology and consume less
power than their NMOS predecessors. This made them more suitable for battery-powered
devices.

Q24.Why 8051 is called 8 bit microcontroller?

The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited
to 8 bits.

Q25.What is the width of data bus?

8-bit data bus

Q26.What is the width of address bus?

DEPT. OF E&CE 84
MC LAB MANUAL SRI VENKATESHWARA COLLEGE OF ENGINEERING, BENGALURU

16-bit address bus

Q27.On-chip RAM is also called _____ memory?

Direct memory

Q28.What location code memory space and data memory space begins?

At location 0x00 for internal or external memory

Q29How Much on chip RAM is available?

128 bytes of RAM (from 0x00 to 0x7F) and can be used to store data.

Q30.With 12 MHz clock frequency how many instructions (of 1 machine cycle and 2
machine cycle) it can execute per second?

A cycle is, in reality, 12 pulses of the crystal. That is to say, if an instruction takes one machine
cycle to execute, it will take 12 pulses of the crystal to execute. Since we know the crystal is
pulsing 11,059,000 times per second and that one machine cycle is 12 pulses, we can calculate
how many instruction cycles the 8051 can execute per second:

11,059,000 / 12 = 921,583

This means that the 8051 can execute 921,583 single-cycle instructions per second. Since a large
number of 8051 instructions are single-cycle instructions it is often considered that the 8051 can
execute roughly 1 million instructions per second, although in reality it is less–and, depending on
the instructions being used, an estimate of about 600,000 instructions per second is more
realistic.

DEPT. OF E&CE 85

You might also like