0% found this document useful (0 votes)
25 views

Embed Lab 1 To 4

The document contains several C programs for an 8051 microcontroller to control LEDs. The programs include: 1) Printing text to continuously display the name of a college and lab. 2) Blinking alternate LEDs on and off. 3) Turning on the least significant LEDs. 4) Turning LEDs on and off with a time delay between states. 5) Alternating between least and most significant LEDs. 6) Controlling LED behavior based on switch states. 7) Additional programs combining switch input with text display and LED control.

Uploaded by

yixexi7070
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)
25 views

Embed Lab 1 To 4

The document contains several C programs for an 8051 microcontroller to control LEDs. The programs include: 1) Printing text to continuously display the name of a college and lab. 2) Blinking alternate LEDs on and off. 3) Turning on the least significant LEDs. 4) Turning LEDs on and off with a time delay between states. 5) Alternating between least and most significant LEDs. 6) Controlling LED behavior based on switch states. 7) Additional programs combining switch input with text display and LED control.

Uploaded by

yixexi7070
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/ 21

Program to display the character “SONA COLLEGE OF

TECHNOLOGY”

#include<stdio.h>
#include<at89x51.h>
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=221;
TR1=1;
TI=1;
while(1)
{
printf("SONA COLLEGE OF TECHNOLOGY,\n");
}
}
Program to display the character “Sona ECE Embedded
Lab”

#include<stdio.h>
#include<at89x51.h>
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=221;
TR1=1;
TI=1;
while(1)
{
printf("SONA ECE EMBEDDED LAB,\n");
}
}
Program to glow alternate LED’s

#include<stdio.h>
#include<at89x51.h>
void main()
{

while(1)
{
P0=0XAA; // ALTERNATE ON
P1= 0X55;
}
}
Program to glow LSB LED’s
#include<stdio.h>
#include<at89x51.h>
void main()
{

while(1)
{
P0=0x0F;
}
}
Program to turn on and turn off the LED’S with time
delay
#include<stdio.h>
#include<at89x51.h>
void delay();
int i;
void delay()
{
for(i=0;i<10000;i++);
}
void main()
{
while(1)
{
P0=0xAA;
delay();
P0=0x00;
delay();
}
}
Program to turn on and turn off LSB and MSB
alternatively
#include<stdio.h>
#include<at89x51.h>
void delay();
int i;
void delay()
{
for(i=0;i<10000;i++);
}
void main()
{
while(1)
{
P0=0x0F;
delay();
P0=0xF0;
delay();
}
}
Program to
Switch 1 on - All the LED’s have to glow
Switch 2 on – Alternate LED’s have to glow
#include<stdio.h>
#include<at89X51.h>
void main()
{
while(1)
{
if(P0_0=='1')
{
P1=0xFF; //switch 1
}
else if(P0_1=='1')
{ //switch2
P1=0xAA;
}
else {
P1=0x00;
}}
switch 1on- all on switch 1 off- alternatively on WITH
TIME DELAY
#include<stdio.h>
#include<at89X51.h>
void delay();
int i;
void delay(){
for(i=0;i<=10000;i++);
//delay
}
void main()
{
while(1)
{
if(P0_0=='1')
{
//SWITCH ON
delay();
P1=0xFF;
delay();
P1=0x00;
}
else {
delay(); //SWITCH OFF
P1=0xAA;
delay();
P1=0x00;
}

}
Switch 1 on – embedded lab
Switch 2 on – switch 2 is pressed
#include<stdio.h>
#include<at89X51.h>
void delay();
int i;
void main()
{
SCON =0x50;
TMOD=0x20;
TH1=221;
TR1=1;
TI=1;

while(1)
{

if(P0==0x01)
{
//SWITCH 1
printf("EMBEDDED LAB\n");
P3=0x22;
}

else if(P0==0x02){ //switch 2


printf("switch 2 is pressed");
delay();
P1=0xAA;
delay();
P1=0x00;

}
else{
P1=0x00;
}
}
}
void delay(){
for(i=0;i<=10000;i++);
//delay
}

You might also like