0% found this document useful (0 votes)
46 views13 pages

Lab 1

The document provides details on 7 experiments conducted using an 8051 microcontroller to develop various programming skills: 1. Experiment 1 develops programming with arithmetic and logic instructions by writing a program to add two 8-bit numbers. 2. Experiment 2 develops programming using ports by creating a square wave of 50% duty cycle on port 1. 3. Experiment 3 develops programming for delay generation using timers to generate a 10ms delay. 4. Experiment 4 develops interrupt handling by getting 8-bit data from port 0 and sending to port 1 while creating a 200us square wave on port 2. 5. Experiment 5 implements standard UART communication by continuously transmitting the letter "A" at 4800 baud

Uploaded by

Sagar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views13 pages

Lab 1

The document provides details on 7 experiments conducted using an 8051 microcontroller to develop various programming skills: 1. Experiment 1 develops programming with arithmetic and logic instructions by writing a program to add two 8-bit numbers. 2. Experiment 2 develops programming using ports by creating a square wave of 50% duty cycle on port 1. 3. Experiment 3 develops programming for delay generation using timers to generate a 10ms delay. 4. Experiment 4 develops interrupt handling by getting 8-bit data from port 0 and sending to port 1 while creating a 200us square wave on port 2. 5. Experiment 5 implements standard UART communication by continuously transmitting the letter "A" at 4800 baud

Uploaded by

Sagar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Camellia Institute of Polytechnic

Subject: -Microcontroller & its Applications Lab Manual

INDEX

SL No Experiment Name
1 To develop programming with Arithmetic
logic Instructions
2 To develop programming using Ports.
3 To develop programming for Delay
Generation using Timers.
4 To develop programming for interrupt
handling.
5 To develop programming for
implementation of standard UART
Communication
6 To develop programming for interfacing
with LCD display.
7 To develop programming for interfacing
with Keypad.

1
EXPERIMENT -1

TITLE: - To develop programming with Arithmetic and Logic Instructions.


AIM: -Write a program to find the addition of two 8-bit numbers.
EQUIPMENT REQUIRED: - 8051 Microcontroller kit.
Program Code: -
ORG 2100
MOV R5, #25H
MOV R0,#35H
MOV A,#00H
ADD A,R5
ADD A,R0
Loop:- SJMP loop
END
Output:- 25+35=5B
CONCLUSION:- Thus, we have performed the addition of two 8 bit number.

2
EXPERIMENT-2

TITLE: - To develop programming using ports.


AIM: -To create a square wave of 50% duty cycle on bit 0 of port 1.
EQUIPMENT REQUIRED: - 8051 Micro controller kit.
PROGRAM Code: -
Loop:- SETB P1.0; set to high bit 0 of port 1
LCALL DELAY; call the delay subroutine
CLR P1.0; P1.0=0
LCALL DELAY
SJMP Loop; Keep doing it.
CONCLUSION:- Thus, we have created a square wave of 50% duty cycle.

EXPERIMENT-3

TITLE: - To develop programming for Delay Generation using Timers


AIM: - To generate a delay of 10ms.
EQUIPMENT REQUIRED: - 8051 Microcontroller kit.
PROGRAM Code: -
MOV TMOD, #10H
MOV R3,#200
AGAIN: -MOV TL1, #00H
MOV TH1, #DCH
SETB TR1
BACK: -JNB TF1, BACK
CLR TR1
CLR TF1
DJNZ R3, AGAIN
CONCLUSION: -Thus, we have generated a 10 ms delay using timer.

3
EXPERIMENT 4

TITLE: - To develop programming for interrupt handling.


AIM: - Write a program that continuously gets 8-bit data from P0 and sends it to P1 while
simultaneously creating a square wave of 200 microseconds period on pin P2.1. Use timer0 to
create the square wave.
PROGRAM CODE:-
ORG 0000H
LJMP MAIN
ORG 000B
CPL P2.1
RETI
ORG 0030H
MAIN:- MOV TMOD, #02H
MOV P0, #0FFH
MOV TH0,#-92
MOV IE,#82
SETB TR0
BACK:- MOV A,P0
MOV P1,A
SJMP BACK
END

Output:- Thus, we have created a square wave of a 200microsecond period using the IE flag,

EXPERIMENT 5

TITLE: - To develop programming for the implementation of standard UART


Communication
AIM: -Write a program to continuously transfer the letter “A” serially at 4800 baud rates.

