Microcontroller and

Interfacing
Laboratory Manual

Enrollment No. _______________
Name of the student:_________________________________

Electronics & Communication Engineering Department

Government Engineering College, Rajkot

GOVERNMENT ENGINEERING COLLEGE,
RAJKOT

CERTIFICATE

This

is

to

certify

that

Mr/Miss

____________________________________Enrollment No. _____________
of B.E. (E.C.) SEM-V has satisfactorily completed the term work
of the subject Microcontroller and interfacing prescribed by
Gujarat Technological University during the academic term
________________

Date:
Lab Manual of Microcontroller and Interfacing

Signature of the faculty
Page 2

INDEX
Sr.
No.
1.

2.

3.

4.

5.

6.

7.

Name of Experiment

Page
No.

Write a assembly language program to ….
 Add two 8 bit numbers stored in register R6 and R7
 Multiply two 8 bit numbers stored in register R6 and R7.
 To find 1’s complement of number stored in register R0
 To perform AND operation between content of register R0
and R1
Write C language program to …
 Read data from port P2 and P3. Add data and display
result on port P0. Glow LED connected at port pinP1.1 if
carry flag set after addition.
 Read data from port P2 and P3. Multiply data and display
result on port P0 and P1
 Write program to read switch connected at port pin P1.0,
toggle it and send to port pin P1.1
Write program to ….
 To add two sixteen bit numbers stored in DPTR and at
memory location 40h,41h.Store result in DPTR
 Multiply two 16 bit numbers. Assume that first 16 bit
number is stored in register R6 and R7, Second 16 bit
number is stored in register R4 and R5. Store answer in
register R0,R1,R2 and R3.
Write a program to ….
 Add block of data stored at location 40h to 45h
 Transfer block of data from the location 40h-4Fh to
external memory location 2000h-200Fh
 Arrange data stored at the location 40h-4Fh in ascending
order
Write a program to perform following:
 Keep monitoring port pin P1.2 until it becomes high
 When P1.2 becomes high, write data 45h to port P0
 Send high to low pulse on pin P2.3
Write a program to generate square wave of 50% duty cycle
having frequency 5 KHz at port pin P1.0 using timer 1 in
mode 2. Modify program to generate pulse waveform of 70%
duty cycle using timer on the same pin.
Generate external interrupt INT0 and INT1 by connecting
push button switch. Glow LEDs connected at port 1 one by
one when interrupt INT0 occurs. LEDs should flash when
interrupt INT1 occurs

EC Department, Government Engineering College, Rajkot

Page 3

Display pulses on the seven segment display 13. Write a program to transmit letter “E” continuously using serial port. Write a program to rotate motor in clockwise and anticlockwise direction in half step and full step mode Interface DC motor with 89C51 microcontroller. 17.200. Use 8 bit UART mode with baud rate 9600. write answers and execute it  Test your all programs with Simulator and actual hardware Lab Manual of Microcontroller and Interfacing Page 4 . Write program to display number 0 to 9 on the seven segment display at the interval of 1 second Interface LCD with the microcontroller. Instructions to the students:  Student has to construct microcontroller mini-project individually as per the given circuit diagram by the faculty. 16. 12. List of components is given at the end of this lab manual  Mounting of RS-232 connector and MAX-232 chip is compulsory for all the students because it will help you to program your chip using Philips Flash Magic Utility (You have to download HEX files in your chip to test your hardware)  Simulate assembly language programs on UMPS assembler and simulator  Simulate C programs using KEIL compiler and simulator  You may use free integrated development environment (IDE) for 8051 with Ubuntu Linux. Interface seven segment display with Port P2. Use 8 bit UART mode with baud rate 19. Modify program to transmit text “YES”. Write a program to count external pulses given at the timer 0 input pin. 15. It is compulsory as a part of term work. Linux operating system is open source so it is convenient to use it. Display it on LCD. 10. Write a program to receive bytes of data serially and display it on port P0. 9. Interface 8 bit DAC chip with 89C51 microcontroller. Display your name on the LCD.8. Write program to display key pressed on seven segment display Interface stepper motor with port P0 of the microcontroller. Interface matrix keyboard with 8051. 11. Write a program to rotate motor with different speed using PWM Interface ADC0808 with 89C51 microcontroller. Many free simulators are available to work with Linux environment  Solve exercise given at end of each practical. Write a program to generate sine wave using look up table 14. Write program to read analog voltage applied at the input of ADC.

R6 MOV B. Store result in register R3 ORG 00h MOV A. 1 AIM: Write a program to …. ORG 00h MOV R6. R7 MUL AB END . Store result in register R1 ORG 00h MOV A. Transfer data 44h to register R7 .#44h MOV A. Transfer data 44h to register R7 . Transfer number stored in R0 to Accumulator EC Department.     Add two 8 bit numbers stored in register R6 and R7 Multiply two 8 bit numbers stored in register R6 and R7.Multiply accumulator and register B. Transfer data 55h to register R6 . Store result in register R1 END Program 4: To perform AND operation between content of register R0 and R1. in A .R0 . Complement the content of accumulator MOV R1. Government Engineering College.R0 . Store result in both Program 3: To find 1’s complement of number stored in register R0. Add content of R7 with accumulator and store result . ORG 00h MOV R6. Transfer data 55h to register R6 .#55h MOV R7. Rajkot Page 5 . To find 1’s complement of number stored in register R0 To perform AND operation between content of register R0 and R1 Assembly language programs: Program 1: To add two 8 bit numbers stored in register R6 and R7.EXPERIMENT NO.A . Transfer content of register R6 to accumulator . End of program Program 2: To multiply two 8 bit numbers stored in register R6 and R7.#44h MOV A.R6 ADD R7 END . Transfer content of R7 in register B . Transfer content of register R6 to accumulator .#55h MOV R7. Transfer number stored in R0 to Accumulator CPL A .

Store result in register R3 Note: Check execution of program 3 and 4 by loading different values in registers. AND operation between A and register R1 . Write result of multiplication at memory location 42h (LSB) and 43h (MSB) _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 6 .ANL A. :: WORKSHEET :: Exercise: [a] Write assembly language program to add two 8 bit data stored at memory locations 60h and 61h.R1 MOV R3.A END . Store result at location 82h(LSB) and 83h (MSB) _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [b] Write assembly language program to multiply two data stored at memory location 40h and 41h.

Government Engineering College. Rajkot Page 7 . Store result in register R1 _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [e] Write and execute program to perform OR operation between data stored at memory location 40h and 50h. Store result in register R7 _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.[c] Write and execute instructions to (1) Transfer content 1234h to DPTR (2) Select register bank 1 and transfer content 45h to register R0 and 54h to R2 _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [d] Write and execute program to find 2’s complement of number stored in register R0.

Consider carry during the addition. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [h] Write program to add two BCD numbers stored at memory location 50h and 51h. Adjust result for BCD number and store it at memory location 52h _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 8 .[f] Write and execute program to subtract content of register R6 from register R7 and store result in register R0 _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [g] Write program to add registers R0.R1 and R2.

P2=0xff. 2 AIM: Write a C language programs to …. //Define port P1 as an output port a=P2. unsigned int c. Government Engineering College. Add data and display result on port P0.EXPERIMENT NO. //Define port P2 as an input port P3=0xff.1 if carry flag set after addition. Glow LED connected at port pinP1.c. Rajkot Page 9 . //Glow LED connected at P1.h> void main(void) { unsigned char a. Multiply data and display result on port P0 and P1 Write program to read switch connected at port pin P1.0 common anode mode } } Program 2: Read data from port P2 and P3.1 C Language Programs: Program 1: Read data from port P2 and P3.1 if carry flag set after addition.0. //Add content of port P2 and P3 P0 = c. //Display result on port P0 if(CY==1) { P1=0x00. //Define port P0 as an output port P1=0x00. //Define port P1 as an output port P1=0x01.b. Multiply data and display result on port P0 and P1 # include <reg51. //Read port P2 EC Department. toggle it and send to port pin P1. //Read port P3 c=a+b. //Read port P2 b=P3. Add data and display result on port P0. // Define port P3 as an input port P0=0x00. //Define port P0 as an output port P1=0x00.    Read data from port P2 and P3.h> void main(void) { unsigned char a. //Define port P2 as an input port P3=0xff. # include <reg51. Glow LED connected at port pinP1. Read data from port P2 and P3. // Define port P3 as an input port P0=0x00. P2=0xff. //Make LED off a=P2.b.

//Read port P3 //Multiply content of port P2 and P3 //Display accumulator content on port P0 //Display register B content on port P1 } Program 3: Write program to read switch connected at port pin P1. Display result on port pin P1. //Read input pin.0 without disturbing other port pins. toggle it and send it to port pin P1. /* Define output pin P1.0 and P1.h> sbit input = P1^0.1.0.b=P3.2 _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 10 .1*/ void main(void) { while(1) //Continuous infinite loop { output=~input.0*/ sbit output=P1^1. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [b] Write C language program to perform OR operation between port pin P1. P0 = ACC. /* Define input pin P1. c=a*b. toggle it and send to output } } :: WORKSHEET :: Exercise: [a] Write C language program to continuously toggle pin P1.1 # include <reg51. P1=B.

1 if lift door is open. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [d] Write a program to sense lift door switch connected at port pin P2. Switch on the alarm connected at port pin P2.0. If data at port P1 is greater than 80h. make port P0=0x00 and if data at port P1 is less than or equal to 80h. Write program in assembly and C language. Rajkot Page 11 . make port P0=0xFF. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department. Government Engineering College. Compare content of port P1 with data 80h._____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [c] Write C language program to read port P1.

