Monday 3 September 2018

8051: Seven Segment Interface Code



Description:

            Interfacing Seven Segment Display with 8051. A seven segment display module is an electronic device used to display digital numbers and it is made up of seven LED segments. Because of the small size of the LEDs, it is really easy for a number of them to be connected together to make a unit like seven segment display. Seven segment display were connected in the port 2 and port 3, port 2 connected with the pins and port 3 pins connects with the display digital numbers in seven segment.

Code:
#include<reg51.h>

sbit a1=P3^0;
sbit b1=P3^1;

void delay(int n)
{
            int i,j;
            for(i=0;i<n;i++)
              for(j=0;j<n;j++);

}
void main()
{
            int a[10]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6},i,j,k;
            P3=P2=0xff;
            while(1)
            {
                        for(i=0;i<10;i++)
                        {
                                    for(j=0;j<10;j++)
                                      {
                                                            for(k=0;k<5;k++)
                                                            {
                                                                        P2=a[i];
                                                                        a1=0;
                                                                        b1=1;
                                                                        delay(70);
                                                                       
                                                                        P2=a[j];
                                                                        a1=1;
                                                                        b1=0;
                                                                        delay(70);
                                                            }
                                    }
                        }
            }
}



Circuit Diagram:


No comments:

Post a Comment