micro controller lab manual

86
0 AN INSTITUTION ACCREDITED BY NBA, NEWDELHI Sivagamipuram, Pavoorchatram - 627808, Tirunelveli District, TamilNadu. E-mail: [email protected] ELECTRIAL AND ELECTRONICS DEPARTMENT Microprocessor and Microcontroller Practical Lab Manual III Year V Semester AUTHOR Mr. Balasubramaniaraju, B.E., LECTURER / EEE PUBLISHER: MSPVL POLYTECHNIC COLLEGE, PAVOORCHATRAM, TIRUNELVELI DIST – 627 808

Upload: karthikeyan

Post on 30-Sep-2014

1.248 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Micro Controller Lab Manual

0

AN INSTITUTION ACCREDITED BY NBA, NEWDELHI Sivagamipuram, Pavoorchatram - 627808,

Tirunelveli District, TamilNadu. E-mail: [email protected]

ELECTRIAL AND ELECTRONICS

DEPARTMENT

Microprocessor and

Microcontroller Practical Lab

Manual

III Year V Semester

AUTHOR Mr. Balasubramaniaraju, B.E.,

LECTURER / EEE

PUBLISHER: MSPVL POLYTECHNIC COLLEGE, PAVOORCHATRAM,

TIRUNELVELI DIST – 627 808

Page 2: Micro Controller Lab Manual

1

INDEX

Sl. No Description Page no

Software Experiments

1 Introduction to 89c51 Microcontroller Kit 2

2 8 Bit Addition and Subtraction 5

3 Multi-Byte Addition 9

4 Multiplication of Two Numbers 12

5 Find the Largest Number in a array of numbers 15

6 Arranging the array of numbers in ascending order 18

7 BCD to Hexadecimal conversion 22

8 Hexadecimal to BCD conversion 25

9 Hexadecimal to ASCII code conversion 28

10 Program using I/O pins in Port 1 31

11 Counter using Timer 33

12 Program using Interrupt 35

Hardware Experiments

13 Matrix Keyboard interfacing with 89C51 37

14 Seven segment Display interfacing with 89C51 40

15 LCD interfacing with 89C51 43

16 Data transfer between two microcontroller kits using serial port 46

17 Control the DC Motor using 89C51 51

18 Control the Stepper Motor using 89C51 54

Extra Syllabus

19 Program interfacing relay and Pushbutton to the 8951 controller 57

20 Program to using DIP switches 59

Page 3: Micro Controller Lab Manual

2

1. Introduction to 89C51 MICROCONTROLLER KIT

PROCEDURE TO ENTER THE PROGRAM IN THE KIT

1. Initially press RST key and sign on message 8051 appears on the display

2. Suppose if you want to start a program from 8200H onwards, then first type the number 8200 and press ADS key.It will be displayed as follows. 8200 XX If you want to write a data 78 in the address 8200, then first type 7 & then 8. It will be displayed as follows. 8200 78

3. If you want to write a data 24 in the address 8201,Then press INC key and type 2 & then 4. It will be displayed as Follows. 8201 24

4. In this way, the program can be loaded

5. To modify a data from a particular location, press RST key then type that particular address and press ADS key then modify the data and once again press the ADS key.

6. To see the program backwards, press DEC key.

PROCEDURE FOR EXECUTION OF THE PROGRAM

1. After entering the last instruction, press INC key.

2. To execute the program, first type RST.

3. 8051 sign on message appears.

4. Type the starting address of the program

5. Press ADS Key then press EXE Key

6. If the program is executed, ‘E’ will be displayed

PROCEDURE FOR SEEING THE RESULT

1. Suppose if you want to see result stored in the location 8240H, and then follow the steps given below.

2. First press RST Key.

3. 8051 sign on message appears

4. Type the 8240.

5. Press ADS Key.

6. Now the content (result) in the location 8240 is displayed in the data display

Page 4: Micro Controller Lab Manual

3

Input / Output Addresses. 1. 8255 - Programmable peripheral interface.

1. Port A - 0A000h 2. Port B - 0A001h 3. Port C - 0A002h 4. Control Word Register - 0A003h

2. 8 Bit Dip switch input port - 0A00Ch 3. 8 Bit LED bar graph o/p - 0A004h 4. 8279 – Keyboard/Display controller.

1. Data port - 0A014h 2. Command port - 0A015h

Address Bus

A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

8255 Programming: Addressing of 8255

A1 A0 /RD /WR /CS Action 0 0 L H L Read the content of port A 0 1 L H L Read the content of port B 1 0 L H L Read the content of port C 0 0 H L L Write to the port A Latch 0 1 H L L Write to the port B Latch 1 0 H L L Write to the port C Latch 1 1 H L L Write to the control regiser x x x x H Data bus to high impedence

Control word of 8255 Group B

Group A

D7 D6 D5 D4 D3 D2 D1 D0

Mode 00 – M0 01 – M1 10 – M2

Port A Address

0 – Output 1 – Input

Upper Port C PC7 – PC4 0 – Output 1 – Input

Mode 00 – M0 01 – M1 10 – M2

Port B Address

0 – Output 1 – Input

Upper Port C PC3 – PC0 0 – Output 1 – Input

Page 5: Micro Controller Lab Manual

4

FLOWCHART: Addition of two 8 bit datas with out carry

Move the Data1 to Acc. Register

Move the Result from Acc. Reg to Memory Location 8300h

FLOWCHART: Addition of two 8 bit datas with carry

Move the Data1 from

Mem.Location 8250 to B reg

Move the Data2 from mem.Location 8251 to Acc. reg

Move the Result from Acc. Reg to Memory Location 8300h

Move the Data 00 to 8301h Mem.Location

