Continue to Site

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.

  • 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.

SEARCH feature is gone? Scrolling on an 8 x 8 matrix

Status
Not open for further replies.

MrDEB

Well-Known Member
Been programming an 18F2420 that will be used on an 18F23K20 in the final project. Been coding a bunch of letters but would look better if they were scrolling across the 8 x 8 Led Matrix. Have seen where the CONST arrays have 64 bytes for scrolling across but is there a better method of manipulating bits to do the scrolling. Looked at shift left etc but ??
For example lets say the CONST ARRAY, using SF, is %00001001. Have the code move the bits one position to the left so after 5 cycles in a loop the output would be %10010000
 
I did it on 4 8x8's in line on a smaller pic16f877a... I still have all the code.... You would need to get it into swordfish as I code in C mainly!!! I can get it into Oshonsoft if you want... Then you should be able to convert it quite easy..
 
I looked at Nigels tutorial and now to decipher. He is using Winpicpro and I guess CONST arrays are not used.
Need more research but will clean up what I have and maybe see if I am even doing this right.
 
I see Ian Rogers has revised the tutorials into C but how to open the unziped files? Thinking mplab??
 
I used mplab and the code looks very similar to what Grahan used on his Tetric on a Pic. Now to decipher what is going on and maybe get something working.
THANKS for the direction
 
I can't help it but I've showed you code in swordfish that can do what you want. And the programmer used doesn't matter you can read a .c file with any text editor word pad note pad even swordfish and mplab.
And the best way to do this for me is to open it in swordfish so I can just open the tab read some of the code and then switch to the tab I'm writing the swordfish code. Don't need two ide's open that way.
 
I got the files opened up and taking a close look at the similarities between SF and C.
Been trying different tings such as
"PORTC= Rows(x)"
rearchering what "pobject(2).Bits(3)" is. The p is pass if I am correct in understanding it.
In the C program it uses "Char" . need to find out more.
 
What I am trying to achieve is to have the letter data in a CONST array then display the data to scroll across the matrix. If I am correct in thinking, a CONST array can't be changed so how to extract the CONST array and display it one column (right to left) as the C code that Ian linked to. Been trying out different things such as "PORTC.BITS(x) .
In the code I posted I get the entire matrix lit up and it blanks one column at a time from right to left but how to integrate the CONST data
Looking over several pieces of code I keep seeing pobject used?? I probally should just resort to using larger CONST arrays with each letter advancing across.
Code:
{
*****************************************************************************
*  Name    : testing routine.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/4/2014                                                       *
*  Version : 1.0                                                            *
*  Notes   : letter testing routine                                                               *
*          :                                                                *
*****************************************************************************
}
Device = 18F2420

Clock = 8
   

// import LCD library...

Include "convert.bas"
Include "InternalOscillator.bas"
Include "Utils.bas"       // Include this file when we compile so that we can use keywords like 'setalldigital'
Include "shift.bas"

// Arrays                                                                                  
Const R_L_Data(8) As Byte =   (%00000000,   'anodes right to left       
                               %00000000,              
                               %00000001,           
                               %00000001,           
                               %00000001,          
                               %00000001,          
                               %00000001,          
                               %00000001)                    
                                     
                          
Const T_B_Data(8) As Byte =(%11111110,       'top
                           %11111101,
                           %11111011,
                           %11110111,      ' cathodes colums
                           %11101111,       ' top to bottom
                           %11011111,
                           %10111111,
                           %01111111)        'bottom
                             
// variable declaration                              
Dim x As Byte
Dim y As Byte
Dim index As Byte                             
// Sub Routines

              

// Start Of Program
y = 0
SetAllDigital                       // Make all Pins digital I/O's
TRISC = %00000000                   // Make PORTD all outputs
TRISB = %00000000                   // Make PORTB all outputs
index = 0
// Main Loop
While True()                        // This creates an infinite loop
  
   
        for x = 0 to 7

        ' x = 0
         'y = 0
      
       ' PORTC = Y_Data(x) >>8
        'PORTB = X_data(x)
       ' DelayMS(10)
       
        PORTC =T_B_Data(x)   ' anodes
        PORTB = 0            'cathodes
        delayms(1000)
        PORTB = 1
      
       ' delayms(500)
    Next
