Monday, 23 January 2017

7 - Segment display with 8051

Now I am going to show "How 7-Segment display with 8051". Here first we know about 7 segment display, In 7-segment there are 8 leds including Decimal point (DP) shown below
Here A-G are 7 leds these are main leds to display 0-9 numbers, another one DP-led. This segment contains 9 pins for 7 pins are assign to 7 leds from A - G, one for Dp and finally the Enable pin. In 7-segment display having enable pin which is either cathode or anode pin. When we use cathode pin it must be connection to Ground-Terminal, if we use anode pin it must be connected to VCC or power supply. 


     

The above table is very important to run the 7-segment display using any micro-controller. As you seen above table the VALUE-column is full of Hexa-decimal code for each and every number from  0-9.

For Example if you want to display number - 4 we need the value 0x66. If you cascading the two       7 - segments we can display 0-99 numbers and so on.

Code:-  

This code is only for single 7-segment display. It counts from 0-9 and each number is display with some delay.


#include<reg51.h>
# define segment P2                                   // 7-segment is assign to Port-2

void delay(unsigned int ms)                          // Delay function
{
int i,j;
for(i=0;i<ms;i++)
for(j=0;j<1275;j++);
}

void main()                                                    // Main function
{
unsigned char i,array[] = {0x3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
while(1)
{
for(i=0;i<10;i++)
          {
             segment = array[i];
            delay(100);
             }
       }
}

This is very simple code to execute 0-9 numbers in 7-segment display using 8051 micro-controller.
Here I am using Array, so this post is useful to how to write arrays in Embedded-C.

See the below video to get clarity about "How this code works ?" Thank you


No comments: