Solution I Main P1 I I I P1 P1 P1 P1: #Include
Solution I Main P1 I I I P1 P1 P1 P1: #Include
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 delay(){
TMOD = 0x10 ;
TH1 = 0xDB ;
TL1 = 0xFF ;
TR1 = 1 ;
while(!TF1) ;
TR1 = 0 ;
TF1 = 0 ;
}
THANK YOU