KEMBAR78
MC Lab Manual | PDF | Computer Hardware | Computer Architecture
0% found this document useful (0 votes)
26 views14 pages

MC Lab Manual

The document outlines steps for interfacing programs with the 8051 microcontroller, including setting up the target device and creating HEX files. It details various experiments such as interfacing with an alphanumeric LCD, HEX keypad, DAC, motors, and an elevator system, providing sample C code for each application. Each experiment aims to demonstrate different functionalities of the 8051 microcontroller in practical applications.

Uploaded by

prakyath.23ec045
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 views14 pages

MC Lab Manual

The document outlines steps for interfacing programs with the 8051 microcontroller, including setting up the target device and creating HEX files. It details various experiments such as interfacing with an alphanumeric LCD, HEX keypad, DAC, motors, and an elevator system, providing sample C code for each application. Each experiment aims to demonstrate different functionalities of the 8051 microcontroller in practical applications.

Uploaded by

prakyath.23ec045
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/ 14

8051 Microcontrollers Lab

STEPS TO BE FOLLOWED FOR INTERFACING PROGRAMS:

1. Follow the initial steps as in software program execution, in addition follow the given
below

2. Again right click on Target1 select OPTION FOR TARGET1

Right click on Target1

Select Option for Target1

3. Select Device then select AT89C51ED2

4. Select Target Xtal(MHz): 11.0592 and Tick on Use On-chip XRAM

5. Select Output and Tick on Create HEX file

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

6. Right click on Target1 and select Rebuild Target


7. Do the power supply connection for Development kit and press Reset 3 to 4 times.
8. Make connection from CPU to Development Board
9. In the μC Development board kit keep the programme switch in PROG[red] mode.

10. Close/Minimize the keil window and double click on

11. Select Device menu find 89C51ED2, click ok


12. Select File menu Load Hex file then browse your created Hex file
13. Select Setting menu Communication, RS232 then set Baud rate as 9600
14. Click on Run
15. Click on Start Application

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

II. 8051 INTERFACING EXPERIMENTS

Experiment No. 7

ALPHANUMERIC LCD INTERFACE

AIM: To write a C program to interface 8051 chip to Alphanumeric LCD panel


#include<reg51.h>
sfr ldata=0x80;
sbit rf=P2^4;
sbit rw=P2^5;
sbit en=P2^6;
void LCD_CMD(unsigned char val);
void LCD_DATA(unsigned char
val);
void DELAY(unsigned int x);
void main()
{
unsigned char
array[100]={"DATA"};
unsigned char i,key;
LCD_CMD(0x38);
DELAY(255);
LCD_CMD(0x0e);
DELAY(255);
LCD_CMD(0x01);
DELAY(255);
Register Operation Hex
LCD_CMD(0x06); value
DELAY(255); Clear display screen 1
LCD_CMD(0x84); Return home 2
DELAY(255); Decrement cursor(Shift left) 4
for(i=0;i<4;i++) Increment cursor(Shift right) 6
Display off, cursor off 8
{
Display off, cursor on A
key=array[i]; Display on, cursor off C
LCD_DATA(key); Display on, cursor blinking E
DELAY(255); Display on, cursor after 5 spacing 84
} 2 lines and 5x7 matrix 38
while(1)
{
}
}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

void LCD_CMD(unsigned char val)


{
ldata=val;
rf=0;
rw=0;
en=1;
en=0;
}
void LCD_DATA(unsigned char
val)
{
ldata=val;
rf=1;
rw=0;
en=1;
en=0;
}
void DELAY(unsigned int x)
{
for(;x>0;x--);
}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

Experiment No. 8

HEX KEYPAD INTERFACE

AIM: To write a C program to interface 8051 chip to Alphanumeric LCD panel and HEX
keypad module.

PS
PS

8051µC

4X4 Keyboard
4X4 Hex keypad
P0
Interface Card
FRC 26pin

Cable

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

