As seven segment display is used to display numeric digits, it become very important in any numeric data display in electronics device. Seven segment display is named so because numeric digit from 0 to 9 can be display by ON/OFF of segment's LED. Generally, seven segment has one more segment to indicate dot. Means, it contain 8 LEDs.
Note : Firstly, identify your seven segment display type i.e. Common Cathode (CC) or Common Anode (CA). Generally, it has 10 pins in a dual in-line (DIP) pakage and center pin of each side is a common pin. You can even identify its type by using LED tester.
//////////global variable declaration start
char digit_count = 1;
unsigned char DIGIT1=1;
unsigned char DIGIT2=2;
unsigned char DIGIT3=3;
unsigned char DIGIT4=4;
unsigned char SEGMENT_CODE[11]={0xBE,0x8 4,0x3D,0xAD,0x87,0xAB,0xBB ,0x8C,0xBF,0xAF,0X40};
//////////global variable declaration end////////////
//////////output assignment start
sfr SEG_DATA at P1;
sbit SEL_DIGIT1 at P3_0_bit;
sbit SEL_DIGIT2 at P3_1_bit;
sbit SEL_DIGIT3 at P3_2_bit;
sbit SEL_DIGIT4 at P3_3_bit;
void INIT_OUTPUT()
{
SEG_DATA = 0;
SEL_DIGIT1 = 0;
SEL_DIGIT2 = 0;
SEL_DIGIT3 = 0;
SEL_DIGIT4 = 0;
}
//////////output assignment end
//////////input assignment start
//////////input assignment end
////////////////// SEVEN SEGMENT DISPLAY SATRT
void _7SEG_DISPLAY() iv IVT_ADDR_ET0 ilevel 0 ics ICS_AUTO
{
TCON.B4 = 0; //stop TIMER0 FOR TIME COUNT
if(digit_count==1)
{
SEL_DIGIT1 = 1;
SEL_DIGIT2 = 0;
SEL_DIGIT3 = 0;
SEL_DIGIT4 = 0;
SEG_DATA = SEGMENT_CODE[(0B00000011 & seconds)];
}
if(digit_count==2)
{
SEL_DIGIT1 = 0;
SEL_DIGIT2 = 1;
SEL_DIGIT3 = 0;
SEL_DIGIT4 = 0;
SEG_DATA = SEGMENT_CODE[(0B01110000 & seconds)>>4];
}
if(digit_count==3)
{
SEL_DIGIT1 = 0;
SEL_DIGIT2 = 0;
SEL_DIGIT3 = 1;
SEL_DIGIT4 = 0;
SEG_DATA = SEGMENT_CODE[0];
}
if(digit_count==4)
{
SEL_DIGIT1 = 0;
SEL_DIGIT2 = 0;
SEL_DIGIT3 = 0;
SEL_DIGIT4 = 1;
SEG_DATA = SEGMENT_CODE[0];
}
digit_count++;
if(digit_count>4)
{
digit_count=1;
}
TH0=0xF0;
TL0=0;
TCON.B4 = 1; //START TIMER1 FOR TIME COUNT
}
void timer0_init()
{
TMOD=0b00000001; //TIMER0 AS 16-BIT COUNTER
TCON.B0=1;
IE.B1=1; //TIMER0 INTERRUPT IS ON
TH0=0;
TL0=0;
TCON.B4 = 1; //START TIMER1 FOR TIME COUNT
IE.B7=1; //interrupt enable
}
////////////////////// SEVEN SEGMENT DISPLAY END
////////////////////// ////////////////////////// //////////
////////////////////// ////////////////////////// //////////
////////////////////// ////////////////////////// //////////
void main() {
Delay_ms(2000);
timer0_init();
while (1) // Endless loop
{
Delay_ms(20); // Wait 1 second
}
}
////////////////////// ////////////////////////// //////////
////////////////////// ////////////////////////// //////////
////////////////////// ////////////////////////// //////////
For any query, feel free to comment below.....
Comments...
Write Your Comment