16x8 LED Matrix using MAX7219 (cascading problem)

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
Stalkermd5
Posts: 6
Joined: 03-03-2012, 16:50

16x8 LED Matrix using MAX7219 (cascading problem)

Post by Stalkermd5 »

Pozdravljam,

radim Led Matrix 16x8 sa MAX7219. Moram obezbjediti smicanje znakova, a poruku ću dobijati preko UART-a.
Koristim PIC 16F628A. Uspio sam skrolovati poruku na jednom LED Matrixu, međutim, ne mogu na drugom. MAXX-ove sam povezao kaskadno (DOUT prvog na DIN drugog, LOAD zajednički, CLK zajednički).
Problem nastaje pri skrolovanju teksta na drugom displeju. Smicanje se vrši sdesna na lijevo.

Evo i kod:

Code: Select all

// Software SPI configuration
sbit  SoftSpi_SDI at RB3_bit;
sbit SoftSpi_SDO at RB4_bit;
sbit SoftSpi_CLK at RB5_bit;



sbit SoftSpi_SDI_Direction at TRISB3_bit;
sbit SoftSpi_SDO_Direction at TRISB4_bit;
sbit SoftSpi_CLK_Direction at TRISB5_bit;

// max7219 LOAD/CS(-) pin configuration
sbit Chip_Select at RB0_bit;
sbit Chip_Select_Direction at TRISB0_bit;

const unsigned short CharData[][8] ={
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001010, 0b00001010, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010},
{0b00000111, 0b00001100, 0b00010100, 0b00001100, 0b00000110, 0b00000101, 0b00000110, 0b00011100},
{0b00011001, 0b00011010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001011, 0b00010011},
{0b00000110, 0b00001010, 0b00010010, 0b00010100, 0b00001001, 0b00010110, 0b00010110, 0b00001001},
{0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000100, 0b00000010},
{0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000100, 0b00001000},
{0b00010101, 0b00001110, 0b00011111, 0b00001110, 0b00010101, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000100},
{0b00000001, 0b00000010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010011, 0b00010001, 0b00010101, 0b00010001, 0b00011001, 0b00001110},
{0b00000100, 0b00001100, 0b00010100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00011111},
{0b00001110, 0b00010001, 0b00000001, 0b00001110, 0b00000001, 0b00000001, 0b00010001, 0b00001110},
{0b00010000, 0b00010000, 0b00010100, 0b00010100, 0b00011111, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00000001, 0b00000001, 0b00000001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011111, 0b00000001, 0b00000001, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00001110, 0b00010001, 0b00010001, 0b00001111, 0b00000001, 0b00000001, 0b00000001, 0b00000001},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00001000},
{0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00000100, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00011110, 0b00000000, 0b00011110, 0b00000000, 0b00000000},
{0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001110, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00010001, 0b00010001, 0b00011110},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001000, 0b00000111},
{0b00011100, 0b00010010, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010010, 0b00011100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010000, 0b00010000, 0b00010111, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00010100, 0b00001000},
{0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00010001, 0b00011011, 0b00011111, 0b00010101, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00010001, 0b00011001, 0b00011001, 0b00010101, 0b00010101, 0b00010011, 0b00010011, 0b00010001},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010011, 0b00001111},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00001110, 0b00010001, 0b00010000, 0b00001000, 0b00000110, 0b00000001, 0b00010001, 0b00001110},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00001010},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00001010, 0b00010001, 0b00010001},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00010000, 0b00011111},
{0b00001110, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001110},
{0b00010000, 0b00001000, 0b00001000, 0b00000100, 0b00000100, 0b00000010, 0b00000010, 0b00000001},
{0b00001110, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001110},
{0b00000100, 0b00001010, 0b00010001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111},
{0b00001000, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00010010, 0b00001111},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00011100},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00010000, 0b00010000, 0b00001110},
{0b00000000, 0b00000001, 0b00000001, 0b00000001, 0b00000111, 0b00001001, 0b00001001, 0b00000111},
{0b00000000, 0b00000000, 0b00000000, 0b00011100, 0b00010010, 0b00011110, 0b00010000, 0b00001110},
{0b00000000, 0b00000011, 0b00000100, 0b00000100, 0b00000110, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00001110, 0b00001010, 0b00001010, 0b00001110, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000100, 0b00000000, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00000010, 0b00000000, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010100, 0b00011000, 0b00011000, 0b00010100, 0b00010000},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010101, 0b00010001, 0b00010001, 0b00010001},
{0b00000000, 0b00000000, 0b00000000, 0b00010100, 0b00011010, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00011100, 0b00010010, 0b00010010, 0b00011100, 0b00010000, 0b00010000, 0b00010000},
{0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00001110, 0b00000010, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00001100, 0b00001000, 0b00001000, 0b00001000},
{0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00011110},
{0b00000000, 0b00010000, 0b00010000, 0b00011100, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010010, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00001010},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001},
{0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00000000, 0b00000000, 0b00000000, 0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111},
{0b00000010, 0b00000100, 0b00000100, 0b00000100, 0b00001000, 0b00000100, 0b00000100, 0b00000010},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00001000, 0b00000100, 0b00000100, 0b00000100, 0b00000010, 0b00000100, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00011110, 0b00010100, 0b00000000, 0b00000000}
};
// max7219 configuration
void max7219_init1()
{
trisa=0;
 Chip_Select = 0;       // SELECT MAX
 Soft_SPI_Write(0x09);      //  Disable BCD mode for digit decoding
 Soft_SPI_Write(0x00);
 Chip_Select = 1;       // DESELECT MAX

 Chip_Select = 0;
Soft_SPI_Write(0x0A);     //  Max segment luminosity intensity
 Soft_SPI_Write(0x0F);
 Chip_Select = 1;

 Chip_Select = 0;
 Soft_SPI_Write(0x0B);
 Soft_SPI_Write(0x07);      // Display refresh
 Chip_Select = 1;
 Chip_Select = 0;
 Soft_SPI_Write(0x0C);
 Soft_SPI_Write(0x01);      // Turn on the display
 Chip_Select = 1;

 Chip_Select = 0;
 Soft_SPI_Write(0x00);
 Soft_SPI_Write(0xFF);      // No test
 Chip_Select = 1;
}