Wend                  // Loop back to the while loop as long as we havent finished.
 
NOT HAPPY with code but been frying my brain trying to conjure up a better method to access the CONST arrays or ?
Tried C_data(x).bits(x) which kinda worked but couldn't access the CONST array as needed.
This posted code is what I was hoping to avoid. Trying to configure a way to put the K0 to K7 CONST arrays into a for next loop
K(0), K(1) etc
Then my graphic is upside down so thinking instead of FOR X = 0 to 7 go with FOR X = 7 to 0. tried but didn't seem to work right. going to work with it some more.
Any suggestions to improve the code. I was hoping to have two arrays of 64 bits each then access each led indivually but could't get that to work properly. If this code wasn't such a train wreck it might be easier to draw out each graphic?
Code:
{
*****************************************************************************
*  Name    : testing routine.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/4/2014                                                       *
*  Version : 1.0                                                            *
*  Notes   : letter testing routine                                                               *
*          :                                                                *
*****************************************************************************
}
DEVICE = 18F2420

CLOCK = 8
   

// import LCD library...

INCLUDE "convert.bas"
INCLUDE "InternalOscillator.bas"
INCLUDE "Utils.bas"       // Include this file when we compile so that we can use keywords like 'setalldigital'
INCLUDE "shift.bas"

// Arrays                                                                                  
// Arrays
CONST B_data(8)AS BYTE = (%11111110,        // K
                          %11111101,
                          %11111011,
                          %11110111,
                          %11101111,
                          %11011111,
                          %10111111,
                          %01111111)
                                                                                 
CONST K0(8)AS BYTE =     (%00000001,        // K
                          %00000001,
                          %00000001,
                          %00000001,
                          %00000001,
                          %00000001,
                          %00000001,
                          %00000001)
                         
CONST K1(8)AS BYTE =     (%00000010,        // K
                          %00000010,
                          %00000010,
                          %00000011,
                          %00000011,
                          %00000011,
                          %00000010,
                          %00000010)
                         
CONST K2(8)AS BYTE =     (%00000100,        // K
                          %00000100,
                          %00000101,
                          %00000110,
                          %00000110,
                          %00000101,
                          %00000100,
                          %00000100)
                         
CONST K3(8)AS BYTE =     (%00001000,        // K
                          %00001001,
                          %00001010,
                          %00001100,
                          %00001100,
                          %00001010,
                          %00001001,
                          %00001000)
                         
CONST K4(8)AS BYTE =     (%00010000,        // K
                          %00010010,
                          %00010100,
                          %00011000,
                          %00011000,
                          %00010100,
                          %00010010,
                          %00010001)
                         
CONST K5(8)AS BYTE =     (%00100000,        // K
                          %00100100,
                          %00101000,
                          %00110000,
                          %00110000,
                          %00101000,
                          %00100100,
                          %00100010)
                         
CONST K6(8)AS BYTE =     (%01000000,        // K
                          %01001000,
                          %01010000,
                          %01100000,
                          %01100000,
                          %01010000,
                          %01001000,
                          %01000100)
                                                 
                                                         
CONST K7(8)AS BYTE =     (%10001000,        // K
                          %10010000,
                          %10100000,
                          %11000000,
                          %11000000,
                          %10100000,
                          %10010000,
                          %10001000)

                     
 
                     
                     
                                               
                                      
                                                     
                             
// variable declaration                              
'DIM x AS BYTE
DIM x AS BYTE
'DIM indexc AS portc
'dim indexb as byte
'DIM bits AS BYTE
dim k(8) as byte
dim b(8) as byte
                 
// Sub Routines

              

