0% found this document useful (0 votes)
4 views

Microcontroller Lab Manual

Microcontroler lab manual

Uploaded by

siuuu20070
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Microcontroller Lab Manual

Microcontroler lab manual

Uploaded by

siuuu20070
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Microcontroller & Applications Lab

Manual (4046)
(Rev 0)

Based on KEIL µVision 5 and Proteus Simulation

Diploma - 2021 Revision

Prepared by:
Arjun P
Lecturer in Electronics Engg
GPTC Kottayam
Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Notes:

1. KEIL µvision 5 (Ver 5.38.0.0) used to write code and generate HEX file.
2. Proteus 8.13 used to simulate AT89C52 circuits.

Dept. of Electronics Engg, GPTC Kottayam Page 2


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 0 Date: D D - M M - Y Y

Writing code in Keil and Proteus simulation


in brief
Steps
1. Create a new Uvision project

2. In the “select device for target” pop up which opens, in Search box type AT89C52. Now
the device will be listed. Click on AT89C52 shown below and then click OK.

3. Click Yes to copy STARTUP.A51 to project folder

Dept. of Electronics Engg, GPTC Kottayam Page 3


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

4. Now click on + sign next to Target1 to expand it.

5. Rt click on Source Group 1 and select Add New Item to Group Source Group 1

Dept. of Electronics Engg, GPTC Kottayam Page 4


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

6. Select Asm file, give a filename and click on Add.

7. In the Text editor which opens, type in the code and after typing in the code and select
Flash -> Configure Flash Tools

8. In the options window which pops up click on Output and check the Create Hex File
And click OK. This is required to create the Hex file for use in Proteus as well as for
Programming the kit.

Dept. of Electronics Engg, GPTC Kottayam Page 5


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

9. After this build the program by clicking on Build button as shown. If the build is successful,
it will show 0 Errors

10. Open Proteus and create a new project and wire up the circuit. Select AT89C52
microcontroller. To load Hex file to the microcontroller, right click on micontroller
schematic and select Edit Properties. Select the .hex file for Program file option.
The .hex file can be found inside Objects folder inside the folder for a particular project.

Dept. of Electronics Engg, GPTC Kottayam Page 6


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

11. After this run the Proteus simulation and observe the output

Dept. of Electronics Engg, GPTC Kottayam Page 7


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 1 Date: D D - M M - Y Y

8-Bit Addition
Aim

Write an assembly language program for 8051 to add two 8-bit numbers and output the
result on LEDs connected to PORT1, turns on LED connected to Port 2 pin 1(p2.1) if there
is a carry

Procedure

1. Use immediate addressing to move first data to Accumulator


2. Add second data to first one
3. Send result to PORT1
4. Go to indefinite loop

Code

Dept. of Electronics Engg, GPTC Kottayam Page 8


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

Sum of two 8-bit numbers is displayed on LEDs connected to PORT3 and led
connected in port 2.1 turned on if a carry occurred.

For Office use only Signature of Lab in charge Remarks

Completion of Experiment

Dept. of Electronics Engg, GPTC Kottayam Page 9


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 2 Date: D D - M M - Y Y

8-Bit Logical AND


Aim

Write an assembly language program for 8051 to find logical AND of two 8-bit numbers
and output the result on LEDs connected to PORT3.

Procedure

1. Use immediate addressing to move first data to Accumulator


2. Add second data to first one
3. Send result to PORT3
4. Go to indefinite loop

Code

Dept. of Electronics Engg, GPTC Kottayam Page 10


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

Logical AND of two 8-bit numbers is displayed on LEDs connected to PORT3.

For Office use only Signature of Lab in charge Remarks

Completion of Experiment

Dept. of Electronics Engg, GPTC Kottayam Page 11


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 3 Date: D D - M M - Y Y

Hexadecimal To BCD Conversion


Aim

Write an assembly language program for 8051 to convert given hexadecimal number
(which is a 2 digit number between 0 and 99 in decimal and 0x00 and 0x63 in Hex) to
BCD and output the result on LEDs connected to PORT3.

Procedure

1. Use immediate addressing to move hexadecimal value to Accumulator


2. Divide it by 0Ah to get the higher & lower nibble of BCD as quotient and
remainder
3. Swap the higher nibble value in accumulator and add lower nibble to it to
get the complete BCD value in accumulator
4. Output the result to PORT3
5. Go to indefinite loop

Code

Dept. of Electronics Engg, GPTC Kottayam Page 12


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

BCD 1001 0110 corresponding to decimal value 96 and hex value 60h
is displayed on PORT3 LEDs.

