module ledmatrix
{
// from forum post #3... either the comments are wrong or the matrix is "random"
// LED1
LED_COL1=1 LED_COL2=0 LED_COL3=0 LED_COL4=0
LED_ROW1=0 //leds 1-4 led1 is on
LED_ROW2=1 //leds 5-8
LED_ROW3=1 //leds 9-12
// LED5??? shouldn't this be LED6 on?
LED_COL1=0 LED_COL2=1 LED_COL3=0 LED_COL4=0
LED_ROW1=1 //leds 1-4
LED_ROW2=0 //leds 5-8 led #5 is on
LED_ROW3=1 //leds 9-12
// LED9??? shouldn't this be LED12 on?
LED_COL1=0 LED_COL2=0 LED_COL3=0 LED_COL4=1
LED_ROW1=1 //leds 1-4
LED_ROW2=1 //leds 5-8
LED_ROW3=0 //leds 9-12 LED #9 is on
anyway, the code below assumes the leds are in proper order...
}
//LED MATRIX
Dim LED_COL1 As PORTB.0
Dim LED_COL2 As PORTB.1
Dim LED_COL3 As PORTB.2
Dim LED_COL4 As PORTB.3
Dim LED_ROW1 As PORTB.4
Dim LED_ROW2 As PORTB.5
Dim LED_ROW3 As PORTB.6
// make led pins outputs and turn them all off
public sub AllOff()
// turn off columns
low(LED_COL1)
low(LED_COL2)
low(LED_COL3)
low(LED_COL4)
// turn off rows
high(LED_ROW1)
high(LED_ROW2)
high(LED_ROW3)
end sub
// turn on a single led
// led_no = 0 -> nothing on (all off)
// = 1-12 -> turn on specified led
// the routine ignores the comments above and sets the leds "in order"
// so it may not match the (unknown) schematic
// it's long-hand so it can easily be adjusted to match
public sub SetLed(led_no as byte=0)
AllOff()
select (led_no)
// ROW1
case 1 // row1, col1
LED_COL1 = 1
LED_ROW1 = 0
case 2 // row1, col2
LED_COL2 = 1
LED_ROW1 = 0
case 3 // row1, col3
LED_COL3 = 1
LED_ROW1 = 0
case 4 // row1, col4
LED_COL4 = 1
LED_ROW1 = 0
// ROW2
case 5 // row2, col1
LED_COL1 = 1
LED_ROW2 = 0
case 6 // row2, col2
LED_COL2 = 1
LED_ROW2 = 0
case 7 // row2, col3
LED_COL3 = 1
LED_ROW2 = 0
case 8 // row2, col4
LED_COL4 = 1
LED_ROW2 = 0
// ROW3
case 9 // row3, col1
LED_COL1 = 1
LED_ROW3 = 0
case 10 // row3, col2
LED_COL2 = 1
LED_ROW3 = 0
case 11 // row3, col3
LED_COL3 = 1
LED_ROW3 = 0
case 12 // row3, col4
LED_COL4 = 1
LED_ROW3 = 0
end select
end sub
// init
AllOff()
end module