1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Seven Segment Display Scrolling

Discussion in 'Microcontrollers' started by sonar_abhi, Jul 25, 2017.

  1. sonar_abhi

    sonar_abhi New Member

    Joined:
    Mar 15, 2016
    Messages:
    24
    Likes:
    0
    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

    Code (text):

    #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 (text):

    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?
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,148
    Likes:
    907
    Location:
    Rochdale UK
    If your original code displays 1234... Then all seems to be working.. So!!

    You need data for all the numbers then an array to hold the data before running it to the SSD..

    That second piece of code doesn't add up? where does n and j come in to it..

    Code (c):

    temp = array4[0];
    for (n=1; n<8; n++)
    {
     array4[j-1] = array[j];
    }
    array[9] = temp;
     
    That should read like this...
    Code (c):

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

Share This Page