Sunteți pe pagina 1din 86

AN INSTITUTION ACCREDITED BY NBA, NEWDELHI Sivagamipuram, Pavoorchatram - 627808, Tirunelveli District, TamilNadu.

E-mail: mspvlp@dataone.in

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

INDEX
Sl. No Description Software Experiments 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Introduction to 89c51 Microcontroller Kit 8 Bit Addition and Subtraction Multi-Byte Addition Multiplication of Two Numbers Find the Largest Number in a array of numbers Arranging the array of numbers in ascending order BCD to Hexadecimal conversion Hexadecimal to BCD conversion Hexadecimal to ASCII code conversion Program using I/O pins in Port 1 Counter using Timer Program using Interrupt Hardware Experiments Matrix Keyboard interfacing with 89C51 Seven segment Display interfacing with 89C51 LCD interfacing with 89C51 Data transfer between two microcontroller kits using serial port Control the DC Motor using 89C51 Control the Stepper Motor using 89C51 Extra Syllabus Program interfacing relay and Pushbutton to the 8951 controller Program to using DIP switches 37 40 43 46 51 54 57 59 2 5 9 12 15 18 22 25 28 31 33 35 Page no

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

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 0 0 L H 0 1 L H 1 0 L H 0 0 H L 0 1 H L 1 0 H L 1 1 H L x x x x Control word of 8255

/CS L L L L L L L H

Action Read the content of port A Read the content of port B Read the content of port C Write to the port A Latch Write to the port B Latch Write to the port C Latch Write to the control regiser Data bus to high impedence Group B Mode 00 M0 01 M1 10 M2 Port B Address 0 Output 1 Input Upper Port C PC3 PC0 0 Output 1 Input

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

Group A

FLOWCHART:

Addition of two 8 bit datas with out carry START

Move the Data1 to Acc. Register

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

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

Stop FLOWCHART: Addition of two 8 bit datas with carry START

Move the Data1 from Mem.Location 8250 to B reg Move the Data2 from mem.Location 8251 to Acc. reg Add Acc. Reg with B Reg. Result stored in Acc. Reg Move the Result from Acc. Reg to Memory Location 8300h

Move the Data 00 to 8301h Mem.Location

NO

Check: C=1

Yes Move the Data 01 to 8301h Mem.Location

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

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 1 Microcontroller kit 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.

Quantity 1

Program: Addition of two 8 bit data without carry Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV A, #Data1 ADD A, #Data2 MOV DPTR, #8300h MOVX @DPTR, A SJMP HLT Comments

HLT Output: Memory address 8300 Data

Program: Addition of two 8 bit datas with carry Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) 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 OUTPUT: Data Memory Address 8300 8301 Data Data Carry Comments

HLT INPUT: Memory address 8250 8251

Program: Subtract a small number from a large number Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) MOV SUB MOV MOVX SJMP A, #Data1 A, #Data2 DPTR, #8300h @DPTR, A HLT Comments

HLT Output: Memory address 8300

Data

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

Flowchart: Multi -Byte addition with carry

START

Move the Lower order byte of Data1 to Acc. Reg Add Acc. Reg with Lower order byte of Data2

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

Move the Higher order byte of Data1 to Acc. Reg Add Acc. Reg and Higher order byte of Data2 with carry

Move the Higher order byte result from Acc. Reg to the Memory location 8301h Move the Data 00 to 8302h Mem.Location

NO

Check: C=1

Yes Move the Data 01 to 8302h Mem.Location

Stop

EX. NO: 3 Aim:

Multi-Byte Addition

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: No 1 Name Quantity Microcontroller kit 1

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.

10

Program: Multi-Byte Addition. Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) CLR C MOV A, #LSB Data1 ADD A, #LSB Data2 MOV DPTR,#8300h MOVX @DPTR, A MOV A, #MSB Data1 ADDC A, #MSB Data2 INC DPTR MOVX @DPTR,A INC DPTR MOVX @DPTR,#00h JNC HLT MOVX @DPTR,#01h SJMP HLT Comments

HLT Output: Memory address 8300 8301 8302

Data Lower order byte Higher order byte Carry

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

11

FLOWCHART:

Multiplication of two 8 bit numbers. START

Move the Data1 from Mem.Location 8250 to B reg Move the Data2 from mem.Location 8251 to Acc. reg Multiply Acc. Reg with B Reg. Move the Result from Acc. Reg to Memory Location 8300h

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

12

EX. NO: 4 Aim:

8 Bit Multiplication

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 1 Microcontroller kit 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.

Quantity 1

13

14

Program: Two 8 Bit Multiplication Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) 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 Comments