#22h .Move the high-byte into the accumulator ADDC A.DPH .Move A (the low-byte) into R3 .EXPERIMENT NO.   To add two sixteen bit numbers stored in DPTR and at memory location 40h.Multiply R5 by R7 MOV A.Transfer MSB of 16 bit data to location 41h MOV A. Get LSB of 16 bit data in accumulator ADD A.#11h MOV R5.Add zero (plus the carry.Load first value in R6 and R7 Program 1: ORG 00h MOV DPTR.R1.DPH .Load first 16 bit value in R6 and R7 MOV R6.R7 .Add with MSB of second data consider previous .A .Move B (the high-byte) into R2 MOV R3.B .A .#22h .DPTR MOV DPL.R2 and R3.R6 .DPL .Transfer LSB of 16 bit data to location 40h MOV 41h.#00h .B .Store result in DPTR Multiply two 16 bit numbers.Move the resulting value back into R2 MOV A.40h .#11h MOV R7.R5 .41h.Move R7 into B MUL AB .Transfer 16 bit data to DPTR MOV 40h.Load second 16 bit value in R4 and R5 MOV R4. if any) Lab Manual of Microcontroller and Interfacing Page 12 .Add the low-byte into the value already in R2 MOV R2.R2 .Move R6 into B MUL AB .A .Add with LSB of second data which is stored in .Save result back in DPH END Program 2: .#11h . Second 16 bit number is stored in register R4 and R5.Save result back in DPL MOV A. MOV A. 3 AIM: Write programs to ….R5 .#22h .carry.Get MSB of first data in accumulator ADC A.Multiply the two values MOV R2.41h . Store answer in register R0.Multiply R5 by R6 MOV A.#2233h .Multiply the two values ADD A.Move the R5 into the Accumulator MOV B. Assume that first 16 bit number is stored in register R6 and R7.Move R5 back into the Accumulator MOV B.

and R3 :: WORKSHEET :: Exercise: [a] Write assembly language program to find square of given number stored in register R0.Move R6 into B MUL AB .MOV R1. if any) MOV R0. Save result in register R1 and R2.A .R2 .Move R7 into B MUL AB .Multiply R4 by R7 MOV A.R7 .Add it to the value already in R0 (plus any carry) MOV R0.Move the resulting answer into R1 MOV A.A .A .Move R4 into the Accumulator MOV B.Move the resulting value back into R1 MOV A. MOV A.A . Rajkot Page 13 .A . .Move the high-byte into the accumulator ADDC A.Move the high-byte into the accumulator ADDC A.Add the current value of R1 (plus any carry) MOV R1.Multiply the two values ADD A. Government Engineering College.R4 .#00h .Multiply the two values ADD A.Move R4 back into the Accumulator MOV B.Add zero (plus the carry.#00h .Move the resulting answer to R1.R1 .A .Move the resulting answer to R0.Move the resulting answer into R1.Add the current value of R0 (plus any carry) MOV R0. . R1.Add the low-byte into the value already in R2 MOV R2.R4 .B .B .#00h . R2.Move the resulting value back into R2 MOV A.A .R1 .Add the low-byte into the value already in R1 MOV R1.Load the accumulator with zero ADDC A.Multiply R4 by R6 MOV A.R6 .Load the accumulator with zero ADDC A.R0 .R0 . _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.Answer is in R0.Move the resulting answer back to R0 .

Store result in DPTR and carry flag _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [c] Divide content of register R1 by 8 using logical shift instruction _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 14 . second 4 digit number stored at location 42h-43h (LSB at 43h). First 4 digit number stored at 40h-41h (LSB at 41h).[b] Write assembly language program to add 4 digit BCD numbers.

   Add block of data stored at location 40h to 45h Transfer block of data from the location 40h-4Fh to external memory location 2000h-200Fh Arrange data stored at the location 40h-4Fh in ascending order Assembly language programs:  Program 1: Add block of data stored at location 40h to 45h In this program.EXPERIMENT NO.@R0 .Add up to memory location 4Fh END . Clear B to save the result MOV R0.Add up to memory location 45h END .#40h . Rajkot Page 15 . accumulator AGAIN: INC R0 ADD A. we assume that the result may be 16 bit so it is saved in register pair A and B with LSB in register A and MSB in register B ORG 00h MOV B.#2000h . Transfer data from first memory location to . Increment DPTR to point next ext. Government Engineering College. CJNE R0. Add data and store result in accumulator .#00h . Clear B to save the result MOV R0. Transfer data from memory to accumulator MOVX @DPTR. Transfer data from accumulator to . Increment R0 to point next location INC DPTR .@R0 JNC LOOP INC B .#00h . End of program Program 2: Transfer block of data from the location 40h-4Fh to external memory location 2000h-200Fh ORG 00h MOV B.Use R0 as a pointer to first memory location MOV DPTR.AGAIN .#50h. Point to next memory location .A . Point to external memory location 2000h NEXT: MOV A. 4 AIM: Write a program to ….#40h . End of program  EC Department.NEXT . external memory location pointed by DPTR INC R0 . If no carry do not increment B LOOP: CJNE R0.@R0 .Use R0 as a pointer to first memory location MOV A. memory loc.#45h.

loop .60h .a CJNE R1.@R1 MOV @R0.@R0 . _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 16 .If A<next data then check next data .R0 MOV b.Transfer data to accumulator for comparison .Check for last location MOV R0.#4Fh.If A>next data then transfer next data to .a INC R1 MOV A.Subtract for comparison .#4Fh. accumulator next: CJNE R0.start .Exchange first data with location of smallest no.@R0 JC next MOV 60h.@R0 .b SUBB A.Save smallest location at RAM address 60h .Get smallest location again MOV a. XCH A.#40h MOV R1.R1 .Point for first location of data . Program 3: Arrange data stored at the location 40h-4Fh in ascending order ORG 30h MOV R0.#40h loop: MOV b.Check for last location END :: WORKSHEET :: Exercise: [a] Write assembly language program to transfer data from external memory locations 5000h-500Fh to the internal memory locations 30-3Fh.Start program from the location 30h (why?) .@R0 start: INC R0 CLR PSW.Point to next data .Start search for small number from next location MOV R0.7 MOV a.Clear carry flag CY before subtraction .

Rajkot Page 17 . Government Engineering College._____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [b] Write program to arrange data stored in the location 20h-2Fh in descending order _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ ____________________________________________________________________ [c] Write program to count number of negative numbers in the array of numbers stored at external memory location 4000h to 40FFh _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 18 .

4/AD4 P0.2.#00h .2 P1.4 P1.3 P1.3 END Circuit Diagram: Vcc 10K 10K RESET 9 RST 31 40 10K 10uF D1 EA VCC 470 Ohm 1K X 8 P1.1/AD1 P0. Make port pin P2. Government Engineering College.5/AD5 P0.EXPERIMENT NO.0 P0.0 P2.2 P2.3 low CHECK: JNB P1.1 P2.6/AD6 P0.2/AD2 P0. Rajkot Page 19 .  Keep monitoring port pin P1.7 P1.0/AD0 P0.2 becomes low. CHECK MOV P0. Configure port P0 as output port CLR P2. Configure port P1 as input port MOV P0.#0FFh .2 until it becomes high  When P1.3 Program: ORG 30h MOV P1.3 .6 P1.5 P1.3 22 PF X2 D8 18 GND 22 PF X1 19 20 EC Department.1 P1.#45h CLR P2. write data 45h to port P0  Send high to low pulse on pin P2.3/AD3 P0. 5 AIM: Write a program to ….7/AD7 39 38 37 36 35 34 33 32 89C51 8 7 6 5 4 3 2 1 SW1 SW2 21 22 23 24 P2.

Construct circuit diagram on general purpose microcontroller board. Download HEX file into Flash memory of microcontroller chip 89C51. :: WORKSHEET :: Exercise: [1] Write assembly language and C program to make ALL LEDs connected at port P1 ON _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [2] Write assembly language and C program to make ALL LEDs connected at port P1 OFF _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 20 . Press the reset button and write your comment about which LEDs are ON and OFF. Assemble and link the program to generate HEX file.

Government Engineering College. Rajkot Page 21 .2 and make all LEDs ON if this switch is pressed and OFF if this switch is released _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department._____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [3] Write assembly language and C program to read input switch connected at port pin P3.

Write a program to perform following: o If Switch is OFF. send data 0x88 to P0 o If Switch is ON.[4] A switch is connected to P3. send data 0x55 to P0 Assembly language program: _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ C language program: _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 22 .2.

0 .#30h . time to execute one cycle is T If 1  12  1S 12  106 We will use pure software delay to generate delay of 100 µS We WeWProgram: ORG 00h .0 to generate square wave next: SJMP next delay: MOV R7. Make P1. Return to main routine END Total number of cycles in delay loop: Total number of cycles C T = C O + C L + C R = 1 + 48 Where. Government Engineering College. Modify program to generate pulse waveform of 70% duty cycle using timer on the same pin. C O = Number of cycles outside the loop C L = Number of cycles inside the loop C R = Number of cycles for return instruction. Decrement R7 until it becomes zero NOP .EXPERIMENT NO.0 .0 output pin ACALL delay . No operation RET .0 using timer 1 in mode 2. Rajkot Page 23 . Complement P1. Call delay of 100 µS CPL P1. Start program from location 00h CLR P1. Calculation of delay: Time = 1/Frequency = 1/(5x103) = 200 µS For 50% duty cycle ON time and OFF time are equal TON = TOFF = 100 µS Time delay required is 100 If we consider crystal frequency 12 MHz. Load count value 48 (30h) loop: DJNZ R7. loop . 6 AIM: Write a program to generate square wave of 50% duty cycle having frequency 5 KHz at port pin P1. Total time = C T x 1s = 100 s EC Department.

Call delay subroutine 16 times for ON time and 4 times for OFF time. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 24 . You can also prepare delay subroutine of 10 s. so use 160 s for ON time and 40 s for OFF time.0 (Measure frequency and verify whether it is giving correct value or not) :: WORKSHEET :: Exercise: [1] Modify program for 80% duty cycle Hint: Use separate delay loop for ON time and OFF time.Execute this program using Keil and observe waveforms at port pin P1. Total time is 200 s.