NO

i

Yes

Move the Data 01 to 8301h Mem.Location

Same as draw the Flow chart for subtraction in your observation.

START

Add Data2 with Acc. Reg and the result stored in Acc. Reg

Stop

START

Add Acc. Reg with B Reg. Result stored in Acc. Reg

Stop

Check: C=1

Page 6: Micro Controller Lab Manual

5

EX. NO: 2 8 BIT Addition and Subtraction

Aim:

To write and execute an assembly language program to multiply the given two 8 bit numbers.

Objectives: To multiply any two 8 bit numbers using immediate addressing and to store the result

Apparatus Required: No Name Quantity 1 Microcontroller kit 1

Algorithm:

Addition with out carry 1. Start the Program.

2. Move the Data1 to the accumulator.

3. Add the Data2 with the accumulator, the result stored in accumulator.

4. Set the DPTR as 8300 in RAM address location.

5. Move the result which is in accumulator to the 8300 address location.

6. Stop the Program.

Addition with carry 1. Start the Program.

2. Move the Data1 from 8250 Memory location to B Register.

3. Move the Data2 from 8251 Memory location to Acc. Reg

4. Add the B Reg with the accumulator, the result is in accumulator.

5. Set the DPTR as 8300 in RAM address location.

6. Move the result which is in accumulator to the 8300 address location.

7. Clear the 8301 memory location

8. Check the carry flag, if carry is there, then move 01 to 8301 memory location

9. Stop the Program.

Same as write the algorithm for subtraction also.

Page 7: Micro Controller Lab Manual

6

Program: Addition of two 8 bit data without carry

Output:

Program: Addition of two 8 bit datas with carry

INPUT: OUTPUT:

Memory address

Hex. code

Label Assembly Codes Comments Mnemonics Operend(s)

HLT

MOV ADD MOV MOVX SJMP

A, #Data1 A, #Data2 DPTR, #8300h @DPTR, A HLT

Memory address Data

8300

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

MOV MOVX MOV INC MOVX ADD MOV MOVX INC CLR MOVX JNC INC MOVX SJMP

DPTR,#8250h A, @DPTR B,A DPTR A,@DPTR A, B DPTR, #8300h @DPTR, A DPTR A @DPTR, A HLT A @DPTR, A HLT

Memory address Data Memory Address Data

8250 8300 Data

8251 8301 Carry

Page 8: Micro Controller Lab Manual

7

Program: Subtract a small number from a large number

Output:

Result: Thus an assembly language program 8 bit addition and subtraction were written and executed successfully.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

MOV SUB MOV MOVX SJMP

A, #Data1 A, #Data2 DPTR, #8300h @DPTR, A HLT

Memory address

Data

8300

Page 9: Micro Controller Lab Manual

8

Flowchart: Multi -Byte addition with carry

Move the Lower order byte of Data1 to Acc. Reg

Move the Lower order byte result from Acc. Reg to the Memory location 8300h

Move the Higher order byte of Data1 to Acc. Reg

Move the Higher order byte result from Acc. Reg to the Memory location 8301h

Move the Data 00 to 8302h Mem.Location

NO

i

Yes

Move the Data 01 to 8302h Mem.Location

START

Add Acc. Reg with Lower order byte of Data2

Stop

Check: C=1

Add Acc. Reg and Higher order byte of Data2 with carry

Page 10: Micro Controller Lab Manual

9

Aim: To write and execute an assembly language program to add two 16 bit numbers. Objectives: Get two 16 bit datas from the starting location of 8250 then add those datas and store in the location of 8300 onwards. Apparatus Required:

Algorithm:

1. Start the program.

2. Move the first data lower order byte to A register.

3. Add the second data lower order byte with A register.

4. Move the lower order byte result data from A reg to 8300 Memory location.

5. Move the first data higher order byte to A register.

6. Add A reg. and Second higher order byte with carry flag.

7. Move the higher order byte result data from A reg to 8301 Memory location.

8. Check the carry flag; if it is one move 01 data to 8302 else move 00 data to 8302.

9. Stop the program.

EX. NO: 3 Multi-Byte Addition

No Name Quantity

1 Microcontroller kit 1

Page 11: Micro Controller Lab Manual

10

Page 12: Micro Controller Lab Manual

11

Program: Multi-Byte Addition.

Output:

RESULT: Thus an assembly language program is written to add Multi Byte numbers and executed successfully.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

CLR MOV ADD MOV MOVX MOV ADDC INC MOVX INC MOVX JNC MOVX SJMP

C A, #LSB Data1 A, #LSB Data2 DPTR,#8300h @DPTR, A A, #MSB Data1 A, #MSB Data2 DPTR @DPTR,A DPTR @DPTR,#00h HLT @DPTR,#01h HLT

Memory address Data

8300 Lower order byte

8301 Higher order byte

8302 Carry

Page 13: Micro Controller Lab Manual

12

FLOWCHART: Multiplication of two 8 bit numbers.

Move the Data1 from

Mem.Location 8250 to B reg

Move the Data2 from mem.Location 8251 to Acc. reg

Move the Result from Acc. Reg to Memory Location 8300h

Move the Result from B. Reg to Memory Location 8301h

START

Multiply Acc. Reg with B Reg.

Stop

Page 14: Micro Controller Lab Manual

13

Aim: To write and execute an assembly language program to multiply the given two 8 Bit Numbers. Objectives: To multiply the give two 8 Bit numbers using MUL command Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Move the multiplicand to accumulator.

2. Move the multiplier to ‘B’ register (SFR with direct address FO)

3. Multiply the contents of Accumulator and ‘B’ register.

4. Store the lower byte result from ‘A’ register to 8300 memory location

