Bi-Color matrix

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply
MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Bi-Color matrix

Post by MrDEB » Tue Sep 18, 2012 7:36 am

trying to get the two colors to work together but the row ports are using two seperate ports (portA & portB..
Got colum 3 (5 colums using a common cathode and uln2803) to cycle but it stops after 4. Supposed to change over from portA to portB but it stops after displaying 4 leds. Tried changing the bits but maybe going backwards?
Using only the RIGHT sub-routine for testing and hopefully get a better nderstanding of what is going on.

Code: Select all

device and clock
 Device = 18f4520
Clock = 20 // 20mhz clock





Include "utils.bas"



'*********************************************************************
'Dimension Statements (variable and constants
//                        row 3     row 2& 4   rows 1 & 5    row 1,2,4,5  all rows                stp
Const ColG(7) As Byte = (%00000100, %00001010,  %00010001,   %00011011,   %00100001, %11111111, %00011100 ) // Active RowPort pins for each section of the arrow
Const ColR(7) As Byte = (%00000100, %00001010,  %00010001,   %00011011,   %00100001, %11111111, %00011100 ) // Active RowPort pins for each section of the arrow
//                     7 colums from right to left                                                  
Const Rows(7) As Byte = (%00000001, %00000010, %00000100, %00001000, %00010000, %00110000, %01100000)  // Active ColPort pin for each section of the arrow
Const RowsB(3) As Byte = (%00111111, %00100000, %01000000)  // Active ColPort pin for each section of the arrow

 //                       col3         col4       col5
 Const stp(8) As Byte = (%00000000, %00001110, %00010001,%00010001,%00010001,%00010001,%00001110, %00000000)        




Dim row As PORTA
Dim row_tris As TRISA      //trisx to make all outputs
Dim rowB As PORTB
Dim rowB_tris As TRISB
Dim Red_led As PORTC
Dim Red_led_tris As TRISC     //red
Dim Green_led As PORTD
Dim Green_led_tris As TRISD     //green
Dim count As Word
Dim i As Byte
dim x as byte
//DIM x AS BYTE
//dim col as byte
'*********************************************************************
'Subroutines and functions


 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Sub right()

 
  For i = 0 To 4  // cycle through the rows 1 to 7
  Red_led=ColR(0)
   row = Rows(i)     //rows 1-4
   delayms(1000)
  next
  for x = 0 to 3 
   Red_led=ColR(0)
   rowB = RowsB(x)
    next
 

 
  

  delayms(1000)
 //next
 
End Sub
//RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL  
Sub left()

 
  For i = 7 To 0 Step -1   // this is to loop it long enough
                    // to see it
  Red_led=ColG(0)
  row = Rows(1)
  DelayMS(70)
  Next

 Red_led=ColR(3)        
  rowB = Rows(1)
  DelayMS(70)
  //next
    Red_led=ColG(2)          
  row = Rows(4)
  DelayMS(70)
End Sub
//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Sub stop()

 
  For i = 0 To 7   // this is to loop it long enough
                    // to see it
  Green_led= %01111110     // L/R sides of stop sign    %01100010
  row = %00011110
  DelayMS(10)
 
 Green_led= %00011100        //TOP BOTTOM of sign
  row = %01100001
 
  DelayMS(10)
  //NEXT
  //   FOR i = 0 TO 10
       Red_led= %000100010
      row = %0000100001
      DelayMS(10)
      Green_led= %00010100
      row = %00001010
      DelayMS(10)
 
     Green_led= %00001000
      row = %00000100
      DelayMS(100)
 
      Next
  // row = Rows(4)  //%00110001

 // colm=stp(1)          
 // row = Rows(6)
  //DELAYMS(1000)
 // NEXT
End Sub  
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'Notice Function name, code steps, function end. Indenting shows what's contained 'inside the function or subroutine

'Note: If any subroutine calls another subroutine or function, the called sub or
'      function must be placed first in the listing

'*********************************************************************
'Program initialization - only gets done once. Define initial variable conditions and etc.
 Red_led= 0
row = 0
rowB =0
row_tris = 0
rowB_tris = 0
 Red_led_tris = 0
count = 0
//x=100

'Note: The above happens only once when the program initializes.


'*********************************************************************
'Main program loop.  This continues forever

While true
 SetAllDigital
      For count = 0 To 20    // this is to loop it long enough
right()
DelayMS(1000)
 //stop
 Next
 Wend
 {    
 FOR count = 0 TO 20
 left
 DELAYMS(100)
 NEXT

  FOR count = 0 TO 20  
 stop
 DELAYMS(100)
 NEXT                
 WEND
 
    }

'Note: the above goes on forever.  This is the main program and all action
'      is directed from within this loop
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          
   

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Tue Sep 18, 2012 5:18 pm

Let me check out the code and i'll post back...

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Tue Sep 18, 2012 9:20 pm

I have gone over your code but I think I am going to need to see a schematic. I don't understand how you have split your rows between the two ports.

Do you have a schematic we can check out?

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Tue Sep 18, 2012 10:21 pm

Here is the Diptrace file for the schematic. I think I popped pin 19 last night? Using two 220 ohm in parallel for brighter but need to reconfigure the Vcc to the ULN2803's as per suggestion.
Looking at using a cheaper PIC that is XLP seeing how this is going to be battery powered. Don't need much ram. The code at this point uses 269 program bytes and 27 variable bytes. After looking at Microchip site perhaps the 18F43K20 or 18F44K20. Eventually needs to be SMT as is the ULN2803's, resistors etc.
After I get this section done I need to start working on the 3 axis accelerator sensor or 2 tilt switches. Then look into compare two or three inputs.
A note on your RETROBALL, great idea but wonder how reputable the KICKSTART thing is? Would hate to see someone get ripped off of $30K. In this economy there are all kinds of people looking for a FREE lunch. Here in the states they have a program on tv called SHARK TANK that would be perfect for your game. They have a website. The program has 5 millionairs that bid on a product to invest in.
Attachments
new bike dip pakw_test.zip
(11.84 KiB) Downloaded 759 times

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Wed Sep 19, 2012 12:47 am

sub routine I wrote that looks like it works. IMO it looks clunky but if it works don't knock it. lol

Code: Select all

Sub right()

 
  
   Red_led=ColR(0) //row 1
   row = Rows(0)
        
   DelayMS(2000)
    Red_led=ColR(1) //row 2
   row = Rows(1)
   
   DelayMS(2000)  
   Red_led=ColR(2)  //row 3
   row = Rows(2)
   
    DelayMS(2000)   
   Red_led=ColR(3) //row 4
   row = Rows(3)
   
    DelayMS(700)       //clear porta rows 
    Red_led=ColR(0)
    row = Rows(4)
   
   Red_led=ColR(4)   //row 5 
   rowB = RowsB(0)   
 
   DelayMS(700)       //row 6
     Red_led=ColR(5)
   rowB = RowsB(1)
   
    DelayMS(700)       //row 7
     Red_led=ColR(6)
   rowB = RowsB(2)
    DelayMS(700)
     rowB = RowsB(3)   //clear bits   
     
    
 
 


  DelayMS(1000)

End Sub
//RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Wed Sep 19, 2012 6:48 am

I screwed up big time!!
Had it working but after I cleaned up the code, straighten up the lines etc it doesn't work now. I took something out but ??
Going to back track to a similar code that appears to work but ?? I must have removed an important piece of code??. I need to print out more stuff as I go.
Cut the Vcc from the ULN2803s but the LEDs didn't get any brighter?

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : Doug Bezaire                                *
*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 4/7/2011                                                       *
*  Version : 1.0                                                            *
*  Notes   :    data file 4/7/2011                                                            *
*          :                                                                *
*****************************************************************************
}
'device and clock
 Device = 18f4520
