0% found this document useful (0 votes)
20 views2 pages

Solution I Main P1 I I I P1 P1 P1 P1: #Include

The document contains solutions to 3 programming problems involving 8051 microcontrollers. The first problem involves toggling LEDs from right to left using port P1. The second problem implements serial communication using interrupts with a crystal frequency of 11.0592 MHz. The third problem performs hardware delay using interrupts with a crystal frequency of 12 MHz by toggling two LEDs on ports P2.0 and P2.1.

Uploaded by

Lokesh Sangrame
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)
20 views2 pages

Solution I Main P1 I I I P1 P1 P1 P1: #Include

The document contains solutions to 3 programming problems involving 8051 microcontrollers. The first problem involves toggling LEDs from right to left using port P1. The second problem implements serial communication using interrupts with a crystal frequency of 11.0592 MHz. The third problem performs hardware delay using interrupts with a crystal frequency of 12 MHz by toggling two LEDs on ports P2.0 and P2.1.

Uploaded by

Lokesh Sangrame
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/ 2

LOKESH SANGRAME 2101210CS CSE

1.Write an 8051 program to toggle LEDs connected to the port P1 from right to left, turning
off the previous LEDs.
Solution
#include<reg51.h>
int i ;
void main()
{
P1 = 0x01 ;
while(1)
{
for (i = 0 ; i < 8 ; i++)
{
P1 = P1<<1 ;
if (P1 == 0x80)
{
P1 = 0x01 ;
}
}
}
}

2. Write a program for serial communication using interrupt. Assume crystal frequency as
11.0592 MHz.
Solution
#include <reg51.h>

int i;
unsigned char tx[8] = "LOKESH";

void main()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;

while (1)
{
for (i = 0; i < 8; i++)
{
SBUF = tx[i];
while (TI == 0);
TI = 0; /
}
LOKESH SANGRAME 2101210CS CSE

}
}

3. Write an 8051 program to perform hardware delay using interrupt. Assume crystal
frequency as 12 MHz.
Solution
#include<reg51.h>
sbit L1=P2^0;
sbit L2=P2^1;

void delay();
void main()
{
IE = 0x81;
TCON=0x01;
while(1){
L1=~L1;
delay();
}

void int0(void) interrupt 0 {


L2=~L2;
delay();
}

void delay(){
TMOD = 0x10 ;
TH1 = 0xDB ;
TL1 = 0xFF ;
TR1 = 1 ;
while(!TF1) ;
TR1 = 0 ;
TF1 = 0 ;
}

THANK YOU

You might also like