Thursday, 4 December 2014

C code for interfacing 7 segment display

Code for interfacing 7-Segment in 8051 and keil
In this lesson I will discuss about how to code to interface 7-segment in 8051 in c language.
Here I have used common anode 7-segment display.
The code is…………
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Seven segment display//
#include <REGX51.H>
#define seg P1
code char digit[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x90} ;

void delay_ms(int milisec)
{
   int i,j,k;
        for(j=0;j<milisec;j++)
        {
      for(k=0;k<20;k++)   
        {               
                  for(i=0;i<4898;i++);
                 }
        }
}
void main(void)
{
        int i;
        P1=0x00;
        while(1)
        {
                for(i=0;i<10;i++);
                {
                        P1=digit[i];
                        delay_ms(1000);
                }
        }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
By this code 7 segment will display 0 1 2 3 4 5 6 7 8 9 0 1…..for a continuas manner.

 Connect all pin of 7 segment to port one (P1).

No comments:

Post a Comment