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.

[SOLVED] Seven Segment Display Scrolling Digits

Status
Not open for further replies.

sonar_abhi

Member level 1
Joined
Mar 15, 2016
Messages
36
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
380
I am coding SSD display using 2 cascaded shift registers. I am using a mikroC for PIC compiler. I can display a static sequence of numbers upto 4 digits with my code

Static Display.png

Here is my complete code

Code:
#define SHIFT_CLOCK PORTB.F1    //Clock Connection of 74HC595 SSD Driver
#define SHIFT_LATCH PORTB.F3    //Latch Connection of 74HC595 SSD Driver
#define SHIFT_DATA PORTB.F2    //Data Connection of 74HC595 SSD Driver

char array4[4] = {6, 91, 79, 102};           //Display 1234 on SSD
char digit[4] = {0xFE, 0xFD, 0xFB, 0xF7};   //Switch on the SSD digits one by one

char i,j,temp,flag1,flag2;

void InitTimer0()
{
 OPTION_REG     = 0x86;
 TMR0           = 6;
 INTCON         = 0xA0;
}

void latch595()
{
 SHIFT_LATCH = 1;
 Delay_us(1);
 SHIFT_LATCH = 0;
}

void shiftdata595(unsigned char _shiftdata)
{
 int i;
 unsigned char temp;
 temp = _shiftdata;
 i=8;
 while (i>0)
 {
  if (temp.F7==0)
   {
    SHIFT_DATA = 0;
   }
   else
   {
    SHIFT_DATA = 1;
   }
   temp = temp<<1;
   SHIFT_CLOCK = 1;
   SHIFT_CLOCK = 0;
   i--;
 }
}

void Interrupt()
{
 if (TMR0IF_bit)
 {
  TMR0IF_bit  = 0;
  TMR0        = 6;
  flag1 = 1;
  flag2 = 1;
 }
}

void main()
{
 TRISB = 0;
 TRISC.F1 = 1;
 InitTimer0();
 while (1)
 {
  if (PORTC.F1==0)
  {
   if (flag2==1)
   {
    shiftdata595(digit[i]);
    i++;
    if(i==4)
    {
     i=0;
    }
    if (flag1==1)
    {
     shiftdata595(array4[j]);
     latch595();
     j++;
     if (j==4)
     {
      j=0;
     }
    }
   }
  }
  else if(PORTC.F1==1)
  {
   shiftdata595(0);
   shiftdata595(0);
   latch595();
  }
 }
}

If I add more digits to the array4[], say upto 9, I will need to scroll the digits to the left sequentially. I tried shifting the array by

Code:
temp = array4[0];
for (n=1; n<8; n++)
{
 array4[j-1] = array[j];
}
array[9] = temp;

I hoped that this code will left shift the array and the display will scroll, but all I am getting is a jumbled up display. If I add a delay, I can see that the numbers are getting displayed but without scrolling.

Is the basic algorithm faulty or can it be used by modifying the code?
 

Code:
void StringMoveLeft (char * String, char Len)
{
        char tmp;
        char dat = String[0];
        char cnt;
        
        for (cnt = 0; cnt != tmp; cnt++) 
          String[cnt] = String[cnt + 1];
        
        String[tmp] = dat;
}

void StringMoveRight (char * String, char Len)
{
        char tmp;
        char dat;
        char cnt;
        
        dat = String[Len - 1];        
        for (cnt = tmp; cnt != 0; cnt--) 
          String[cnt] = String[cnt - 1];
        String[0] = dat;
}
 

Hi,

Your array4 needs to have 9 items. Let´s say 0...8
If your code wants to perform left shift, then item 0 is the most left, item 8 is the most right.

then it should loop from 1 to 7 (not 8)
* you need to decide what happens with previous item 0 (is it lost?)
* you need to decide what happens with new item 8 (is it blank)
* you need to decide how often you run the left_shift. (once per second is slow, once per 100ms is too fast). It should be precisely timed.
* you need to decide how often your display is updated, and how long this takes. Best is if the shift is synchronized with the display update.

What is the 10th array item (9) in your code good for?
What does temp contain?

Klaus
 

Code:
void StringMoveLeft (char * String, char Len)
{
        char tmp;
        char dat = String[0];
        char cnt;
        
        for (cnt = 0; cnt != tmp; cnt++) 
          String[cnt] = String[cnt + 1];
        
        String[tmp] = dat;
}

void StringMoveRight (char * String, char Len)
{
        char tmp;
        char dat;
        char cnt;
        
        dat = String[Len - 1];        
        for (cnt = tmp; cnt != 0; cnt--) 
          String[cnt] = String[cnt - 1];
        String[0] = dat;
}