HLT Output: Memory address 8300 8301

Data Lower order byte Higher order byte

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

15

FLOW CHART: Find the Largest number from an array of numbers START

Move the Total no of Data to R0. Reg from8250 memory location Increment Data Pointer/ Decrement R0 Move the I data to R1 register Increment Data Pointer/ Decrement R0

Move the Next data to Acc register Subtract R1 Reg from Acc Reg NO Check: C=1 i Yes Exchange the R1Data and subtracted Data

No

Check R0 = 0

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

Stop

16

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 1 Microcontroller kit

Quantity 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.

17

18

Program: Find the Largest number from an Array. Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) MOV DPTR,#8250h MOVX A, @DPTR MOV R0,A INC DPTR DEC R0 MOVX A, @DPTR MOV R1,A INC DPTR DEC R0 MOVX A,@DPTR SUBB A,R1 JNC L1 MOVX A,@DPTR XCH A,R1 MOV A,R0 JNZ L2 MOV A,R1 MOV DPTR,#8300h MOVX @DPTR, A SJMP HLT Comments

L2

L1

HLT

Input: Memory address 8250 8251 8252 8253 8254 8255 Output: Memory address 8300 Data Large Number Data 05 (No of datas) Data1 Data2 Data3 Data4 Data5

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

19

FLOW CHART: Arrange the array of numbers in ascending order

START

Move the Total no of Data to R0. Reg from8250 memory location Increment Data Pointer/ Decrement R0 Move the I data to R1 register Increment Data Pointer/ Decrement R0

Move the Next data to Acc register Subtract R1 Reg from Acc Reg NO Check: C=1 i Yes Exchange the R1Data and subtracted Data

No Check R0 = 0

Stop

20

EX. NO: 6 Aim:

Arrange the given 8 bit array in Ascending Order

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

Apparatus Required: No 1 Name Microcontroller kit Quantity 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

21

Program: Find the Largest number from an Array.

Memory address

Hex. code

Label

L1

L2

HLT INPUT: Memory address 8300 8301 8302 8303 8304 8305

Assembly Codes Mnemonics Operend(s) MOV DPTR,#8300h MOVX A, @DPTR MOV R0,A INC DPTR DEC R0 MOVX A, @DPTR MOV R1,A INC DPTR DEC R0 MOVX A,@DPTR SUBB A,R1 JNC L2 MOVX A,@DPTR XCH A,R1 DEC DPTR DEC DPTR MOVX @DPTR,A INC DPTR MOV A,R1 MOVX @DPTR,A MOV A,R0 JNZ L1 SJMP HLT

Comments

Data 05 (No of datas) Data1 Data2 Data3 Data4 Data5

OUTPUT: Memory address 8300 8301 8302 8303 8304 8305 Data 05 (No of datas) Data1 Data2 Data3 Data4 Data5

22

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

23

FLOW CHART: BCD to Hex conversion

START

Move the Data to Acc. Reg from8300 memory location Move the MSB of Acc to R1 Reg Move the LSB of Acc to R2 Reg Multiply the MSB by 0Ah And store the result in Acc. reg

ADD the Acc with LSB Move the HEX output to 8300 Memory location

Stop

24

EX. NO: 7

BCD TO HEX CONVERSON

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

Quantity 1

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

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

25

26

Program: BCD to Hex conversion

Memory address

Hex. code

Label

HLT INPUT: Memory address 8300

Assembly Codes Mnemonics Operend(s) MOV DPTR,#8300h MOVX A, @DPTR MOV R5,A ANL A, #F0h SWAP A MOV R1,A MOV A,R5 ANL A, #0Fh MOV R2,A MOV A,R1 MOV B, #0Ah MUL A,B ADD A,R2 INC DPTR MOVX @DPTR, A SJMP HLT

Comments

Data BCD Data

OUTPUT: Memory address 8301 Data HEX Data

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

27

FLOW CHART: HEX to BCD conversion

START

Move the Data to Acc. Reg from8300 memory location Divide the Acc. Reg by 64h Move the Data from Acc. Reg to 8301 memory location

Move the Data from B reg to Acc. Reg Divide the Acc. Reg by 0Ah Change the Position of MSB and LSB of A Reg Add A reg with B reg

Move the Data from Acc. Reg to 8302 memory location

Stop

28

EX. NO: 8

HEX TO BCD CONVERSION

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

Apparatus Required: No 1 Name Quantity

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.

29

30

Program: HEX to BCD conversion Memory address Hex. Label code Assembly Codes Mnemonics Operend(s) MOV DPTR,#8300h MOVX A, @DPTR MOV B,#64h DIV A,B INC DPTR MOV @DPTR,A MOV A,B MOV B, #0Ah DIV A, B SWAP A ADD A,B INC DPTR MOVX @DPTR, A SJMP HLT Comments