For Office use only Signature of Lab in charge Remarks

Readiness to do experiment

Dept. of Electronics Engg, GPTC Kottayam Page 13


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 4 Date: D D - M M - Y Y

Port Pins as Input And Output


Aim

To read switches connected to PORT3 and output the value to LEDs connected to PORT1.

Circuit Diagram

Theory

8051 has 8 bit wide 4 PORT. Each port has one Px eight bit register. The x may be
replaced by 1, 2, 3 or 4 based on the PORT you are using. Bit 0 of this register is
associated with Pin 0 of the port; Bit1 of this register is associated with Pin1 and so on.
Procedure

1. Use register addressing to move values from P3 to P1


2. Go to step 1

Dept. of Electronics Engg, GPTC Kottayam Page 14


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Code

Result

Read switches connected to PORT3 and values output to LEDs connected to PORT1.

For Office use only Signature of Lab in charge Remarks

Readiness to do experiment

Dept. of Electronics Engg, GPTC Kottayam Page 15


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 5 Date: D D - M M - Y Y

Led Blinking using Software delay


Aim

To blink LEDs connected to PORT1 at appropriate time interval using software delay

Procedure

1. Use immediate addressing to move value to port 1


2. Set PORT1 as low
3. Apply software delay
4. Set PORT1 as high
5. Apply software delay
6. Go to step1

Code

Dept. of Electronics Engg, GPTC Kottayam Page 16


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

LEDs connected to PORT1 are blinked at appropriate time interval.

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 17


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 6 Date: D D - M M - Y Y

Led Blinking using Timer


Aim

To blink LED connected to PORT1 Pin 0 at appropriate time interval using Timer 1

Procedure

1. Mov 0x10 to TMOD register to set Timer 1 Mod 1


2. Set delay counter value in R3
3. Move initial values in TL1 and TH1 registers and start Timer1
4. Monitor Timer 1 flag and if it is set, stop the timer and clear the timer 1 flag.
5. Decrement R3 value and if it is not zero, reload the timer.
6. Repeat the steps for continuous led blinking

Code

Dept. of Electronics Engg, GPTC Kottayam Page 18


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

LED connected to PORT1 pin 0 is blinked using Timer 1.

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 19


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 7 Date: D D - M M - Y Y

DC Motor interface
Problem Statement

To interface a DC Motor with Microcontroller and to monitor the status of a switch and perform
the following operations:
(a) If Switch is open, the DC motor rotates clockwise.
(b) If Switch is closed, the DC motor rotates counterclockwise.

Procedure

1. Set Port1 pin 0 as input pin


2. Set Port 2 pin 2 to enable ENA pin of L298 motor driver
3. If switch is closed clear IN1 pin and set IN2 pin of L298 motor driver
4. If switch is open, set IN1 pin and clear IN2 pin of L298 motor driver
5. Repeat the process.

Code

Dept. of Electronics Engg, GPTC Kottayam Page 20


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

DC motor is interfaced with AT89C52 and direction of rotation is controlled


using a switch

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 21


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 8 Date: D D - M M - Y Y

ADC Interface to read and display room temperature


Problem Statement

To interface ADC IC AD0804 with AT89C52 to measure room temperature using LM34 and
display the value in 8 bit binary using 8 LEDs connected to AD0804.

Procedure

1. Clear Port2 pin 1 and then set Port2 pin 1 for L-to-H to start conversion signal
For WR pin of AD0804
2. Wait for end of conversion by monitoring INTR pin
3. Set Port2 pin 0 and then clear Port2 pin 0 for applying a H-to-L to RD pin to get the
data out of the ADC0804.
4. Call a delay to slow down the conversion so that the output can be displayed using
LEDs
5. Again set Port2 pin 0 to make RD=1 for next round
6. Repeat the process

Code

Dept. of Electronics Engg, GPTC Kottayam Page 22


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

8 bit binary value corresponding to the LM34 reading is displayed using 8 LEDs

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 23


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 9 Date: D D - M M - Y Y

Unipolar Stepper motor interface


Problem Statement

To interface Unipolar Stepper motor with AT89C52 and to monitor the status of a switch
and perform the following:
(a) If Switch is open, the Stepper motor rotates clockwise.
(b) If Switch is closed, the Stepper motor rotates counterclockwise.

Procedure

1. Set Port1 pin 0 as input pin


2. If the switch is closed jump to loop3 and output the code sequence to rotate the
Stepper Motor in counter clockwise direction
3. If the switch is open output the code sequence to rotate the stepper
Motor in clockwise direction
4. Repeat the process

