Interfacing Seven Segment with 8051

7 Segment LED Display:





Image result for 7 segment display gif

Hardware connection:

 
7seg LED display with 8051
7seg LED display with 8051

Program:



1st method:


#include <reg52.h>
void Delay(unsigned int ms_Count)
{
    unsigned int i,j;
    for(i=0; i<ms_Count; i++)
    {
        for(j=0; j<100; j++);
    }
}


int main()
{
    P1 = 0x00;
   
    while(1)
    {
        P1 = 0x06;                //Display 1
        Delay(1000);
        P1= 0x5B;                //Display 2
        Delay(1000);
        P1 = 0x4F;                //Display 3
        Delay(1000);
    }        
}


2nd Method:




#include <reg51.h>

void delay(unsigned int k)
{
    unsigned int i,j;
    for(i=0;i<k;i++)
    {
        for(j=0;j<100;j++);
    }
}

int main() {
    char seg_code[]={0x06,0x5b,0x4f};   
    int i;

    while (1)
    {
        for (i = 0; i <= 2; i++)        // loop to display 1-3
        {
            P1 = seg_code[i];
            delay(1000);
        }
    }
}



 If you have any doubts do comment, thank you.