Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

MURUGAPPA POLYTECHNIC COLLEGE

SATHYAMURTHY NAGAR, CHENNAI – 62.

(AN ACADEMICALLY AUTONOMOUS INSTITUTION OFFERING NBA ACCREDITED DIPLOMA


PROGRAMMES)

DEPARTMENT OF ELECTRONICS (ROBOTICS)

ERN65 – MICROCONTROLLER PRACTICAL MANUAL


MURUGAPPA POLYTECHNIC COLLEGE
SATHYAMURTHY NAGAR, CHENNAI – 62.

(AN ACADEMICALLY AUTONOMOUS INSTITUTION OFFERING NBA ACCREDITED DIPLOMA


PROGRAMMES)

PRACTICAL MANUAL

DEPARTMENT : ELECTRONICS (ROBOTICS)

COURSE CODE : ERN65

COURSE NAME : MICROCONTROLLER PRACTICAL

CLASS : VI SEM (SW)

PREPARED BY : Mrs. M.DEVI


Lecturer/Electronics (Robotics)
LIST OF EXERCISES:

The following experiments can be written using Assembly language or C compiler


and to be executed.

Part A
1. 8 bit addition
2. 8 bit subtraction
3. 8 bit multiplication
4. 8 bit division
5. BCD to Hex code conversion
6. Hex to BCD code conversion
7. Biggest number
8. Time delay routine (Demonstrate by Blinking LEDS).

Part B (Interfacing Application Boards)


9. Interfacing Digital I/O board user
10. Interfacing DAC
11. Interfacing Stepper motor
12. Interfacing Seven segment LED display or LCD
13. Sending data through the serial port between microcontroller kits
14. Interfacing DC motor using PWM.
EX.NO.1 8 BIT ADDITION

Aim:
To write an assembly language for 8 bit addition and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the first number in register A
Step 3: Get the second number in register R0
Step 4: Add the numbers stored in registers A and R0
Step 5: Store the result in the location 60H
Step 6: End the program

Program:

org 0000h
mov a,#0A5h
mov r0,#06h
add a,r0
mov 60h,a
end

Result:
Thus an assembly language for 8 bit addition has been written and executed.
EX.NO.2 8 BIT SUBTRACTION

To write an assembly language for 8 bit subtraction and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the first number in register A
Step 3: Get the second number in register R0
Step 4: Subtract the number stored in register R0 from register A
Step 5: Store the result in the location 60H
Step 6: End the program

Program:

org 0000h
mov a,#0Ah
mov r0,#06h
subb a,r0
mov 60h,a
end

Result:
Thus an assembly language for 8 bit subtraction has been written and executed.
EX.NO.3 8 BIT MULTIPLICATION

Aim:
To write an assembly language for 8 bit multiplication and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the first number in register A
Step 3: Get the second number in register B
Step 4: Multiply the numbers stored in registers A and B
Step 5: Store the lower order value in the location 60H
Step 6: Store the higher order value in the location 61H
Step 7: End the program

Program:

org 0000h
mov a,#27h
mov b,#16h
mul ab
mov 60h,a
mov 61h,b
end

Result:
Thus an assembly language for 8-bit multiplication has been written and executed.
EX.NO.4 8 BIT DIVISION

Aim:
To write an assembly language for 8 bit division and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the first number in register A
Step 3: Get the second number in register B
Step 4: Divide the number stored in register A by register B
Step 5: Store the quotient value in the location 60H
Step 6: Store the remainder value in the location 61H
Step 7: End the program

Program:

org 0000h
mov a,#09h
mov b,#02h
div ab
mov 60h,a
mov 61h,b
end

Result:
Thus an assembly language for 8 bit division has been written and executed.
EX.NO.5 BCD TO HEX CODE CONVERSION

Aim:
To write an assembly language for BCD to Hex code conversion and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the BCD value in accumulator
Step 3: Load the accumulator value into register r5
Step 4: Mask the lower order byte using “anl a, #0f0h” instruction
Step 5: Swap the value in accumulator
Step 6: Store the result in register r1
Step 7: Again load the value from register r5 into accumulator
Step 8: Mask the lower order byte using “anl a, #0fh” instruction
Step 9: Store the result in register r2
Step 10: Load the value stored in register r1 into accumulator
Step 11: Load the value 0ah in register b
Step 12: Multiply the values stored in register a and b
Step 13: Add the values of register r2 and accumulator
Step 14: Store the hex value into the location 31h
Step 15: End the program

Program:

org 0000h
mov a,#40h
mov r5,a
anl a,#0f0h
swap a
mov r1,a
mov a,r5
anl a,#0fh
mov r2,a
mov a,r1
mov b,#0ah
mul ab
add a,r2
mov 31h,a
end

