Microcontroller Lab Manual
Microcontroller Lab Manual
Manual (4046)
(Rev 0)
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.
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.
5. Rt click on Source Group 1 and select Add New Item to Group Source Group 1
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.
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.
11. After this run the Proteus simulation and observe the output
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
Code
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.
Completion of Experiment
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
Code
Result
Completion of Experiment
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
Code
Result
BCD 1001 0110 corresponding to decimal value 96 and hex value 60h
is displayed on PORT3 LEDs.
Readiness to do experiment
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
Code
Result
Read switches connected to PORT3 and values output to LEDs connected to PORT1.
Readiness to do experiment
To blink LEDs connected to PORT1 at appropriate time interval using software delay
Procedure
Code
Result
To blink LED connected to PORT1 Pin 0 at appropriate time interval using Timer 1
Procedure
Code
Result
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
Code
Result
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
Result
8 bit binary value corresponding to the LM34 reading is displayed using 8 LEDs
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
Code
Result
Unipolar stepper motor is interfaced with AT89C52 and direction of rotation is controlled
using a switch
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
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.
Code
Result
Procedure
Code
Result
16X2 LCD Display has been interfaced with AT89C52 and message displayed
Procedure
Code
Result
A Matrix keypad has been interfaced with AT89C52 and ASCII code for the
pressed key displayed in output LEDs