j. wave_pin=0. Rajkot Page 25 . } } void sqdelay(unsigned int t) { unsigned int i. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.[2] Execute following C program in Keil and measure frequency of the square wave. sqdelay(100).j++).j<1000. for(i=0.i<t. sqdelay(100). } Draw waveform (show on time and off time) [3] What modifications you suggest in above program to reduce frequency of square wave to half? _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [4] Suggest modification in the program to achieve duty cycle 60% without changing frequency of the square wave. # include <reg51. void main(void) { while(1) { wave_pin=1.i++) for(j=0. void sqdelay(unsigned int).h> sbit wave_pin P1^0. Government Engineering College.

Make all LEDs ON Lab Manual of Microcontroller and Interfacing Page 26 . Glow LEDs connected at port P1 one by one when interrupt INT0 occurs.0 P1. 7 Aim: Generate external interrupt INT0 and INT1 by connecting push button switch. Vector location for External interrupt INT1 ajmp flash . Negative edge trigger for INT0 mov P1. LEDs should flash when interrupt INT1 occurs Circuit Diagram: Vcc 10K 10K 100 RESET 9 RST D1 EA VCC 10K 31 40 10uF 470 12 13 P1.3 P1.5 P1.2 P3. Jump to flash program reti mov IE.#10000101B .#0ffh acall delay mov P1. Negative edge trigger for INT1 setb IT0 .#00h .2 P1.3 1 2 3 4 5 6 7 8 89C51 22 PF SW1 SW2 X2 D8 18 GND 22 PF X1 19 20 Program: start: org 00h ajmp start org 03h .EXPERIMENT NO.Enable External interrupts setb IT1 .#00h . Port P1 output port flash: mov P1. Vector location for External interrupt INT0 ajmp sequence . Make all LEDs OFF .4 P1.1 P1.7 P3. Jump to sequence program reti org 13h .6 P1.

acall delay ajmp flash sequence: mov a.#02h R6. others OFF Transfer bit pattern to port P1 Rotate for next LED Delay Repeat loop R4.loop2 r4. . Bit pattern for First LED ON.#0FEh next: mov P1.#0ffh R5.loop1 R6. LEDs flash ten times and then stop. Rajkot Page 27 .#0ffh R5. Hint: Use separate register as a counter _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department. . When INT1 occurs LEDs glows one by one sequentially only once and then stop.a rl a acall delay ajmp next delay: loop3: loop2: loop1: mov mov mov djnz djnz djnz ret end .loop3 :: WORKSHEET :: Exercise: Modify program such that when INT0 occurs. Government Engineering College. . .

0/AD0 P0.4/AD4 P0.4/T0 P3.Configure port 1 as output port again: MOV DPTR.7/RD X2 X1 P0.#00h .1 P1.3/INT1 P3.4/A12 P2.7 PSEN ALE 39 38 37 36 35 34 33 32 1K X 8 1 2 3 4 5 6 7 8 29 30 20 Program 1: Display Count value on seven segment display ORG 00h AJMP start ORG 03h RETI start: MOV P1.0/A8 P2.5 P1.5/T1 P3.6/AD6 P0.2/AD2 P0.3/A11 P2.5/A13 P2.A .6 P1.5/AD5 P0.0/RXD P3.7/A15 P3.2/A10 P2.2/INT0 P3.6/WR P3. Get seven segment code JZ AGAIN MOV P1.#CODE .1/TXD P3. 8 Aim: Interface seven segment display with Port P1.Initialize DPTR as a base address for code next: CLR A MOVC A.3 P1. Write program to display number 0 to 9 on the seven segment display.@A+DPTR .3/AD3 P0.Display count value ACALL DELAY INC DPTR Lab Manual of Microcontroller and Interfacing Page 28 .EXPERIMENT NO.2 P1.6/A14 P2.4 P1.1/AD1 P0.7/AD7 89C51 21 22 23 24 25 26 27 28 RST GND 9 EA VCC RESET 10K 31 40 100 P1.1/A9 P2.0 P1. Use delay between two count Circuit diagram: 10uF Vcc 22 PF 6 MHz 22 PF 10 11 12 13 14 15 16 17 18 19 P2.

