0% found this document useful (0 votes)
26 views33 pages

ESY Ch-4_2

Uploaded by

ameymane2412
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)
26 views33 pages

ESY Ch-4_2

Uploaded by

ameymane2412
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/ 33

LCD

LCD Command Codes


LCD Interfacing
LCD Interfacing
LCD Interfacing
#include<reg51.h> lcddata('T');
sbit rs=P3^2; delay(10);
sbit rw=P3^1; lcddata('E');
sbit en=P3^0; delay(10);
}
void delay(unsigned int);
void lcdcmd(unsigned char x)
void lcdcmd(unsigned char);
{
void lcddata(unsigned char);
rs=0;
void main(void)
rw=0;
{ P2=x;
rs=0; en=1;
rw=0; delay(1);
en=0; en=0;
lcdcmd(0x38); //delay(2);
delay(10); }
lcdcmd(0x0e); void lcddata(unsigned char d)
delay(10); {
rs=1;
lcdcmd(0x06);
rw=0;
delay(10);
P2=d;
lcdcmd(0x01); en=1;
delay(10); delay(1);
lcdcmd(0x80); en=0;
delay(10); delay(2);
lcddata('M'); }
delay(10); void delay(unsigned int itime)
lcddata('S'); {
delay(10); unsigned int i,j;
lcddata('B'); for (i=0; i<=itime; i++)
for (j=0; j<=1275; j++);
delay(10);
}
Keyboard Interfacing
Flow Chart
Matrix Keyboard & 7-segment Display Interfacing
Keyboard & LCD Interfacing
Write and execute C language program to display key code of a pressed key on line of
LCD
#include <reg51.h>
sbit rs=P3^2; lcdcmd(0x0e);
delay(100);
sbit rw= P3^1;
lcdcmd(0x01);
sbit en= P3^0;
delay(100);
void delay(unsigned int); lcdcmd(0x06);
void lcdcmd(unsigned char); delay(100);
void lcddata(unsigned char); lcdcmd(0x80);
unsigned char keycode; delay(100);
unsigned char keypad [4][4]={ '0','1','2','3',
'4','5','6','7', while(1)
{
'8','9','A','B',
do
'C','D','E','F'};
{
void main(void) P1=0xf0; // P1.0 to P1.3 lines are Row lines
{ colloc=P0; // P0.4 to P0.7 are Column lines
unsigned char colloc, rowloc; colloc&=0xf0; // Mask the status of Lower nibble of port 0
rs=0; }
rw=0; while(colloc!=0x0f);
en=0;
lcdcmd(0x38);
delay(100);
do while(1)
{ {
do P1=0xfe; // Make the 1st row status 0
{ colloc=P0; // Read the column status
delay(20); colloc&=0xf0; // Mask off lower
colloc=P0; // nibble, read the
colloc&=0xf0; // upper nibble status
} if(colloc!=0xf0) // if not equal to f0
// then it means the key
while (colloc==0xf0); //is pressed from row 0
delay(20); { rowloc=0;
colloc=P0; break;
colloc&=0xf0; }
}
while (colloc==0xf0); P1=0xfd;
colloc=P0;
colloc&=0xf0;
if(colloc!=0xf0)
{ rowloc=1;
break;
}
P1=0xfb; if (colloc==0xe0)
colloc=P0; keycode=keypad[rowloc] [0];
colloc&=0xf0;
if(colloc!=0xf0) else if (colloc==0xd0)
{ rowloc=2; keycode=keypad[rowloc] [1];
break;
}
else if (colloc==0xb0)
P1=0xf7; keycode=keypad[rowloc] [2];
colloc=P0;
colloc&=0xf0; else
if(colloc!=0xf0) keycode=keypad[rowloc] [3];
{rowloc=3;
break; lcdcmd(0x85);
} lcddata(keycode);
}
}
}
DAC Interfacing with 8051
DAC Interfacing
// Ramp wave generation or // square wave generation
// Sawtooth wave generation #include<reg51.h>
void delay (unsigned int);
#include <reg51.h> void main (void)
void main (void) {
{ while(1)
unsigned char a; {
while (1) P2=0x00;
{ delay(2);
for (a=0; a<0xff; a++) P2=0xff;
{ delay(2);
P2=a; }
} }
} void delay (unsigned int itime)
} {
unsigned int i, j;
for (i=0; i<itime; i++)
for (j=0; j<1275; j++);
}
//Triangular wave generation
#include<reg51.h> # include<reg51.h>
void delay ( ); void main (void)
void main (void) {
{ unsigned char a,b;
unsigned char a; while (1)
while (1) {
{ for (a=0; a<0xff; a++)
for (a=0; a<0xff; a++) {
{ P2=a;
P2=a; }
delay( ); for (b=0xff; b>0x00; b--)
} {
for (a=0xff; a>0x00; a--) P2=b;
{
P2=a; }
delay( );
} }
} }
}

void delay ( )
{
unsigned int j;
for (j=0; j<5; j++);
}
or
Simple function generator-
Generate square waveform when switch 1 is pressed &
generate saw tooth waveform when switch2 is pressed.
ADC
ADC Interfacing
ADC Interfacing
#include<reg51.h>
delay(2);
void delay (unsigned int);
SC=0;
sbit ALE= P0^2; while(EOC==1); // Wait untill conversion is
sbit OE= P0^0; completed
sbit SC= P0^1; {OE=1;
delay(10);
sbit EOC= P0^4;
// make output enable pin = high
void main (void)
{ ADC_val0ue=P3; //conversion is
unsigned char ADC_value; completed. Now read ADC data on port3.
P1=ADC_value; // Now output that
P3=0xff; //Make port P3 as an input data to LEDs connected to Port1
ALE=0; // make ALE pin low }
SC=0; // make ALE pin low }
OE=0; // make output enable pin low }
void delay(unsigned int t)
P2=0x02; // Channel 1 (Pot) is selected
{
while(1) unsigned int i,j;
{ for (i=0; i<=t; i++)
ALE=1; for (j=0; j<=1000; j++);
delay(2);
ALE=0;
}
delay(2);
SC=1;
Stepper Motor
Stepper Motor Interfacing with 8051
Rotate stepper motor in clockwise direction.

#include<reg51.h> void delay(unsigned int t)


void delay(unsigned int); {
void main (void) unsigned int i,j;
{ for (i=0; i<=t; i++)
while(1) for (j=0; j<=1000; j++);
{ }
P0=0x08;
delay(10);
P0=0x04;
delay(10);
P0=0x02;
delay(10);
P0=0x01;
delay(10);
}
}
Rotate stepper motor in clockwise direction.

#include<reg51.h> void delay(unsigned int t)


void delay(unsigned int); {
void main (void) unsigned int i,j;
{ for (i=0; i<=t; i++)
while(1) for (j=0; j<=1000; j++);
{ }
P0=0x08;
delay(10);
P0=0x04;
delay(10);
P0=0x02;
delay(10);
P0=0x01;
delay(10);
}
}
Rotate stepper motor in counter clockwise direction.

#include<reg51.h> void delay(unsigned int t)


void delay(unsigned int); {
void main (void) unsigned int i,j;
{ for (i=0; i<=t; i++)
while(1) for (j=0; j<=1000; j++);
{ }
unsigned char x, a[4]={0x01, 0x02,
0x04, 0x08};
for (x=0; x<4; x++)
P0=a[x];
delay(10);
}
}
Rotate stepper motor in clockwise direction.

#include<reg51.h> void delay(unsigned int t)


void delay(unsigned int); {
void main (void) unsigned int i,j;
{ for (i=0; i<=t; i++)
while(1) for (j=0; j<=1000; j++);
{ }
P0=0x08;
delay(10);
P0=0x04;
delay(10);
P0=0x02;
delay(10);
P0=0x01;
delay(10);
}
}
Write a program to monitor the status of SW and perform the following.
1. If SW=0, the stepper motor moves clockwise.
2. If SW=1, the stepper motor moves counter clockwise.
DC Motor
H- bridge using Diodes
Working of H-Bridge
L293D Motor driver IC
Interfacing of DC motor

You might also like