0
1.7kviews
A key is connected at P3.2 and 8 LEDs are connected to P1 of 8951. Write a C program to display 0 to 255 in binary on LEDs, when a key is pressed.
1 Answer
0
66views

(Asssuming that P3.2 =0, when the key is pressed)

#include< reg51.h>

sbit sw = P3^2;

void delay (unsigned int);

void main(void)

{

    sw=1;

    unsigned char i;

    P1=0X00;

    while(1)

    {

        if(sw==0)

        {

            for(i=0;i<=255;i++)

            {

                P1=i;

                delay(100);

            }

        }

        else

            P1=0;

    }

}

void delay (unsigned int i time)

{

    unsigned int i,j:

    for (i=0;i<itime;i++)

        for(j=0;j<1275;j++);

}
Please log in to add an answer.