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

Module-5

Uploaded by

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

Module-5

Uploaded by

anu.spamm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Department of Electronics and Computer Science

TE(ETRX) SEM-V
Microcontrollers & Applications
By
Dr. Arun Chavan

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
WAP to display the numbers form ‘0 to 9’ on 7segment displays at
regular interval continuously ?

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
WAP to display the numbers form ‘0 to 9’ on 7segment displays at
regular interval continuously ?
org 0000h mov p1,#07h
sjmp start acall delay
start: mov p1,#7fh
mov p1,#3fh acall delay
acall delay mov p1,#67h
mov p1,#06h acall delay
acall delay sjmp start
mov p1,#5bh
acall delay delay:
mov p1,#4fh mov r0,#255
acall delay back:mov r1,#255
mov p1,#66h mov r2,#255
acall delay here:djnz r2,here
mov p1,#6dh again:djnz r1,again
acall delay djnz r0,back
mov p1,#7dh ret
acall delay end
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
WAP to display the numbers form ‘0 to 9’ on 7segment displays at
regular interval continuously ?

#include<reg51.h>

void main()
{
unsigned char n[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
unsigned int i,j;

while(1)
{
for(i=0;i<10;i++);
{
P1=n[i];
for(j=0;j<40000;j++);
}
}

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
LCD Interfacing with 8051 Microcontroller

• VDD : +5V, VSS : GND, VEE : Contrast Control


• RS : 1-for Data Register & 0-for Control Register
• RW : 1-for read & 0-for write
• E : High to Low to latch the data into LCD
• D0-D7 : Data bus Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
LCD Interfacing with 8051 Microcontroller
Hex Code Command to LCD instruction Register
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
08 Display off, cursor off
0A Display off, cursor on
0C Display on, cursor off
0E Display on, cursor on
0F Display on, cursor blinking
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning ( 1st line)
C0 Force cursor to beginning ( 2nd line)
38 2 lines and 5×7 matrix
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
LCD Interfacing with 8051 Microcontroller

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller

org 0000h mov a,#06h


Shift Cursor
sjmp start acall comnwrt
Right
start: acall delay
mov a,#38h mov a,#82h
Initialize Force Cursor to 1st
acall comnwrt acall comnwrt Line, 2nd Position
LCD
acall delay acall delay
mov a,#0eh mov a,#'W'
Display On,
acall comnwrt Cursor On acall datawrt
acall delay acall delay
mov a,#01h mov a,#'e'
Clear
acall comnwrt Display acall datawrt
acall delay acall delay
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller
mov a,#'l' mov a,#'e' mov a,#' '
acall datawrt acall datawrt acall datawrt
acall delay acall delay acall delay
mov a,#'c' mov a,#' ' mov a,#'V'
acall datawrt acall datawrt acall datawrt
acall delay acall delay acall delay
mov a,#'o' mov a,#'t' mov a,#'I'
acall datawrt acall datawrt acall datawrt
acall delay acall delay acall delay
mov a,#'m' mov a,#'o' mov a,#'T'
acall datawrt acall datawrt acall datawrt
acall delay acall delay acall delay
Dr. Arun Chavan, Department of Electronics
and Computer Science
here:sjmp here
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller

comnwrt: datawrt: delay:


mov p1,a mov p1,a mov r3,#50
clr p2.0 setb p2.0 same:mov r4,#255
clr p2.1 clr p2.1 back:djnz r4,back
setb p2.2 setb p2.2 djnz r3,same
acall delay acall delay ret
clr p2.2 clr p2.2 end
ret ret

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller

#include<reg51.h> void main()


#define outport P1 {
void lcd_initi(); lcd_initi();
void lcd_data(unsigned char ); lcd_cmd(0xc0);
void lcd_cmd(unsigned int ); delay(100);
void delay(); display(“Welcome to ETRX”,15);
void display(unsigned char *s, unsigned int r) while(1);
sbit rs=P2^0; }
sbit rw=P2^1;
sbit en=P2^2;

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller

void display(unsigned char *s, unsigned int r) void lcd_initi()


{ {
unsigned int w; lcd_cmd(0×38);
for(w=0;w<r;w++) delay(100);
{ lcd_cmd(0×0e);
lcd_data(s[w]); delay(100);
} lcd_cmd(0×01);
} delay(100);
lcd_cmd(0x06);
delay(100);
}
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
LCD Programming with 8051 Microcontroller

void lcd_data(unsigned char dat) Void lcd_cmd(unsigned int cmd)


{ {
outport = dat; outport=cmd;
rs=1; rs=0;
rw=0; rw=0;
en=1; en=1;
delay(100); delay(100);
en=0; en=0;
} }

void delay( unsigned int n)


{
unsigned int a;
for(a=0;a<n;a++);
}
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad

org 0000h cjne a,#0fh,next djnz r1,loop5


sjmp start sjmp loop2 again:sjmp again
start: next:acall delay loop3:ret
mov sp,#30h mov r0,#00h display:mov p2,r0
clr TR0 mov r1,#04h ret
acall keyboard mov r2,#0feh delay:
acall display loop5:mov p0,r2 mov TMOD,#01h
sjmp start mov a,p1 mov TL0,#0dfh
keyboard:mov p0,#00h anl a,#0fh mov TH0,#0b1h
loop1:mov a,p1 mov r3,#04h setb TR0
anl a,#0fh loop4:rrc a here:jnb TF0,here
cjne a,#0fh,loop1 jnc loop3 clr TR0
acall delay inc r0 clr TF0
loop2:mov a,p1 djnz r3,loop4 ret
anl a,#0fh mov a,r2 end
rl a
mov r2,a
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad & LCD

Dr. Arun Chavan, Department of Electronics


and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad

#include <reg51.h>

void MSDelay(unsigned int );


void LCDtransfer(unsigned char );
void send_command(unsigned int);

sfr COL = 0xB0; //P3=Connected to columns


sfr ROW = 0xA0; //P2=Connected to rows
sfr ldata = 0x90; //P1 = LCD data pins
sbit rs = P0^2;
sbit rw = P0^1;
sbit en = P0^0;
unsigned char keypad[4][4] = {{'A','B','C','D’},
{'E','F','G','H’},
{'I','J','K','L’},
{'M','N','O','P’}};
Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad
void main()
{
unsigned int collocation,rowlocation;

while(1)
{
do
{
ROW =0x00;
collocation = COL;
collocation &= 0x0F;
}while(collocation != 0x0F);
MSDelay(200);
do
{
collocation = COL;
collocation &= 0x0F;
}while(collocation == 0x0F);
MSDelay(200); Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad
while(1) ROW = 0xFB;
{ collocation = COL;
ROW = 0xFE; collocation &=0x0F;
collocation = COL; if(collocation != 0x0F)
collocation &=0x0F; {
if(collocation != 0x0F) rowlocation = 2;
{ break;
rowlocation = 0; }
break; ROW = 0xF7;
} collocation = COL;
ROW = 0xFD; collocation &=0x0F;
collocation = COL; rowlocation = 3;
collocation &=0x0F; break;
if(collocation != 0x0F) }
{
rowlocation = 1;
break;
} Dr. Arun Chavan, Department of Electronics
and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad
send_command(0x38); // 16_bit mode; Enable 5x7 dot matrix for each character
MSDelay(200);
send_command(0x0E); // Display ON & cursor ON
MSDelay(200);
send_command(0x01); // Clear the Display
MSDelay(200);
send_command(0x06); // To shift the cursor right
MSDelay(200);
send_command(0x83); // Set the cursor at line 1, position 3
MSDelay(200);
if(collocation ==0x0E)
LCDtransfer(keypad[rowlocation][0]);
else if(collocation == 0x0D)
LCDtransfer(keypad[rowlocation][1]);
else if(collocation == 0x0B)
LCDtransfer(keypad[rowlocation][2]);
else
LCDtransfer(keypad[rowlocation][3]);
} Dr. Arun Chavan, Department of Electronics
} and Computer Science
8051 Interfacing Part-1
Interfacing 8051 with 4×4 matrix keypad
void LCDtransfer(unsigned char keypress)
{
ldata = keypress; void MSDelay(unsigned int value)
rs = 1; {
rw = 0; unsigned int y;
en = 1; for(y=0;y<value;y++);
MSDelay(100); }
en = 0;
return;
}
void send_command(unsigned int value)
{
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(100);
en = 0;
return; Dr. Arun Chavan, Department of Electronics
} and Computer Science
Assignment no - 8
Short Questions (2 Marks)

1. Draw the logic interface of 7-segment display with 8051.

Descriptive Questions (5 Marks)

1. Explain the 7-seg code generation for BCD numbers, assume the 7-seg display of common
cathode type, also assume the pattern for code generation.
2. Draw the detailed single logic interface of Keyboard & LCD display with 8051.

Descriptive Questions (10 Marks)

1. Interface 16 x 2 lcd display with 8051. Draw the logic interface and write embedded C
program to display ‘Welcome to VIT’ on it. Assume the oscillator frequency as 12 MHz.
2. Interface a 4 x 4 matrix type of keyboard with 8051. Draw the logic interface and write
Embedded C program to detect the key closure. Assume the oscillator frequency as 12 MHz.
Thank You

Dr. Arun Chavan, Department of Electronics


and Computer Science

You might also like