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