Clock = 20 // 20mhz clock
'*********************************************************************
'Compiler directives like oscillator settings
'*********************************************************************
'#Options for include statements - must be before include statements

'*********************************************************************
'Includes


Include "utils.bas"

'*********************************************************************
'Dimension Statements (variable and constants
//                        colum 3    colum 2&4   colum 1 & 5   colum 1,2,4,5         all colum                stp
Const ColG(7) As Byte = (%00010001, %00010010,  %00000100,   %00011011,   %00100001, %11111111, %00011100 ) // Active RowPort pins for each section of the arrow
  
Const RowsB(4) As Byte = (%00000001, %00000010, %00000100, %00000000 )  // Active ColPort pin for each section of the arrow

Const ColR(7) As Byte = (%00010001, %000010010,  %00000100,   %00011011,   %00100001, %11111111, %00000000 ) // Active RowPort pins for each section of the arrow
Const Rows(7) As Byte = (%00000001, %00000010,  %00000100,   %0001000,   %00000000, %0000010, %0000100 )

// NOTE matrix has pin 1 in bottom left corner for test viewing
//                    rows from left to right                                                  



 //                       col3         col4       col5
 Const stp(8) As Byte = (%00000000, %00001110, %00010001,%00010001,%00010001,%00010001,%00001110, %00000000)        