5. Store the higher byte result from ‘B’ register to 8301 memory location

6. Stop or Halt the program execution.

EX. NO: 4 8 Bit Multiplication

Page 15: Micro Controller Lab Manual

14

Page 16: Micro Controller Lab Manual

15

Program: Two 8 Bit Multiplication

Output:

Result: Thus an assembly language is written to multiply two 8 bit numbers and executed successfully.

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

HLT

MOV MOVX MOV INC MOVX MUL MOV MOVX INC MOV MOVX SJMP

DPTR,#8250h A, @DPTR B,A DPTR A, @DPTR A,B DPTR,#8300h @DPTR, A DPTR A,B @DPTR,A HLT

Memory address Data

8300 Lower order byte

8301 Higher order byte

Page 17: Micro Controller Lab Manual

16

FLOW CHART: Find the Largest number from an array o f numbers

Move the Total no of Data to R0. Reg from8250 memory location

Move the I data to R1 register

Move the Next data to Acc register

NO

i

Yes

No

Move the Data from R1 Reg to 8301h Mem.Location

START

Stop

Check: C=1

Subtract R1 Reg from Acc Reg

Exchange the R1Data and subtracted Data

Check R0 = 0

Increment Data Pointer/ Decrement R0

Increment Data Pointer/ Decrement R0

Page 18: Micro Controller Lab Manual

17

EX. NO: 5 Find the Largest Number in an array Aim:

To write and execute an assembly language program to add the given array of 8 bit numbers.

Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Load the R0 register with length of the array and load DPTR with memory

location 8250.

2. Get first element to B register

3. Get the next element in accumulator.

4. Decrement the R0 register each time by 1 for every data taken from the array.

5. Subtract the B register from the accumulator.

6. Check the carry flag.

7. If carry is not there, then A register is greater that means 2nd data is larger than 1st

Data. So exchange the A and B register.

8. If carry is there, then B register is greater that means 1st data is larger than 2nd

Data. So do not exchange the A and B register.

9. Check the R0 register. If R0 is not equal to zero, repeat from the 3rd step else

Move the B register to 8300 memory location and stop the program.

Page 19: Micro Controller Lab Manual

18

Page 20: Micro Controller Lab Manual

19

Program: Find the Largest number from an Array.

Input:

Output:

Result: Thus an assembly language program is written to find largest number from an array and executed successfully.

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

L2 L1 HLT

MOV MOVX MOV INC DEC MOVX MOV INC DEC MOVX SUBB JNC MOVX XCH MOV JNZ MOV MOV MOVX SJMP

DPTR,#8250h A, @DPTR R0,A DPTR R0 A, @DPTR R1,A DPTR R0 A,@DPTR A,R1 L1 A,@DPTR A,R1 A,R0 L2 A,R1 DPTR,#8300h @DPTR, A HLT

Memory address

Data

8250 05 (No of datas)

8251 Data1

8252 Data2

8253 Data3

8254 Data4

8255 Data5

Memory address

Data

8300 Large Number

Page 21: Micro Controller Lab Manual

20

FLOW CHART: Arrange the array of numbers in ascending order

Move the Total no of Data to R0. Reg from8250 memory location

Move the I data to R1 register

Move the Next data to Acc register

NO

i

Yes

No

START

Stop

Check: C=1

Subtract R1 Reg from Acc Reg

Exchange the R1Data and subtracted Data

Check R0 = 0

Increment Data Pointer/ Decrement R0

Increment Data Pointer/ Decrement R0

Page 22: Micro Controller Lab Manual

21

EX. NO: 6 Arrange the given 8 bit array in Ascending Order

Aim: To write and execute an assembly language program to arrange an 8 bit array of datas in ascending order. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Load the R0 register with length of the array and load DPTR with memory

location 8300.

2. Get first element to R1 register

3. Get the next element in accumulator.

4. Decrement the R0 register each time by 1 for every data taken from the array.

5. Subtract the R1 register from the accumulator.

6. Check the carry flag.

7. If carry is not there, then A register is greater that means 2nd data is larger than 1st

Data. So do not exchange the A and R1 register.

8. If carry is there, then R1 register is greater that means 1st data is larger than 2nd

Data. So exchange the A and R1 register.

9. Check the R0 register. If R0 is not equal to zero, repeat from the 3rd step else

Move the B register to 8300 memory location and stop the program.

Data1 – R1, Data2 – A

Page 23: Micro Controller Lab Manual

22

Program: Find the Largest number from an Array.

INPUT:

OUTPUT:

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

L1 L2 HLT

MOV MOVX MOV INC DEC MOVX MOV INC DEC MOVX SUBB JNC MOVX XCH DEC DEC MOVX INC MOV MOVX MOV JNZ SJMP

DPTR,#8300h A, @DPTR R0,A DPTR R0 A, @DPTR R1,A DPTR R0 A,@DPTR A,R1 L2 A,@DPTR A,R1 DPTR DPTR @DPTR,A DPTR A,R1 @DPTR,A A,R0 L1 HLT

Memory address Data

8300 05 (No of datas)

8301 Data1

8302 Data2

8303 Data3

8304 Data4

8305 Data5

Memory address Data

8300 05 (No of datas)

8301 Data1

8302 Data2

8303 Data3

8304 Data4

8305 Data5

Page 24: Micro Controller Lab Manual

23

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

Page 25: Micro Controller Lab Manual

24

FLOW CHART: BCD to Hex conversion

Move the Data to Acc. Reg from8300 memory location

Move the HEX output to 8300 Memory location

START

Stop

Move the MSB of Acc to R1 Reg

ADD the Acc with LSB