Thanks for the code Easyrider83 but I can't understand how to use this in my code. Can you please explain?

- - - Updated - - -

Hi KlausST,

My algorithm is as follows. Please check if it is correct.

Lets say,
array4[10] = {6, 91, 79, 102, 109, 125, 7 , 127, 111, 63 };

Now the array needs to be left shifted to give and the first element in the array4[] goes to a temporary variable. The array is left shifted from array4[1] onwards toll array4[9]. Afterwards the temporary variable is placed in the array4[10] place.

Thus,
*the previous item is placed at the last position at each loop
*the new item 10 is the first item
*It needs to be precisely timed because the cathode terminals are switched on and off every 32 mS via a timer. Any change in the speed might result in the character being displayed at the different position than intended
 

Hi,

if you take a pencil and a sheet of paper you will see what happens.
Before you had 10 items in your array (0 ... 9) now it seems you have 11 items (0 ... 10).

There are several (obvious) problems with your code.
To avoid confusion let´s take this code from post #1
Code:
temp = array4[0];
for (n=1; n<8; n++)
{
 array4[j-1] = array[j];
}
array[9] = temp;

You are using the folowing array items:
* array4[0]
* array4[1]
* array4[2]
* array4[3]
* array4[4]
* array4[5]
* array4[6]
* array4[7]
(* array4[8] never used in your code)
* array4[9]
--> you see this are 10 items, but you talk about 9 digits only. How do you handle this?

temp = array4[0];
--> this is OK

for (n=1; n<8; n++)
--> Now you use variable "n" to count from 1 to 7

array4[j-1] = array[j];
--> here you use varaible "j" but not variable "n".
you want to perform these operations: (but to do this you first need to change "j" to "n"
* array4[0] ... array4[1]
* array4[1] ... array4[2]
* array4[2] ... array4[3]
* array4[3] ... array4[4]
* array4[4] ... array4[5]
* array4[5] ... array4[6]
* array4[6] ... array4[7]

array[9] = temp;
--> this is OK.

this is what your code does so far.
--> but why don´t you update
* array4[7]
* array4[8]

???
******

Don´t forget to initialize the data properly. Especially don´t forget to initialize ALL array items when a new value is written to the array.

******
I recommed to use a trace tool for your code. And a sheet of paper and a pencil to write down the data values.

Klaus
 

Hi,

if you take a pencil and a sheet of paper you will see what happens.
Before you had 10 items in your array (0 ... 9) now it seems you have 11 items (0 ... 10).

There are several (obvious) problems with your code.
To avoid confusion let´s take this code from post #1
Code:
temp = array4[0];
for (n=1; n<8; n++)
{
 array4[j-1] = array[j];
}
array[9] = temp;

You are using the folowing array items:
* array4[0]
* array4[1]
* array4[2]
* array4[3]
* array4[4]
* array4[5]
* array4[6]
* array4[7]
(* array4[8] never used in your code)
* array4[9]
--> you see this are 10 items, but you talk about 9 digits only. How do you handle this?

temp = array4[0];
--> this is OK

for (n=1; n<8; n++)
--> Now you use variable "n" to count from 1 to 7

array4[j-1] = array[j];
--> here you use varaible "j" but not variable "n".
you want to perform these operations: (but to do this you first need to change "j" to "n"
* array4[0] ... array4[1]
* array4[1] ... array4[2]
* array4[2] ... array4[3]
* array4[3] ... array4[4]
* array4[4] ... array4[5]
* array4[5] ... array4[6]
* array4[6] ... array4[7]

array[9] = temp;
--> this is OK.

this is what your code does so far.
--> but why don´t you update
* array4[7]
* array4[8]

???
******

Don´t forget to initialize the data properly. Especially don´t forget to initialize ALL array items when a new value is written to the array.

******
I recommed to use a trace tool for your code. And a sheet of paper and a pencil to write down the data values.

Klaus


Hi Klaus,

Thanks for the advice. I actually did figure out what was wrong with the code by writing down the data values.

Here is the code that worked,

Code:
 if (flag2==1)
    {
     shiftdata595(array4[tmp7]);
     latch595();
     tmp7++;
     if (tmp7>=4)
     {
      tmp7=0;
      tmp1 = sizeof(array4)/sizeof(array4[0]);
      tmp2 = array4[0];
      for (n=1;n<tmp1;n++)
      {
       array4[n-1] = array4[n];
      }
      array4[tmp1-1] = tmp2;
     }
    }

Now i need to figure out how to synchronize the timing for the values and the cathode elements for a smoother display.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top