// Start Of Program
'portc = 0
'portb = 1
SetAllDigital                       // Make all Pins digital I/O's
TRISC = %00000000                   // Make PORTD all outputs
TRISB = %00000000                   // Make PORTB all outputs
'index = 7
// Main Loop
WHILE True()
        for x = 0 to 7
            portc = k0(x)
            portb = B_data(x)
            delayms(1)
        next
        portc = %00000000
         delayms(50)
        for x = 0 to 7
            portc = k1(x)
            portb = B_data(x)
             delayms(1)
        next
        portc = %00000000 
         delayms(50)
          for x = 0 to 7
            portc = k2(x)
            portb = B_data(x)
            delayms(1)
        next
        portc = %00000000
         delayms(50)
        for x = 0 to 7
            portc = k3(x)
            portb = B_data(x)
             delayms(1)
        next
        portc = %00000000 
         delayms(50)
          for x = 0 to 7
            portc = k4(x)
            portb = B_data(x)
            delayms(1)
        next
        portc = %00000000
         delayms(50)
        for x = 0 to 7
            portc = k5(x)
            portb = B_data(x)
             delayms(1)
        next
        portc = %00000000 
         delayms(50)
          for x = 0 to 7
            portc = k6(x)
            portb = B_data(x)
            delayms(1)
        next
        portc = %00000000
         delayms(50)
        for x = 0 to 7
            portc = k7(x)
            portb = B_data(x)
             delayms(1)
        next
        portc = %00000000 
         delayms(50)
   
   
   
   
WEND                  // Loop back to the while loop as long as we havent finished.
 
Mrdeb think about this ok You can use a port like a array and set just a pin at a time but what you want is to do two arrays at a time swordfish doesn't do that.
 
I have been studying what Graham did in the Tetris by assigning each pin and X and Y coordinate but haven't found out how to and what why for the BYREF and Pobject(pass).
As far as two arrays, one array is loaded into PortC and second array is loaded into PortB.
I tried using Data(x).bits(x). This works ok but can't get the display to scroll.
Here is a C code that is supposed to do what I want but I tried using in SF the << and STEP command. Going to continue to work with it and lots of experimental code to see what each snippet does. Have yet to look at CHAR
Code:
#include <pic.h>                // pic specific identifiers
#define _XTAL_FREQ  20000000    // Xtal speed
__CONFIG(0x37F2);                // Config bits

#define ROW_PORT        PORTB            //
#define ROW_TRIS        TRISB
#define COL_PORT        PORTC            //
#define COL_TRIS        TRISC

extern const unsigned char fnt[];   // delclare as external (in another file)

    // Required prototypes
void DelayMs(int x), scroll(char dir), invert(void);
void clear(void), display(const char* str);

    // Variables
unsigned char pos;                // keep tabs on rows
unsigned char leds[8];            // led buffer
unsigned char leds2[8];            // 2nd led buffer
unsigned char pow[] = {1,2,4,8,16,32,64,128}; // power array

void main(void)                            // program entry
    {
    char x,y,z,t;
    ADCON1 = 0x6;
    ROW_TRIS = 0b00000000;                // row port as outputs
    COL_TRIS = 0b00000000;                // col port as outputs
    T2CON = 0x16;                        // setup timer 2
    ROW_PORT = 0;
    COL_PORT = 0xFF;                    // setup led array
    PR2 = 249;                            // timer preload value
    TMR2IE = 1;                            // enable timer 2 interrupt
    PEIE = 1;                            // enable peripheral interrupt
    GIE = 1;                            // enableglobal interrupt
    pos = 0;                            // start at beginning
    while(1)                            // endless Loop
        {
        display("Hello world!!");        // display a message
        clear();                        // start again
        DelayMs(1000);
        }
    }

void display(const char* str)
    {
    int addr;                            // large table (requires an int)
    int z;                                // looping variable
    while(*str!=0)
        {
        addr = ((int)*str++ - 0x20);    // locate character in table
        addr *= 8;                        // 8 bytes in each char
        for(z=0;z<8;z++)
            leds2[z] = fnt[addr+z];        // load em up!!
        for(z=0;z<8;z++)
            scroll(1);                    // scroll right.
        }
    }

void interrupt ISR()
    {
    if(TMR2IF)            // omly do if timeout occured
        {
        ROW_PORT = 0xff;
        COL_PORT = leds[pos];            // Retrive current array
        ROW_PORT -= pow[pos];            // Keep powers in table
        if(pos++ == 7) pos = 0;            // cycle through array buffer
        TMR2IF = 0;                        // clear interrupt
        }
    }

void clear()        // clear buffer
    {
    char x;
    for(x=0;x<8;x++)
        leds[x] = 0;

    }
