P. 1
MICROCONTROLLER LAB MANUAL

MICROCONTROLLER LAB MANUAL

|Views: 333|Likes:
Published by Zarrar Haider

More info:

Published by: Zarrar Haider on Nov 16, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/13/2015

pdf

text

original

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

0

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

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

2

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

3

Reg to Memory Location 8300h Move the Data 00 to 8301h Mem.Location Stop Same as draw the Flow chart for subtraction in your observation. Reg and the result stored in Acc. Register Add Data2 with Acc. Reg Move the Result from Acc.Location 8251 to Acc. Reg with B Reg. Result stored in Acc.FLOWCHART: Addition of two 8 bit datas with out carry START Move the Data1 to Acc.Location 8250 to B reg Move the Data2 from mem.Location NO Check: C=1 i Yes Move the Data 01 to 8301h Mem. 4 . Reg to Memory Location 8300h Stop FLOWCHART: Addition of two 8 bit datas with carry START Move the Data1 from Mem. reg Add Acc. Reg Move the Result from Acc.

Add the B Reg with the accumulator. Quantity 1 5 . 5. 2. Add the Data2 with the accumulator. Move the Data2 from 8251 Memory location to Acc. 3. 2. 5. then move 01 to 8301 memory location 9. Move the Data1 from 8250 Memory location to B Register. Move the Data1 to the accumulator. Clear the 8301 memory location 8. the result is in accumulator. Addition with carry 1. NO: 2 8 BIT Addition and Subtraction Aim: To write and execute an assembly language program to multiply the given two 8 bit numbers. 7. Set the DPTR as 8300 in RAM address location. Set the DPTR as 8300 in RAM address location. Same as write the algorithm for subtraction also. Stop the Program. Reg 4. Move the result which is in accumulator to the 8300 address location. Stop the Program. 4. if carry is there. 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. 3.EX. Check the carry flag. Start the Program. Move the result which is in accumulator to the 8300 address location. the result stored in accumulator. 6. 6.

#8250h A. #8300h @DPTR. A HLT A @DPTR. B DPTR. #8300h MOVX @DPTR. code Label Assembly Codes Mnemonics Operend(s) MOV MOVX MOV INC MOVX ADD MOV MOVX INC CLR MOVX JNC INC MOVX SJMP DPTR. A HLT OUTPUT: Data Memory Address 8300 8301 Data Data Carry Comments HLT INPUT: Memory address 8250 8251 6 .A DPTR A. A SJMP HLT Comments HLT Output: Memory address 8300 Data Program: Addition of two 8 bit datas with carry Memory address Hex. @DPTR B. A DPTR A @DPTR. #Data2 MOV DPTR.@DPTR A. address code Label Assembly Codes Mnemonics Operend(s) MOV A.Program: Addition of two 8 bit data without carry Memory Hex. #Data1 ADD A.

7 . #Data1 A. #8300h @DPTR.Program: Subtract a small number from a large number Memory address Hex. #Data2 DPTR. code Label Assembly Codes Mnemonics Operend(s) MOV SUB MOV MOVX SJMP A. 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.

Reg Add Acc. Reg and Higher order byte of Data2 with carry Move the Higher order byte result from Acc.Flowchart: Multi -Byte addition with carry START Move the Lower order byte of Data1 to Acc. Reg to the Memory location 8300h Move the Higher order byte of Data1 to Acc. Reg Add Acc. Reg with Lower order byte of Data2 Move the Lower order byte result from Acc.Location Stop 8 .Location NO Check: C=1 i Yes Move the Data 01 to 8302h Mem. Reg to the Memory location 8301h Move the Data 00 to 8302h Mem.

3. NO: 3 Aim: Multi-Byte Addition To write and execute an assembly language program to add two 16 bit numbers. Apparatus Required: No 1 Name Quantity Microcontroller kit 1 Algorithm: 1. 2. Move the lower order byte result data from A reg to 8300 Memory location. 6. Stop the program. 4. Objectives: Get two 16 bit datas from the starting location of 8250 then add those datas and store in the location of 8300 onwards. Add A reg. Move the first data higher order byte to A register. Start the program. if it is one move 01 data to 8302 else move 00 data to 8302. Move the higher order byte result data from A reg to 8301 Memory location. Add the second data lower order byte with A register. 9 .EX. Check the carry flag. 9. and Second higher order byte with carry flag. Move the first data lower order byte to A register. 7. 5. 8.