Move the LSB of Acc to R2 Reg

Multiply the MSB by 0Ah And store the result in Acc. reg

Page 26: Micro Controller Lab Manual

25

Aim: Write an assembly language program to convert 8 bit two digit BCD number system into Hexadecimal number system. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1 Algorithm:

1. Start the Program 2. Get the data from the 8300 memory location to R5 register. (R5 = 99). 3. Separate the MSB and LSB of R5 register using ANL 0Fh and ANL F0h commands. 4. Move the MSB to Accumulator and LSB to R2 register.( A = 09, R2 = 09) 5. Multiply the MSB with 0Ah Data.(09*0A) = 5A) 6. Add the Accumulator with LSB of the Data. (5A+9 = 63) 7. Move the Accumulator to 8301 memory location.(8301 = 63) 8. Stop the program.

Example:

1. 8300 = 99(BCD). 8301 = 63h

EX. NO: 7 BCD TO HEX CONVERSON

Page 27: Micro Controller Lab Manual

26

Page 28: Micro Controller Lab Manual

27

Program: BCD to Hex conversion

INPUT:

OUTPUT: Result: Thus the assembly language program was written to verify the Boolean equation and it was executed.

Memory address Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

HLT

MOV MOVX MOV ANL SWAP MOV MOV ANL MOV MOV MOV MUL ADD INC MOVX SJMP

DPTR,#8300h A, @DPTR R5,A A, #F0h A R1,A A,R5 A, #0Fh R2,A A,R1 B, #0Ah A,B A,R2 DPTR @DPTR, A HLT

Memory address Data

8300 BCD Data

Memory address Data

8301 HEX Data

Page 29: Micro Controller Lab Manual

28

FLOW CHART: HEX to BCD conversion

Move the Data to Acc. Reg from8300 memory location

Move the Data from Acc. Reg to 8301 memory location

Move the Data from B reg to Acc. Reg

Change the Position of MSB and LSB of A Reg

Move the Data from Acc. Reg to 8302 memory location

START

Stop

Divide the Acc. Reg by 64h

Divide the Acc. Reg by 0Ah

Add A reg with B reg

Page 30: Micro Controller Lab Manual

29

Aim: To convert the given hexadecimal value to its equivalent BCD conversion. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Start the program.

2. Move the data from memory location 8300 to Accumulator.(A = FFh)