4
PROGRAM Code:-
MOV TMOD, #20H
MOV TH1,#-6
MOV SCON,#50H
SETB TR1
AGAIN:- MOV SBUF, “#A”
HERE:- JNB TI,HERE
CLR TI
SJMP AGAIN

Output:- Thus, we have transmitted the letter “A” serially using UART communication.

EXPERIMENT-6

TITLE:- To develop programming for interfacing with LCD display.


THEORY:-
Liquid Crystal Display (LCD) is very commonly used electronic display module and having a
wide range of applications such as calculators, laptops, mobile phones etc. 16×2 character lcd
display is very basic module which is commonly used in electronics devices and projects. It
can display 2 lines of 16 characters. Each character is displayed using 5×7 or 5×10 pixel
matrix.
Interfacing 16×2 LCD with 8051 using Keil C is bit complex because there is no powerful
libraries in Keil C. To solve this problem we have developed a LCD library which includes
commonly used features, you just need to include our header file and use it. You can
download the header file at the bottom of this article.
LCD can be interfaced with microcontroller in 4 Bit or 8 Bit mode. These differs in how data
is send to LCD. In 8 bit mode to write a character, 8 bit ASCII data is send through the data
lines D0 – D7 and data strobe is given through E of the LCD. LCD commands which are also
8 bit are written to LCD in similar way.
But 4 Bit Mode uses only 4 data lines D4 – D7. In this mode 8 bit character ASCII data and
command data are divided into two parts and send sequentially through data lines. The idea
of 4 bit communication is used save pins of microcontroller. 4 bit communication is a bit
slower than 8 bit communication but this speed difference can be neglected since LCDs are
slow speed devices. Thus 4 bit mode data transfer is most commonly used.
All the pins are clearly understandable by their name and functions, except the control pins,
so they are explained below:

5
RS: RS is the register select pin. We need to set it to 1, if we are sending some data to be
displayed on LCD. And we will set it to 0 if we are sending some command instruction like
clear the screen (hex code 01).

RW: This is Read/write pin, we will set it to 0, if we are going to write some data on LCD.
And set it to 1, if we are reading from LCD module. Generally this is set to 0, because we do
not have need to read data from LCD. Only one instruction “Get LCD status”, need to be read
some times.
E: This pin is used to enable the module when a high to low pulse is given to it. A pulse of
450 ns should be given. That transition from HIGH to LOW makes the module ENABLE.
There are some preset command instructions in LCD, we have used them in our program
below to prepare the LCD (in lcd_init() function). Some important command instructions are
given below:

Hex Code Command to LCD Instruction Register


0F LCD ON, cursor ON
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor (shift cursor to right)
05 Shift display right
07 Shift display left
0E Display ON, cursor blinking
80 Force cursor to beginning of first line
C0 Force cursor to beginning of second line
38 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
08 Display OFF, cursor OFF
C1 Jump to second line, position 1
OC Display ON, cursor OFF
C1 Jump to second line, position 1
C2 Jump to second line, position 2

Program Code

6
// Program for LCD Interfacing with 8051 Microcontroller (AT89S52)

#include<reg51.h>
#define display_port P2 //Data pins connected to port 2 on microcontroller
sbit rs = P3^2; //RS pin connected to pin 2 of port 3
sbit rw = P3^3; // RW pin connected to pin 3 of port 3
sbit e = P3^4; //E pin connected to pin 4 of port 3

void msdelay(unsigned int time) // Function for creating delay in milliseconds.


{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command) //Function to send command instruction to LCD
{
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}

void lcd_data(unsigned char disp_data) //Function to send display data to LCD


{
display_port = disp_data;
rs= 1;
rw=0;
e=1;

7
msdelay(1);
e=0;
}

void lcd_init() //Function to prepare the LCD and get it ready


{
lcd_cmd(0x38); // for using 2 lines and 5X7 matrix of LCD
msdelay(10);
lcd_cmd(0x0F); // turn display ON, cursor blinking
msdelay(10);
lcd_cmd(0x01); //clear screen
msdelay(10);
lcd_cmd(0x81); // bring cursor to position 1 of line 1
msdelay(10);
}
void main()
{
unsigned char a[15]="CIRCUIT DIGEST"; //string of 14 characters with a null
terminator.
int l=0;
lcd_init();
while(a[l] != '\0') // searching the null terminator in the sentence
{
lcd_data(a[l]);
l++;
msdelay(50);
}
}

