0% found this document useful (0 votes)
114 views8 pages

Experiment No.1: Aim: To Interface 8 LED's at Input-Output Port and Create Different Patterns

This document contains 7 experiments conducted by Akash Nair (Roll No. 6151) involving an 8051 microcontroller. Experiment 1 involves interfacing 8 LEDs to create alternating and nibble patterns. Experiment 2 generates a 50ms time delay using timer control registers. Experiment 3 simulates a binary counter using 8 LEDs. Experiment 4 demonstrates a 7-segment LED display to count from 0 to 99. Experiment 5 blinks an LED using a timer without delays. Experiment 6 generates a 50Hz square wave on an oscilloscope. Experiment 7 generates a triangular wave on an oscilloscope. The document provides the code for each experiment and expected output.

Uploaded by

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

Experiment No.1: Aim: To Interface 8 LED's at Input-Output Port and Create Different Patterns

This document contains 7 experiments conducted by Akash Nair (Roll No. 6151) involving an 8051 microcontroller. Experiment 1 involves interfacing 8 LEDs to create alternating and nibble patterns. Experiment 2 generates a 50ms time delay using timer control registers. Experiment 3 simulates a binary counter using 8 LEDs. Experiment 4 demonstrates a 7-segment LED display to count from 0 to 99. Experiment 5 blinks an LED using a timer without delays. Experiment 6 generates a 50Hz square wave on an oscilloscope. Experiment 7 generates a triangular wave on an oscilloscope. The document provides the code for each experiment and expected output.

Uploaded by

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

NAME:AKASH NAIR

ROLL NO:6151

Experiment No.1
Aim: To interface 8 LED’s at input-output port and create different patterns

1. Alternative/ Dancing pattern

#include<reg51.h>
void main(void)
{
unsigned int x;
for(;;)
{
P1=0xAA;
for(x=0;x<25500;x++);
P1=0x55;
for(x=0;x<25500;x++);
}
}

Output:

2. Nibble ON/OFF pattern


#include<reg51.h>
void main(void)
{
unsigned int x;
for(;;)
{
P2=0xF0;
for(x=0;x<25500;x++);
P2=0x0F;
for(x=0;x<25500;x++);
}
}
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.2
Aim: Configure timer control registers of 8051 and develop a program to generate given
time delay.

Below program is used to generate a time delay of 50ms.

Delay calculation

#include<reg51.h>
sbit led=P2^0; // led at PORT 2 pin 0
void Delay(void); // Delay function declaration
void main () // main function
{
led=0; //output PORT
while(1) // infinite loop
{
led = 1; // LED ON
Delay();
led = 0; // LED OFF
Delay();
}
}
void Delay()
{
TMOD = 0x01; // Timer0 mode1
TH0=0x46; //initial value for 10ms
TL0=0xFD;
TR0 = 1; // timer0 start
while (TF0 == 0); // check overflow condition
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
}
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.3
Aim: Use one of the four ports of 8051 for output interfaced to eight LED’s. Simulate
Binary Counter using 8 LED’s

Program:
#include <reg51.h>
void main (void)
{
unsigned char x;
for (x=0;x<=255;x++)
P1=x;
}

Output:
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.4
Aim: To demonstrate interfacing of seven segment LED display and generate counting
from 0 to 99 with fixed delay.

Program:
#include<reg51.h>
void delay(unsigned int ms)
{ unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<=1275;j++);
}
void main(void)
{
char number[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i,j;
P2=0x00;
P3=0x00;
while(1)
{
for(i=0;i<=9;i++)
{
P2=number[i];
for(j=0;j<=9;j++)
{
P3=number[j];
delay(50);
}
}
}

//mpx1 cc
Output:
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.5

Aim:To demonstrate timer working in timer mode and blink LED without using any
loop delay routine.

Program:
#include<reg51.h>
sbit led=P2^0; // led at PORT 2 pin 0
void Delay(void); // Delay function declaration
void main () // main function
{
led=0; //output PORT
while(1) // infinite loop
{
led = 1; // LED ON
Delay();
led = 0; // LED OFF
Delay();
}
}
void Delay()
{
TMOD = 0x01; // Timer0 mode1
TH0=0xDC; //initial value for 10ms
TL0=0x00;
TR0 = 1; // timer0 start
while (TF0 == 0); // check overflow condition
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
}

Output:
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.6
Aim: To generate Square wave of given frequency on oscilloscope
Consider frequency as 50Hz

Program:

#include<reg51.h>
void Delay(void);
void main (void)
{
P2=0xFF;
Delay();
P2=0x00;
Delay();
}
void Delay()
{
TMOD= 0x01;
TH0=0xDC;
TL0=0x00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

Output:
NAME:AKASH NAIR
ROLL NO:6151

Experiment No.7
Aim: To generate Triangular wave of given frequency on oscilloscope

Program:

#include<reg51.h>
void Delay();
void main()
{
unsigned char i;
while(1)
{
for(i=0;i<0xff;i++)
{
Delay();
P2= i;
}
for(i=0xfe;i>0x00;i--)
{
Delay();
P2 = i;
}
}
}
void Delay()
{
TMOD= 0x01;
TH0=0xFC;
TL0=0x66;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}

Output:
NAME:AKASH NAIR
ROLL NO:6151

You might also like