void max7219_init2() {
  Chip_Select = 0;       // SELECT MAX
  Soft_SPI_Write(0x09);      // BCD mode for digit decoding
  Soft_SPI_Write(0xFF);      // using Code-B
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);
  Chip_Select= 1;       // DESELECT MAX

  Chip_Select= 0;       // SELECT MAX
  Soft_SPI_Write(0x0A);
  Soft_SPI_Write(0x0F);      // Segment luminosity intensity
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);
  Chip_Select1 = 1;       // DESELECT MAX

  Chip_Select1 = 0;       // SELECT MAX
 Soft_SPI_Write(0x0B);
  Soft_SPI_Write(0x07);      // Display refresh
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);
  Chip_Select = 1;       // DESELECT MAX

  Chip_Select= 0;       // SELECT MAX
  Soft_SPI_Write(0x0C);
  Soft_SPI_Write(0x01);      // Turn on the display
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);
  Chip_Select = 1;       // DESELECT MAX

  Chip_Select1 = 0;       // SELECT MAX
  Soft_SPI_Write(0x00);
  Soft_SPI_Write(0xFF);      // No test
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);
  Chip_Select1 = 1;
  
  }
//Send data function
void Write_Byte(unsigned short myRow, unsigned short myValue)
{
 Chip_Select = 0;       // select max7219.
 Soft_SPI_Write(myRow);  // send myRow value to max7219 (digit place).
 Soft_SPI_Write(myValue);

 Chip_Select = 1;       // deselect max7219.
 }
 
 void Write_Byte1(unsigned short myRow, unsigned short myValue)
{
 Chip_Select = 0;
      // select ma7219.
 Soft_SPI_Write(myRow); 
 Soft_SPI_Write(myValue);
  Soft_SPI_Write(0x00);    // Bypass the 1st Chip
  Soft_SPI_Write(0x00);

 Chip_Select = 1;    
 }

//Clear matrix function
void Clear_Matrix(void)
{
 unsigned short x;

 for(x=1;x<9;x++)
 {
  Write_Byte(x,0x00);
  }
}


unsigned int DisplayBuffer[]={0,0,0,0,0,0,0,0};
unsigned int DisplayBuffer1[]={0,0,0,0,0,0,0,0};
unsigned int speed=10;
short i, l, k, ShiftAmount, scroll, temp,temp1, shift_step=1, StringLength;
char message[]="MIPS LED MATRIX 2014" ;
char index,index1;
void main() 
{

   Chip_Select_Direction = 0;
   Soft_SPI_init();
 max7219_init1();
 max7219_init2();
 Clear_Matrix();
 StringLength = strlen(message) ;



while(1)
 {
 for (k=0; k<StringLength; k++)
 {
  for (scroll=0; scroll<(8/shift_step); scroll++)
   {
         for (ShiftAmount=0; ShiftAmount<8; ShiftAmount++)
         {
          index = message[k];
          index1=message[k-1];
          temp =CharData[index-32][ShiftAmount];
          temp1 =CharData[index-32][ShiftAmount];
          
          DisplayBuffer[ShiftAmount] = (DisplayBuffer[ShiftAmount] << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
          DisplayBuffer1[ShiftAmount] = (DisplayBuffer1[ShiftAmount] << shift_step)| (temp1 >> ((8-shift_step)-scroll*shift_step));
         }


        for(l=0; l<5;l++)
        {
                 for (i=0; i<8; i++)
                 {
                     Write_Byte(i+1,DisplayBuffer[i]);  //Scrolling k character on firt LED Matrix
                     if(k>0)
                     Write_Byte1(i+1,DisplayBuffer1[i]);Scrolling k-1 character on second LED Matrix

                 }
        }


   }
   }

 }

}
Post Reply