Wednesday, 26 August 2015

Seven-segment display using switch

#include<reg51.h>
#define  led P2              // 7-segment connection
sbit sw=P3^0;                // Switch connection
unsigned int x,a[]={0x06,0x5B,0x4F,0x66,0x6D,0x7C,0x07,0x7F,0x67,0x3F},j=0;  // Values from 0-9
        void delay(unsigned int x)
        {
                while(x--);
             
        }
        void main()
{
        while(1)
        {
             
                if(sw==0)
                {
                P2=a[j];
                delay(100000);
          j++;
}      
                if(j==10)
                        j=j-10;
                     
}
}

//Please comment below for any queries

No comments: