This is too painful to watch.
Do you have pullup resistors on PORTA.3 and PORTA.4 for the switches, and do the switches ground the input pins when pressed?
Here's a version of the code you posted with all the extra junk and shared global variables removed, counters corrected, etc (but I'm sure the hardware has changed since you posted this)
Do you have pullup resistors on PORTA.3 and PORTA.4 for the switches, and do the switches ground the input pins when pressed?
Here's a version of the code you posted with all the extra junk and shared global variables removed, counters corrected, etc (but I'm sure the hardware has changed since you posted this)
Code:
Device = 18F2420
Clock = 20
// external xtal
config OSC = HS
// uncomment next line to use internal osc
//Include "InternalOscillator.bas" // module sets Config OSC = INTIO7 for you
Include "shift.bas"
Include "utils.bas"
Include "convert.bas"
Dim SDI As PORTC.4
Dim CLK As PORTC.5
Dim LE As PORTC.3
Dim RED_OE As PORTC.0
Dim GREEN_OE As PORTC.1
Dim DataPin As SDI
Dim ClockPin As CLK
Dim ResetPin_R As RED_OE
Dim ResetPin_G As GREEN_OE
// pushbutton switches inputs S1 and S2
dim s1 as PORTA.3
dim s2 as PORTA.4
dim count as byte
Const Data(15)As Byte = (%00010001, %00001010 ,%00000100, %00010001, %00001010, %00000100,
%00010001, %000001010 ,%00000100, %000010001,%00001010, %00000100, %000010001,%00001010, %00000100)
Const Rows(15) As Byte =(%00000001, %000000010 ,%00000100, %000000010, %00000100, %00001000,
%00000100 ,%000001000 ,%00010000 ,%00001000,%00010000 ,%00100000, %00010000 ,%00100000, %01000000)
Const L_TRows(15) As Byte =( %01000000,%00100000,%00010000,%00100000,%000010000, %00001000,
%00010000, %00001000, %00000100 ,%00001000, %000000100,%00000010,%00000100, %000000010,%00000001)
Const Ride_Data(15)As Byte = (%00011111, %00000100 ,%00011111, %00000100, %00011111, %00000100,
%00011111, %00000100 ,%00011111, %00000100,%00011111, %00000100, %00011111,%00000100, %00011111)
Const R_Rows(15) As Byte =(%00001000, %011111110 ,%00001000, %011111110, %00001000, %01111110,
%00001000 ,%011111110 ,%00001000 ,%01111110,%00001000 ,%01111110, %00001000 ,%01111110, %00001000)
Sub RIDE()
Dim index As Byte
Dim X As Byte
For index = 0 To Bound (Ride_Data)
DelayMS(100)//10 500us for constant on
X = Ride_Data(index)
LE = 0
ResetPin_R = 1 // disable OE RED
ResetPin_G = 1 // disable OE Green
Shift.Out(MSB_FIRST, X ,8)
LE = 1 //Latch data
PORTB = R_Rows(index)
DelayUS(200) //20 us
ResetPin_G = 0 // output LOW = ON HIGH = OFF
ResetPin_R = 1
LE = 0
Next
End Sub
Sub RIGHT()
Dim index As Byte
Dim X As Byte
For index = 0 To Bound (Data)
DelayMS(10)//10 500us for constant on
X = Data(index)
LE = 0
ResetPin_R = 1 // disable OE RED
ResetPin_G = 1 // disable OE Green
Shift.Out(MSB_FIRST, X ,8)
LE = 1 //Latch data
PORTB = Rows(index)
DelayUS(20) //20 us
ResetPin_R = 0 // output LOW = ON HIGH = OFF
ResetPin_G = 1
LE = 0
Next
End Sub
Sub LEFT()
Dim index As Byte
Dim X As Byte
For index = 0 To Bound (Data)
DelayMS(10)//10 500us for constant on
X = Data(index)
LE = 0 // move to top
ResetPin_R = 1 // disable OE RED
ResetPin_G = 1 // disable OE Green
Shift.Out(MSB_FIRST, X ,8)
LE = 1 //Latch data
PORTB = L_TRows(index) // display byte on matrix
DelayUS(200) //10 1 us for constant on
ResetPin_R = 0 // output LOW = ON HIGH = OFF
ResetPin_G = 1
Next
End Sub
// start of main
SetAllDigital
Shift.SetOutput(DataPin)
Shift.SetClock(ClockPin)
high(ResetPin_R) // make output and set high
high(ResetPin_G) // make output and set high
low(LE) // make output and set low
PORTB = 0
TRISB = %00000000 // make PORTB outputs
// make S1 and S2 switch inputs (assumes there are external pullups on the pins)
input(s1)
input(s2)
While true
If s1 = 0 Then // sw 1 closed
count = 0
Repeat
LEFT()
DelayMS(200)
//ResetPin_G = 1 // output LOW = ON HIGH = OFF this shuts off trailing byte in shifter reg.
Inc(count)
Until count = 10 // total of 11 arrows
End If
If s2 = 0 Then // sw 2 closed
count = 0
Repeat
RIGHT()
DelayMS(200)
// ResetPin_G = 1 // output LOW = ON HIGH = OFF this shuts off trailing byte in shifter reg.
Inc(count)
Until count = 10 // total of 11 arrows
End If
If s1 = 1 And s2 = 1 Then
RIDE()
DelayMS(200)
// ResetPin_G = 1 // output LOW = ON HIGH = OFF this shuts off trailing byte in shifter reg.
End If
Wend
End
Last edited: