10 x 5 led matrix using pic18f2550

Discussion in 'Embedded Systems and Microcontrollers' started by anoopmb25, Jan 15, 2011.

  1. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    i made a 10 x 5 led matrix display using pic18f2550 and 10 bc548 transistor for 10 columns (negative supply) and 5 bc548 and 5 bc557 coupling for 5 rows(positive supply). positive supply is from a lm317 ic its the basic hardware

    pic is configured as 8 bit internal oscillator without prescaler for better row scanning

    i made into each led is x y addressable and working fine i can liight any led using x and y positions of the matrix

    i can show characters or any thing but the problem with is with scrolling messages


    am using mplapbs c18 compiler so please give me the correct code using x and y positions from left to right and right to left
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    How many characters can you display at once?


    Scrolling is fairly simple. You need a string of characters, a start index and an end index. The start index is initialized at zero and the end index is initialized to your total number of characters you can display.


    Display the characters from the start index to the end index then increment both by the number of characters you can display. If the end index exceeds the total number of characters in the string then reset things back to start. Delay a bit, then start the loop all over again.
     
  3. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    i am just trying to scroll the word "STOP" from left to right
    each character taking 3 columns and a space at right so total 4 columns for each caracter
     
  4. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    0 1 2 3 4 5 6 7 8 9
    1
    2
    3
    4

    thats the led arrangement


    currently letter S is displayed using columns 0 to 3 including one space (0x17,0x15,0x1d,0x00)
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Well if you can display an S then you should be able to display an ST. Start there then think about the algorithm I posted.
     
  6. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    i had the function "display( x , y)" and "x" represent each column(0 to 9) and "y" represents each row(0 to 4)

    for displaying characters am using the below function

    Code ( (Unknown Language)):
    1. void showtext(void )
    2. {
    3. // i want to show the word "STOP" only so no input for function
    4.  
    5.    
    6.     unsigned char x = 0;
    7.     unsigned char y = 0;    
    8.     unsigned char currentCol;
    9.        int tmpCol = 0;
    10.     int tmpRow = 0;
    11.  
    12. Clear();        // a function which putting all leds off
    13.  
    14.  
    15.    
    16.     for (currentCol = 0; currentCol< 10; currentCol++)
    17.     {
    18.         if (tmpCol < 4)
    19.            
    20. {
    21.                 // Display a single column
    22.  
    23.  if ((MyFontLib[tmpCol][tmpRow] & 0b00000001) != 0) display(x, y);
    24.  
    25.  y++;
    26.  
    27.  if ((MyFontLib[tmpCol][tmpRow] & 0b00000010) != 0) display(x, y);
    28.  
    29.  y++;
    30.  
    31.  if ((MyFontLib[tmpCol][tmpRow] & 0b00000100) != 0) display(x, y);
    32.  
    33.  y++;
    34.  
    35.  if ((MyFontLib[tmpCol][tmpRow] & 0b00001000) != 0) display(x, y);
    36.  
    37.  y++;
    38.  
    39.  if ((MyFontLib[tmpCol][tmpRow] & 0b00010000) != 0) display(x, y);
    40.  
    41.     y =y- 4;
    42.     x++;
    43. }
    44.        
    45.         tmpRow++;
    46.  
    47.         if (tmpRow == 4)
    48.         {
    49.             tmpRow = 0;
    50.             tmpCol++;
    51.         }
    52.    }
    53. }
    my font lib is here

    Code ( (Unknown Language)):
    1.  
    2. // total 4 columns for each character
    3. //character taking first 3 columns and one column blank to create space between characters
    4.  
    5. const unsigned char MyFontLib[][4] = {
    6. 0x17,0x15,0x1d,0x00,   //s
    7. 0x01,0x1f,0x01,0x00,   //t
    8. 0x1f,0x11,0x1f,0x00,   //o
    9. 0x1f,0x05,0x07,0x00,  //p
    10.  
    11. };
    please help me to update this code

    i just want to scroll the characters from left to right and from right to left
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    You are going to need to do some work on your own.

    Get the following string to display.

    char c[] = "ST";

    Sorry but I do not have access to your hardware so if I wrote something, it would just be a guess.

    When you get to displaying the string, post back and I will help you with scrolling.

    Here is some pseudo code to get you started

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4. void DisplayChar(char c, pos unsigned char)
    5. {
    6.     // Display c at position c
    7.  
    8.  
    9. }
    10.  
    11. void DisplayString(char *str)
    12. {
    13.     for (i=0; i<2; i++)
    14.         DisplayChar(str[i],i);
    15.  
    16.  
    17.  
    18.  
    19. }
    20.  
    21. [/i]


    You are going to have to work out displaying a character at a given position.


    Your display would be divided into two character blocks or regions.
    The code will scroll one character block at a time. If you want nice smooth scrolling that can be done too but will be more complicated. Do the one character block and we can move on from there.
     
  8. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    how can i assign position for each character using x and y please help me

    when i am using above code (my code) i get display of letter "S" (4 column) "T" (4 column) half of letter "O" (2 column) so total 10 column how can i shift it to left or right one column

    all over am a hobbyist studying pharmacy interested in pic ics having moderate knowledge in electronics and c laungage
     
    Last edited: Jan 17, 2011
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    If you have ST and part of O being displayed then that is good (depending on how you did it).

    Here is how I would do it:

    I would have my font array so that each byte in the array represents a column. One byte can actually represent two columns but no need to get complicated.


    So an S would be


    0b11101,0b10101,0b10101,0b10111,0b00000

    The first byte is the first column of the S starting from top to bottom (one bit for every row) , the second byte the second column of the S and so on


    Then I would convert my string of characters into an array

    So if you just want to display an S then the array would be simply

    0b11101,0b10101,0b10101,0b10111,0b00000

    T might be (it might look a little strange because of the even number of rows)

    0b10000,0b11111,0b11111,0b1000,0b00000


    O would be

    0b11111,0b10001,0b10001,0b11111,0b00000

    For STOP your array would be 20 bytes long.

    Since all you want to do is display STOP, no conversion is really needed, you could simply string all of your font bytes into one big string.


    So STO would look like


    Code ( (Unknown Language)):
    1.  
    2. unsigned  char array[] = {0b11101,0b10101,0b10101,0b10111,0b00000,
    3.                                    0b10000,0b11111,0b11111,0b1000,0b00000,
    4.                                    0b11111,0b10001,0b10001,0b11111,0b00000};
    5.  
    6. // then a simple for loop to set the columns
    7.  
    8.  
    9. for (c=0; c<maxcolumns, c++)
    10. {
    11.     SetColumn(array(c);
    12.  
    13.  
    14. }
    15.  
    16.  
    This will give you the same results that you have but it will set you up for scrolling. Get ST and part of O working with the pseudo code above and post back and I will help with scrolling.
     
    Last edited: Jan 17, 2011
    anoopmb25 likes this.
  10. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Ideas on scrolling can also be found in "Propeller"/persistence of vision displays, which use a single column of LEDs (1 per row) and use the movement to create the message/time/etc.
     
  11. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    wat about rows?
     
  12. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    What do you mean "wat about rows"? Please provide a complete questions or this will take foreaver to get anywhere.

    A byte represents a colomn. Each bit of each byte represents a row. The LSB is the top row and the MSB is the bottom row of the given column.
     
    Last edited: Jan 18, 2011
  13. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    sorry sir in your pseudo code only setcolumn that means my x cordinate how shall i st y cordinate

    i tried and got a code sniplet from net that scroll the whole word STOP
    but the problem is the letter S start from column zero not from column 9

    means

    first up all when the circuit is connected it shows

    letter S take columns 0 to 3 (3 column +1 blank column)

    letter T take columns 4 to 7 (3 column +1 blank column)

    letter O take columns 8 to 9 (2 column showing half of letter)

    then it scrolls to left according to delay
    how can i start the letter S from the column 0 and then each letter scrolls to left


    my new scroll code given below

    void ScrollText(void)
    {
    int temp;

    int row = 0;
    int col = 0;
    int currentCol;
    int tmpCol;
    int tmprow;
    unsigned char x = 0;
    unsigned char y = 0;

    do
    {
    // Store the temp variables
    tmpCol = col;
    tmprow = row;


    x = 0;
    y = 0;

    displayClear();


    for (currentCol = 0; currentCol < 10; currentCo++)
    {

    if (tmpcol < 4)
    {


    if ((MyFontLib[tmpCol][tmpRow] & 0b00000001) != 0) display(x, y);

    y++;

    if ((MyFontLib[tmpCol][tmpRow] & 0b00000010) != 0) display(x, y);

    y++;

    if ((MyFontLib[tmpCol][tmpRow] & 0b00000100) != 0) display(x, y);

    y++;

    if ((MyFontLib[tmpCol][tmpRow] & 0b00001000) != 0) display(x, y);

    y++;

    if ((MyFontLib[tmpCol][tmpRow] & 0b00010000) != 0) display(x, y);

    y =y- 4;
    x++;
    }

    tmprow++;


    if (tmprow == 4)
    {
    // Next character
    tmprow = 0;
    tmpcol++;
    }
    }


    col++;

    if (col == 4)
    {
    col = 0;
    row++;

    }

    for (temp = 0; temp < 50; temp++) delay_ms(1);
    } while(row < 4);
    }
     
  14. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Your code is far more complicated then it has to be.


    Try this function for setting your leds

    Code ( (Unknown Language)):
    1.  
    2. void SetColumnLEDs( unsigned char column, unsigned char rowbyte)
    3. {
    4.     unsigned char row;
    5.     unsigned char rowbit;
    6.     unsigned char bit = 1;
    7.  
    8.    
    9.     for (row=0; row<MAXROWS; row++)
    10.     {        
    11.         rowbit = rowbyte & 0x01;
    12.         if (rowbit) Display(column,row);
    13.  
    14.         rowbyte = rowbyte >> 1;
    15.     }
    16.    
    17.  
    18. }
    19.  

    You call the function above with the column and a byte which represents a column of LEDs.

    Be warned that this may not work with your current Display(x.y) function. It is just to give you an idea.


    I would improve Display by adding an isOn parameter. Use this to decide if LED is on or off. You will need this for scrolling anyway.


    So then in function above you would just call

    Display(column,row,rowbit);

    instead of

    if (rowbit) Display(column,row);


    There is really no need to store your fonts in separate arrays.

    If you put all of your bytes into a single dimension array I can show you how to easily scroll it.

    As I said the first byte would be the first column of the first character, the second byte the second column of the first character and so on.


    It is very late here and I should have been to sleep about 30 minutes ago. I will help more tomorrow. See if that function helps you.
     
    anoopmb25 likes this.
  15. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    the setcolumnleds function working thanx very much pls give me next instructions for scrolling

    i also updated my display function to display(x,y,state)
    state = on or off
    till now i have no use for the state input is it useful in scrolling? thanx again
     
  16. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    I am trying to give you the best way to do scrolling. If you want to follow my advice then I am happy to help you. If you want to do it your way then I am not going to spend my time trying to make your code to work. You can do that on your own or get someone else to help.

    If you still want my help and are willing to follow my advice then post your schematic. Even better draw it using Protus Isis Lite. It is free.

    I will then be able to simulate your circuit. You should know I have have not used this software much so I am not positive if this will work but it should. It will give me a good chance to learn the software.

    Regardless of what you decide, I might draw something up close to what you have, just to learn Isis.
     
  17. anoopmb25

    Thread Starter New Member

    Jan 15, 2011
    17
    0
    i posted the schematic do you want my source code?

    schematic is ugly sorry for that i have no idea on how to draw beautifully

    please help me i really want your help

    in my PC on stimulation Proteus give message that high CPU load simulation not running on real time
     
  18. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    I cannot make any promises but I will try to help. It might take a few days. Yes please post your code. I would like to see how you turn on individual LEDs.
     
  19. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
  20. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Tried my best to follow your schematic. Sorry but it is very hard to read and I am not exactly sure what you are doing there. Sorry but I think you are on your own.

    Plus it looks like you dis it is Protus 7.0? You cannot save in the demo version. :(.

    My best advice:

    Take a look at the link I posted for ideas.

    Instead of using all of those multi-dimension arrays, use one big single dimension array. You can have an index for the start of your bytes to display and one for the end. To scroll, you just increment the index in your array.

    This is an interesting project. I might give it a try myself. If I come up with something good, I will post it here.
     
Loading...