Dim row As PORTA
Dim row_tris As TRISA      //trisx to make all outputs
Dim rowB As PORTB
Dim rowB_tris As TRISB
Dim Green_led As PORTC
Dim Green_led_tris As TRISC     //red
Dim Red_led As PORTD
Dim Red_led_tris As TRISD     //green

Dim count As Word
Dim i As Byte
Dim x As Byte

'*********************************************************************
'Subroutines and functions


 //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Sub right()

 
  
  
 
 
 
   Red_led=ColR(0) //row 1
   row = Rows(0)
 
   DelayMS(2000)
   Red_led=ColR(1) //row 2
   row = Rows(1)
 
   DelayMS(2000)  
   Red_led=ColR(2)  //row 3
   row = Rows(2)
 
    DelayMS(2000)   
   Red_led=ColR(3) //row 4
   row = Rows(3)
 
    DelayMS(700)       //clear porta rows 
    Red_led=ColR(0)
    row = Rows(4)
 
    Red_led=ColR(4)   //row 5 
    rowB = RowsB(0)   
 
 
 
 
    DelayMS(700)       //row 6
   Red_led=ColR(5)
   rowB = RowsB(1)
 
    DelayMS(700)       //row 7
    Red_led=ColR(6)
    rowB = RowsB(2)
    DelayMS(700)
    rowB = RowsB(3)   //clear bits   
 
 
 
 
 
 
 
 
 
  DelayMS(1000)
 
 
End Sub
//RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL  
Sub left()

 
  

 
  
   Red_led=ColR(0) //row 1
   row = Rows(0)
        
   DelayMS(2000)
    Red_led=ColR(1) //row 2
   row = Rows(1)
   
   DelayMS(2000)  
   Red_led=ColR(2)  //row 3
   row = Rows(2)
   
    DelayMS(2000)   
   Red_led=ColR(3) //row 4
   row = Rows(3)
   
    DelayMS(700)       //clear porta rows 
    Red_led=ColR(0)
    row = Rows(4)
   
   Red_led=ColR(4)   //row 5 
   rowB = RowsB(0)   
 
   DelayMS(700)       //row 6
     Red_led=ColR(5)
   rowB = RowsB(1)
   
    DelayMS(700)       //row 7
     Red_led=ColR(6)
   rowB = RowsB(2)
    DelayMS(700)
     rowB = RowsB(3)   //clear bits   
     
    
 
 


  DelayMS(1000)

End Sub
//RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
End Sub
//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Sub stop()

 
  For i = 0 To 7   // this is to loop it long enough
                    // to see it
  Green_led= %01111110     // L/R sides of stop sign    %01100010
  row = %00011110
  DelayMS(10)
 
 Green_led= %00011100        //TOP BOTTOM of sign
  row = %01100001
 
  DelayMS(10)
  //NEXT
  //   FOR i = 0 TO 10
       Red_led= %000100010
      row = %0000100001
      DelayMS(10)
      Green_led= %00010100
      row = %00001010
      DelayMS(10)
 
     Green_led= %00001000
      row = %00000100
      DelayMS(100)
 
      Next
  // row = Rows(4)  //%00110001

 // colm=stp(1)          
 // row = Rows(6)
  //DELAYMS(1000)
 // NEXT
End Sub  
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'Notice Function name, code steps, function end. Indenting shows what's contained 'inside the function or subroutine

'Note: If any subroutine calls another subroutine or function, the called sub or
'      function must be placed first in the listing

'*********************************************************************
'Program initialization - only gets done once. Define initial variable conditions and etc.

row = 0
row_tris = 0
rowB =0
rowB_tris = 0
Red_led = 0
Green_led = 0
Red_led_tris = 0
Green_led_tris = 0
count = 0


'Note: The above happens only once when the program initializes.


'*********************************************************************
'Main program loop.  This continues forever

While true
 SetAllDigital
      For count = 0 To 20    // this is to loop it long enough
right()
DelayMS(1000)
 //stop
 Next
 Wend

'Note: the above goes on forever.  This is the main program and all action
'      is directed from within this loop
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx          
   
      

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Wed Sep 19, 2012 10:37 pm

Unfortunately I can't open the file, it says format is incorrect.

If you are sharing your common cathodes between porta and portb then I would do something like this:

let say that you use PORTA - 0, 1, 2 and 3 for the first four rows, then PORTB - 0, 1, 2 and 3 for the last four (giving you eight rows.) You would want to send your red and green data, then activate just one of these rows:

Code: Select all

PORTA = 0                                  ' make sure all led cathodes connected to PORTA are disabled
PORTB = 0                                  ' make sure all led cathodes connected to PORTB are disabled
for x = 0 to 7
    RedLEDs = RedData(x)            ' grab our data for the RED lED's
    GreenLEDs = GreenData(x)     ' and now grab the data for the GREEN LED's (then we can see which row to activate to display this data)
    if x <= 3 then                        ' for the first four counts, we want to focus on PORTA
        PORTA.bits(x) = 1              ' enable just one row of cathodes. So PORTA.0, PORTA.1, PORTA.2 or PORTA.3 will be enabled
    else                                        ' if our count is greater than the first 4, we then want to focus on turning on PORTB
        portb.bits(x - 4) = 1          ' enable just one row of cathodes. So PORTB.0, PORTB.1, PORTB.2 or PORTB.3 will be enabled
    endif                                      ' Now that we have loaded our data, and displayed it. We need to hold it there just for a moment, then turn it off.
    delayms(1)
    portA = 0                               ' turn off all of PORTA
    portb = 0                               ' and turn off all of PORTB
next

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Thu Sep 20, 2012 6:01 am

starting over as per suggestion but syntax errors. If I hack it too much am going to really screw it up more than I already have.
I can't figure out what to do with redleds etc. Thought it needed to be using to designate the const data

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 9/19/2012                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device=18f4520
Clock = 20
Config MCLRE = Off
'*********************************************************************
'Includes


Include "utils.bas"



'*********************************************************************
'Dimension Statements (variable and constants
//                        colum 3    colum 2&4   colum 1 & 5   colum 1,2,4,5         all colum                stp
Const ColG(7) As Byte = (%00010001, %00010010,  %00000100,   %00011011,   %00100001, %11111111, %00011100 ) // Active RowPort pins for each section of the arrow
  
Const RowsB(4) As Byte = (%00000001, %00000010, %00000100, %00000000 )  // Active ColPort pin for each section of the arrow

Const ColR(7) As Byte = (%00010001, %00100010,  %00000100,   %00011011,   %00100001, %11111111, %00000000 ) // Active RowPort pins for each section of the arrow
Const Rows(7) As Byte = (%00000001, %00000010,  %00000100,   %0001000,   %00000000, %0000010, %0000100 )

// NOTE matrix has pin 1 in bottom left corner for test viewing
//                    rows from left to right                                                  