Dept. of Electronics Engg, GPTC Kottayam Page 24


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Code

Dept. of Electronics Engg, GPTC Kottayam Page 25


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

Unipolar stepper motor is interfaced with AT89C52 and direction of rotation is controlled
using a switch

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 26


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 10 Date: D D - M M - Y Y

Serial Data Transfer


Problem Statement

To transfer data serially from microcontroller and display the data on a virtual terminal
in proteus.

Procedure

1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode
2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with one of the values to set baud rate as 9600.
3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-
bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. The character byte to be transferred serially is written into SBUF register
6. The TI flag bit is monitored with the use of instruction JNB TI,xx to see if the
character has been transferred completely
7. TI is cleared by CLR TI instruction
8. In Proteus set the internal clock frequency of microcontroller to 11.0592MHz. This
Is done by Right clicking on AT89C52 -> Edit properties -> Clock frequency is set
as 11.0592MHz. This is done to match Baud rate of 9600

Dept. of Electronics Engg, GPTC Kottayam Page 27


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

9. To select Virtual terminal click on Virtual Instruments Mode and select Virtual Terminal

10. After adding virtual terminal Right click on Virtual Terminal -> Edit properties ->
Baud Rate is set as 9600.

Dept. of Electronics Engg, GPTC Kottayam Page 28


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Code

Dept. of Electronics Engg, GPTC Kottayam Page 29


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

Serial data from microcontroller displayed on virtual terminal.

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 30


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 11 Date: D D - M M - Y Y

16X2 LCD Display interface


Problem Statement

To interface a 16X2 LCD Display with AT89C52

Procedure

1. Connect Port1 pins P1.7 - P1.0 to data pins D7 - D0 of LCD


2. P2.0 connected to RS pin, P2.1 to R/W pin and P2.2 to E pin of LCD
3. Give initialization commands to LCD by placing the command byte in accumulator
and calling the COMMAND sub routine, which first checks whether LCD is ready by
monitoring the busy flag. If busy flag is cleared, it will clear RS and R/W pins and apply
a high to low pulse on E pin to latch the command byte to LCD.
4. Then aplly data bytes to LCD by placing the data byte in accumulator and calling
the DATA_DISPLAY sub routine, which first checks whether LCD is ready by
monitoring the busy flag. If busy flag is cleared, it will set RS pin, clear R/W pin and
apply a high to low pulse on E pin to latch the data byte to LCD.
5. Repeat the process

Code

Dept. of Electronics Engg, GPTC Kottayam Page 31


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Dept. of Electronics Engg, GPTC Kottayam Page 32


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Dept. of Electronics Engg, GPTC Kottayam Page 33


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

16X2 LCD Display has been interfaced with AT89C52 and message displayed

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 34


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Exp No. 12 Date: D D - M M - Y Y

Matrix keyboard interface


Problem Statement

To interface a matrix keyboard with AT89C52

Procedure

1. Connect output LEDs to Port1 pins P1.7 - P1.0


2. Port 3 pins P3.0-P3.3 connected to 4 rows and Port 2 pins P2.0-P2.2 to 3 columns.
P2 is made an input port
3. To make sure that the preceding key has been released, 0s are output to all rows
at once, and the columns are read and checked repeatedly until all the columns
are high
4. To detect a pressed key, the microcontroller grounds all rows by providing 0 to the
output latch, and then it reads the columns.
5. To detect which row key press belongs to, it grounds one row at a time, reading the
columns each time
6. Upon finding the row that the key press belongs to, it sets up the starting address for
the look-up table holding the scan codes (orASCII) for that row
7. To identify the key press, it rotates the column bits, one bit at a time, into the
carry flag and checks to see if it is low
8. Upon finding the zero, it pulls out the ASCII code for that key from the look-up table,
otherwise, it increments the pointer to point to the next element of the look-up table

Dept. of Electronics Engg, GPTC Kottayam Page 35


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Code

Dept. of Electronics Engg, GPTC Kottayam Page 36


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Dept. of Electronics Engg, GPTC Kottayam Page 37


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Dept. of Electronics Engg, GPTC Kottayam Page 38


Microcontroller & Applications Lab - 4046 Prepared by:
Arjun P, Lr. in Electronics Engg

Result

A Matrix keypad has been interfaced with AT89C52 and ASCII code for the
pressed key displayed in output LEDs

For Office use only Signature of Lab in charge Remarks

Dept. of Electronics Engg, GPTC Kottayam Page 39

You might also like