CIRCUIT DIAGRAM

8
Circuit diagram for LCD interfacing with 8051 microcontroller is shown in the above figure.
If you have basic understanding of 8051 then you must know about EA(PIN 31), XTAL1 &
XTAL2, RST pin(PIN 9), Vcc and Ground Pin of 8051 microcontroller. I have used these
Pins in above circuit. If you don’t have any idea about that then I recommend you to read this
Article LED Interfacing with 8051 Microcontroller before going through LCD interfacing.
So besides these above pins we have connected the data pins (D0-D7) of LCD to the Port 2
(P2_0 – P2_7) microcontroller. And control pins RS, RW and E to the pin 12,13,14 (pin 2,3,4
of port 3) of microcontroller respectively.
PIN 2(VDD) and PIN 15(Backlight supply) of LCD are connected to voltage (5v), and PIN 1
(VSS) and PIN 16(Backlight ground) are connected to ground.
Pin 3(V0) is connected to voltage (Vcc) through a variable resistor of 10k to adjust the
contrast of LCD. Middle leg of the variable resistor is connected to PIN 3 and other two legs
are connected to voltage supply and Ground.

9
EXPERIMENT-7

TITLE:- To develop programming for interfacing with Keypad.


THEORY:- Keypad is used as an input device to read the key pressed by user and to process
it.
4x4 keypad consists of 4 rows and 4 columns. Switches are placed between the rows and
columns. A key press establishes a connection between corresponding row and column
between which the switch is placed.
To read the key press, we need to configure the rows as outputs and columns as inputs.
Columns are read after applying signals to the rows in order to determine whether or not a
key is pressed and if pressed, which key is pressed.
CIRCUIT DIAGRAM:-

Program Code:-
#include<reg52.h> //including sfr registers for ports of the controller
#include<lcd.h>

10
//LCD Module Connections
sbit RS = P0^0;
sbit EN = P0^1;
sbit D0 = P2^0;
sbit D1 = P2^1;
sbit D2 = P2^2;
sbit D3 = P2^3;
sbit D4 = P2^4;
sbit D5 = P2^5;
sbit D6 = P2^6;
sbit D7 = P2^7;
//End LCD Module Connections

//Keypad Connections
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit R4 = P1^3;
sbit C1 = P1^4;
sbit C2 = P1^5;
sbit C3 = P1^6;
sbit C4 = P1^7;
//End Keypad Connections

void Delay(int a)
{
int j;
int i;
for(i=0;i<a;i++)
{
for(j=0;j<100;j++)
{
}
}
}

char Read_Keypad()
{
C1=1;
C2=1;
C3=1;
C4=1;
R1=0;
R2=1;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '7';}
if(C2==0){Delay(100);while(C2==0);return '8';}
if(C3==0){Delay(100);while(C3==0);return '9';}

11
if(C4==0){Delay(100);while(C4==0);return '/';}
R1=1;
R2=0;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '4';}
if(C2==0){Delay(100);while(C2==0);return '5';}
if(C3==0){Delay(100);while(C3==0);return '6';}
if(C4==0){Delay(100);while(C4==0);return 'X';}
R1=1;
R2=1;
R3=0;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '1';}
if(C2==0){Delay(100);while(C2==0);return '2';}
if(C3==0){Delay(100);while(C3==0);return '3';}
if(C4==0){Delay(100);while(C4==0);return '-';}
R1=1;
R2=1;
R3=1;
R4=0;
if(C1==0){Delay(100);while(C1==0);return 'C';}
if(C2==0){Delay(100);while(C2==0);return '0';}
if(C3==0){Delay(100);while(C3==0);return '=';}
if(C4==0){Delay(100);while(C4==0);return '+';}
return 0;
}

void main()
{
int i=0;
char c,p;
Lcd8_Init();
while(1)
{
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("Keys Pressed:");
Lcd8_Set_Cursor(2,1);
Lcd8_Write_String("Times:");
while(!(c = Read_Keypad()));
p=c;
while(p==c)
{
i++;
Lcd8_Set_Cursor(1,14);
Lcd8_Write_Char(c);
Lcd8_Set_Cursor(2,7);
Lcd8_Write_Char(i+48);
Delay(100);
while(!(c = Read_Keypad()));

12
}
i=0;
Lcd8_Clear();
}
}

CONCLUSION:- Thus, we have studied the key board interfacing with 8051.

13

You might also like