HLT INPUT:

Memory address 8300

Data HEX Data

OUTPUT: Memory address 8301 8302 Data Higher BCD Data Lower BCD Data

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

31

FLOW CHART: HEX to ASCII conversion

START

Move the Data to Acc. Reg from8300 memory location Divide the Acc. Reg by 64h and Add the A Reg with 30h Move the Data from Acc. Reg to 8301 memory location

Move the Data from B reg to Acc. Reg Divide the Acc. Reg by 0Ah and Add the A Reg with 30h Move the Data from Acc. Reg to 8302 memory location

Move the Data from B Reg to A Reg Add the A Reg with 30h Move the Data from Acc. Reg to 8303 memory location

Stop

32

EX. NO: 9

Hexadecimal to ASCII conversion

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

Apparatus Required: No 1 Name Microcontroller kit Quantity 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.

33

34

Program: HEX to ASCII conversion

Memory address

Hex. code

Label

HLT INPUT: Memory address 8300

Assembly Codes Mnemonics Operend(s) MOV DPTR,#8300h MOVX A, @DPTR MOV B,#64h DIV A,B ORL A, #30h INC DPTR MOV @DPTR,A MOV A,B MOV B, #0Ah DIV A, B ORL A, #30h INC DPTR MOVX @DPTR,A MOV A,B ORL A, #30H INC DPTR MOVX @DPTR, A SJMP HLT

Comments

Data HEX Data

OUTPUT: Memory address 8301 8302 8303 Data ASCII Data ASCII Data ASCII Data

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

35

Flowchart: Program for Port1 Pins used as Input and Outputs START

Move the Data 0Fh to Port1 Read the P1.0 and P1.1 switches

OR the P1.0 and P1.1

OR the P1.0 and P1.1

Move the OR Output to ACC.4

Move the AND output to ACC.6

Complement the output Move the OR Output to ACC.5

Complement the output Move the AND output to ACC.7

Move A Reg Data to Port1 Stop

36

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 1 Name Quantity

Microcontroller kit 1

Algorithm: 1. 2. port. 3. 4. Read the Port1 and move the data to Accumulator. 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. Start the Program Send the 0Fh data to Port1. This make the LSB of port1 as input

37

Program: Use the P1 port as input and output pins Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) 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 Comments

Make the P1 LSB as input ports

HLT TABULATION: SL NO 1 2 3 4 INPUT A P1.0 0 0 1 1

OUTPUT B P1.1 0 1 0 1 OR P1.4 0 1 1 1 NOR P1.5 1 0 0 0 AND P1.6 0 0 0 1 NAND P1.7 1 1 1 0

Result:

38

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

EX. NO: 11 Aim:

Timer 0 as used a counter

Write a program to use the TIMER 0 as a counter

Apparatus Required: No 1 Name Microcontroller kit Quantity 1

Algorithm: 1. 2. 3. 4. 5. TMOD (06h) D7 Gate 0

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

D6 C/T 0

D5 M1 0

D4 M0 0

D3 Gate 0

D2 C/T 1

D1 M1 1

D0 M0 0

Timer 1 1. set. 2. 3. 0 0 1 1 0 1 0 1

Timer 0 Gate: Gate bit is high while INTRx pin is high and TRx bit is C/T: Select Counter or Timer. 1 counter / 0 Timer M1 and M0 give the Mode of the timer. - mode 0 13 bit timer. - mode1 - 16 bit timer - mode 2 8 bit Auto reload timer. - mode 3 Split timer mode.

TCON (Bit Addressable) D7 D6 TF1 1. hardware. 2. 3. 4. TR1

D5 TF0

D4 TR0 TF0/TF1

D3 IE1

D2 IT1

D1 IE0

D0 IT0

- Timer 0 and Timer 1 overflow flag. Cleared by

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

39

Program: Timer 0 used as a counter Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) 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 Comments

Next L1

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

40

EX. NO: 12

Program using Interrupt

Aim: Write a program using EX0 interrupt function.

Apparatus Required: No Name 1 Microcontroller kit

Quantity 1

Algorithm: Start the program. 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. 1. 2.

41

Program: Program using interrupt Memory Hex. code Label address 8200 8002 8300 L1 Assembly Codes Mnemonics Operend(s) 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 Comments

L3

L2

IE,#81h IT0 B,#10h R4, #00h A P1, A calc R4,#05H,L2 L3 Delay A,B R0 A,B A A,B

Calc

Delay D3 D2 D1