4/A12 P2.0/A8 P2.5/A13 P2.4/AD4 P0.0/AD0 P0.92h. END Program 2: Interface DIP Switch with port P2 (P2.0 P1.2 P1.7/A15 89C51 RESET EA VCC RN1 10Kx4 31 40 10uF P1.2/AD2 P0.Configure port 1 as output port EC Department.3 P1.1/AD1 P0.5/AD5 P0.99h.1 P1.0 to P2.0A4h.7 39 38 37 36 35 34 33 32 1K X 8 1 2 3 4 5 6 7 8 22 PF D IP S WITCH 19 22 PF X2 X1 GND 18 PSEN ALE 29 30 20 Program: ORG 00h AJMP start ORG 03h RETI start: MOV P1.90h.0F9h.#0FFh DJNZ R5.3/AD3 P0.#0FFh MOV R5. Write a program to read status of the switch and display its HEX value on the seven segment display connected at port P1 Circuit diagram: Vcc 9 RST P0.3/A11 P2.7/AD7 10K 21 22 23 24 25 26 27 28 P2.0F8h.L3 RET db 0C0h.6 P1.DELAY: L3: L2: L1: CODE: AJMP next .2/A10 P2.#00h .6/A14 P2.L1 DJNZ R6.80h.82h.#22h MOV R6.3).5 P1.6/AD6 P0. Rajkot Page 29 . Next digit MOV R7.1/A9 P2.0B0h.L2 DJNZ R7.00h.4 P1. Government Engineering College.

Initialise DPTR as a base address for code MOV A.0C6h. db 83h.0C8h.again: MOV P2.@A+DPTR MOV P1.#0FFh .Continue DIP switch reading process DELAY: LOOP1: CODE: MOV R6.0A4h.Display count value AJMP again .0B0h.0F8h.A .#0ffh DJNZ R6.Configure port 2 as input port MOV DPTR.0A1h.80h.82h.92h. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 30 . 8Eh. 00h END :: WORKSHEET :: Exercise: [1] Write program to display count value F to 0 at the interval of 1 second on seven segment display connected at port P1.0F9h.P2 .#CODE . 86h.LOOP1 RET db 0C0h.90h.Read status of the switch ACALL DELAY MOVC A.99h.

6/AD6 P0.7/AD7 RST C1 10K R3 P2.  Enable line is connected with port pin P2.2/AD2 P0.0 22 PF C3 16 4 1 2 R5 Q1 SL-100 RELAY_SPDT_1A 4.7K Pin connections:  Data lines of LCD are connected with port P0. Interfacing diagram: +5V 10K R4 U2 10uF 9 40 R2 VCC R1 150 RESET EA 10K 31 100 10K P0.3 89C51 +5V C2 SW1 SW2 LS1 22 PF 5 18 D1 X2 X1 20 19 12 MHz 3 1 GND P1.0/AD0 P0.EXPERIMENT NO.2 P3.1  Relay is driven by transistor SL-100.1/AD1 P0.0/A8 P2. Send command word #3Ch EC Department.3/AD3 P0.3 (External interrupts pins) Programming steps:  Initialize the LCD. For example send command word #38h to intialise LCD for 57 dots/character and 2 rows. Government Engineering College. Transistor SL-100 is controlled by port pin P1.4/AD4 P0.0  R/W pin is directly connected to ground. 9 AIM: Interface LCD with the microcontroller.1/A9 12 13 39 38 37 36 35 34 33 32 7 D0 8 9 10 11 12 13 14D7 15 3 LCD MODULE 4 RS 21 22 2 6 5 R/W E 1 P3.2 and P3. Display your name on the LCD.  RS (Register Select) line is connected with port pin P2.  Push button switches SW1 and SW2 are connected with port Pin P3. Rajkot Page 31 .0.5/AD5 P0.

1 RW EQU P2.Issue command to the LCD MOV A. 2 lines.#80h acall command . For Kit prepared for LAB .RW is grounded RS EQU P2.Clear LCD MOV A. for movement of cursor to display data at particular position etc.#00h . Port P2 output port MOV A.  for 510 dots/character and two rows. Program: . we will enable LCD by sending pulse at port pin P3.Write when display not busy clr RS . Write separate routine to send data to the LCD in which we will make RS=1 and after transferring data to port P1.Force cursor at beginning of the first line MOV DPTR.0 EN. we will enable LCD to display data.1 EN EQU P2.Initialize LCD. 06h to make LCD ON & Cursor ON.LCD ON.1-RS. to clear display.0 DATA equ P0 org 00h MOV P0.Point to text message acall disp_msg .A setb EN . Port P0 output port MOV P2. P2.#0eh acall command . We will use this command routine whenever we want to issue certain commands during initialization. Write separate routine to send command in which we will make RS=0 and after transferring command word to port P1.#01h acall command .Display message on second line here: sjmp here command: acall delay . Program to Display text message on LCD .#38h .#06h acall command .Shift cursor right MOV A. Port 1 Drives data lines. P2.Set Enable terminal of LCD Lab Manual of Microcontroller and Interfacing Page 32 .1. Cursor ON MOV A.Select command register clr RW mov DATA. 5X7 matrix acall command . Send other command words like 01h to clear LCD screen. We will not check whether LCD is busy or not but we will put certain amount of delay (about 5 ms) between two data which gives enough time to LCD for its operation and does not require to check the status whether it is busy or not.#msg .#00h . 80h to start from first line and first character etc.

a .Get data for display clr RW setb RS .Clear Enable and latch data ret disp_msg: acall delay clr a movc a.@a+dptr jz exit acall disp_data inc dptr sjmp disp_msg exit: ret delay: loop1: msg: mov R6.loop1 ret DB ‘ Your name '.Select data register setb EN .nop nop clr EN ret disp_data: acall delay mov DATA.Enable LCD (Strobe LCD) nop nop clr EN .0 END :: WORKSHEET :: Exercise: [1] Modify LCD program to display two lines: “WELCOME TO E.#0ffh djnz R6. Government Engineering College.” on first line and “GEC RAJKOT” on the second line. Execute program in your hardware _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.C. Rajkot Page 33 .

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [2] Modify program to read status of the switches connected to the port pins P3. If switch SW1 is pressed display “ DEVICE ON” and make relay ON.3. If switch SW2 is pressed display “DEVICE OFF” and make relay OFF.2 and P3. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 34 . Execute in your hardware.

Government Engineering College. Rajkot Page 35 ._____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.

4 P1. • Use time delay between transmission of two characters.0/AD0 P0. data will be lost. Each character takes 33.3 P1. Time delay can be chosen slightly higher than known transmission time of one character.1/AD1 P0.2 12 11 D8 11 X2 18 1 GND 22 PF X1 19 20 22uF 3 V+ R1OUT T1IN 22 PF C1+ C1- 22uF 2 16 10 R1IN T1OUT C2+ V- P3.0 P2. If program does not wait.2 P1.6/AD6 P0.3/AD3 P0.4/AD4 P0.7 P1. This method is most simplest. Next character should be placed only after TI flag is set i.2/AD2 P0. • Monitor TI flag of the SCON special function register (SFR) to check whether character transmission is completed or not. Serial interrupt can be invoked by TI or RI flag of SCON special function register. The vector Lab Manual of Microcontroller and Interfacing Page 36 .5/AD5 P0. • We can also use interrupt method to check whether transmission is over or not.  TI Flag must be cleared by the program before transmission of next character.200. Use 8 bit UART mode with baud rate 19.3 to 0.6 P1.5 P1.EXPERIMENT NO.0 39 38 37 36 35 34 33 32 MAX232 21 22 23 1K X 8 P0.1(TxD) P2. Circuit diagram: Vcc 10uF 31 40 P3.1 P2.e.5 milliseconds for the transmission depending of the baud rate used. The program must wait until transmission of character is over before loading the next character in the SBUF.1 P1.0(RxD) VCC P1. Modify program to transmit text “YES”. 10 AIM: Write a program to transmit letter “E” continuously using serial port. This can be prevented with any one of the following method mentioned here. transmission is over.7/AD7 GND 8 7 6 5 4 3 2 1 D1 C2- RxD 1 13 2 14 3 9 TxD 4 4 5 5 6 22uF DB9 Connector Serial Port of PC 6 Connector 1 2 3 4 5 6 7 8 RST 15 9 EA VCC RESET 89C51 10K 22uF Serial data transmission: Data transmission is unidirectional from microcontroller to the destination device.

location for the serial interrupt is 0023h. The serial interrupt
bit ES(IE.4) and Enable interrupts bit
EA(IE.7)are set in
IE(Interrupt Enable) SFR. When transmission is over, TI flag
will set and serial interrupt will be invoked. Program will jump
to the location 0023h where user should write a routine to clear
TI flag and load SBUF register by new character. In this
practical, We will first write a program using polling method i.e.
continuously checking TI flag and then we will write a program
using interrupt method.
Program:
ORG 00H
AJMP START
START: MOV TMOD,#20h
MOV TH1,#0fdh

;Configure Timer 1 in mode 2 auto reload mode.
;Load TH1 with FDh to achieve baud rate 9600

MOV SCON,#50h ;8 bit, 1 stop bit, REN Enabled.
MOV A,PCON

; Transfer content of PCON to accumulator

SETB ACC.7

; Set bit 7 of accumulator

MOV PCON,A

; Set SMOD bit to 1 to double the baud rate

SETB TR1
NEXT:

MOV SBUF,#’E’

HERE: JNB TI,HERE
CLR TI

;Transfer alphabet ‘A’ to SBUF
;Wait for the last bit
;Clear TI for next ‘A’

SJMP NEXT
END
Modified program:
;Program to transmit text “YES” using Look up table in ROM through
;serial port of the microcontroller using 8 bit UART mode with baud rate
;19,200. TI flag is checked in this program to know whether transmission
;is over or not?
ORG 00H
AJMP START
START: MOV TMOD,#20h
MOV TH1,#0fdh

;Configure Timer 1 in mode 2 auto reload mode.
;Load TH1 with FDh to achieve baud rate 9600

MOV SCON,#50h ;8 bit, 1 stop bit, REN Enabled.
MOV A,PCON

; Transfer content of PCON to accumulator

SETB ACC.7

; Set bit 7 of accumulator

MOV PCON,A

; Set SMOD bit to 1 to double the baud rate

EC Department, Government Engineering College, Rajkot

Page 37

SETB TR1
REPT:

MOV DPTR,#0400h

NEXT:

CLR A
MOVC A,@A+DPTR

; Get letter from look up table

JZ REPT
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI

;Transfer letter from look up table
;Wait for the last bit
;Clear TI for next character

INC DPTR
SJMP NEXT
ORG 0400h
DB 'YES',0
EXIT:
END
Modified program for Serial transmission using interrupt method:
;Program to transmit data from RAM through serial port of
;the microcontroller using 8 bit UART mode with baud rate 9600
;Serial port interrupt is used for data transmission.
ORG 00h
AJMP start
ORG 23h
;Location for serial interrupt
ajmp serial
RETI
;Return from the ISR
start:
MOV P1,#0ffh
;Make P1 output port
MOV P2,#00h
;Make P2 output port
MOV TMOD,#20h ;Timer 1, mode-2 ( auto reload mode)

next:

MOV TH1,#0FDh ;Count value for baud rate 9600
MOV SCON,#50h ;8 bit UART mode, REN enable
MOV IE,#90h
; Enable serial interrupt and EA bit
MOV R0,#20h
;Pointer to the RAM location
SETB TR1 ;Start timer 1 to generated baud rate.
MOV A,@R0
MOV SBUF,A
INC R0
CJNE R0,#2Fh,next

serial:
JB TI,transmit
MOV A,SBUF
MOV P0,A
CLR RI
Lab Manual of Microcontroller and Interfacing

Page 38

RETI
transmit:
CLR TI
RETI
END

:: WORKSHEET::
Exercise:
Modify program to transmit string “WELCOME TO GEC RAJKOT” using
serial port. Use interrupt method and baud rate 9600.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_________________________________________________________________

EC Department, Government Engineering College, Rajkot

Page 39

8-bit data.Write C program to transfer the message “GTU” 255 times serially at 9600 buad. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 40 . 1 stop bit.

0 P2.3 P1.6/AD6 P0.6 P1. Max 232 provides necessary voltage conversion from TTL to serial port standards.5 P1.1(TxD) P2. Rajkot Page 41 . indicating serial mode 1 in which 8 bit data is framed with start and stop bits. The value FDh is loaded in TH1 register to generate baud rate 9600 for the crystal of 11.7/AD7 GND 8 7 6 5 4 3 2 1 D1 C2- RxD 1 13 2 14 3 9 TxD 4 4 5 5 6 22uF DB9 Connector Serial Port of PC 6 Connector 1 2 3 4 5 6 7 8 RST 15 9 EA VCC RESET 89C51 10K 22uF Pin connections:  LEDs are connected to port 0 to display received data from the serial port  Serial data transfer pins RxD and TxD are connected to the serial port of the computer thorugh IC MAX 232.4/AD4 P0. Government Engineering College.0(RxD) VCC P1.1/AD1 P0. 11 AIM: Write a program to receive bytes of data serially and display it on port P0. • The SCON register is loaded with the value 50h.1 P2.2 P1.2 12 11 D8 11 X2 18 1 GND 22 PF X1 19 20 22uF 3 V+ R1OUT T1IN 22 PF C1+ C1- 22uF 2 16 10 R1IN T1OUT C2+ V- P3.5/AD5 P0.7 P1.0 39 38 37 36 35 34 33 32 MAX232 21 22 23 1K X 8 P0.4 P1.059 MHz. Interfacing diagram: Vcc 10uF 31 40 P3. As per RS232 standard. logic 1 has voltage range -3 to -25 V and logic 0 has voltage range +3 to +25 V.0/AD0 P0.1 P1. Programming steps: • The TMOD special function register is loaded with the value 20h to use timer 1 in mode 2 (8 bit auto-reload) to set baud rate. Use 8 bit UART mode with baud rate 9600. EC Department.3/AD3 P0.EXPERIMENT NO.2/AD2 P0.

CHECK MOV P0. When RI flag set. ORG 00h AJMP start ORG 23h MOV P0.Return from the ISR start: MOV P1.Timer 1. program will automatically jump to the location 0023h which is vector location of serial interrupt.#0ffh MOV P2.Count value for baud rate 9600 MOV SCON. CHECK” instruction to check whether entire character has been received or not. Program 1: Serial data reception using polling method: ORG 00h . Start program from memory location 00h MOV TMOD. instead of checking RI flag continuously we use serial port interrupt.Make P1 output port .Repeat task Program 2: Serial data reception using interrupt method: In interrupt method. Display received data on port P0 . • The RI flag is cleared with the instruction CLR RI • The RI flag is monitored with the instruction: “CHECK: JNB RI.• The timer 1 run control bit TR1 is set to high.Make P2 output port Lab Manual of Microcontroller and Interfacing Page 42 .8 bit UART mode. Check whether data byte is received or not .#0FDh .SBUF CLR RI SJMP CHECK END . REN enable MOV P0.#00h . Display received data on port P0. .#20h .#50h . CHECK: JNB RI.SBUF CLR RI RETI .Port P0 output port SETB TR1 . mode-2 ( auto reload mode) MOV TH1.Location for serial interrupt .#00h . In this program we read port P1 continuously and display its content on port P2. • When reception is over. RI is raised by microcontroller which indicates that SBUF has a byte and we can read it and display it at LEDs connected at Port P0. Clear RI flag .Start timer 1 to generated baud rate.

0x03). No Parity.Divisor Latch High Byte outportb(PORT1 + 3 .h> #include <conio.A . and OUT2 */ printf("\nSerial Communication with microcontroller. Enable serial interrupt and EA bit SETB TR1 . /* If key pressed.400 BPS */ outportb(PORT1 + 1 .Timer 1. /* Turn on DTR.Start timer 1 to generated baud rate. P1 . mode-2 ( auto reload mode) MOV TH1. RTS./* If so. /* 8 Bits. /* Baud rate 9600 */ /* Set Baud rate .#90h . 0xC7). /* FIFO Control Register */ outportb(PORT1 + 4 .600 BPS /* 0x06 = 19. /* Turn off interrupts .#20h . REN enable MOV IE.h> #define PORT1 0x3F8 /* Defines Serial Ports Base Address */ /* COM1 0x3F8 COM2 0x2F8 COM3 0x3E8 COM4 0x2E8 */ void main(void) { int c.#0FDh . outportb(PORT1 + 1 .#50h . SJMP next .ch.200 BPS 0x02 = 57.800 BPS */ /* 0x30 = 2. Alternately we can use hyper terminal or XTalk software for serial communication.MOV TMOD.} /* Print Char to Screen */ if (kbhit()){ch = getch(). /* Quit when ESC (ASC 27) is pressed */ } EC Department.600 BPS 0x18 = 4.Count value for baud rate 9600 MOV SCON.400 BPS 0x01 = 115. 1 Stop Bit */ outportb(PORT1 + 2 . /* Check to see if char has been received */ if (c & 1) {ch = inportb(PORT1). 0x0B). Government Engineering College.8 bit UART mode. Display content of port P1 on port P2. 0). get Char */ outportb(PORT1.Repeat task END Program 3: Program at computer side: Program for serial communication in “C” language is given here.Divisor Latch Low Byte */ /* Default 0x03 = 38.200 BPS 0x0C = 9. Press ESC to quit \n"). /* Set Baud rate . #include <dos. 0x00). ch).} /* Send Char to Serial Port */ } while (ch !=27). do { c = inportb(PORT1 + 5). 0x0C).Port1 */ outportb(PORT1 + 0 . next: MOV A.h> #include <stdio. then get Char */ printf("%c". Read port P1 MOV P2. Rajkot Page 43 .ch).

Store data from the RAM location 20h . REN enable MOV IE.#00h . mode-2 ( auto reload mode) MOV TH1.#0ffh . mode-2 ( auto reload mode) MOV TH1.#50h .Repeat task store: MOV A.Pointer to the RAM location SETB TR1 .Program to receive data through serial port of microcontroller at the .#20h .Count value for baud rate 9600 MOV SCON.baud rate 9600.#20h .#20h . P1 MOV P2.#90h .Timer 1.This program uses polling method.#0FDh .Start timer 1 to generated baud rate.Program to receive data through serial port of microcontroller at the .#50h .Location for serial interrupt ACALL store RETI . Enable serial interrupt and EA bit MOV R0.8 bit UART mode.8 bit UART mode.A SJMP next . Lab Manual of Microcontroller and Interfacing Page 44 .#0FDh .baud rate 9600.Start timer 1 to generated baud rate. ORG 00h AJMP start start: MOV TMOD. next: MOV A.SBUF MOV @R0.#20h .Make P1 output port MOV P2.Count value for baud rate 9600 MOV SCON.This program uses interrupt method for reception of data ORG 00h AJMP start ORG 23h .A INC R0 CLR RI RET END Program 5: Receive and store data using polling (status checking) .Make P2 output port MOV TMOD.Pointer to the RAM location SETB TR1 . REN enable MOV R0.Return from the ISR start: MOV P1.Timer 1.Program 4 : Receive and store data in RAM using interrupt . Store data from the RAM location 20h .

Assume control lines of LCD RS.HERE CLR RI MOV @R0.Repeat task END :: WORKSHEET :: [1] Modify program to display received data on the LCD connected at port P1. EN and WR are connected to P2.SBUF HERE: JNB RI.0. Government Engineering College.A INC R0 SJMP next . Rajkot Page 45 . _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department. P2.next: MOV A.2 respectively.1 and P2.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 46 .

EXPERIMENT NO. Display pulses on the LCD connected at port P1.2 RW .0 P2.2 P1..6 P2.5 P2.0-RS.2 P2.4 P1.2 P0. Circuit diagram: +5V 10uF 21 22 23 24 25 26 27 28 10K RST P2.6 P1.To measure frequency of external pulses using 89C51 .3 P2.5 P0.4 P2.0 P3. Government Engineering College.Port 1 Drives data lines.4 P0.P3.1 P2.  Control lines RS (Register select) is connected with port pin P3. We can connect input signal with amplitude up to 12V to the opto-coupler.5 P1. Pulses from the opto-coupler PC817 connected to timer input pin T0.7 22 PF 18 6 MHz 22 PF 19 X2 X1 GND Signal Input P3. 12 AIM: Write a program to measure frequency of external pulses given at the timer 0 input pin.4/T0 P0.1 P1.Signal connected through optocoupler PC817 at pin T0 (P3.1 P3.2 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 10K 7 D0 8 9 10 11 12 13 14D7 10 11 12 15 2 3 LCD MODULE 4 6 5 RS E R/W 1 16 20 Interfacing details:  LCD data lines are connected to port P1. read/write line connected with P3.2.0. P3. Rajkot Page 47 .1.4) ORG 00H AJMP START EC Department.0 P0.1 EN.0 P1.7 P1.7 PC817 14 1K 150 89C51 9 EA VCC RESET 10K 31 40 100 P3.  Opto-coupler PC817 is used to provide optical isolation between signal to be measured and microcontroller.6 P0. Enable line connected with pin P3.LCD Interfacing details: .1 P0. We may connect 230V AC signal by using series resistor of 47K at the input of opto-coupler.3 P0.P3.3 P1. Program: .

#00H MOV A.#50H .#15H .#088H . Cursor ON .Load Timer 1 with 45535(B1E0h) MOV TH1.Load Timer 1 with 45536(b1e0h) results .results in 0.#0B1H SETB TR1 INC R1 CJNE R1.#00h MOV A. position 8 ACALL COMMAND MOV R1.Issue command to the LCD .Clear LCD .LCD ON.#00H .Stop timer 0 Lab Manual of Microcontroller and Interfacing Page 48 .Set P3 as an output port .#64H. 5X7 matrix .Shift cursor right . 2 lines.Timer 1 as a timer in mode 2 & .#06H ACALL COMMAND MOV A.Start timer 0 and timer 1 CHECK: JNB TF1.ORG 03H RETI ORG 0BH RETI ORG 13H RETI ORG 1BH RETI ORG 23H RETI START: MOV SP.Force cursor at begining of the first line .#00H MOV P3.in 0.#MSG ACALL DISP_MSG MOV TCON.Timer 0 as a counter in mode 1.#01H ACALL COMMAND MOV A.Initialize LCD.01 SECOND DELAY) MOV TH1.01 second delay) MOV TL0.CHECK CLR TF1 MOV TL1.Reset counter for counting operation MOV TH0.Timer 0 & Timer 1 off.Count 100 interrupts to provide delay .Display message on first line .#0E0H .Set P1 as an output port .Clear R1 for overflow counting MOV TCON.100X0.#0E0H .01 =1second READ_FREQ: CLR TR0 .#0B1H .#0EH ACALL COMMAND MOV A.#38H ACALL COMMAND MOV A.#00H MOV TMOD.#60H MOV P1. LOOP: MOV TL1. flags in reset condition .Move cursor to line 2.#80H ACALL COMMAND MOV DPTR.#00H .CHECK .Point to message "Freq:" .

SKIP ADD A. now all registers are 1 higher ACALL TRANSF . add to 34h.Transfer LSB of 16 bit count value at RAM location30h MOV 31H. Point to 35h ACALL TRANSF .Transfer MSB of 16 bit count value at RAM location 31h ACALL HEXBCD . Transform 36h to 3 higher positions GO_NEXT: MOV R0.Convert hex number into binary numbers MOV A.#0 MOV 37h.TL0 . Government Engineering College.#33h .#10 DIV AB MOV 33h.6. Value in 35h is 256 times higher than value standing in 33h.#0 MOV 36h.CLR TR1 . 34h. Repeat from 36h.B MOV 34h.Stop timer 1 MOV 30H.#36H JNB PSW. Rajkot Page 49 .#07H SKIP: SUBB A.34H ACALL HEXASCI ACALL DISP_DATA MOV A.33H ACALL HEXASCI ACALL DISP_DATA AJMP LOOP HEXASCI: ADD A.#35h . add to 33h. first digit ACALL DECADJ EC Department.e.37H .B MOV 36h.36H ACALL HEXASCI ACALL DISP_DATA MOV A. .#10 DIV AB MOV 35h.#06H RET HEXBCD: MOV 35h.30h MOV B.#0 MOV A.35H ACALL HEXASCI ACALL DISP_DATA MOV A. Point to lowest digit i.31h JZ GO_NEXT MOV B. mply 35h with 2 and replace itself in 35h MOV R0.Convert the number stored at 37h into ASCII ACALL HEXASCI ACALL DISP_DATA . mply 35h with 5.TH0 .A MOV A. Display ASCII code of number at LCD MOV A. Mply 35h with 6.A . Transform 35h to 3 lower position INC R0 .

@R0 MOV B.@R0 DECLOP: MOV B.#37h.A INC R0 INC R0 MOV A. Mply with 2 MOV @R0.#6 MUL AB DEC R0 DEC R0 ADD A.Select command register CLR P3.A ACALL DELAY .DECLOP RET COMMAND: PUSH DPH PUSH DPL MOV P1.1 POP DPL POP DPH RET DISP_DATA: PUSH DPH PUSH DPL Lab Manual of Microcontroller and Interfacing Page 50 .@R0 MOV @R0.2 .A RET DECADJ: MOV A.1 .Write when when display not busy CLR P3.0 .RET TRANSF: MOV A.@R0 MOV B.A INC R0 MOV A.@R0 MOV @R0.B INC R0 ADD A.Set Enable terminal of LCD NOP NOP CLR P3.@R0 RL A .@R0 MOV @R0.Write Enable SETB P3.#10 DIV AB MOV @R0.A CJNE R0.#5 MUL AB DEC R0 ADD A.

Enable Write SETB P3. :: WORKSHEET :: Exercise: Simplify program to count external pulses given at T0 pin.Select data register CLR P3.ACALL DELAY MOV P1.1 . Government Engineering College.LOOP1 DJNZ R7.2 .LOOP2 RET MSG: DB 'FREQ:'.0 .0 END Connect signal from the function generator to the input of opto-coupler and measure frequency of the signal. Rajkot Page 51 .#22H LOOP2: MOV R6.Enable LCD (Strobe LCD) CLR P3.1 .#0FFH LOOP1: DJNZ R6.Clear Enable and latch data POP DPL POP DPH RET DISP_MSG: ACALL DELAY CLR A MOVC A.Get data for display SETB P3. Display this pulses on seven segment display connected at port P0. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.A .@A+DPTR JZ EXIT ACALL DISP_DATA INC DPTR SJMP DISP_MSG EXIT: RET DELAY: MOV R7.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 52 .

0 to P2.7/A15 22 PF 19 1K X 8 VCC 10K EA 10K 31 10uF X1 32 33 34 35 36 37 38 39 8 7 6 5 25 26 27 28 X2 20 20 18 22 PF GND 1K X 8 Interfacing details:  Rows of matrix keyboard are connected to port pins P1.1/AD1 P0.6 P1. These LEDs may be used to indicate which row is scanned and which column is read by the program.4/A12 P2.7 P1.3  Columns of matrix keyboard are connected to port pins P2.6/A14 P2. Rajkot Page 53 .4 to P2.7/AD7 P0.3 P2.1/A9 P2.0 to P1. EC Department. Write program to display key pressed on seven segment display Circuit Diagram: Vcc 10K RESET 10K 9 U2 40 10K RST P0.6/AD6 P0.0/AD0 10K 1 2 3 4 21 22 23 24 10K 10K 89C51 10K P1.2 P1.5 P1.4 P2.5/AD5 P0. It may be used to indicate which key is pressed at present.2/AD2 P0.2/A10 P2. 13 AIM: Interface matrix keyboard with 8051.7 to P1.3/A11 P1.3  Common anode seven segment display is connected to port P0  LEDs are connected to port P1.EXPERIMENT NO.3/AD3 P0. Government Engineering College.4/AD4 P0.1 P1.0 P1.0/A8 P2.4 and P2.7.5/A13 P2.

P1.#0FH.#0FH .Program: .READ ALL COLUMNS ANL A.R_1 .7 o/p pins MOV P1.KEY IS PRESSED IN FIRST ROW (ROW 0).P2 .CHECK . COLUMNS MOV P1.MAKS UPPER BITS BECAUSE THEY ARE NOT USED CJNE A. COLUMNS MOV P1.#00h MOV P2.#0FH. Ground ROW 1 MOV A.P2 .#00H .MASK UNUSED UPPER BITS CJNE A.CHECK TILL ALL KEYS RELEASED AGAIN: ACALL DELAY MOV A.#0FH . Port Pins P2.3 & Columns are connected to Port pins P2.CHECK .0-P1.READ ALL COLUMNS ANL A.P2 . IF A IS NOT EQUAL TO 0Fh THEN KEY IS . Rows are grounded .#0FH.Port P0 output port REL: MOV P1.REL .KEY IS PRESSED IN SECOND ROW (ROW 1).3.READ PORT P2 TO ENSURE THAT ALL KEYS RELEASED ANL A.#0FBH .#0FH .CHECK . PRESSED SJMP AGAIN .R_0 .#0FH .0-P2. CHECK AGAIN IF KEY IS NOT PRESSED KPRESS1: MOV P1.0 to P2.#0FH .CHECK .4 to P2.MASK UNUSED UPPER BITS CJNE A.KEY IS PRESSED IN THIRD ROW (ROW 2).MASK UNUSED UPPER BITS CJNE A.MASK UNUSED UPPER BITS CJNE A.#0FH . Ground ROW 2 MOV A. IF A IS NOT EQUAL TO 0Fh THEN KEY IS .MASK UPPER BITS CJNE A.KEY IS PRESSED IN FOURTH ROW (ROW 3).P2 .P2 .P2 .0FH. Ground ROW 0 MOV A.SEE IF ANY KEY PRESSED OR NOT? ANL A.0FH. ANL A.#0FH .READ ALL COLUMNS ANL A.KPRESS1 .#0FDH .0FH. CHECK AGAIN IF KEY IS NOT PRESSED KPRESS: ACALL DELAY MOV A.3 i/p pins and P2. Program to interface matrix keyboard 4x4. one by one and read columns . MAKE ALL ROWS GROUND TO CHECK ALL KEYS MOV A. COLUMNS MOV P1.0FH.P2 .MASK UNUSED UPPER BITS CJNE A. Rows are connected to the Port pins .READ ALL COLUMNS ANL A.R_3 .KPRESS .PRESSED SJMP AGAIN .#0FEH . Seven segment display is connected at port P0 ORG 00h AJMP START ORG 13h RETI START: MOV P0.R_2 .#00H .#0FH . COLUMNS Lab Manual of Microcontroller and Interfacing Page 54 . Ground ROW 0 MOV A.#0F7H .

@A+dptr MOV P0.'9'. WORKSHEET :: Exercise: [1] Prepare seven segment code for common anode seven segment display and replace it with ASCII code in look up table as shown in the program. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.DLOOP RET KCODE0: DB '0'.#KCODE1 SJMP CHECK_C R_2: MOV DPTR.Replace this code by seven .#KCODE0 SJMP CHECK_C R_1: MOV DPTR.'5'.'E'.#KCODE3 CHECK_C: RRC A .'A'.Circuit.'D'.'7' KCODE2: DB '8'. Government Engineering College.'3' KCODE1: DB '4'.#0FFh D_LOOP: DJNZ R6.SET DPTR=START OF ROW 2 .#0FFh DLOOP: MOV R6.'B' KCODE3: DB 'C'.SET DPTR=START OF ROW 1 .CHECK JNC GET_CODE INC DPTR SJMP CHECK_C GET_CODE: CLR A MOVC A.'6'.#KCODE2 SJMP CHECK_C R_3: MOV DPTR.D_LOOP DJNZ R7.'2'. Rajkot Page 55 .SET DPTR=START OF ROW 0 .A LJMP REL R_0: .SET DPTR=START OF ROW 3 WHETHER CARRY OCCURS OR NOT DELAY: MOV R7.segment code as per your . Run the program and see the result.These codes are for LCDs .'F' .LJMP AGAIN MOV DPTR.'1'.

7 shows which row is scanned by the program and P2. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 56 .7 shows which key is pressed in each row.4 to P1._____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [2] Modify program such that LEDs connected at P1.4 to P2.

This IC consists of internal suppression diodes for the inductive loads.0 to P1. Government Engineering College.2 P0. Each Darlington pair can drive load current upto 500 mA. Such motor requires current rating of 0. When transistor switched from ON to OFF state.EXPERIMENT NO. Write a program to rotate motor in clockwise and anticlockwise direction in half step and full step mode.5 A per phase. Program will remain same. Circuit diagram: +5V or +12V or +24V Depending on type of m otor +5V 10uF 10 P0. IC ULN 2803 is used to supply necessary drive current to the motor.1 1 SW1 SW2 2 22 PF 18 19 22 PF P0. 14 AIM: Interface stepper motor with port P0 of the microcontroller. +12V it requires current of 2A/phase. This stepper motor requires combination of transistor SL-100 and 2N3055 as shown in the following circuit diagram. The suppression diode discharge energy stored in the inductor when transistor is in OFF condition. EC Department. As PORT P0 cannot supply desired current. ULN2803 is high voltage high current Darlington arrays consists of eight Darlington open collector transistors.1 GREEN BLUE ORANGE X2 X1 GND 12 IN1 ULN2803 18 OUT1 17 OUT2 16 OUT3 15 OUT4 V P0. large voltage induced across coil of stepper motor can damage the transistor.3 are shown.0 1 GND RST 39 9 9 40 RESET 10K VCC 10K EA 10K 31 RED 20 Interfacing details: Interfacing of small torque stepper motor with torque of 2Kg-cm is shown in above diagram. In this circuit control signals from port pins P1. Control signals may come from any port of microcontroller. Rajkot Page 57 . To drive stepper motor with torque 7 kg-cm. Four terminals of the stepper motor are controlled with PORT P0. These diodes are used to protect switching transistor from breakdown.0 89C51 13 INT0 38 P1.3 INT1 2 37 3 36 4 IN2 IN3 IN4 P1.

Delay to control speed .Configure port P0 as an output port . of steps<100 .Sequence of pulses required to send on port P0 to rotate motor in clockwise and anticlockwise direction for full step mode: Program 1: To rotate motor for 100 steps in clockwise direction (Full step) ORG 30h MOV P0.Change this count to change speed Lab Manual of Microcontroller and Interfacing Page 58 .Continue rotation if no.#11h MOV P0.Sent data to port 1 (stepper motor) .A ACALL delay RL A DJNZ R0.Next data .d_loop RET END .#0FFh DJNZ R2.Load count value for 100 steps .Load accumulator with 11h .#00h MOV R0. #64h loop: delay: d_loop: MOV A. loop MOV R2.

#0Ch CALL DELAY MOV P0.Sent data to port 1 (stepper motor) .Change this count to change speed EC Department.Sequence of pulses required to send on port P0 to rotate motor in clockwise and anticlockwise direction for half step mode: Program 2: To rotate motor in half step mode continuously in clockwise direction LOOP: DELAY: d_loop: ORG 40h MOV P0.Delay to control speed .#08h CALL DELAY MOV P0.Define port P0 as output port .Sent data to port 1 (stepper motor) .Sent data to port 1 (stepper motor) .#0FFh DJNZ R2.#04h CALL DELAY MOV P0.Continue rotation .#03h CALL DELAY MOV P0.Delay to control speed .Delay to control speed .Sent data to port 1 (stepper motor) . Government Engineering College.Delay to control speed . Rajkot Page 59 .#01h CALL DELAY MOV P0.Delay to control speed .d_loop RET END .Delay to control speed .#09h CALL DELAY JMP LOOP MOV R2.Sent data to port 1 (stepper motor) .Sent data to port 1 (stepper motor) ..#02h CALL DELAY MOV P0.Delay to control speed .#00h MOV P0.#06h CALL DELAY MOV P0.Sent data to port 1 (stepper motor) .Sent data to port 1 (stepper motor) .Delay to control speed .

:: WORKSHEET :: Exercise: [1] Consider that two push-button switches are connected at port pins P3. Write a program so that speed of the motor increases if switch connected at P3.3 is pressed) _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 60 . (Hint: use polling method or interrupt method to monitor key press event. reduce timer delay counter if switch connected at P3.2 is pressed. Increase time delay counter if switch connected at P3.3.3 is pressed.2 pressed and speed of the motor reduces if switch connected at port pin P3.2 and P3.

2 and P3. Enable external interrupt bits in IE SFR) _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department. stepper motor rotates clockwise and when switch SW2 pressed. Prepare anticlockwise routine and call it at vector location 13h. Rajkot Page 61 . Government Engineering College. stepper motor rotates anticlockwise. Write a program so that when switch SW1 is pressed. (Hint: Use external interrupt vector location. Prepare clockwise routine and call it at location 03h.[1] Consider that switch SW1 and SW2 shown in the circuit are two limit switches are connected at external interrupt pins P3.3.

ON time is more than OFF time) speed is more and if duty cycle is less (ON time is less than OFF time). speed of motor is also highest and when width of pulse is lowest. When width of pulse is highest.0/AD0 P0.EXPERIMENT NO.5/AD5 P0. speed of the motor is also less.0 33 PF 33 PF 19 1 X2 X1 P1.3/AD3 P0.3/INT1 SW2 P1. we can use variable DC voltage source.1/AD1 P0. Lab Manual of Microcontroller and Interfacing Page 62 .e. if we apply PWM (Pulse Width Modulated) waveform to the motor. If we switch ON and OFF DC power supply continuously. 15 AIM: Interface DC motor with 89C51 microcontroller. If we switch OFF DC power supply before it gets maximum speed.2/AD2 P0. speed of DC motor will be in between zero and full rated speed.7/AD7 89C51 13 RST 1 9 10K EA VCC RESET 10K 31 40 100 2 Q1 TIPL751 20 Basic concept: DC motor speed control is useful in controlling motion in industrial control systems as well as arm of robots.4/AD4 P0. it takes some time to reach at full speed.2/INT0 P0. When supply is given to DC motor.6/AD6 P3. we can change speed of the motor. If duty cycle is more (i. it starts to slow down. Write a program to rotate motor with different speed using PWM Circuit Diagram: +5V +6 V 10uF 10K 12 39 38 37 36 35 34 33 32 P3. Thus.1 GND 18 12 MHz DCM 2 SW1 1K X 8 P0. To control speed of DC motor. speed of motor is also lowest.

Decrease R7 to decrease width of pulse RETI MOV IE.B . Program: START: next: ORG 00h SJMP START ORG 03h INC B . Decrement R6 until it becomes zero DJNZ R7. Load count value from register B L3: MOV R6. Transistor acts as a switch which becomes ON when port pin P1. L2 . Initial speed SETB P1. Government Engineering College.1 output pin MOV B.#0FFh L2: DJNZ R6. Call delay for OFF time SJMP next OFF_delay: MOV R4.#00h L1: DJNZ R4.Interfacing details: Simple DC motor control circuit is shown in the circuit diagram. Return to main routine END EC Department.1 . No operation RET . Increase R7 to increase width of pulse RETI ORG 13h DEC B . Transistor is controlled by signal from microcontroller port pin P1. DC motor is connected to the collector of transistor (We can use transistor TIP122 or 2N 3055). Negative edge triggered interrupt SETB IT1 . This will control speed of the motor. Call delay for ON time CLR P1.0 to generate square wave ACALL OFF_delay . Enable external interrupt 0 and 1 SETB IT0 . L1 RET ON_delay: MOV R7. Rajkot Page 63 . We can write program such that width of pulses increases when we press switch SW1 and width of pulses decreases when we press the switch SW2. Two push button switches SW1 and SW2 are connected at external interrupt pins to control speed of the DC motor.L3 NOP .Negative edge triggered interrupt CLR P1.#85h . Make P1. Common anode seven segment display is connected to port P0 to show the speed of the motor in numeric form.1 is reset.1 is set and becomes OFF when port pin P1.1.#80h . Complement P1.0 .0 ACALL ON_delay .

If motor voltage rating is higher than the voltage used for microcontroller then opto-isolator prevents damage to the microcontroller by providing optical isolation.3/INT1 89C51 13 1K X 8 P0. By controlling ON and OFF time of the LED.1 is low. set). we can control speed of the DC motor.7/AD7 1 10K RST 2 20 1K Opto Isolator PC817 or ILD74 2 9 10K EA VCC RESET 10K 31 40 100 Q1 TIP 120 When port pin P1. Program will be very much similar to the previous program. When port pin P1.1 Lab Manual of Microcontroller and Interfacing Page 64 .1 GND 12 MHz 220 P1.0 33 PF 18 +6 or +12 or +24V +5V P3.6/AD6 P3.1/AD1 P0.2/INT0 P0. microcontroller is safe.0/AD0 P0. Current flows through base of transistor TIP120 and motor gets DC supply.1 is high (i.1 and CLR P1. LED will not glow. except we will interchange SETB P1. Transistor of opto-isolator and TIP120 forms Darlington pair. LED of opto-isolator will glow which makes transistor of opto-isolator ON.5/AD5 P0.e.4/AD4 P0. If there is any fault in motor circuit or power supply.3/AD3 P0.2/AD2 P0. Modified circuit using optoisolator is shown below: +5V 10uF 12 SW1 39 38 37 36 35 34 33 32 SW2 33 PF 19 1 DCM X2 X1 P1. both transistors remains off and motor will not get DC supply.Optical isolation: It is better to use opto-isolator between motor circuit and microcontroller because it will protect microcontroller from EMI created by the motor brushes.

4 are high. Interfacing of H-bridge with microcontroller is shown in the following circuit diagram. +5V 10uF RST 10K 12 40 P3. When port pins P1. Optical isolation is not shown in the circuit but it is better to use optical isolation for safety of microcontroller. This IC produces heat during the operation. Government Engineering College.2 P1. motor rotates in anticlockwise direction because of reversal in current.H-Bridge configuration for bi-directional rotation: Direction of DC motor can be changed by changing polarity of DC voltage.2/INT0 P1.0 89C51 13 Q2 and Q3 ON ---> Motor rotates Anticlockwise VCC 9 10K EA RESET 10K 31 Q1 and Q4 ON ---> Motor rotates Clockwise 100 +6 or +12 or +24V 1 Q1 2 1 3 Q2 Q3 1K DCM 2 Q4 4 1K 20 H-bridge is available in single IC form such as L293.2 are high. Quad optocoupler IC has four in-built optocoupler which provides optical isolation between H-bridge circuit and microcontroller 89C51. Interfacing of H-bridge IC with microcontroller using Quad optocoupler IC ILQ74 is shown in the following circuit diagram. H-Bridge configuration is very popular for bi-directional speed control.0 and P1. Rajkot Page 65 . EC Department. Separate power supply can be used for microcontroller and motor circuit.3 GND SW1 P3. We need four microcontroller pins to control direction and speed of the DC motor. Four transistors are inbuilt in this IC.1 P1.3/INT1 SW2 33 PF 12 MHz 33 PF 18 19 X2 X1 P1.1 and P1. hence it requires heat sink for continuous operation. motor rotates in clockwise direction and when pins P1.

Make P1. Use external interrupts for the program.1 CLR P1.do -RETI ORG 13h .#85h . Rotate motor in clockwise direction CLR P1.0 SW2 12 MHz 33 PF 18 19 P1. Enable external interrupt 0 and 1 SETB IT0 .2 . Vector location for external interrupt 0 SETB P1.do -RETI CLR P1. Make P1.2 output pin MOV IE.1 output pin CLR P1. motor rotates in anti-clockwise direction.0 Enable H bridge 10uF SETB P1.1 .1 Motor anticlockwise SETB P1.3/INT1 89C51 13 P3.0 .+5V SETB P1.2 Motor clockwise 40 15 13 11 P3.2 2 3 2 1 4 3 5 1K 16 14 12 1 2 7 1/2EN 1A 2A 13 5 1Y 2Y 3 1 DCM 2 6 4 12 6 X2 X1 L293 H-Bridge GND 33 PF P1.2 CLR P1. -.Negative edge triggered interrupt SETB P1.2/INT0 P1.0 output pin CLR P1.0 .1 . 12 SW1 16 VCC2 8 10K +12V VCC1 RST VCC 9 10K EA RESET 10K 31 470 100 ILQ74 Opto-isolator 20 Program: Write a program to rotate DC motor connected in above circuit such that when switch SW1 is pressed.0 .1 . Enable chip L293 (H-bridge) SJMP HERE Lab Manual of Microcontroller and Interfacing Page 66 . Make P1. Negative edge triggered interrupt SETB IT1 . motor rotates in clockwise direction and when SW2 is pressed. Vector location for external interrupt 1 SETB P1. -.0 . START: HERE: ORG 00h AJMP START ORG 03h .1 1 GND . Rotate motor in anticlockwise direction CLR P1.

Government Engineering College.2. so that speed of the DC motor displayed on the seven segment display (Hint: Use look up table method to display 0 for minimum speed and 9 to display maximum speed) _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department. clockwise _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ [2] Modify the first program of this practical. Rajkot Page 67 .:: WORKSHEET :: Exercise: [1] Modify previous program without using interrupts Hint: using polling method to check whether switch is pressed or not like JNB P3.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 68 .

START EQU P3. Microcontroller connections to ADC0808/9 lines. 0/RXD P2.#0FFH .LOOP EC Department. Pin 6 Start EOC EQU P3.#00H . Circuit diagram: +5V 10K 12 11 EOC ALE START OE A2 A1 A0 17 14 15 8 18 19 20 21 1 2 3 4 5 6 7 8 7 22 6 9 12 15 16 17 23 24 25 23 22 21 P3.6 .2/I NT0 P3.5/CEX2 P1.0/A8 10 16 13 40 P1. 5/AD5 P0.6/CEX3 P1. 0/AD0 P3.0/T2 P1.4/CEX1 P1. P0 OUTPUT PORT TO DRIVE LEDs MOV P1.#00H ACALL DELAY DJNZ R0.2/A10 P2. Pin 9 Output Enable ALE EQU P3. Display hex code of analog value on LEDs connected at port P0.2/ECI P1. 4/AD4 P0.7/CEX4 30 CLK D1 89C51 IN0 IN1 IN2 IN3 IN4 IN5 IN6 IN7 D0 D1 D2 D3 D4 D5 D6 D7 GND 26 27 28 1 2 3 4 5 ADC0808 REF+ VCC Analog Input POT 10K RST VCC 9 U3 EA R ESET 10K 31 10uF CLK GND 1 CD4024B RST U5 Program: . 2/AD2 P0. 3/AD3 P0. Rajkot Page 69 .P1 INPUT PORT TO READ ADC MOV P2.2 .7 . Pin 22 ALE LOOP: ORG 00h MOV P0. Government Engineering College. 16 AIM: Interface ADC0808 with 89C51 microcontroller.1/TXD 32 33 34 35 36 37 38 39 10 11 D8 22 PF X2 18 22 PF ALE +5V X1 19 20 11 7 2 Q2 VDD 14 20 REFGND 1K X 8 P0.3/CEX0 P1.6 .7/RD P3.EXPERIMENT NO.1/T2EX P1.#00h .1/A9 P2. 1/AD1 P0.#05H MOV P0.6/WR P3. 7/AD7 P0.5/T1 P3. Write program to read analog voltage applied at the input of ADC. P2 OUTPUT PORT TO SELECT CHANNEL MOV R0.#0FFH ACALL DELAY MOV P0. 6/AD6 P0. Pin 7 EOC OE EQU P3.

HERE HERE1: JNB EOC.SL1 DJNZ R6.#00h L1: DJNZ R5.#00h SL1: DJNZ R5.#00h SL2: MOV R5.#00H .BACK: MOV P2.HERE1 SETB OE ACALL SDELAY MOV A.5V 1V 2V 2.L2 DJNZ R7.L3 RET SDELAY: MOV R6.SL2 RET END Observations: Input LED Status (ON/OFF) Voltage D7 D6 D5 D4 D3 D2 D1 D0 Hex Value 0.MAKE EOC INPUT CLR ALE CLR OE CLR START SETB START ACALL SDELAY CLR START HERE: JB EOC.5 V 3V 4V 5V Lab Manual of Microcontroller and Interfacing Page 70 .#02h L3: MOV R6.L1 DJNZ R6.P1 CPL A MOV P0.A CLR OE AJMP BACK DELAY: MOV R7. SELECT ADC CHANNEL 0 ACALL SDELAY SETB EOC .#00h L2: MOV R5.

:: WORKSHEET:: Exercise: Write a program to read analog value at the interval of 1 second and store it at memory location 50h onwards. Rajkot Page 71 . Government Engineering College. Store total 16 values. _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ EC Department.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 72 .Draw interfacing diagram to interface ADC0804 with 89C51 microcontroller. Write program to read analog data and display its digital value on seven segment display connected at port P0.

1/AD1 P0.1 P1.#00h start: clr a movc a.01uF -12v Interfacing details:  Data lines of DAC-0808 are connected with Port P1 of the microcontroller 89C51.  Zener diode is used to provide reference voltage to the DAC  Current output of the DAC is converted into voltage by I to V converter circuit formed by Op-AMP 741  Connect C. GND 29 30 +12v -Vee EA VCC PSEN ALE 1 2 3 4 5 6 7 8 5.2 P1.5/T1 P3.#127 mov P1.0/RXD P3.0/A8 P2.7/AD7 P2.5/A13 P2.1/TXD P3. 7 13 Vcc Iout 4 2 3 741 5.O.2/A10 P2.7 39 38 37 36 35 34 33 32 3 6 MHz P0.1/A9 P2.6/AD6 P0.4/AD4 P0.4 P1. Rajkot Page 73 .EXPERIMENT NO.4/A12 P2.1uF 15 . Write a program to generate sine wave using look up table Circuit diagram: 10uF +5V X1 22 PF 16 20 .6 P1.1k Vref + Analog Output 14 10V 5.R.3/INT1 P3.6/A14 P2. Government Engineering College.6/WR P3. at the output of DAC to observe analog signal Program: org 30h rept: mov dptr.3/A11 P2.7/RD X2 P1.5/AD5 P0.7/A15 GND 22 PF 10 11 12 13 14 15 16 17 18 RST + 9 21 22 23 24 25 26 27 28 - RESET 31 40 100 10K 0.0/AD0 P0.2/AD2 P0.@a+dptr jz rept add a.3/AD3 P0.#0400h mov P1.4/T0 P3.1k Vref - 6 4 D0 D1 D2 D3 D4 D5 D6 D7 DAC 0808 89C51 U2 12 11 10 9 8 7 6 5 -12v 0. 17 AIM: Interface 8 bit DAC chip with 89C51 microcontroller.3 P1.0 P1.5 P1.1k +12v 2 1 19 P3.2/INT0 P3.a EC Department.

0 end :: WORKSHEET:: Exercise: [1] Modify DAC program to generate ramp waveform at the output _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ Lab Manual of Microcontroller and Interfacing Page 74 .7 acall delay inc dptr ajmp start delay: mov R7.-75.-127.-124.-88.-126.75.loop ret org 0400h DB 1.-93.116.124.119.82.-127.-119.-47.-24.122.108.-124.16.124.-122.99.24.1.-54.-16.1.-69.-112.24.-125.-116.-127.-88.88.124 DB 126.-62.-47.40.-54.-82.-122.-104.-24.-82.54 DB 47.-8.-62.-40.112.99.93.8.-32.-123.93.47.-112.104.88.-75.40.122.32.-104 DB -108.127.75.127.104.62.124.-32.setb P0.127.112.54.69.116.-69.-8.69.126.-93.82.119.108.62.-108.32.-99.-99.-126.#0ffh loop: djnz R7.8.-40.-16.-119 DB -116.16.

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _[2] Modify DAC program to generate Full wave rectifier waveform at the output _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ ___________________________________________________________________ EC Department. Rajkot Page 75 . Government Engineering College.

[2] Group 3: [1] IC L293D [2] Small DC motor [3] ILQ 74 opto-isolator Group 4: [1] DIP Switch (array of 4 switch) ---. 25V ---[1] [6] Resistors 10K ---.1K ---(2) [5] Capacitors 0. [2]Op-amp 741 (with socket) [3] Zener diode 10V [4] Resistors 5.01µF and 0. 13 to 15) Part 2: Components as per group: Group 1: [1] LCD Module 16 character/2 line (With socket) and necessary connectors [2] 10K preset Group 2: [1] Common anode seven segment display---[2] [2] Resistors 680Ω ---.[2] Group 5: [1] Matrix keyboard [2] Common anode seven segment display Group 6: [1] Relay 12V.[2] 1000µF. Common anode seven segment display and PCB mounted relay Group 10: [1] DAC 0808.059 MHz IC Max232 with socket Male female connectors strip (According to PCB) Capacitors: 33pF ---.Component list for microcontroller mini-project and practical: Part 1: List of components compulsory for all the students [1] [2] [3] [4] [5] Microcontroller IC Phillips 89V51RD2 with socket Crystal 11. 25V ----[1] 10µF.[12] 470Ω --. eight resistors in array.[8] 100 Ω ---[2] RN10K (Resistor network.[9] [9] LED (Red and Green) ---. Bulb holder Group 7: [1] PC817 opto-coupler and LCD module with socket Group 8: [1] Small stepper motor [2] IC ULN 2803 Group 9: [1] Thumb wheel switch. 10K Ω) ---[2] [7] Transistor SL-100 ---[1] [8] Tactile push-button switch ---.[8] 1 K ---.1 µF Group 11: [1] ADC0808 (with socket) [2] IC CD4024 with socket [3] POT 10K Lab Manual of Microcontroller and Interfacing Page 76 . 100 Ω (PCB mounted).[4 each] [10] General purpose microcontroller PCB [11] Serial cable [12] DC power supply socket (Female) [13] IC LM7805 [14] Bridge rectifier 1 A [15] Transformer 0-12V (Student can purchase +5V DC adapter (charger) instead of item no. 25V ----[6] 100µF.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.