Need some help with a program for a LED matrix.

This is a discussion on Need some help with a program for a LED matrix. within the C Programming forums, part of the General Programming Boards category; Hey. I've recently received a 32x16 LED matrix board from Sure Electronics along with a driver card with a e ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8

    Need some help with a program for a LED matrix.

    Hey.

    I've recently received a 32x16 LED matrix board from Sure Electronics along with a driver card with a e PIC16F723 on it.
    I thought at the time of purchase, that the software they had, would be compatible with the board, but it wasn't. This forced me to get into C-coding.

    I'm sorta getting a hand of it by writing the sample program they provided with the baord, and reading up on things to understand the program.
    However, I'm sorta stuck at the moment.

    The board uses 4 HT1632C chips to control the LED displays. They each control a 16x8 part of the board. The board has both red and green LEDs in each pixel.
    The way the chips operate, is that they have divided their 16x8 area into 32 8-bit areas. 16 for green and 16 for red.

    Now, here comes the part where I'm stuck.
    In this piece of code:
    Code:
    void main()
    {
        unsigned char i,j;
        SystemInit();                //System Initialization
        SetHT1632C_As3208();        //Set all HT1632s to work in 32*8 master mode
        for(i=1; i<=CHIP_MAX; i++)
        {
            ChipSelect(i);            //Chip select the corresponding HT1632C
            AddressWriteHT1632C(0x00);    //Get the selected start address of the chip
            SPI_ModelConfigure();    //Open SPI mode, continuously send data to HT1632C    
            for(j=0; j<16; j++)        //Take "0x00" as the start address, continuously write data
            {
                SPI_DataSend(0x55);    //Write data as 2-digit hex number. The corresponding LEDs will light in binary code.
            }
            for(j=16; j<32; j++)
            {
                SPI_DataSend(0xaa);
            }
            SSPCON = 0x11;            //Clode SPI mode
        }
        while(1);
    }
    "j" is the definition of a column of LEDs, while SPI_DataSend() defines the pattern the LEDs light up in that column.

    Now, what I want to do, is to i.e. only light up the LEDs in column 5 in a "aaHex" pattern.
    The problem is that no matter what i try to put in the first part of the for-loop (j=0 or j=16 etc.) it always assumes that the number i entered is the first column.
    Thus, I can only light up the first column and out. I can't get it to light up only a column in the middle of the board.

    Can anyone see what I'm doing wrong here, or how i can possibly solve this?

    Thanks for any help

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    52
    My first thought is I don't think its actually receiving the value of 'j'. I think its only writing at this address 'AddressWriteHT1632C(0x00);' have you tried changing it and see what happens?

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    j is not being passed into any of the SPI functions. So if there isn't another function to set the column, then perhaps you would do this:
    Code:
    for(j=0; j<4; j++)
        SPI_DataSend(0x00);
    SPI_DataSend(0xAA);   /* column 5 */
    for(j=5; j<32; j++)
        SPI_DataSend(0x00);

  4. #4
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    Quote Originally Posted by mnd22 View Post
    My first thought is I don't think its actually receiving the value of 'j'. I think its only writing at this address 'AddressWriteHT1632C(0x00);' have you tried changing it and see what happens?
    I have tried this before. It didn't produce any results. However, now that I have 2 colors on the display going every second line, I see that changing it to "0xaa" gives me a start of 5 red ones then the rest of the line in green.
    Then the next line is opposite, and so on.

    Quote Originally Posted by oogabooga View Post
    j is not being passed into any of the SPI functions. So if there isn't another function to set the column, then perhaps you would do this:
    Code:
    for(j=0; j<4; j++)
        SPI_DataSend(0x00);
    SPI_DataSend(0xAA);   /* column 5 */
    for(j=5; j<32; j++)
        SPI_DataSend(0x00);
    Yes, this will light the fifth column, but I was sort of hoping there was an easier way than having to make a for-loop for each line I wanted to light up differently :P
    Last edited by Kakefarmer; 01-09-2012 at 06:02 PM.

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Try this. It's just a guess. What does it do?
    Code:
    int main()
    {
        SystemInit();                //System Initialization
        SetHT1632C_As3208();        //Set all HT1632s to work in 32*8 master mode
        ChipSelect(1);            //Chip select the corresponding HT1632C
        //AddressWriteHT1632C(0x00);    //Get the selected start address of the chip
        SPI_ModelConfigure();    //Open SPI mode, continuously send data to HT1632C    
    
        /* Light 5th column all green. */
        AddressWriteHT1632C(0x08);
        SPI_DataSend(0xFF);
    
        /* Light 5th column all red. */
        //AddressWriteHT1632C(0x28);
        //SPI_DataSend(0xFF);
    
        SSPCON = 0x11;            //Clode SPI mode
    
        while(1);
    }

  6. #6
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    Tried the code. It didn't really produce anything. The screen was left blank.

  7. #7
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    The only other variation I can think of (with the given info) is this.
    Code:
    int main()
    {
        SystemInit();               //System Initialization
        SetHT1632C_As3208();        //Set all HT1632s to work in 32*8 master mode
        ChipSelect(1);              //Chip select the corresponding HT1632C
    
        AddressWriteHT1632C(0x08);  //Get the selected start address of the chip
    
        SPI_ModelConfigure();       //Open SPI mode, continuously send data to HT1632C    
        SPI_DataSend(0xFF);
        SSPCON = 0x11;              //Clode SPI mode
    
        while(1);
    }

  8. #8
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    This one actually works. Also, I can add a new SPI_DataSend under it and it appears on the next line.
    Now I'm one step further down my line :P
    However, if I wish to skip some lines, I have to repeat the Addresswrite... or send 0x00 several times :P
    Thanks man

    Is it possible to write functions for patterns such as characters and call them from a library file?

  9. #9
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    How about something like this. If it works, could you post a picture?
    Code:
    #include <assert.h>
    
    typedef unsigned char byte_t;
    
    byte_t alpha[][8] = {
        /* A */ { 0 },
        /* B */ { 0 },
        /* C */ { 0 },
        /* D */ { 0 },
        /* E */ { 0 },
        /* F */ { 0 },
        /* G */ { 0 },
        /* H */ { 0x00, 0xFF, 0x08, 0x08, 0x08, 0x08, 0xFF, 0x00 },
        /* I */ { 0x00, 0x81, 0x81, 0xFF, 0x81, 0x81, 0x00, 0x00 }
        /* etc */
    };
    
    void sendLetter(char letter) {
        int i;
        assert(letter >= 'A' && letter <= 'Z');
        letter -= 'A';
        for (i = 0; i < 8; i++) {
            SPI_DataSend(alpha[letter][i]);
            // SPI_DataSend(alpha[letter][i]); // this may need to be done twice
        }
    }
    
    int main() {
        SystemInit();               //System Initialization
        SetHT1632C_As3208();        //Set all HT1632s to work in 32*8 master mode
        ChipSelect(1);              //Chip select the corresponding HT1632C
    
        // green H
        AddressWriteHT1632C(0x00);  //Get the selected start address of the chip
        SPI_ModelConfigure();       //Open SPI mode, continuously send data to HT1632C
        sendLetter('H');
        SSPCON = 0x11;              //Close SPI mode
    
        // red I
        AddressWriteHT1632C(0x30);  //Get the selected start address of the chip
        SPI_ModelConfigure();       //Open SPI mode, continuously send data to HT1632C
        sendLetter('I');
        SSPCON = 0x11;              //Close SPI mode
    
        while(1);
    }
    Last edited by oogabooga; 01-11-2012 at 07:04 PM.

  10. #10
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    The compiler (HI TECH) gives me an error telling me that assert is undefined.
    Guessing that perhaps assert.h isn't included with HI TECH?

  11. #11
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Just get rid of the asserts then. However, the code I wrote made what I now believe is an incorrect assumption, that the memory map had one bit per led. But I now believe there are 2 bits per led (for 4 intensity levels, including off), which is a little more complicated. Still, it's a start!

  12. #12
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    I've read quite a bit on the board.
    And as i get it, the board has 4 HT1632C chips that each control a 16x8 matrix with 2 different colors.
    To get it to stay off, the corresponding address needs a binary low.
    To get a green light, it needs a binary high on ports 0-15.
    to get a red light, it needs a binary high on ports 16-31.
    And to get a "yellow" or red+green light it needs a high on both corresponding addresses at both 0-15 and 16-31.

    This page has some info:
    Controlling the Sure Electronics 3216 LED matrix with an Arduino UNO | arduino education
    It however says that they are divided into 64 addresses. It might be possible to use it that way, but since we can control a complete row using 8 bits (2 hex) I think it works better that way :P

  13. #13
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    Here's a picture of the board with your code without asserts.
    http://i43.tinypic.com/dlsvwx.jpg

  14. #14
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Interesting, but also confusing. It says there are 16 levels, which implies 4 bits per led. But the memory map seems to map one address to 4 leds. I suppose the memory could have 16 bits per address.... Have you tried the Plot function they give there? They also mention that someone has already created the kind of library you mentioned.

    EDIT: The H looks good in the pic, but the I is totally out to lunch. Did you have to uncomment the second SPI_DataSend?

  15. #15
    Registered User
    Join Date
    Jan 2012
    Location
    Bardufoss, Norway
    Posts
    8
    The picture is without uncommenting the SPI_DataSend.
    Here it is uncommented:
    http://i41.tinypic.com/o5821h.jpg

    I've seen the library. That page has a link to it. However, the values are transmitted in pure binary.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem - Matrix Program
    By stdq in forum C Programming
    Replies: 4
    Last Post: 05-14-2011, 12:02 AM
  2. Matrix c program help!!!
    By kclew in forum C Programming
    Replies: 21
    Last Post: 02-25-2009, 04:46 AM
  3. Help! matrix program
    By jadman in forum C Programming
    Replies: 3
    Last Post: 06-21-2005, 12:20 PM
  4. 2x2 matrix program
    By screamer903 in forum C Programming
    Replies: 2
    Last Post: 03-23-2005, 08:02 AM
  5. matrix program
    By J in forum C Programming
    Replies: 4
    Last Post: 04-21-2002, 09:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21