#include<reg51.h> CALLED FUNCTIONS (SUB PGMS)


sfr col=0x0a0;
sfr row=0x90; void LCD_CMD(unsigned char val)
sfr ldata=0x80; {
sbit rf=P2^4; ldata=val;
sbit rw=P2^5; rf=0;
sbit en=P2^6; rw=0;
void LCD_CMD(unsigned char val); en=1;
void LCD_DATA(unsigned char val); en=0;
void DELAY(unsigned int x); }
unsigned char keypad[4][4]={'0','1','2','3',
'4','5','6','7',
'8','9','A','B', void LCD_DATA(unsigned char val)
'C','D','E','F'}; {
void main() ldata=val;
{ rf=1;
unsigned char colloc,rowloc; rw=0;
LCD_CMD(0x38); en=1;
DELAY(255); en=0;
LCD_CMD(0x0e); }
DELAY(255);
LCD_CMD(0x01); void DELAY(unsigned int x)
DELAY(255); {
LCD_CMD(0x06); unsigned int y,z;
DELAY(255); for(y=0;y<1274;y++)
LCD_CMD(0x80); for(z=0;z<x;z++); }
DELAY(255);
col=0xff;
while(1)
{
do
{
row=0x00;
colloc=col;
colloc&=0x0f;
}while(colloc!=0x0f);
do
{
do
{
DELAY(20);
colloc=col;
colloc&=0x0f;
}while(colloc==0x0f);
DELAY(20);
colloc=col;
colloc&=0x0f;
}while(colloc==0x0f);
while(1)
{

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

row=0xfe;
colloc=col;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=0;
break;
}
row=0xfd;
colloc=col;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=1;
break;
}
row=0xfb;
colloc=col;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=2;
break;
}
row=0xfe;
colloc=col;
colloc&=0x0f;
if(colloc!=0x0f)
{
rowloc=0;
break;
}
row=0xf7;
colloc=col;
colloc&=0x0f;
if(colloc!=0x0f)
rowloc=3;
break;
}
if(colloc==0x0e)
LCD_DATA(keypad[rowloc][0]);
else if(colloc==0x0d)
LCD_DATA(keypad[rowloc][1]);
else if(colloc==0x0b)
LCD_DATA(keypad[rowloc][2]);
else
LCD_DATA(keypad[rowloc][3]);
}
}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

Experiment No. 9

DAC INTERFACE

AIM: To write a C program to interface 8051 chip to DAC, and to generate different
waveforms such as Sine, Square, Triangular, Ramp etc. of different frequency and amplitude.
SINE:
#include<reg51.h>
main()
{
unsigned char a[ ]
={128,192,238,255,238,192,128,64,17,0,17,64
};
int i;
while(1)
{
for(i=0;i<12;i++)
P0=a[i];
}}

SQUARE:
#include<reg51.h>
void delay(unsigned int x)
{
for(;x>0;x--);
}
main()
{
unsigned char on=0xff,off=0x00;
while(1)
{
P0=on;
delay(500);
P0=off;
delay(500);
}}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

TRIANGULAR:
#include<reg51.h>
main()
{
unsigned char i;
w hile(1)
{
for(i=0x00;i<0xff;i++)
{
P0=i;
}
for(i=0xff;i>0x00;i--)
{
P0=i;
}}}

RAMP:
#include<reg51.h>
void main()
{
unsigned char i;
while(1)
{
for(i=0;i<0xff;i++)
P0=i;
}
}

STAIR CASE:
#include<reg51.h>
void main()
{
unsigned char i;
while(1)
{
for(i=0;i<0xff;i+0x33)
P0=i;
}
}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

EXERCISE: write C program to interface 8051 chip to DAC, and to generate different stair
case waveforms, ,
Use below for loops to generate different 1.
stair case structures as shown
1.
2.

3.

2. 3.

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

Experiment No. 10

STEPPER MOTOR & DC MOTOR INTERFACE

FULL STEP -TWO PHASE ON SCHEME