dim row as porta
dim rowb as portd
dim row_tris as trisa
dim rowb_tris as trisb
dim red as portc
dim red_tris as trisc
dim green as portd
dim green_tris as trisd
dim count as word
dim redleds as byte
dim x as byte
sub test()
     
     for x = 0 to 7
     redleds = reddata(x)
     greenleds=greendata(x)
     if x<= 3 then
     porta.bits(x)=1   //enable one row of cathodes  enable portA-0,1,2,3
     else on portb
     portb.bits(x-4)=1  // enable one row of cathodes portB 0,1,2
     endif
     delayms(1)
     porta=0
     portb=0

   next

end sub



red = 0 //disable all cathodes
green = 0 // disable all cathodes
count = 0

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Thu Sep 20, 2012 9:19 am

making some progress but no display. can't help but wonder if the const are set up right?

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 9/19/2012                                                      *
*  Version : 1.0                                                            *
*  Notes   :brads suggestion 9/19/2012                                                                *
*          :                                                                *
*****************************************************************************
}
Device=18f4520
Clock = 20
Config MCLRE = Off
'*********************************************************************
'Includes


Include "utils.bas"



'*********************************************************************
'Dimension Statements (variable and constants
//                        colum 3    colum 2&4   colum 1 & 5   colum 1,2,4,5         all colum                stp
Const greendata(7) As Byte = (%00010001, %00010010,  %00000100,   %00011011,   %00100001, %11111111, %00011100 ) // Active RowPort pins for each section of the arrow
  
Const RowsB(4) As Byte = (%00000001, %00000010, %00000100, %00000000 )  // Active ColPort pin for each section of the arrow

Const reddata(7) As Byte = (%00010001, %00100010,  %00000100,   %00011011,   %00100001, %11111111, %00000000 ) // Active RowPort pins for each section of the arrow
Const Rows(7) As Byte = (%00000001, %00000010,  %00000100,   %0001000,   %00000000, %0000010, %0000100 )

// NOTE matrix has pin 1 in bottom left corner for test viewing
//                    rows from left to right                                                  

Dim row As PORTA
Dim rowb As PORTB
Dim row_tris As TRISA
Dim rowb_tris As TRISB
Dim red As PORTC
Dim red_tris As TRISC
Dim green As PORTD
Dim green_tris As TRISD
Dim count As Word
Dim redleds As Byte
Dim x As Byte



Sub test()
     
     For x = 0 To 7
     redleds = reddata(x)
     green=greendata(x)
     If x<= 3 Then
     PORTA.bits(x)=1   //enable one row of cathodes  enable portA-0,1,2,3
     DelayMS(2000)
     Else 
     PORTB.bits(x-4)=1  // enable one row of cathodes portB 0,1,2
     EndIf
     DelayMS(1)
     PORTA=0
     PORTB=0

   Next

End Sub



red = 0 //disable all cathodes
red_tris = 0
green = 0 // disable all cathodes
green_tris = 0
count = 0
SetAllDigital

While true
 For count =0 To 20    // run 21 times
 test()                // sub call
 DelayMS(1000)
 Next Wend

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Thu Sep 20, 2012 9:22 am

here is the schematic.
Attachments
bike schematic.jpg
bike schematic.jpg (107.56 KiB) Viewed 19108 times

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Thu Sep 20, 2012 8:05 pm

thanks for the schematic, but do you have a better quality version, I can't make out the writing! :)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Thu Sep 20, 2012 9:51 pm

not sure if this is any better?
last night I got to wondering why I failed to put the red_tris as trisc etc.
Was studying and doing some experimenting on what effect certain statements do. The red_tris as trisc if I am correct males the C port all outputs.
Attachments
bike in paint.jpg
bike in paint.jpg (319.27 KiB) Viewed 19097 times

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Fri Sep 21, 2012 7:30 am

Oh, now I see! You're using a 5x7 matrix and not an 8x8 matrix! It all starts to make a little bit more sense now :)

Code: Select all

RED_TRIS as TRISC

Does not make PORTC all outputs. all it does is gives a nick name (alias) for trisc.