10 .

A MOV A. 11 . #LSB Data2 MOV DPTR.A INC DPTR MOVX @DPTR. code Label Assembly Codes Mnemonics Operend(s) CLR C MOV A. #MSB Data2 INC DPTR 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.#00h JNC HLT MOVX @DPTR. #LSB Data1 ADD A.Program: Multi-Byte Addition.#8300h MOVX @DPTR. Memory address Hex. #MSB Data1 ADDC A.

FLOWCHART: Multiplication of two 8 bit numbers. reg Multiply Acc.Location 8251 to Acc. Reg to Memory Location 8301h Stop 12 .Location 8250 to B reg Move the Data2 from mem. Move the Result from Acc. Reg to Memory Location 8300h Move the Result from B. START Move the Data1 from Mem. Reg with B Reg.

Store the lower byte result from ‘A’ register to 8300 memory location 5. NO: 4 Aim: 8 Bit Multiplication To write and execute an assembly language program to multiply the given two 8 Bit Numbers.EX. Move the multiplier to ‘B’ register (SFR with direct address FO) 3. 4. Store the higher byte result from ‘B’ register to 8301 memory location 6. Quantity 1 13 . Objectives: To multiply the give two 8 Bit numbers using MUL command Apparatus Required: No Name 1 Microcontroller kit Algorithm: 1. Stop or Halt the program execution. Move the multiplicand to accumulator. 2. Multiply the contents of Accumulator and ‘B’ register.

14 .

A DPTR A. @DPTR A.B DPTR.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. A DPTR A. @DPTR B.#8250h A.B @DPTR. 15 .#8300h @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.

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.FLOW CHART: Find the Largest number from an array of numbers START Move the Total no of Data to R0.Location Stop 16 .

8. 7. So do not exchange the A and B register. Get the next element in accumulator. 2. 4. 6. If carry is there. Subtract the B register from the accumulator. Decrement the R0 register each time by 1 for every data taken from the array. Check the R0 register. repeat from the 3rd step else Move the B register to 8300 memory location and stop the program. 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. then A register is greater that means 2nd data is larger than 1st Data. 17 . Get first element to B register 3. If R0 is not equal to zero. If carry is not there. 5. Apparatus Required: No Name 1 Microcontroller kit Quantity 1 Algorithm: 1. 9.EX. Load the R0 register with length of the array and load DPTR with memory location 8250. So exchange the A and B register. Check the carry flag. then B register is greater that means 1st data is larger than 2nd Data.

18 .

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.@DPTR XCH A. code Label Assembly Codes Mnemonics Operend(s) MOV DPTR.@DPTR SUBB A.R0 JNZ L2 MOV A.R1 JNC L1 MOVX A. Memory address Hex. @DPTR MOV R0.A INC DPTR DEC R0 MOVX A. @DPTR MOV R1.#8300h MOVX @DPTR.R1 MOV DPTR.A INC DPTR DEC R0 MOVX A.Program: Find the Largest number from an Array. 19 .#8250h MOVX A.R1 MOV A.

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 .FLOW CHART: Arrange the array of numbers in ascending order START Move the Total no of Data to R0.

9. repeat from the 3rd step else Move the B register to 8300 memory location and stop the program. 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. Get the next element in accumulator. Decrement the R0 register each time by 1 for every data taken from the array. Subtract the R1 register from the accumulator. Data2 – A 21 . Data1 – R1. then A register is greater that means 2nd data is larger than 1st Data. 5. 4. Check the carry flag. Apparatus Required: No 1 Name Microcontroller kit Quantity 1 Algorithm: 1. So do not exchange the A and R1 register. 2. If carry is there. Check the R0 register. 6. So exchange the A and R1 register.EX. If carry is not there. 7. Load the R0 register with length of the array and load DPTR with memory location 8300. then R1 register is greater that means 1st data is larger than 2nd Data. Get first element to R1 register 3. If R0 is not equal to zero. 8.

