Write an Embedded C program to blink
the alternate LEDs in using PORT using Switch
#include"reg51.h"
sbit
sw = P1^0;
void
MSDelay(unsigned int);
void
main(void)
{
while(1)
{
if(sw==1)
{
P2=0x55;
//ON all LEDs
MSDelay(50);
//Delay
}
else
{
P2=0x00;
//OFF all LEDs
MSDelay(50);
//Delay
//Delay
}
}
}
void
MSDelay(unsigned int itime)
{
unsigned
int i,j;
for(i=0;i<=itime;i++)
for(j=0;j<=1275;j++);
}
Write an Embedded C program to blink the alternate LEDs in using PORT using Two Switch
#include"reg51.h"
sbit sw1 = P1^0;
sbit sw2 = P1^1;
void delay(unsigned char ms)
{
unsigned char n;
unsigned int i;
{
for (n=0; n<ms; n++)
for (i=0; i<15; i++);
}}
void main(void)
{
while (1)
{
if (sw1==1)
{
P2=0xff;
//ON all LEDs
delay(1);
//Delay
}
else
{
P2=0x00;
delay(1);
}
if (sw2==1)
{
P3=0xff;
//ON all LEDs
delay(1);
//Delay
}
else
{
//Delay
P3=0x00;
delay(1);
//Delay
P2=0x00;
delay(1);
//Delay
}
}
}
#include"reg51.h"
sbit
sw1 = P1^0;
sbit
sw2 = P1^1;
sbit
sw3 = P1^2;
void
MSDelay(unsigned int);
void
main(void)
{
P1=0x00;
while(1)
{
if(sw1==1 && sw2==0
&& sw3==1)
{
P2=0x55; //ON all LEDs
MSDelay(50); //Delay
}
else
{
P2=0x00; //OFF
all LEDs
MSDelay(50); //Delay //Delay
}
}
}
0 comments:
Post a Comment