R1, #0FFh R2, #0FFh R3, #10h R3,D1 R2,D2 R1,D3

42

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

Program - 13 Aim:

INTERFACING 4 X 4 KEYBOARD

To interface the 4 x 4 matrix keyboard with the 89C51 microcontroller and to verify the output. Apparatus Required: No 1 2 Name Microcontroller kit 4x4 matrix keyboard Quantity 1 1

Algorithm: 1. 2. 3. lower nibble. 4.

Load the DPTR with address 8400h where data is stored. Move the data to A register and R5 register. Eliminate lower nibble and swap it that means higher nibble to 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. Store the result in memory location 8401 and 8402 from R6 and R4 register. Halt the program execution.

5. 6. 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.

43

Program: 4X4 Array Key Board Interfacing Memory address Hex. code Assembly Codes Mnemonics Operend(s) MOV DPTR,#A003h MOV A, #81h MOVX @DPTR,A START MOV R7, #04h MOV R6, #EEh MOV R5, #00h MOV R4,#00h MOV DPTR, #A002h SCAN MOV A,R6 MOVX @DPTR,A NOP MOVX @DPTR,A ANL A, #0Fh CJNE A, 0Fh,0Bh MOV A, R6 RL A MOV R6,A MOV A, R5 ADD A, #04h MOV R5,A DJNZ R7, EEh(SCAN) SJMP E1(Start) K1 SETB C K2 RRC A JC 08(K3) MOV A,R5 ADD A,R4 MOV DPTR, #A004h MOVX @DPTR,A SJMP D5(INT) K3 INC R4 SJMP F2(K2) Label Comments

44

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.

45

46

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.

47

Program: Display the MSP character in the LCD Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV A, #80h MOV DPTR, #A003h MOVX @DPTR,A MOV A, #38h ACALL WR_CMD ACALL DELAY MOV A,#0Eh ACALL WR_CMD ACALL DELAY MOV A,#01h ACALL WR_CMD ACALL DELAY MOV A,M ACALL WR_DATA ACALL DELAY MOV A,S ACALL WR_DATA ACALL DELAY MOV A,P ACALL WR_DATA ACALL DELAY SJMP HLT Comments

HLT

Program: Subroutine for WR_Cmd Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR, #A000h MOVX @DPTR,A INC DPTR MOV A, #04h MOVX @DPTR,A MOV A, #00h MOVX @DPTR,A RET Comments

Program: Subroutine for WR_DATA Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR, #A000h MOVX @DPTR,A INC DPTR MOV A, #05h MOVX @DPTR,A MOV A, #01h MOVX @DPTR,A RET Comments

48

Program: Delay Subroutine Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV R3, #10h MOV R4, #FFh DJNZ R4, C1 DJNZ R3, C2 RET Comments

C2: C1:

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.

49

50

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 1 Microcontroller kit 2 Keyboard display interface

Quantity 1 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.

51

52

Memory Hex. address code

Label

Assembly Codes Mnemonics Operend(s) MOV A, #81h MOV DPTR, #A003h MOVX @DPTR,A MOV A, #7Fh MOV DPTR, #A000h MOVX @DPTR,A MOV A, #FEh MOV DPTR, #A001h MOVX @DPTR,A ACALL DELAY MOV A, #3Fh MOV DPTR, #A000h MOVX @DPTR,A MOV A, #FDh MOV DPTR, #A001h MOVX @DPTR,A ACALL DELAY SJMP START MOV MOV DJNZ DJNZ RET R3, #10h R4, #FFh R4, C1 R3, C2

Comments

C2: C1:

Memory address 8210 821F

Data

7 segment display

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.

53

54

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 1 2

Quantity

Microcontroller kit 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 datas yes (ASCII) value are stored from 8400h onwards in the kit2. S.no Character ASCII CODE 1 2 3 4 y e s # 79 65 73 23

SCON - Register D7 D6 SM0 SM1 0 1 1. 0 0 0 1 1 2. 3. 4. 1 0 1

D5 SM2 0

D4 REN 1

D3 TB8 0

D2 RB8 0

D1 TI 0

D0 RI 0

SM0, SM1 and SM2 used for serial mode control bits 0 - Shift register Baud rate = f/12 - 8 Bit UART, Variable Data Mode. - Mode 1 - 9 Bit UART, Fixed Data rate. - Mode 2 - 9 Bit UART, Variable Data Mode - Mode 3 REN Receiver enable. TB8 Select the transmitter is 8bit or 9bit mode RB8 Select the receiver is 8bit or 9 bit mode

- Mode

55

5. 6.

TI Transmitter interrupt Flag RI Receiver interrupt Flag.

