Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

seven segment display blinks

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
640
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
6,922
Hi all....
i am trying to interface 2 digit x 3 seven segment with 89s52. one to show secounds, one for minute and one for hour. it works proper... the only thing is i does not stay stable.... i mean the display blinks. please help me where i am wrong
code is....
Code:
#include<stdio.h>
#include<reg51.h>
unsigned char SetDisplay(unsigned char);
void delay();

sbit sec0 = P3^7;
sbit sec1 = P3^6;
sbit min0 = P3^5;
sbit min1 = P3^4;
sbit hour0 = P3^3;
sbit hour1 = P3^2;

unsigned char d0,d1,d2,d3,d4,d5;
unsigned char SetDisplay(unsigned char value)
{
unsigned char segment[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
 if(value<=10)
return segment[value];
 else
return 0;

}

//--------------
//Delay Function
//--------------

void delay()
{
 int i;
 for(i=0; i<1250; i++)
i = i + 0;
}

//--------------
//Main Program

//--------------
void main(void)
{
 unsigned char count = 0;
 unsigned long timer = 0;
 int turn = 1;
// P2 = 0xff;
 while(1)
{
 if(turn==1) //7-Seg Display 0
{
sec0=1;
sec1=0;
min0=0;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2) //7-Seg Display 1
{
sec0=0;
sec1=1;
min0=0;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3) //7-Seg Display 2
{
sec0=0;
sec1=0;
min0=1;
min1=0;
hour0=0;
hour1=0;
P2=SetDisplay(d2);
turn = 4;
delay();
}
else if(turn==4)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=1;
hour0=0;
hour1=0;
P2=SetDisplay(d3); 	
turn = 5;
delay();
}

else if(turn==5)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=0;
hour0=1;
hour1=0;
P2=SetDisplay(d4); 	
turn = 6;
delay();
}
else if(turn==6)//7-Seg Display 3
{
sec0=0;
sec1=0;
min0=0;
min1=0;
hour0=0;
hour1=1;
P2=SetDisplay(d5); 	
turn = 1;
delay();
}

 if(timer == 100)
	 {
     d0++;
	 timer=0;
 if(d0>=10)
	 {
     d0=0;
	 d1++;
 if(d1>=10)
	 {
     d1=0;
     d2++;
 if(d2>=10)
	 {
     d2=0;
     d3++;
 if(d3>=10)
	 {
     d3=0;
   }
   }
   }
   }
   }
timer++;
 }
}
 

Hi,

"It blinks" sounds like a timing problem.
But you don't give any timing information. Neither in description, nor in the code.

So please add clock frequecy, delay function timing, scope pictures, and other timing information..

I assume the display is multiplexed. You need at lees a complete display cycle every 20ms. Better is to go in direction to 5ms.

Klaus
 

Hi,

"It blinks" sounds like a timing problem.
But you don't give any timing information. Neither in description, nor in the code.

So please add clock frequecy, delay function timing, scope pictures, and other timing information..

I assume the display is multiplexed. You need at lees a complete display cycle every 20ms. Better is to go in direction to 5ms.

Klaus
Yes but when i tried interfacing only two instead of three 2 digit seven segment display... it works perfectly without blinking...
 

You have some strange delays in that program. It would be better to balance the timing so all the digits get equal time slots and equal spacing. You flicker is probably due to the slow down in the program while it performs long checking routines:
Code:
if(timer == 100)
{
  d0++;
  timer=0;
  if(d0>=10)
  {
    d0=0;
    d1++;
    if(d1>=10)
    {
      d1=0;
      d2++;
      if(d2>=10)
      {
        d2=0;
        d3++;
        if(d3>=10)
        {
          d3=0;
        }
      }
    }
  }
}

timer++;
which seems only to run once in 100 counts of 'timer' therefore only 1% of total time. Use hardware timers to create delays wherever possible.

Brian.
 
Hi,

Code:
Use hardware timers to create delays wherever possible.
I'd do the complete display control and multiplexing within a hardware timer ISR, not only the delay.

1:3 mux, update rate of 100Hz needs an interrupt every 3.3ms.
With a bit of optimisation then the complete display control may need as low as 30us, this means only 1% of processing power.
Add some overhead, then still 95% of processing power is available for the main loop.

Klaus
 

You have some strange delays in that program. It would be better to balance the timing so all the digits get equal time slots and equal spacing. You flicker is probably due to the slow down in the program while it performs long checking routines:
Code:
if(timer == 100)
{
  d0++;
  timer=0;
  if(d0>=10)
  {
    d0=0;
    d1++;
    if(d1>=10)
    {
      d1=0;
      d2++;
      if(d2>=10)
      {
        d2=0;
        d3++;
        if(d3>=10)
        {
          d3=0;
        }
      }
    }
  }
}

timer++;
which seems only to run once in 100 counts of 'timer' therefore only 1% of total time. Use hardware timers to create delays wherever possible.

Brian.

sorry... as i am new to programming and seven segment display concept.... didn't get you point....
 

They are giving advice that you have to create delay using Timer Interrupt and write the 7 Segment Multiplexing code inside the Timer Interrupt Service Routine.
 

Hi,

A reviewed the code, now I assume it is an 1:6 multiplex rate

I'd use an array with 6 items of "char" containing the values for the segments: seg (0..5)
The six values numbered 0..5 contain:
0: seconds, units
1: seconds, tens
2: minutes, units
3: minutes, tens
4: hours, units
5: hours, tens

Within the ISR, you just have to: (the ISR continously runs once every about 3.3ms
* increment the segment pointer: sp = (sp +1) modulo 6. So it continously runs from 0 to 5.
* clear all digits, just to avoid artifacts
* set new digit sements: D2 = seg (sp)
* activate the new digit:

The segment values seg (0..5) may be updated every second by the software clock unit either in an ISR or in main loop.

Klaus
 

here is a code for a digital clock displayed in 6 7seg i developed it few weeks ago
makes sure to insert some delay between each display
Code:
/*******************************************************************/
void prepareCount(unsigned int decimal){
	unsigned char hours,min,sec;
	unsigned int rem;
	//CONVERT THE DECIMAL NUMBER INTO BCD
	hours = decimal /3600;
	rem = decimal %3600;
	min = rem/60;
	sec = rem%60;
	Seven_Segment_Digit[5] =hours/10;
	Seven_Segment_Digit[4] =hours%10;
	Seven_Segment_Digit[3] =min/10;
	Seven_Segment_Digit[2] =min%10;
	Seven_Segment_Digit[1] =sec/10;
	Seven_Segment_Digit[0] =sec%10;

	
	Seven_Segment_Digit[0] =BCD_to_7Seg( Seven_Segment_Digit[0]);
	if(decimal >=10 )
		Seven_Segment_Digit[1] =BCD_to_7Seg( Seven_Segment_Digit[1]);
	if(decimal >=60)
		Seven_Segment_Digit[2] =BCD_to_7Seg( Seven_Segment_Digit[2]);
	if(min >9 ||hours>0)
		Seven_Segment_Digit[3] =BCD_to_7Seg( Seven_Segment_Digit[3]);
	if(hours>0)
		Seven_Segment_Digit[4] =BCD_to_7Seg( Seven_Segment_Digit[4]);
	if(hours>9)
		Seven_Segment_Digit[5] =BCD_to_7Seg( Seven_Segment_Digit[5]);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top