STEP A B C D

1 1 0 0 1

2 1 1 0 0

3 0 1 1 0

4 0 0 1 1

AIM: To write a C program to interface 8051 chip to Stepper and DC motor control
CLOCKWISE ROTATION: DC MOTOR

#include<reg51.h> #include<reg51.h>
void delay(unsigned int x) sbit enable=P2^6;
{ sbit mtr_1=P2^7;
for(;x>0;x--); sbit mtr_2=P2^4;
} void main()
main() {
{ enable=1;
unsigned char val,i; while(1)
while(1) {
{ mtr_1=1;
val=0x88; mtr_2=0;
for(i=0;i<4;i++) }}
{
P2=val;
val=val>>1;
delay(575);
}}}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

ANTICOLCKWISE ROTATION CLOCKWISE ROTATION (ANOTHER


TYPE)
#include<reg51.h>
void delay(unsigned int x) #include<reg51.h>
{ void delay(unsigned int x)
for(;x>0;x--); {
} for(;x>0;x--);
main() }
{ main()
unsigned char val,i,j,k; {
while(1) unsigned char val;
{ while(1)
for(i=0;i<0x19;i++) {
{ val=0x03;
val=0x88; P2=val;
for(j=0;j<4;j++) delay(5750);
{ val=0x09;
P2=val; P2=val;
val=val>>1; delay(5750);
delay(1000); val=0x0c;
}} P2=val;
for(k=0;k<0x32;k++) delay(5750);
{ val=0x06;
val=0x11; P2=val;
for(j=0;j<4;j++) delay(5750);
{ }}
P2=val;
val=val<<1;
delay(1000);
}}}}

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

Experiment No. 11

ELEVATOR INTERFACE

AIM: To write a C program to interface 8051 chip to ELEVATOR

#include <at89c51xd2.h>
#include "lcd.h"
unsigned char xdata msg[]={"Elevator Interface "};
unsigned char xdata *cptr;
void delay(unsigned int);
main()
{
unsigned char xdata Flr[9] = {0xff,0x00,0x03,0xff,0x06,0xff,0xff,0xff,0x09};
unsigned char xdata FClr[9] = {0xff,0xE0,0xD3,0xff,0xB6,0xff,0xff,0xff,0x79};
unsigned char ReqFlr,CurFlr = 0x01,i,j;
P0 = 0x00;
P0 = 0x0f0;
cptr = msg;
clear_lcd();
lcd_outstr(cptr);
while(1)
{
P1 = 0x0f;
ReqFlr = P1 | 0x0f0;
while(ReqFlr == 0x0ff)
ReqFlr = P1 | 0x0f0; /* Read Request Floor from P1 */
ReqFlr = ~ReqFlr;
if(CurFlr == ReqFlr) /* If Request floor is equal to Current Floor */
{
P0 = FClr[CurFlr]; /* Clear Floor Indicator */
continue; /* Go up to read again */
}
else if(CurFlr > ReqFlr) /* If Current floor is > request floor */
{
i = Flr[CurFlr] - Flr[ReqFlr]; /* Get the no of floors to travel */
j = Flr[CurFlr];
for(;i>0;i--) /* Move the indicator down */
{
P0 = 0x0f0|j;
j--;
delay(50000);

Dept. of ECE, SMVITM, Bantakal


8051 Microcontrollers Lab

}
}
else /* If Current floor is < request floor */
{
i = Flr[ReqFlr] - Flr[CurFlr]; /* Get the no of floors to travel */
j = Flr[CurFlr];
for(;i>0;i--) /* Move the indicator Up */
{
P0 = 0x0f0 | j;
j++;
delay(50000);
}

}
CurFlr = ReqFlr; /* Update Current floor */
P0 = FClr[CurFlr]; /* Clear the indicator */
}
}
void delay(unsigned int x)
{
for(;x>0;x--);
}

Dept. of ECE, SMVITM, Bantakal

You might also like