If SCON is 50h, then it set the mode 1 serial communication and it enables the receiver. TMOD (20h) D7 Gate 0 D6 C/T 0 D5 M1 1 D4 M0 0 D3 Gate 0 D2 C/T 0 D1 M1 0 D0 M0 0

Timer 1 1. set. 2. 3. 0 0 1 1 0 1 0 1

Timer 0 Gate: Gate bit is high while INTRx pin is high and TRx bit is C/T: Select Counter or Timer. 1 counter / 0 Timer M1 and M0 give the Mode of the timer. - mode 0 13 bit timer. - mode1 - 16 bit timer - mode 2 8 bit Auto reload timer. - mode 3 Split timer mode.

56

Program: Transmitter Program Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV TMOD, #20h MOV TH1, #FDh MOV SCON,#50h SET TR1 MOV A, #Y ACALL 1D[TRANS] MOV A, #E ACALL 1D[TRANS] MOV A, #S ACALL 1D[TRANS] MOV A, ## ACALL 1D[TRANS] SJMP HLT MOV JNB CLR RET SBUF,A TI, FDh TI Comments

HLT

Program: Receiver Program Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR, #8400 MOV TMOD, #20h MOV TH1, #FDh MOV SCON,#50h SET TR1 JNB RI,#FDh[L1] MOV MOVX INC SJMP A, SBUF @DPTR,A DPTR L1 Comments

L1:

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 transfer 3. The SCON register is loaded with the value 50 H, indicating serial mode 1, where an 8bit data is framed with start and stop bits. serial data

57

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.

58

59

60

61

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 1 Microcontroller kit 2 DC motor Interface board

Quantity 1 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

62

Memory address

Hex. code

Label

MAIN L1:

FwRD:

Assembly Codes Mnemonics Operend(s) MOV DPTR, #A003 MOV A, #91h MOVX @DPTR,A MOV DPTR, #A002 MOV A, @DPTR JNB ACC.0, MAIN JB ACC.1, REV MOV DPTR, #A001h MOV A, #05h MOVX @DPTR,A SJMP MAIN MOV MOV MOVX SJMP DPTR, #A001 A, #06h @DPTR,A MAIN

Comments

REV:

Theory: 1.

2.

3. 4. 5.

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

63

64

Program -18

INTERFACING STEPPER MOTOR

65

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 1 2 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 01 02 03 04 Winding1 1 0 0 1 Winding2 0 1 1 0 Winding3 0 0 1 1 Winding4 1 1 0 0 Hex.code 09 05 06 0A Name Quantity Microcontroller kit 1 Stepper motor Interface card 1

66

Program: Stepper motor interfacing Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR, #A003 MOV A, #80h MOVX @DPTR,A MOV DPTR, #A000h 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 AGAIN Comments

Program: Delay Subroutine Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV R3, #10h MOV R4, #FFh DJNZ R4, C1 DJNZ R3, C2 RET Comments

C2: C1:

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.

67

68

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 1 2 Name Microcontroller kit Digital interface board Quantity 1 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.

69

Program: Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR, #A003 MOV A, #91h MOVX @DPTR,A MOV DPTR, #A002h MOV A, #00h MOVX @DPTR,A MOVX A, @DPTR JNC ACC.0, L1 MOV A, #10h MOVX @DPTR, A MOV R1, #0Ah MOV R0, #64h DJNZ R0, CNT1 DJNZ R1, CNT2 LJMP 8206 Comments

L1

CNT2 CNT1

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

70

Program -20

Program using DIP switches

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

Apparatus Required: No 1 Name Microcontroller kit Quantity 1

Algorithm: 1. 2. 3. 4. addition operation. 5. 6.

Start the program Move the data1 to R0 reg and Data 2 to R1 reg. Scan the Dip switches. If Dip switch scanned data is 0Fh then do subtraction else do Store the result in 8300 memory location. Stop the program.

71

Program: Memory address Hex. code Label Assembly Codes Mnemonics Operend(s) MOV R0, #Data1 MOV R1, #Data2 MOVX DPTR, #0A00Ch MOV A, @DPTR MOVX DPTR, #8300h CJNE A, #0Fh,add MOV A, R0 SUBB A,R1 MOVX @DPTR,A SJMP HLT MOV A, R0 ADD A,R1 MOVX @DPTR,A SJMP HLT Comments

HLT ADD

HLT

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

72

Mnemonics, arranged by Function:


Arithmatic Function:

73

74

75

76

77

Internal RAM and SRF addresses

78

Internal RAM and SRF addresses.

79

OPCODE SHEET

80

81

82

83

84

85

S-ar putea să vă placă și