Result:
Thus an assembly language for BCD to Hex code conversion has been written and
executed.
EX.NO.6 HEX TO BCD CODE CONVERSION

Aim:
To write an assembly language for Hex to BCD code conversion and execute it.

Software Required:
Keil µVision5

Algorithm:
Step 1: Start the program
Step 2: Get the hex value in accumulator
Step 3: Add the accumulator value with 00h
Step 4: Convert the value into BCD using “da a” instruction
Step 5: Store the result in the location 31h
Step 6: End the program

Program:

org 0000h
mov a,#0fh
add a,#00h
da a
mov 31h,a
end

Result:
Thus an assembly language for Hex to BCD code conversion has been written and
executed.
EX.NO.7 BIGGEST NUMBER

Aim:
To write an assembly language for finding biggest number and execute it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Load the 16 bit address in dptr
Step 3: Load the counter value in register r2
Step 4: Mask the lower order byte using “anl a, #0f0h” instruction
Step 5: Swap the value in accumulator
Step 6: Store the result in register r1
Step 7: Again load the value from register r5 into accumulator
Step 8: Mask the lower order byte using “anl a, #0fh” instruction
Step 9: Store the result in register r2
Step 10: Load the value stored in register r1 into accumulator
Step 11: Load the value 0ah in register b
Step 12: Multiply the values stored in register a and b
Step 13: Add the values of register r2 and accumulator
Step 14: Store the hex value into the location 31h
Step 15: End the program

Program:
org 0000h
mov dptr,#6000h
mov r2,#09 //setting counter value
movx a,@dptr
mov 05h,a
up: inc dptr
movx a,@dptr
cjne a,05h,dn //compare values
sjmp next
dn: jc next
mov 05h,a //store largest value in r5
next: djnz r2,up //decrement counter until it becomes zero
inc dptr
mov a,05h
movx @dptr,a
exit:sjmp exit
end

Result:
Thus an assembly language for finding biggest number has been written and executed.
EX.NO.8 TIME DELAY ROUTINE
(Demonstrate by Blinking LEDS)

Aim:
To write an assembly language program for time delay routine and execute it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Load the tmod value
Step 3: Load the initial values in th1 and tl1 registers.
Step 4: Start timer
Step 5: Set the Port pin
Step 6: Monitor the timer flag tf1 using jnb instruction
Step 7: Stop timer
Step 8: Clear timer flag tf1
Step 9: Clear the port pin
Step 10: For Continuous Operation, goto step 2
Step 11: End the program
Program:
$mod51
org 00h
ljmp main
org 8200h
main: mov tmod,#10h
back: mov th1,#0A0h
mov tl1,#00h
setb tr1
setb p1.5
loop: jnb tf1,loop
clr tf1
clr tr1
clr p1.5
sjmp main
end

Result:
Thus an assembly language for time delay routine has been written and executed.
EX.NO.9 INTERFACING DIGITAL I/O BOARD USER

Aim:
To write an assembly language program for Interfacing Digital I/O board user and execute
it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Load the DIP Switch address in dptr
Step 3: Load the status of DIP switch into accumulator
Step 4: Load the Bar Graph LED address in dptr
Step 5: Load the status of DIP Switch address in accumulator to Bar Graph LED.
Step 6: For Continuous Operation, goto step 2
Step 7: End the program

Program:
$mod51
org 00h
ljmp main
org 8100h
main: mov dptr,#0a00ch
movx a,@dptr
mov dptr, #0a004h
movx @dptr,a
sjmp main
end

Result:
Thus an assembly language for time delay routine has been written and executed.
EX.NO.10 INTERFACING DAC

Aim:
To write an assembly language program for Interfacing DAC and execute it.

Software Required:
Keil µVision
Algorithm:
Step 1: Start the program
Step 2: Load the step values in DPTR in dptr
Step 3: Load the count (No. Of values) in r2 register
Step 4: Clear accumulator
Step 5: Load the values into program memory
Step 6: Store all the values in Port 1
Step 7: For Continuous Operation, goto step 2
Step 8: End the program
Program:
$mod51
org 00h
ljmp main
org 8100h
main: mov dptr,#table
mov r2,#0dh
back: clr a
movc a,@a+dptr
mov p1,a
inc dptr
djnz r2,back
sjmp main
table: DB 128,192,238,255,238,192
DB 128,64,17,0,17,64,128
end
Result:
Thus an assembly language for Interfacing DAC has been written and executed.
EX.NO.11 INTERFACING STEPPER MOTOR