To make PORTC all outputs, you need to have this line of code, after all of your sub routines and just before your main program loop:

Code: Select all

TRISC = %00000000
or now that you have made a nick-name (or alias) for TRISC, you can do it like this:

Code: Select all

RED_TRIS = %00000000
or you could do it in decimal:

Code: Select all

RED_TRIS = 0
give that a try!

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by MrDEB » Fri Sep 21, 2012 1:37 pm

I dissected your suggestion to see what made the code work or not work and found out several different things.
I took a code that I am using to test port/LEDs and took in apart and discovered several things.
I was getting GHOSTING on some LEDs that were not supposed to be on. Put the PORTA=0 etc in and no ghosting. Kinda got the code to work. Using only the test() sub routine. I get LEDs that turn blink in sequence from top down (rows 0-3)
BUT the const for Red_Data (colums 0 to 4 Left to Right) has no effect. The LEDs blink sequentially in colum 3 only regardless what number I use for Red_Data(x).
The GHOSTING appeared in 2 colums and 4 rows to be green LEDs when one row of RED leds were on.
This is a 5 x 7 bi color matrix common cathode driven by UNL2803 so both the row and colum pins must be HIGH
Hopefully after I get the const arrays to play nice with the rest of the code I can then maniulape the bits for my desired patterns. I got this to work with a red matrix but can't get it to work here?

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 9/19/2012                                                      *
*  Version : 1.0                                                            *
*  Notes   :brads suggestion 9/19/2012                                                                *
*          :                                                                *
*****************************************************************************
}
Device=18f4520
Clock = 20
Config MCLRE = Off
'*********************************************************************
'Includes


Include "utils.bas"



'*********************************************************************
'Dimension Statements (variable and constants

Dim row As PORTA    // colums 0 to 3 and portb = 4 to 4 to 7 
//Dim rowB As PORTB
Dim red As PORTc   //colum  1 to 7
//Dim green As PORTD
Dim count As Word
Dim x As Byte
//
Const Red_Data(5) As Byte =   (%00000001, %00000011, %00000111 ,%00001111, %00011111)// 5 colums left to right
//Const green_data(7) As Byte = (%00000001, %00000011, %00000111 ,%00011111, %00111111, %01111111, %01111111)
Const R_ows(7) As Byte =      (%00000001, %00000011, %00000111 ,%00001111, %00011111, %01111111, %0000000)// 7 rows top to bottom

Sub test()
    
     For x = 0 To 3            // increment rows  top to bottom
     red = Red_Data(0)         // colum designation
     //row = 1         // colums data increment
     //row = R_ows(x)            // get row data
     delayms(500)
    // row = R_ows(6)            // clear the rows
    // If x<= 3 Then
     PORTA.bits(x)=1   //enable one row of cathodes  enable portA-0,1,2,3
     DelayMS(500)
    // Else 
    // PORTB.bits(x-4)=1  // enable one row of cathodes portB 0,1,2
    // DelayMS(1000)
    // EndIf
    // DelayMS(3000)
    porta = 0
    portb = 0
    portc = 0
    portd = 0
    
   Next
    
End Sub
sub right()
   for x = 0 to 3
    red =Red_Data(1) 
    row = 1
    delayms(1000)
   
    delayms(1000)
  next
porta = 0  
portb = 0
portc = 0
portd = 0
end sub
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000       // set ports as outputs
TRISD = %00000000

red = 0 //disable all cathodes

//green = 0 // disable all cathodes

count = 0
SetAllDigital
red = 0
row = 0
portb = 0
portc = 0
porta = 0
portd=0
While true
 For count =0 To 20    // run 21 times
 test()                // sub call
 DelayMS(1000)
 Next Wend

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bi-Color matrix

Post by brad » Fri Sep 21, 2012 9:13 pm

I can remember I had a similar problem a couple of years ago.

Some things to look into is that you are turning off the green columns when you only want red and vice versa. Also, make sure you send the data to the display before activating any of the rows.

Sometimes it may help if you have a slight delay between sending the data and activating the rows.

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 17 guests