3. Divide the accumulator with 64h( FF/64 ( A= 2 and B = 37h )

4. Move the accumulator to 8301h ( 8301 = 02)

5. Move the B reg to accumulator (A = 37h)

6. Divide the accumulator with 0Ah (37/0A ( A=05 and B = 05 )

7. Swap the Accumulator.(A = 50)

8. Add the accumulator with B register.(A = 50+5)

9. Move the accumulator to 8302h(8302 = 55)

10. Stop the program.

Example:

1. 8300 = FFh 2. 8301=02 3. 8302 = 55.

EX. NO: 8 HEX TO BCD CONVERSION

Page 31: Micro Controller Lab Manual

30

Page 32: Micro Controller Lab Manual

31

Program: HEX to BCD conversion

INPUT:

OUTPUT: Result Thus the assembly language program was written to convert the hexa decimal value into its equivalent BCD value and it was executed successfully.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

MOV MOVX MOV DIV INC MOV MOV MOV DIV SWAP ADD INC MOVX SJMP

DPTR,#8300h A, @DPTR B,#64h A,B DPTR @DPTR,A A,B B, #0Ah A, B A A,B DPTR @DPTR, A HLT

Memory address Data

8300 HEX Data

Memory address Data

8301 Higher BCD Data

8302 Lower BCD Data

Page 33: Micro Controller Lab Manual

32

FLOW CHART: HEX to ASCII conversion

Move the Data to Acc. Reg from8300 memory location

Move the Data from Acc. Reg to 8301 memory location

Move the Data from B reg to Acc. Reg

Move the Data from Acc. Reg to 8302 memory location

Move the Data from B Reg to A Reg

Move the Data from Acc. Reg to 8303 memory location

START

Stop

Divide the Acc. Reg by 64h and Add the A Reg with 30h

Divide the Acc. Reg by 0Ah and Add the A Reg with 30h

Add the A Reg with 30h

Page 34: Micro Controller Lab Manual

33

EX. NO: 9 Hexadecimal to ASCII conversion

Aim: To convert the given hexadecimal value to its equivalent ASCII code. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Start the program.

2. Move the data from memory location 8300 to Accumulator.(A = FFh)

3. Divide the accumulator with 64h( FF/64 ( A= 2 and B = 37h )

4. Add the accumulator with 30h

5. Move the accumulator to 8301h ( 8301 = 32)

6. Move the B reg to accumulator (A = 37h)

7. Divide the accumulator with 0Ah (37/0A ( A=05 and B = 05 )

8. Add the accumulator with 30h

9. Move the accumulator to 8302h(8302 = 35)

10. Move B reg to Accumulator.

11. Add the accumulator with 30h

12. Move the accumulator to 8303h(8303 = 35)

13. Stop the program.

Page 35: Micro Controller Lab Manual

34

Page 36: Micro Controller Lab Manual

35

Program: HEX to ASCII conversion

INPUT:

OUTPUT: Result Thus the assembly language program was written to convert the hexadecimal value into its equivalent ASCII value and it was executed successfully.

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

HLT

MOV MOVX MOV DIV ORL INC MOV MOV MOV DIV ORL INC MOVX MOV ORL INC MOVX SJMP

DPTR,#8300h A, @DPTR B,#64h A,B A, #30h DPTR @DPTR,A A,B B, #0Ah A, B A, #30h DPTR @DPTR,A A,B A, #30H DPTR @DPTR, A HLT

Memory address Data

8300 HEX Data

Memory address Data

8301 ASCII Data

8302 ASCII Data

8303 ASCII Data

Page 37: Micro Controller Lab Manual

36

Flowchart: Program for Port1 Pins used as Input and Outputs

Move the Data 0Fh to Port1

Read the P1.0 and P1.1 switches

Move the OR Output to ACC.4 Move the AND output to ACC.6

Move the OR Output to ACC.5 Move the AND output to ACC.7

Move A Reg Data to Port1

START

Stop

OR the P1.0 and P1.1 OR the P1.0 and P1.1

Complement the output Complement the output

Page 38: Micro Controller Lab Manual

37

EX. NO: 10 Program using I/O pins in Port 1

Aim: Write a program to use the Port pins P1.0 and P1.1 as input, P1.4, P1.5, P1.6 and P1.7 are output. Objective: Write a program to take the P1.0 and P1.1 as input of logic gates and P1.4, P1.5, P1.6 and P1.7are the output of OR, NOR, AND, and NAND gates. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Start the Program 2. Send the 0Fh data to Port1. This make the LSB of port1 as input

port. 3. Read the Port1 and move the data to Accumulator. 4. Take the Last two LSB of accumulator and do the OR and AND

operations and move the result to Acc.4 and Acc.6 5. Complement the result of Acc.4, Acc.6 and store in Acc.5,

Acc.7 6. Move the accumulator to P1 register. 7. Stop the program.

Page 39: Micro Controller Lab Manual

38

Program: Use the P1 port as input and output pins

TABULATION:

SL NO

INPUT OUTPUT

A P1.0

B P1.1

OR P1.4

NOR P1.5

AND P1.6

NAND P1.7

1 0 0 0 1 0 1

2 0 1 1 0 0 1

3 1 0 1 0 0 1

4 1 1 1 0 1 0

Result:

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

HLT

MOV MOV MOV ORL MOV CPL MOV MOV ANL MOV CPL MOV ORL MOV SJMP

P1, #0Fh A, P1 C, ACC.0 C, ACC.1 ACC.4, C C ACC.5,C C, ACC.0 C, ACC.1 ACC.6, C C ACC.7, C A, 90h 90h,A HLT

Make the P1 LSB as input ports

Page 40: Micro Controller Lab Manual

39

Thus the assembly Language program for to use the Port1 as input and output pins are written and executed successfully.

EX. NO: 11 Timer 0 as used a counter

Aim: Write a program to use the TIMER 0 as a counter Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Start the Program. 2. Set the data pointer to point the LED bar graph. 3. Set the Timer 0 using TMOD register. 4. If you get the T0 pin goes to low then, increase the LED bar graph display. 5. Stop the program.

TMOD (06h)

D7 D6 D5 D4 D3 D2 D1 D0

Gate C/T M1 M0 Gate C/T M1 M0

0 0 0 0 0 1 1 0

Timer 1 Timer 0

1. Gate: Gate bit is high while INTRx pin is high and TRx bit is set.

2. C/T: Select Counter or Timer. 1 – counter / 0 – Timer 3. M1 and M0 give the Mode of the timer.

0 0 - mode 0 – 13 bit timer. 0 1 - mode1 - 16 bit timer 1 0 - mode 2 – 8 bit Auto reload timer. 1 1 - mode 3 – Split timer mode.

TCON (Bit Addressable)

D7 D6 D5 D4 D3 D2 D1 D0

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

1. TF0/TF1 - Timer 0 and Timer 1 overflow flag. Cleared by

hardware. 2. TR0/TR1 - Timer 0 and Timer 1 Run control bit. 3. IE0/IE1 - External Interrupt 0/1flag. 4. IT0/IT1 - Timer0/1 Interrupt flag

Page 41: Micro Controller Lab Manual

40

Program: Timer 0 used as a counter

Result: Thus the program for counter using timer was written and executed successfully.

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

Next L1

MOV MOV MOV SETB SETB MOV MOVX JNB CLR CLR SJMP

DPTR, #0A004h TMOD, #06h TH0, #00h P3.4 TR0 A, TL0 @DPTR,A TF0, L1 TR0 TF0 Next

Page 42: Micro Controller Lab Manual

41

EX. NO: 12 Program using Interrupt Aim: Write a program using EX0 interrupt function. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

Algorithm:

1. Start the program. 2. Set the IE register as 81h

EA - ET2 ES ET1 EX1 ET0 EX0 1 0 0 0 0 0 0 1

3. This will enable the interrupt and set the external zero interrupt. 4. The reset of the programs are written to work the four LEDs on

Port 1 light up like a level indicator. Once is complete the level then it start from the zero level.

5. The program continuously works on the LEDs which are connected on the P1, once it gets the external interrupt from the switch, and then it will do the same work on the LED BAR and return back to the LEDs.

Page 43: Micro Controller Lab Manual

42

Program: Program using interrupt

Memory address Hex. code Label

Assembly Codes Comments

Mnemonics Operend(s) 8200 8002 8300

L1 L3 L2 Calc Delay D3 D2 D1

MOV MOV MOV CLR MOVX LCALL CJNE RETI MOV SETB MOV MOV CLR MOV LCALL CJNE LJMP LCALL ADD INC XCH RL XCH RET MOV MOV MOV DJNZ DJNZ DJNZ RET

DPTR, 0A004h B, #01h R0, #00h A @DPTR, A Calc R0,#09H,L1 IE,#81h IT0 B,#10h R4, #00h A P1, A calc R4,#05H,L2 L3 Delay A,B R0 A,B A A,B R1, #0FFh R2, #0FFh R3, #10h R3,D1 R2,D2 R1,D3

Page 44: Micro Controller Lab Manual

43

Result: Thus the program for interrupt was written and executed successfully.

Program - 13 INTERFACING 4 X 4 KEYBOARD

Aim:

To interface the 4 x 4 matrix keyboard with the 89C51 microcontroller and to verify

the output.

Apparatus Required: No Name Quantity 1 Microcontroller kit 1 2 4x4 matrix keyboard 1

Algorithm: 1. Load the DPTR with address 8400h where data is stored.

2. Move the data to A register and R5 register.

3. Eliminate lower nibble and swap it that means higher nibble to lower nibble.

4. Compare with OAh,if data is larger than OAh,add 37h with data and move into R6 register. If data is smaller than OAh,add 30h with data and move into R6 register.

5. Store the result in memory location 8401 and 8402 from R6 and R4 register.

6. Halt the program execution.

Procedure:

1. Connections are made as per the diagram shown.

2. Enter the program in the microcontroller kit and execute it.

3. Press any key in the keyboard and execute it again.

4. Verify the result in seven segment LED display.

Page 45: Micro Controller Lab Manual

44

Program: 4X4 Array Key Board Interfacing

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

START SCAN K1 K2 K3

MOV MOV MOVX MOV MOV MOV MOV MOV MOV MOVX NOP MOVX ANL CJNE MOV RL MOV MOV ADD MOV DJNZ SJMP SETB RRC JC MOV ADD MOV MOVX SJMP INC SJMP

DPTR,#A003h A, #81h @DPTR,A R7, #04h R6, #EEh R5, #00h R4,#00h DPTR, #A002h A,R6 @DPTR,A @DPTR,A A, #0Fh A, 0Fh,0Bh A, R6 A R6,A A, R5 A, #04h R5,A R7, EEh(SCAN) E1(Start) C A 08(K3) A,R5 A,R4 DPTR, #A004h @DPTR,A D5(INT) R4 F2(K2)

Page 46: Micro Controller Lab Manual

45

THEORY: In 4*4 keyboard, there are 4 rows and 4 column lines. In the intersection of row and columns, the keys are wired. The row lines are called scan lines and the column lines are called return lines. In the board , PC0-PC3 are used as row lines (input port) and PC4-PC7 are used as column lines(output port).The column lines are read inside the controller through port. Normally, column lines are tied with 5V and hence they will be in 1 level. Then the row lines are given 0 level one by one .At the instant, any key is pressed in that row, 0 level is transferred to the column line. It is read inside as kept input. Now row lines and column lines generate the key code. Result: Thus the 4 x 4 matrix keyboard was interfaced with 89C51 microcontroller and its output was verified.

Page 47: Micro Controller Lab Manual

46

Page 48: Micro Controller Lab Manual

47

Program -14 INTERFACING OF LCD DISPLAY

Aim:

To interface the LCD display with 89C51 microcontroller and to verify data on LCD display.

Objectives: Display Alphabet character in the LCD using micro controller. Apparatus Required:

No Name Quantity 1 Microcontroller kit 1 2 LCD display 1

Procedure:

1. Connect the LCD display interface board as required.

2. Enter the program and execute it.

3. The output will be displayed on two LCD display.

Page 49: Micro Controller Lab Manual

48

Program: Display the MSP character in the LCD

Program: Subroutine for WR_Cmd

Program: Subroutine for WR_DATA

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

MOV MOV MOVX MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL SJMP

A, #80h DPTR, #A003h @DPTR,A A, #38h WR_CMD DELAY A,#0Eh WR_CMD DELAY A,#01h WR_CMD DELAY A,”M” WR_DATA DELAY A,”S” WR_DATA DELAY A,”P” WR_DATA DELAY HLT

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

MOV MOVX INC MOV MOVX MOV MOVX RET

DPTR, #A000h @DPTR,A DPTR A, #04h @DPTR,A A, #00h @DPTR,A

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

MOV MOVX INC MOV MOVX MOV MOVX RET

DPTR, #A000h @DPTR,A DPTR A, #05h @DPTR,A A, #01h @DPTR,A

Page 50: Micro Controller Lab Manual

49

Program: Delay Subroutine

Result: Thus an assembly language program was written to interface LCD display with 89 C 51 micro controller and to verify data on LCD display and it was executed.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

C2: C1:

MOV MOV DJNZ DJNZ RET

R3, #10h R4, #FFh R4, C1 R3, C2

Page 51: Micro Controller Lab Manual

50

Page 52: Micro Controller Lab Manual

51

Program -15 INTERFACING SEVEN SEGMENT LED DISPLAY

Aim: To interface two seven segment LED display in 89C51 microcontroller and to

verify datas on LED display. Objective: Display a number in LED display using microcontroller.

Apparatus Required:

No Name Quantity 1 Microcontroller kit 1

2 Keyboard 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.

Page 53: Micro Controller Lab Manual

52

Page 54: Micro Controller Lab Manual

53

Memory address

Data 7 segment display

8210 821F

Result: Thus an assembly language program was written to interface two seven segment LED display with 89 C 51 micro controller and it was executed.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

C2: C1:

MOV MOV MOVX MOV MOV MOVX MOV MOV MOVX ACALL MOV MOV MOVX MOV MOV MOVX ACALL SJMP MOV MOV DJNZ DJNZ RET

A, #81h DPTR, #A003h @DPTR,A A, #7Fh DPTR, #A000h @DPTR,A A, #FEh DPTR, #A001h @DPTR,A DELAY A, #3Fh DPTR, #A000h @DPTR,A A, #FDh DPTR, #A001h @DPTR,A DELAY START R3, #10h R4, #FFh R4, C1 R3, C2

Page 55: Micro Controller Lab Manual

54

Page 56: Micro Controller Lab Manual

55

Program -16 SERIAL COMMUNICATION Aim: To transfer the data serially between two microcontroller kit using RS232C. Objective: To Transfer data from one microcontroller kit to another microcontroller kit serially. Apparatus Required:

No Name Quantity

1 Microcontroller kit 2

2 RS232C Interface wire 1 Procedure:

1. Connect the two microcontroller kit using RS232 cable

2. Enter the transmitter program in 1ST microcontroller kit & receiver program in 2nd

microcontroller kit.

3. First run the receiver program in kit2 and then run the transmitter program in kit1.

4. After executing the transmitter program, reset the kit and go to location 8400h

5. The transferred data’s “yes” (ASCII) value are stored from 8400h onwards in the kit2.

SCON - Register D7 D6 D5 D4 D3 D2 D1 D0

SM0 SM1 SM2 REN TB8 RB8 TI RI

0 1 0 1 0 0 0 0

1. SM0, SM1 and SM2 used for serial mode control bits

0 0 - Shift register Baud rate = f/12 - Mode 0

0 1 - 8 Bit UART, Variable Data Mode. - Mode 1 1 0 - 9 Bit UART, Fixed Data rate. - Mode 2 1 1 - 9 Bit UART, Variable Data Mode - Mode 3

2. REN – Receiver enable. 3. TB8 – Select the transmitter is 8bit or 9bit mode 4. RB8 – Select the receiver is 8bit or 9 bit mode

S.no Character ASCII CODE

1 y 79

2 e 65 3 s 73 4 # 23

Page 57: Micro Controller Lab Manual

56

5. TI – Transmitter interrupt Flag 6. RI – Receiver interrupt Flag.

If SCON is 50h, then it set the mode 1 serial communication and it enables the receiver. TMOD (20h)

D7 D6 D5 D4 D3 D2 D1 D0

Gate C/T M1 M0 Gate C/T M1 M0

0 0 1 0 0 0 0 0

Timer 1 Timer 0

1. Gate: Gate bit is high while INTRx pin is high and TRx bit is set.

2. C/T: Select Counter or Timer. 1 – counter / 0 – Timer 3. M1 and M0 give the Mode of the timer.

0 0 - mode 0 – 13 bit timer. 0 1 - mode1 - 16 bit timer 1 0 - mode 2 – 8 bit Auto reload timer. 1 1 - mode 3 – Split timer mode.

Page 58: Micro Controller Lab Manual

57

Program: Transmitter Program

Program: Receiver Program

Programming the 8051 to transfer data serially

In programming the 8051 to transfer character bytes serially, the following steps must

be taken.

1. The TMOD register is loaded with the value 20H, indicating the use of timer I in mode

2 (8-bit auto-reload) to set the baud rate.

2. The THI is loaded with one of the values in Table to set the baud rate 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.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

HLT

MOV MOV MOV SET MOV ACALL MOV ACALL MOV ACALL MOV ACALL SJMP MOV JNB CLR RET

TMOD, #20h TH1, #FDh SCON,#50h TR1 A, #”Y” 1D[TRANS] A, #”E” 1D[TRANS] A, #”S” 1D[TRANS] A, #”#” 1D[TRANS] HLT SBUF,A TI, FDh TI

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

L1:

MOV MOV MOV MOV SET JNB MOV MOVX INC SJMP

DPTR, #8400 TMOD, #20h TH1, #FDh SCON,#50h TR1 RI,#FDh[L1] A, SBUF @DPTR,A DPTR L1

Page 59: Micro Controller Lab Manual

58

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, xx” to see if the

character has been transferred completely.

8. Tc’ transfer the next character, go to Step 5.

Programming the 8051 to receive date serially

In the programming of the 8051 to received character bytes serially, the following steps must

be taken.

1. The TMOD register is loaded with the value 201-1, indicating the use of timer I in

mode 2 (8b1t auto-reload) to set the baud rate.

2. THI is loaded with one of the values in Table to set the baud rate

3. The SCON register is loaded with the value 5011, indicating serial mode I, where 8-bit

data is & framed with start and stop bits.

4. TR1 Is set to I to start timer 1.

5. RI is cleared with the “CLR RI” Instruction.

6. The RI flag bit is monitored with the use of the Instruction” JNC RI, XX” 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.

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

Page 60: Micro Controller Lab Manual

59

Page 61: Micro Controller Lab Manual

60

Page 62: Micro Controller Lab Manual

61

Page 63: Micro Controller Lab Manual

62

Program -17 DC MOTOR CONTROL

Aim:

To interface the DC motor with 89C51 microcontroller and to rotate it in forward and reverse direction.

Objective: To Control the operation of dc motor using microcontroller Apparatus Required:

No Name Quantity 1 Microcontroller kit 1

2 DC motor Interface board 1

Procedure:

1. Connect the interface circuit as shown in fig.

2. Enter the program.

3. Switch ON the board ,the motor rotates in forward direction.

4. Place the forward reverse switch to reverse direction.It reverses.

5. Stop the program execution.

Program: Dc motor interfacing

Page 64: Micro Controller Lab Manual

63

Theory:

1. IC L293 D is a driver IC which how 2 inputs- input 1, input 2, the inputs are sent the respective outputs normally output1, output 2. It is possible only when enable pin is in level 1.

2. P 1.0 is given to input 1 p1.1 is given to input 2 for forward direction input 2 is grounded and pulse is given in input 1 for reverse direction input 1 is grounded and pulse is given to input 2.

3. Enable pin is connected to p1.2. by sending level 1 in p 1.2. The input, input 1, input 2, are sent to output 1, output2, The motor is connected to the output 1 & output 2.

4. ON/OFF switch is connected to p1.6. It is checked in the program, If it is 1 level then only the pulse input will be given.

5. Forward/reverse switch is connected to p1.7 Result:

Thus the assembly language program was written to interface DC motor with 89c51 micro controller and to rotate is in either direction & it was executed.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

MAIN L1: FwRD: REV:

MOV MOV MOVX MOV MOV JNB JB MOV MOV MOVX SJMP MOV MOV MOVX SJMP

DPTR, #A003 A, #91h @DPTR,A DPTR, #A002 A, @DPTR ACC.0, MAIN ACC.1, REV DPTR, #A001h A, #05h @DPTR,A MAIN DPTR, #A001 A, #06h @DPTR,A MAIN

Page 65: Micro Controller Lab Manual

64

Page 66: Micro Controller Lab Manual

65

Program -18 INTERFACING STEPPER MOTOR

Page 67: Micro Controller Lab Manual

66

Aim:

To interface the stepper motor with 89C51 microcontroller and to rotate it in clockwise

Direction.

Objective: To Control the stepper motor using microcontroller. Apparatus Required:

No Name Quantity

1 Microcontroller kit 1

2 Stepper motor Interface card 1

Procedure:

1. Connections are made as shown in fig.

2. Enter the program and execute it.

3. Verify the result; the motor rotates in clockwise direction.

4. Stop program execution.

Winding Excitation Chart:

Step Winding1 Winding2 Winding3 Winding4 Hex.code

01 1 0 0 1 09 02 0 1 0 1 05 03 0 1 1 0 06 04 1 0 1 0 0A

Page 68: Micro Controller Lab Manual

67

Program: Stepper motor interfacing

Program: Delay Subroutine

Result:

Thus the assembly language program was written to interface stepper motor with 89c51 micro controller and to rotate is in either direction & it was executed.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

MOV MOV MOVX MOV MOV MOVX ACALL MOV MOVX ACALL MOV MOVX ACALL MOV MOVX ACALL SJMP

DPTR, #A003 A, #80h @DPTR,A DPTR, #A000h A, #09h @DPTR,A DELAY A, #05h @DPTR,A DELAY A, #06h @DPTR,A DELAY A, #0Ah @DPTR,A DELAY AGAIN

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

C2: C1:

MOV MOV DJNZ DJNZ RET

R3, #10h R4, #FFh R4, C1 R3, C2

Page 69: Micro Controller Lab Manual

68

Page 70: Micro Controller Lab Manual

69

EXTRA SYLLABUS

Program -19 INTERFACING RELAY AND PUSHBUTTON

Aim:

To interface the pushbutton switch and relay and make relay ON - OFF using pushbutton switch.

Apparatus Required:

No Name Quantity 1 Microcontroller kit 1 2 Digital interface board 1

Procedure:

1. Make the connections as per the circuit using interface card.

2. Enter the program and execute.

3. Press the pushbutton and verify the result by seeing the relay ON or OFF.

Page 71: Micro Controller Lab Manual

70

Program:

Result: Thus the program for interfacing the relay and push button to 8951 microcontroller was written and executed successfully.

Memory address

Hex. code

Label Assembly Codes Comments

Mnemonics Operend(s)

L1 CNT2 CNT1

MOV MOV MOVX MOV MOV MOVX MOVX JNC MOV MOVX MOV MOV DJNZ DJNZ LJMP

DPTR, #A003 A, #91h @DPTR,A DPTR, #A002h A, #00h @DPTR,A A, @DPTR ACC.0, L1 A, #10h @DPTR, A R1, #0Ah R0, #64h R0, CNT1 R1, CNT2 8206

Page 72: Micro Controller Lab Manual

71

Program -20 Program using DIP switches Aim:

To select addition program or a subtraction program using DIP switch.

Apparatus Required:

No Name Quantity 1 Microcontroller kit 1

Algorithm:

1. Start the program 2. Move the data1 to R0 reg and Data 2 to R1 reg. 3. Scan the Dip switches. 4. If Dip switch scanned data is 0Fh then do subtraction else do

addition operation. 5. Store the result in 8300 memory location. 6. Stop the program.

Page 73: Micro Controller Lab Manual

72

Program:

Result: Thus the program using DIP switch was written and executed successfully.

Memory address

Hex. code Label

Assembly Codes Comments Mnemonics Operend(s)

HLT ADD HLT

MOV MOV MOVX MOV MOVX CJNE MOV SUBB MOVX SJMP MOV ADD MOVX SJMP

R0, #Data1 R1, #Data2 DPTR, #0A00Ch A, @DPTR DPTR, #8300h A, #0Fh,add A, R0 A,R1 @DPTR,A HLT A, R0 A,R1 @DPTR,A HLT

Page 74: Micro Controller Lab Manual

73

Mnemonics, arranged by Function: Arithmatic Function:

Page 75: Micro Controller Lab Manual

74

Page 76: Micro Controller Lab Manual

75

Page 77: Micro Controller Lab Manual

76

Page 78: Micro Controller Lab Manual

77

Page 79: Micro Controller Lab Manual

78

Internal RAM and SRF addresses

Page 80: Micro Controller Lab Manual

79

Internal RAM and SRF addresses.

Page 81: Micro Controller Lab Manual

80

OPCODE SHEET

Page 82: Micro Controller Lab Manual

81

Page 83: Micro Controller Lab Manual

82

Page 84: Micro Controller Lab Manual

83

Page 85: Micro Controller Lab Manual

84

Page 86: Micro Controller Lab Manual

85