void scroll(char dir)
    {
    char x;
    switch (dir)
        {
        case 0:                    // scroll left
            for(x=0;x<8;x++)
                {
                if(leds2[x] & 1)
                    leds[x]+=128;
                leds[x] >>= 1;
                leds2[x]>>= 1;
                }
            DelayMs(100);
            break;
        case 1:                    // scroll right
            for(x=0;x<8;x++)
                {
                if(leds2[x] & 128)
                    leds[x]+=1;
                leds[x] <<= 1;
                leds2[x] <<= 1;
                }
            DelayMs(100);
            break;
        case 2:                    // scroll up
            for(x=7;x>0;x--)
                leds[x] = leds[x-1];
            leds[0] = leds2[7];
            for(x=7;x>0;x--)
                leds2[x] = leds2[x-1];
            leds2[0] = 0;
            DelayMs(100);
            break;
        case 3:                     // scroll down
            for(x=0;x<8;x++)
                leds[x] = leds[x+1];
            leds2[7] = leds[0];
            for(x=0;x<8;x++)
                leds2[x] = leds2[x+1];
            leds2[7] = 0;
            DelayMs(100);
        }

    }

void DelayMs(int x)
    {    // wrapper function for larger delays.
    while(x--)
        __delay_ms(1);
    }
 
Char is a byte in swordfish int is a word if you look at swordfish help file you'd see that it's just types to hold data.
 
I have been insistently looking over the help files as well as the Swordfish reference and Swordfish bible. Comprehending but finding a solution has been a slow process. I realize that a CONST array can't be changed in the program so my attempt to change the order of the bits in the CONST arrays is futile
I am attempting to find a way to address each led individually so then we end up with 128 bits. Am wondering if this is why Graham used 16 bits in his Tetris code CONST arrays. This is what I am looking at trying. The first 8 bits for the Y location and the second 8 bits for the X location.??Just need method to decipher each byte
 
At some point, trying to adapt code you don't understand becomes pointless. It's necessary to start at the beginning to figure out how to accomplish what you're trying to do.

The way I would accomplish this is to set up an array to contain my message. It can be as big as needed to contain your entire message, even an entire sentence. You'll map the characters you want to display into this array.

To display the data on the 8x8 matrix, consider the matrix as a window scrolling across the data in the message array. It starts are the beginning and steps along the array to display the data. This works the same whether you have one display or several. The figure below shows the idea.

Now some details. The array doesn't need to be two dimensional - in fact, it may be easier to use a one-dimensional array. The arrangement on the array is shown in the lower picture. The array starts at the top, goes down the eight positions for the column and then on to the next column. The data to be displayed in mapped into the array starting at an 8 bit boundary. The M starts at 0, the E starts at 64 and so on. The characters must be mapped starting at the top of a column.

Now, to display the data. The first window starts at the first value of the array. Then the window is stepped one column over, so the 64 bits starting at position 8 are displayed. Always step be an increment of 8.

Note that this concept is based on binary data. One bit per location, either off or on.

Scrolling 8x8.jpg
 
The array for "MESSAGE" above would be

Code:
%11111111  %10000000  %01000000 %00100000 %01000000 %10000000 %11111111 %00000000
%11111111 %10001001 %10001001 %10000001 %00000000
%00100010 %01010001 %10001001 %10001010 %01000100 %00000000
%00100010 %01010001 %10001001 %10001010 %01000100 %00000000
%00011111 %00101000 %11001000 %01001000 %00101000 %00011111 %00000000
%00000000
%00111100 %01000010 %10000001 $10000101 %01000110 %00000000
%11111111 %10001001 %10001001 %10000001 %00000000
 
That is what I am trying to do. But would i not be a two dimensional arry? One for the Anodes and one for the cathodes. I realize it shouldn't really matter weather common anodes or common cathodes but I need to control both the anodes and cathodes. I Tried putting all the cathodes to low then cycl;e through the data but turning one one anode I get an entire row on. I am going to start over mapping the matrix again. At present the portC are the anodes. Top left corner = PortC=%100000000 & portB = %01111111
The bottom right corner is C = %00000001 B= %11111110
will draw a diagram for clarity. I am doing some thing backwards.
 
diagram of matrix map. NOTE I could change the orientation if needed by rotating?
After studying your code for message I am wondering why some are missing? 6 lines down.
going to take a look at how you achieved using only 44 bytes if I am reading this right??
 

Attachments

  • matrix.png
    matrix.png
    31.4 KB · Views: 322
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top