A MOV A.R1 MOVX @DPTR. @DPTR MOV R0.@DPTR SUBB A.#8300h MOVX A. @DPTR MOV R1. Memory address Hex.Program: Find the Largest number from an Array.A INC DPTR MOV A.A INC DPTR DEC R0 MOVX A.A INC DPTR DEC R0 MOVX A.@DPTR XCH A.R1 JNC L2 MOVX 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 . code Label L1 L2 HLT INPUT: Memory address 8300 8301 8302 8303 8304 8305 Assembly Codes Mnemonics Operend(s) MOV DPTR.R1 DEC DPTR DEC DPTR MOVX @DPTR.

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

Reg to 8302 memory location Stop 28 . Reg to 8301 memory location Move the Data from B reg to 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 Divide the Acc. Reg by 64h Move the Data from Acc. Reg from8300 memory location Divide the Acc.FLOW CHART: HEX to BCD conversion START Move the Data to Acc.

Move the B reg to accumulator (A = 37h) 6. 2. Divide the accumulator with 0Ah (37/0A ( A=05 and B = 05 ) 7. 8301=02 3. Move the accumulator to 8302h(8302 = 55) 10.(A = 50+5) 9. Start the program. Apparatus Required: No 1 Name Quantity Microcontroller kit 1 Algorithm: 1. 8300 = FFh 2. Move the accumulator to 8301h ( 8301 = 02) 5.(A = FFh) 3.(A = 50) 8. 29 . 8302 = 55. Example: 1. Stop the program. Divide the accumulator with 64h( FF/64 ( A= 2 and B = 37h ) 4. Swap the Accumulator. Move the data from memory location 8300 to Accumulator.EX. NO: 8 HEX TO BCD CONVERSION Aim: To convert the given hexadecimal value to its equivalent BCD conversion. Add the accumulator with B register.

30 .

#64h DIV A.Program: HEX to BCD conversion Memory address Hex.A MOV A. B SWAP A ADD A.B INC DPTR MOVX @DPTR.B MOV B. 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.#8300h MOVX A. #0Ah DIV A. Label code Assembly Codes Mnemonics Operend(s) MOV DPTR.B INC DPTR MOV @DPTR. @DPTR MOV B. 31 .

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 8301 memory location Move the Data from B reg to Acc. Reg by 64h and Add the A Reg with 30h Move the Data from Acc. Reg Divide the Acc.FLOW CHART: HEX to ASCII conversion START Move the Data to Acc. Reg from8300 memory location Divide the Acc. Reg to 8303 memory location Stop 32 .

33 . Move the accumulator to 8302h(8302 = 35) 10. Move the data from memory location 8300 to Accumulator. Add the accumulator with 30h 9.EX. Start the program. Move the B reg to accumulator (A = 37h) 7. Apparatus Required: No 1 Name Microcontroller kit Quantity 1 Algorithm: 1.(A = FFh) 3. Move B reg to Accumulator. Add the accumulator with 30h 12. 2. 11. NO: 9 Hexadecimal to ASCII conversion Aim: To convert the given hexadecimal value to its equivalent ASCII code. Divide the accumulator with 0Ah (37/0A ( A=05 and B = 05 ) 8. Divide the accumulator with 64h( FF/64 ( A= 2 and B = 37h ) 4. Move the accumulator to 8303h(8303 = 35) 13. Stop the program. Add the accumulator with 30h 5. Move the accumulator to 8301h ( 8301 = 32) 6.

34 .

#30h INC DPTR MOV @DPTR.A MOV A. @DPTR MOV B. 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.B MOV B.Program: HEX to ASCII conversion Memory address Hex. #0Ah DIV A.#8300h MOVX A.#64h DIV A. 35 .B ORL A.A MOV A. code Label HLT INPUT: Memory address 8300 Assembly Codes Mnemonics Operend(s) MOV DPTR. #30h INC DPTR MOVX @DPTR.B ORL A. B ORL A. #30H INC DPTR MOVX @DPTR.

1 switches OR the P1.4 Move the AND output to ACC.7 Move A Reg Data to Port1 Stop 36 .0 and P1.6 Complement the output Move the OR Output to ACC.1 OR the P1.1 Move the OR Output to ACC.0 and P1.0 and P1.Flowchart: Program for Port1 Pins used as Input and Outputs START Move the Data 0Fh to Port1 Read the P1.5 Complement the output Move the AND output to ACC.

1 as input of logic gates and P1. P1. P1. P1. Take the Last two LSB of accumulator and do the OR and AND operations and move the result to Acc.5. Move the accumulator to P1 register.4.4 and Acc.5. Objective: Write a program to take the P1.7 6. Start the Program Send the 0Fh data to Port1. This make the LSB of port1 as input 37 . Complement the result of Acc.7 are output. port.EX.6 and store in Acc. 4.0 and P1. Stop the program.6 and P1. 3. 2.6 5.4.7are the output of OR. Acc.0 and P1.5. P1.6 and P1.4. AND. NOR. 7.1 as input. P1. NO: 10 Program using I/O pins in Port 1 Aim: Write a program to use the Port pins P1. Acc. Apparatus Required: No 1 Name Quantity Microcontroller kit 1 Algorithm: 1. Read the Port1 and move the data to Accumulator. and NAND gates.

C C ACC.7. ACC.A HLT Comments Make the P1 LSB as input ports HLT TABULATION: SL NO 1 2 3 4 INPUT A P1.1 ACC.0 0 0 1 1 OUTPUT B P1. C A. ACC.1 0 1 0 1 OR P1.4.6.5.7 1 1 1 0 Result: 38 .4 0 1 1 1 NOR P1.1 ACC. C C ACC.0 C.Program: Use the P1 port as input and output pins Memory address Hex.6 0 0 0 1 NAND P1. 90h 90h. 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.0 C. ACC.5 1 0 0 0 AND P1.C C. ACC.

16 bit timer .mode 0 – 13 bit timer. 2. Stop the program. . . EX. 2. Cleared by TR0/TR1 . Set the data pointer to point the LED bar graph. . 1 – counter / 0 – Timer M1 and M0 give the Mode of the timer.mode 3 – Split timer mode. 4.Timer 0 and Timer 1 Run control bit. 4. Set the Timer 0 using TMOD register.mode 2 – 8 bit Auto reload timer. TCON (Bit Addressable) D7 D6 TF1 1.Timer 0 and Timer 1 overflow flag.Timer0/1 Interrupt flag 39 . 5. 3. IE0/IE1 . IT0/IT1 . hardware. 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. increase the LED bar graph display. set. 2. 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. TMOD (06h) D7 Gate 0 Start the Program. 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.mode1 . 3. If you get the T0 pin goes to low then.External Interrupt 0/1flag.Thus the assembly Language program for to use the Port1 as input and output pins are written and executed successfully. TR1 D5 TF0 D4 TR0 TF0/TF1 D3 IE1 D2 IT1 D1 IE0 D0 IT0 . 3.

40 .Program: Timer 0 used as a counter Memory address Hex. #0A004h TMOD. #00h P3.4 TR0 A.A TF0. TL0 @DPTR. L1 TR0 TF0 Next Comments Next L1 Result: Thus the program for counter using timer was written and executed successfully. code Label Assembly Codes Mnemonics Operend(s) MOV MOV MOV SETB SETB MOV MOVX JNB CLR CLR SJMP DPTR. #06h TH0.

once it gets the external interrupt from the switch. 41 . 2. Apparatus Required: No Name 1 Microcontroller kit Quantity 1 Algorithm: Start the program. The reset of the programs are written to work the four LEDs on Port 1 light up like a level indicator. and then it will do the same work on the LED BAR and return back to the LEDs. Once is complete the level then it start from the zero level. NO: 12 Program using Interrupt Aim: Write a program using EX0 interrupt function. 5. Set the IE register as 81h EA .EX. The program continuously works on the LEDs which are connected on the P1.ET2 ES ET1 EX1 ET0 EX0 1 0 0 0 0 0 0 1 3. 1. 4. This will enable the interrupt and set the external zero interrupt.

A calc R4.#09H.#10h R4.L2 L3 Delay A. #0FFh R2.Program: Program using interrupt Memory Hex.B A A. #00h A P1. #10h R3. #00h A @DPTR. 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. A Calc R0.D1 R2.#81h IT0 B.B R0 A.D3 42 .#05H.B Calc Delay D3 D2 D1 R1. #01h R0.L1 Comments L3 L2 IE.D2 R1. 0A004h B. #0FFh R3.

3. Procedure: 1.Result: Thus the program for interrupt was written and executed successfully. Apparatus Required: No 1 2 Name Microcontroller kit 4x4 matrix keyboard Quantity 1 1 Algorithm: 1. 2. 5.13 Aim: INTERFACING 4 X 4 KEYBOARD To interface the 4 x 4 matrix keyboard with the 89C51 microcontroller and to verify the output. 6. If data is smaller than OAh. 2. Eliminate lower nibble and swap it that means higher nibble to Compare with OAh.if data is larger 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.add 37h with data and move into R6 register. Halt the program execution. 43 . lower nibble. Load the DPTR with address 8400h where data is stored. 3. 4. Move the data to A register and R5 register. Verify the result in seven segment LED display. Program . Connections are made as per the diagram shown. Enter the program in the microcontroller kit and execute it. Press any key in the keyboard and execute it again. 4.

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

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

46 .

47 . 3. Connect the LCD display interface board as required.Program -14 INTERFACING OF LCD DISPLAY Aim: To interface the LCD display with 89C51 microcontroller and to verify data on LCD display. Apparatus Required: No Name Quantity 1 Microcontroller kit 1 2 LCD display 1 Procedure: 1. Objectives: Display Alphabet character in the LCD using micro controller. The output will be displayed on two LCD display. 2. Enter the program and execute it.

#05h MOVX @DPTR. address code Label Assembly Codes Mnemonics Operend(s) MOV A. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR.A RET Comments 48 . #04h MOVX @DPTR.#01h ACALL WR_CMD ACALL DELAY MOV A.A MOV A.A INC DPTR MOV A. #01h MOVX @DPTR.A RET Comments Program: Subroutine for WR_DATA Memory Hex.A INC DPTR MOV A. #A000h MOVX @DPTR.Program: Display the MSP character in the LCD Memory Hex.A MOV A.#0Eh ACALL WR_CMD ACALL DELAY MOV A. #A000h MOVX @DPTR.”P” ACALL WR_DATA ACALL DELAY SJMP HLT Comments HLT Program: Subroutine for WR_Cmd Memory Hex. #38h ACALL WR_CMD ACALL DELAY MOV A.”M” ACALL WR_DATA ACALL DELAY MOV A. #A003h MOVX @DPTR.”S” ACALL WR_DATA ACALL DELAY MOV A.A MOV A. #00h MOVX @DPTR. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR. #80h MOV DPTR.

49 .Program: Delay Subroutine Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV R3. #FFh DJNZ R4. #10h MOV 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.

50 .

Objective: Display a number in LED display using microcontroller. 3. 2. 51 . Enter the program. Connect the display interface board as per required. Apparatus Required: No Name 1 Microcontroller kit 2 Keyboard display interface Quantity 1 1 Procedure: 1. The output would be displayed on two seven segment LED.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.

52 .

Memory Hex.A ACALL DELAY MOV A.A ACALL DELAY SJMP START MOV MOV DJNZ DJNZ RET R3. #10h R4. #A001h MOVX @DPTR.A MOV A.A MOV A. #A001h MOVX @DPTR. #7Fh MOV DPTR. #FDh MOV DPTR. #A000h MOVX @DPTR. #A003h MOVX @DPTR. #A000h MOVX @DPTR. address code Label Assembly Codes Mnemonics Operend(s) MOV A. 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. C1 R3.A MOV A. #FFh R4. #81h MOV DPTR. #FEh MOV DPTR. 53 . #3Fh MOV DPTR.

54 .

Mode 55 .Mode 3 REN – Receiver enable. TB8 – Select the transmitter is 8bit or 9bit mode RB8 – Select the receiver is 8bit or 9 bit mode . Variable Data Mode. S. After executing the transmitter program. First run the receiver program in kit2 and then run the transmitter program in kit1.Shift register Baud rate = f/12 .8 Bit UART. 4. . SM1 and SM2 used for serial mode control bits 0 . The transferred data’s “yes” (ASCII) value are stored from 8400h onwards in the kit2. 3. Objective: To Transfer data from one microcontroller kit to another microcontroller kit serially. 1 0 1 D5 SM2 0 D4 REN 1 D3 TB8 0 D2 RB8 0 D1 TI 0 D0 RI 0 SM0. .Mode 2 . Fixed Data rate. Enter the transmitter program in 1ST microcontroller kit & receiver program in 2nd microcontroller kit. Variable Data Mode . 3.no Character ASCII CODE 1 2 3 4 y e s # 79 65 73 23 SCON . 0 0 0 1 1 2.9 Bit UART.Register D7 D6 SM0 SM1 0 1 1. Connect the two microcontroller kit using RS232 cable 2. 4. reset the kit and go to location 8400h 5. Apparatus Required: No Name 1 2 Quantity Microcontroller kit 2 RS232C Interface wire 1 Procedure: 1.Program -16 SERIAL COMMUNICATION Aim: To transfer the data serially between two microcontroller kit using RS232C.Mode 1 .9 Bit UART.

5. . . If SCON is 50h. 1 – counter / 0 – Timer M1 and M0 give the Mode of the timer. 2. 3.16 bit timer . set. . 56 . then it set the mode 1 serial communication and it enables the receiver.mode 2 – 8 bit Auto reload timer. 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. 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. 6.mode 0 – 13 bit timer.mode1 .mode 3 – Split timer mode. TI – Transmitter interrupt Flag RI – Receiver interrupt Flag.

#20h MOV TH1. The TMOD register is loaded with the value 20H. #”S” ACALL 1D[TRANS] MOV A.#50h SET TR1 MOV A. SBUF @DPTR. serial data 57 . indicating the use of timer I in mode 2 (8-bit auto-reload) to set the baud rate. #”#” ACALL 1D[TRANS] SJMP HLT MOV JNB CLR RET SBUF. address code Label Assembly Codes Mnemonics Operend(s) MOV TMOD. #FDh MOV SCON. #FDh MOV SCON. The THI is loaded with one of the values in Table to set the baud rate for transfer 3.A DPTR L1 Comments L1: Programming the 8051 to transfer data serially In programming the 8051 to transfer character bytes serially. where an 8bit data is framed with start and stop bits. #”Y” ACALL 1D[TRANS] MOV A. 2. indicating serial mode 1. #8400 MOV TMOD. 1. the following steps must be taken. #20h MOV TH1.#50h SET TR1 JNB RI.A TI.Program: Transmitter Program Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR. The SCON register is loaded with the value 50 H. FDh TI Comments HLT Program: Receiver Program Memory Hex.#FDh[L1] MOV MOVX INC SJMP A. #”E” ACALL 1D[TRANS] MOV A.

The TMOD register is loaded with the value 201-1. 1. 7. 2. The character byte to be transferred serially is written into the SBUF register. 8. xx” to see if the character has been transferred completely. 7.4. go to Step 5. indicating serial mode I. TRI is set to l to start timer l. TR1 Is set to I to start timer 1. TI is cleared by the “CLR TI” instruction. XX” to see if an entire character has been received yet. When RI is raised. go to Step 5. the following steps must be taken. The SCON register is loaded with the value 5011. The RI flag bit is monitored with the use of the Instruction” JNC RI. 6. where 8-bit data is & framed with start and stop bits. Its contents are moved into a safe place. Tc’ transfer the next character. THI is loaded with one of the values in Table to set the baud rate 3. indicating the use of timer I in mode 2 (8b1t auto-reload) to set the baud rate. The TI flag bit is monitored with the use of the instruction “JNB TI. 4. Result: Thus the assembly language was written to transfer the data serially between two micro controller kit using RS232 cable and it was executed. SBUF has the byte. Programming the 8051 to receive date serially In the programming of the 8051 to received character bytes serially. 8. RI is cleared with the “CLR RI” Instruction. 58 . To receive the next character. 5. 6. 5.

59 .

60 .

61 .

Enter the program. Program: Dc motor interfacing 62 . Switch ON the board . 4.the motor rotates in forward direction. Place the forward reverse switch to reverse direction. 5. 2.Program -17 DC MOTOR CONTROL Aim: To interface the DC motor with 89C51 microcontroller and to rotate it in forward and reverse direction. Stop the program execution. Connect the interface circuit as shown in fig. 3. 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.It reverses.

3. IC L293 D is a driver IC which how 2 inputs. are sent to output 1. code Label MAIN L1: FwRD: Assembly Codes Mnemonics Operend(s) MOV DPTR. Enable pin is connected to p1. 5.A MAIN Comments REV: Theory: 1. output 2. the inputs are sent the respective outputs normally output1. 2.0.A SJMP MAIN MOV MOV MOVX SJMP DPTR.Memory address Hex. input 2. 63 .input 1.1. It is possible only when enable pin is in level 1. 4. #A001 A.A MOV DPTR.2. If it is 1 level then only the pulse input will be given. #A003 MOV A. REV MOV DPTR. #A002 MOV A. Forward/reverse switch is connected to p1. input 2. by sending level 1 in p 1. MAIN JB ACC. It is checked in the program. The motor is connected to the output 1 & output 2.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. #06h @DPTR. The input.6. #A001h MOV A. @DPTR JNB ACC.0 is given to input 1 p1. P 1. input 1.2. #91h MOVX @DPTR. ON/OFF switch is connected to p1. output2.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. #05h MOVX @DPTR.

64 .

Program -18 INTERFACING STEPPER MOTOR 65 .

Stop program execution. Objective: To Control the stepper motor using microcontroller. 4. Apparatus Required: No 1 2 Procedure: 1.code 09 05 06 0A Name Quantity Microcontroller kit 1 Stepper motor Interface card 1 66 . the motor rotates in clockwise direction. 2. Connections are made as shown in fig.Aim: To interface the stepper motor with 89C51 microcontroller and to rotate it in clockwise Direction. Verify the result. 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. 3. Enter the program and execute it.

A MOV DPTR. #FFh DJNZ R4. #10h MOV R4. address code Label Assembly Codes Mnemonics Operend(s) MOV R3. #05h MOVX @DPTR. #09h MOVX @DPTR.A ACALL DELAY SJMP AGAIN Comments Program: Delay Subroutine Memory Hex. #80h MOVX @DPTR. C1 DJNZ R3.A ACALL DELAY MOV A.A ACALL DELAY MOV A.A ACALL DELAY MOV A. 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. #0Ah MOVX @DPTR. #06h MOVX @DPTR. #A003 MOV A.Program: Stepper motor interfacing Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR. 67 . #A000h MOV A.

68 .

OFF using pushbutton switch. Apparatus Required: No 1 2 Name Microcontroller kit Digital interface board Quantity 1 1 Procedure: 1. Enter the program and execute. 3.EXTRA SYLLABUS Program -19 INTERFACING RELAY AND PUSHBUTTON Aim: To interface the pushbutton switch and relay and make relay ON . Make the connections as per the circuit using interface card. 69 . 2. Press the pushbutton and verify the result by seeing the relay ON or OFF.

L1 MOV A. @DPTR JNC ACC. A MOV R1.A MOVX A. 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. CNT1 DJNZ R1. #10h MOVX @DPTR. 70 . #0Ah MOV R0. #A002h MOV A. #A003 MOV A.A MOV DPTR. #64h DJNZ R0. #00h MOVX @DPTR. #91h MOVX @DPTR.Program: Memory Hex. address code Label Assembly Codes Mnemonics Operend(s) MOV DPTR.0.

Start the program Move the data1 to R0 reg and Data 2 to R1 reg.Program -20 Program using DIP switches Aim: To select addition program or a subtraction program using DIP switch. If Dip switch scanned data is 0Fh then do subtraction else do Store the result in 8300 memory location. 4. 5. Scan the Dip switches. 2. Stop the program. 71 . addition operation. 3. Apparatus Required: No 1 Name Microcontroller kit Quantity 1 Algorithm: 1. 6.

Program: Memory address Hex.A SJMP HLT MOV A. #8300h CJNE A. R0 SUBB A.R1 MOVX @DPTR. @DPTR MOVX DPTR.A SJMP HLT Comments HLT ADD HLT Result: Thus the program using DIP switch was written and executed successfully.R1 MOVX @DPTR. code Label Assembly Codes Mnemonics Operend(s) MOV R0. #Data2 MOVX DPTR. #Data1 MOV R1.add MOV A. 72 . R0 ADD A. #0A00Ch MOV A. #0Fh.

Mnemonics. arranged by Function: Arithmatic Function: 73 .

74 .

75 .

76 .

77 .

Internal RAM and SRF addresses 78 .

79 .Internal RAM and SRF addresses.

OPCODE SHEET 80 .

81 .

82 .

83 .

84 .

85 .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->