Module-5
Module-5
TE(ETRX) SEM-V
Microcontrollers & Applications
By
Dr. Arun Chavan
#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++);
}
}
#include <reg51.h>
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. 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.
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