Micro Controller and Applicatioins Lab: Baiju.G.S Lecturer Electronics Engineering
Micro Controller and Applicatioins Lab: Baiju.G.S Lecturer Electronics Engineering
Baiju.G.S
Lecturer in Electronics Engineering
Baiju G S 1
Program : Diploma in Electronics/ Electronics and Communication Engineering/ Biomedical Engineering
Course Objectives:
To equip the student with the concept of coding microcontrollers using ASM.
To encourage students to utilize internet resources for working out simple day
to day applications.
To enable the student to code any similar microcontroller in ASM.
Baiju G S 2
Tools and Equipments:
1. Keil µVision.
2. 89C51 prototype board to support IO ports, ADC, LCD display, 7 segment LED
display, 4x4 matrix keyboard, Relay and Buzzer interface, USB compatible
programmer.
3. Computer system to support Keil µVision
Duration
COn Description Cognitive level
(Hours)
Lab Exam 6
Baiju G S 3
Experiments
• 1. Familiarization of Microcontroller Kit
• 2. Familiarization of Keil micro vision IDE software
• 3. Addition of two 8 BIT numbers
• 4. Substraction of two 8 bit numbers
• 5. Multiplication of two 8bit numbers
• 6. Division of two 8bit numbers
• 7. Addition of two 16 bit numbers
• 8. Binary to ASCII conversion
• 9. Hexadecimal to Decimal conversion
Baiju G S 4
Experiments
• 10. Generation of Natural numbers
• 11. No of 1’s in a given number
• 12. Number of 0’s in a given number
• 13. LED interfacing
• 14.DC Motor Interfacing
• 15. Stepper Motor Interfacing
Baiju G S 5
Exp No.1:
Baiju G S 6
8051 MICROCONTROLLER KIT
• 1. Switch ON the Microcontroller KIT
• Type ‘a’ and press the Enter Key to enable the assembler
• While display ask the orgin address,give the same ORG:
(Eg: 4100)
• Instruction by Instruction type the Assebly Language
Program
• After each instruction press the Enter key and note the
OPCODE and ADRESS LOCATION of the same
• Final instruction of the ALP program must be HERE: SJMP
HERE ( Give the adress location in place of HERE)
• Close the program with the directive END ( This is not
needed while using KIT since we run the instruction
SJMP at the end of program)
Baiju G S 7
• After entering all the instructions RESET the Kit
• Then type SD Memory location , to access the
external memory locatiob to enter the data ( Eg SD
4500)
• Give the input in 8bit Hex format and press the
Enter key for next location
• After the completion of input values RESET the kit
• Execute the program by GO orgin adress ( Eg
GO 4100)
Baiju G S 8
• Again Reset the kit
• To view the output, type SD memory location
( SD 4502)
Baiju G S 9
Exp No.2: Keil vision
Baiju G S 10
Project --- New vision project
Baiju G S 11
Save the project with required file name ( No extensions required)
Baiju G S 12
While saving the project need to select the device
Baiju G S 13
For our 8051 micro controller projects Select the brand Atmel and
device AT89c51
for Keil vision 5 select Intel
Baiju G S 14
To copy the startup programs select Yes . For our lab experiments that
is not required. So select NO
Baiju G S 15
For the New ALP create file .
File--- New ( Cntrl+N). It generate a new file to enter the program
Baiju G S 16
Select file Save as and in which save the file with an asm extension
Baiju G S 17
To add the program file to the required project group
Select project target1 source group 1
Baiju G S 18
Select add files to Group
select the file type as asm to view the files in the list (Defualt it is C )
Select the file from the list and click Add .Then click close
Ensure the plus (+) sigh in the source group after adding the file
Baiju G S 19
After the complete entry of the ALP program --- Project---- Build
Target (F7)
Baiju G S 23
• INC R0
• Ahead: INC DPTR
• MOVX @DPTR,A
• MOV A,R0
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 24
Exp No:4 Subtraction of two 8 bit numbers
• ORG 4100H
• MOV DPTR ,#4500H
• MOV R0,#00H
• MOVX A,@DPTR
• MOV R1,A
• INC DPTR
• MOVX A,@DPTR
• XCH A,R1
• SUBB A,R1
Baiju G S 25
• JNC Ahead
• INC R0
• Ahead: INC DPTR
• MOVX @DPTR,A
• MOV A,R0
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 26
Exp No.5: Multiplication of two 8bit numbers
• ORG 4100H
• MOV DPTR ,#4500H
• MOVX A,@DPTR
• MOV B,A
• INC DPTR
• MOVX A,@DPTR
• MUL AB
Baiju G S 27
• INC DPTR
• MOVX @DPTR,A
• MOV A,B
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 28
Exp No.6: Division of two 8bit numbers
• ORG 4100H
• MOV DPTR ,#4500H
• MOVX A,@DPTR
• MOV B,A
• INC DPTR
• MOVX A,@DPTR
• XCH A,B
Baiju G S 29
• DIV AB
• INC DPTR
• MOVX @DPTR,A
• MOV A,B
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 30
Exp No. 7: Addition of two 16 bit numbers
• MOV DPTR,#4500H
• MOV R2,#00H
• MOVX A,@DPTR
• MOV R0,A
• INC DPTR
• MOVX A,@DPTR
• MOV R1,A
• INC DPTR
• MOVX A,@DPTR
Baiju G S 31
• ADD A,R0
• MOV R6,A
• INC DPTR
• MOVX A,@DPTR
• ADDC A,R1
• JNC LOOP1
• INC R2
Baiju G S 32
• LOOP1: INC DPTR
• MOVX @DPTR,A
• INC DPTR
• MOV A,R6
• MOVX @DPTR,A
• INC DPTR
• MOV A,R2
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 33
Exp No. 8: Binary to ASCII conversion
ORG 4100H
MOV DPTR,#4500H
MOVX A,@DPTR
MOV B,A
CLR C
SUBB A,#0AH
JC SKIP
MOV A,B
ADD A,#37H
Baiju G S 34
SJMP DOWN
SKIP: MOV A,B
ADD A,#30H
DOWN: INC DPTR
MOVX @DPTR,A
STOP: SJMP STOP
END
Baiju G S 35
Exp No. 9 : Hexadecimal to Decimal conversion
• MOV DPTR,#0000H
• MOVX A,@DPTR
• MOV B,#64H
• DIV AB
• INC DPTR
• MOVX @DPTR,A
• MOV A,B
• MOV B,#0AH
Baiju G S 36
• DIV AB
• INC DPTR
• MOVX @DPTR,A
• MOV A,0F0H
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 45
37
Exp No. 10 : Generation of Natural numbers
ORG 4100H
MOV DPTR,#4500H
MOVX A,@DPTR
MOV R2,A
MOV A,#00H
MOV R1,#01
AGAIN : ADD A,R1
DA A
Baiju G S 38
INC DPTR
MOVX @DPTR,A
DJNZ R2 AGAIN
HERE: SJMP HERE
Baiju G S 39
Exp No.11: Number of 1’s in a given number
• ORG 4100H
• MOV DPTR,#4500H
• MOV R2,#08H
• MOV R1,#00H
• MOVX A,@DPTR
• CLR C
• AGAIN: RLC A
• JNC AHEAD
Baiju G S 40
• INC R1
• AHEAD: DJNZ R2,AGAIN
• MOV A,R1
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 41
Exp No.12: Number of 0’s in a given number
• ORG 4100H
• MOV DPTR,#4500H
• MOV R2,#08H
• MOV R1,#00H
• MOVX A,@DPTR
• CLR C
• AGAIN: RLC A
• JC AHEAD
Baiju G S 42
• INC R1
• AHEAD: DJNZ R2,AGAIN
• MOV A,R1
• INC DPTR
• MOVX @DPTR,A
• HERE: SJMP HERE
• END
Baiju G S 43
Exp No. 13: LED Interfacing
• ORG 4100H
• L0OP: MOV P1,#AAH
• ACALL DELAY
• MOV P1,#55H
• ACALL DELAY
• SJMP LOOP
• DELAY: MOV R1,#FFH
• YY1: MOV R2,# FFH
• XX1: DJNZ R2,XXI
• DJNZ R1,YY1
• RET Baiju GS
Baiju.G.S 44
48
Procedure
• Use the P1 port of Microcontroller, in the VI
Microsystem kit for interfacing
• Connect the Ribbon cable from Port1 to the
port of LED ( marked P9 in the VI
microcontroller Kit)
• Enter and Execute the program with a
reasonable delay time to alternately enable
the LED
• 10101010 – AAH and 01010101 -55H
Baiju G S 45
Procedure to execute the program
using VI microcontroller kit
• While using microcontroller kit for executing
the interfacing program use the address of
the memory locations instead of labels
• Eg : ACALL DELAY
( Give the address of the location were we start
the DELAY , instead of typing DELAY . Same also
applicable to other Call and Jump instructions
Baiju G S 46
Exp No. 13: LED Interfacing
• ORG 41000 Type ‘A’ and give 4100 ( instead of typing
ORG 4100)
• 4100 : MOV P1,#AAH ( The label LOOP is not required
while using the assembler in the Kit, instead of label
pls note the address )
• 4103 : ACALL 410C ( Give the address o f memory
location instead of label DELAY )
• 4105 : MOV P1,#55H
• 4108 : ACALL 410C ( Give the address o f
memory location instead of label DELAY )
• 410A: SJMP 4100 ( Give the address o f
memory location insteadBaiju ofG S label LOOP )
Baiju.G.S 47
48
• 410C: MOV R1,#FFH
• 410E: MOV R2,#FFH
• 4110: DJNZ R2,4110 ( Give the address o f
memory location instead of XX1)
• DJNZ R1, 410E ( Give the address o f
memory location instead of labelYY1)
• RET
Baiju G S 48
Exp No. 14: DC Motor Interfacing
• CLOCKWISE ROTATION
• ANTICLOCKWISE ROTATION
Baiju G S 49
DC motor Interfacing - Procedure VI microcontroller Kit
• ORG 4100H (Type ‘A’ and give 4100 ( instead of using assembler
directive ORG )
4100 : MOV P1, #20H
4103: SJMP 4100 (Use 4100 instead of Label START)
• ANTICLOCKWISE ROTATION
• ORG 4100H (Type ‘A’ and give 4100 ( instead of using assembler
directive ORG )
4100 : MOV P1, #10H
4103:SJMP 4100 ( Use 4100 instead of Label START)
Baiju G S 51
Exp No. 15: Stepper Motor Interfacing
• ORG 4100H
• L0OP: MOV P1,#09H
• ACALL DELAY
• MOV P1,#05H
• ACALL DELAY
MOV P1,#06H
• ACALL DELAY
• MOV P1,#0AH
• ACALL DELAY
• SJMP LOOP
Baiju G S 52
• DELAY: MOV R1,#FFH
• YY1: MOV R2,# FFH
• XX1: DJNZ R2,XXI
• DJNZ R1,YY1
• RET
• NB: While using microcontroller kit for executing
this program use the address of the memory
locations instead of labels
• ACALL DELAY
( Give the address of the location were we start the
DELAY , instead of typing DELAY . Same also
applicable for other Call and Jump instructions
Baiju G S 53
Procedure
• Use the P1 port of Microcontroller, in the VI
Microsystem kit for interfacing
• Use the P1 port of Microcontroller,in the VI
Microsystem kit for interfacing
• For the same connect the Ribbon cable from
Port1 to the port of Stepper motor ( from P9
to P12 in the Kit )
• The pin P1.0 to P1.3 of the interfacing port
were connected to Stepper motor
Baiju G S 54
• Write program to give supply to the port pins
connected to four Stator motors alternatively
Baiju G S 55
• ORG 4100H (Type ‘A’ and give 4100 ( instead of
using assembler directive ORG )
• 4100: MOV P1,#09H ( The label LOOP is not required
while using the assembler in the Kit, instead of label
pls note the address )
• ACALL 4116 ( Give the address o f memory location
instead of label DELAY )
• MOV P1,#05H
• ACALL 4116
MOV P1,#06H
• ACALL 4116
Baiju G S 56
• MOV P1,#0AH
• ACALL 4116
• SJMP 4100 ( Give the address o f memory location
instead of label LOOP )
• 4116 : MOV R1,#FFH ( Delay program )
• 4118 : MOV R2,#FFH
• 411A : DJNZ R2,411A ( Give the address o f memory
location instead of XX1)
• 411C: DJNZ R1,4118 ( Give the address o f memory
location instead of YY1)
• RET
Baiju G S 57
Thank You
Baiju G S 58