Aim:
To write an assembly language program for interfacing stepper motor and execute it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Load the control word address
Step 3: Configure Port A as output and Port B as input
Step 4: Load Port A address in dptr
Step 5: Load 09h into Port A and call delay
Step 6: Load 05h into Port A and call delay
Step 7: Load 06h into Port A and call delay
Step 8: Load 0ah into Port A and call delay
Step 9: For continuous operation, goto step 5
Step 10: End the program

Program:
$mod51
org 00h
ljmp main
org 8200h
main: mov dptr,#0a003h
mov a,#82h
movx @dptr,a
mov dptr, #0a000h
repeat: mov a,#09h
movx @dptr, a
acall delay
mov a,#05h
movx @dptr, a
acall delay
mov a,#06h
movx @dptr, a
acall delay
mov a,#0ah
movx @dptr, a
acall delay
sjmp repeat
delay: mov r1, #10h
again: mov r0, #255
back: djnz r0, back
djnz r1, again
ret
end

Result:
Thus an assembly language for interfacing stepper motor has been written and executed.
EX.NO.12 INTERFACING SEVEN SEGMENT LED DISPLAY OR LCD

Aim:
To write an assembly language program for interfacing seven segment LED display or
LCD and execute it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Select any one port to display number
Step 3: Enable or Disable the port pins (based on number)
Step 4: End the program

Program:
$mod51
org 00h
ljmp main
org 8100h
main: setb p1.0
clr p1.1
setb p1.2
setb p1.3
clr p1.4
setb p1.5
setb p1.6
setb p1.7
sjmp $
end
Pin Diagram:

Result:
Thus an assembly language for interfacing seven segment LED display or LCD has been
written and executed.
EX.NO.13 SENDING DATA THROUGH THE SERIAL PORT BETWEEN
MICROCONTROLLER KITS

Aim:
To write an assembly language program for sending data through the serial port between
microcontroller kits and execute it.

Software Required:
Keil µVision

Algorithm:
Transmitting Data:
Step 1: Start the program
Step 2: Load the tmod value
Step 3: Load the baud rate value in th1 register
Step 4: Load serial mode value
Step 5: Start timer
Step 6: Send character through sbuf register
Step 7: Check ti flag and send next character
Step 8: Clear the flag ti
Step 9: End the program
Receiving Data:
Step 1: Start the program
Step 2: Load the tmod value
Step 3: Load the baud rate value in th1 register
Step 4: Load serial mode value
Step 5: Store the received data in dptr
Step 6: Start timer
Step 7: Check ri flag and receive next character
Step 8: Receive the character through sbuf register
Step 9: Check for the last character using cjne instruction
Step 10: Store the received data to the memory
Step 11: End the program
Program:
Transmitting Data:
org 00h
ljmp main
org 8100h
main: mov tmod,#20h
mov th1,#0fdh
mov scon,#50h
setb tr1
next: mov a, #'E'
acall delay
mov a,#'R'
acall delay
mov a,#'#'
acall delay
sjmp next
delay: mov sbuf,a
loop: jnb ti,loop
clr ti
ret
end

Receiving Data:
$mod51
org 00h
ljmp main
org 8200h
main: mov tmod,#20h
mov th1,#0fdh
mov scon,#50h
mov dptr,#8400h
setb tr1
loop: jnb ri,loop
mov a,sbuf
clr ri
cjne a,#'#',go
sjmp $
go: movx @dptr,a
inc dptr
sjmp loop
end

Result:
Thus an assembly language for sending data through the serial port between
microcontroller kits has been written and executed.
EX.NO.14 INTERFACING DC MOTOR USING PWM

Aim:
To write an assembly language program for Interfacing DC motor using PWM and execute
it.

Software Required:
Keil µVision

Algorithm:
Step 1: Start the program
Step 2: Load the control word address
Step 3: Configure Port A and Port B as input
Step 4: Load Port A address in dptr
Step 5: Set P1.0, P1.1 and clear P1.1 for forward direction
Step 6: Set P1.0, P1.1 and clear P1.1 for reverse direction
Step 7: Call time delay
Step 8: End the program

Program:
$mod51
org 00h
ljmp main
org 8200h
main: clr p1.0
setb p1.1
setb p1.2
acall delay1
clr p1.1
acall delay2
sjmp main
delay1:mov a,r2
mov r0,a
again: mov r1,#0ffh
back: djnz r1, back
djnz r0, again
ret
delay2: clr c
mov a,#0ffh
subb a,r2
mov r0,a
k2: mov r1,#50h
k1: djnz r1,k1
djnz r0,k2
ret
end

Result:
Thus an assembly language for Interfacing DC motor using PWM has been written and
executed.

You might also like