#PICAXE 40X2 ; Define PICAXE 40X2 type
#NO_DATA ;Stop EEPROM data from being cleared during programming
#NO_TABLE ;Ignore TABLE data - loads program faster
#Terminal 9600
;setfreq m16 ;ENABLE this when not using the serial terminal, for final product (sppeds up rotary pot reads and LED matrix updates).
;Initialize: ' Initialise pins and set up variables
;Setup all the port bits to a clean state...
dirsA=$00:dirsB=$00:dirsC=$FF:dirsD=$00 ;11111111, Port C as OUTPUTS, Port A,B & D as INPUTS
outpinsA=$00:outpinsB=$00:outpinsC=$00:outpinsD=$00 ;00000000, clear ALL Port outputs to all 0's
;
Hi2cSETUP i2cmaster,%11100000, i2cfast, i2cbyte
PAUSE 10 ; wait 1 ms for the display chip to initialise
Hi2cOUT ($21) ; start clock/oscillator
; $00 turns off the whole row
;
Symbol MASKA = %00010000 ; D.4
Symbol MASKB = %01000000 ; D.6
Symbol MASK = %01010000 ; All of the above
Symbol reserveB0 = b0
Symbol countA = b2
Symbol countB = b3
Symbol lastA = b4
Symbol lastB = b5
Symbol Buffer1 = b22 ;Temp holding buffer variable
Symbol ROW_1 = b23 ;RGB LEDS 1 & 2
Symbol ROW_2 = b24 ;RGB LEDS 1 & 2
Symbol ROW_3 = b25 ;RGB LEDS 1 & 2
Symbol ROW_4 = b26 ;RGB LEDS 1 & 2
Symbol ROW_5 = b27 ;RGB LEDS 1 & 2
Symbol ROW_6 = b28 ;RGB LEDS 1 & 2
Symbol ROW_7 = b29 ;RGB LEDS 1 & 2
Symbol ROW_8 = b30 ;RGB LEDS 1 & 2
Symbol _F0 = b40 ;RGB LEDS 1 & 2
Symbol _0F = b41 ;RGB LEDS 1 & 2
Symbol SEG7_1 = b31 ;SEG7-1 is the LEFT side display, (the 10's column).
Symbol SEG7_2 = b32 ;SEG7-2 is the RIGHT side display. (the 1's column).
Hi2cOUT ($80) ; clear the display
Hi2cOUT ($EF) ' set to full brightness
ROW_1 = $00 : ROW_2 = $00 : ROW_3 = $00 : ROW_4 = $00 : ROW_5 = $00 : ROW_6 = $00 : ROW_7 = $00 : ROW_8 = $00
_F0 = $F0 ;Pre-defined "$F0" buffer
_0F = $0F ;Pre-defined "$0F" buffer
PowerOnReset:
SerTxd( "Started", CR, LF )
Gosub Interrupt_Enable
MainLoop:
Do
If countA <> lastA Then
SerTxd( "A = ", #countA, CR, LF )
lastA = countA
End If
If countB <> lastB Then
SerTxd( "B = ", #countB, CR, LF )
lastB = countB
End If
;##################################################################
select case countb
case 0 : gosub blankit
case 1 : gosub blankit : ROW_1 = _F0 ;Set to Pre-defined value of "$F0"
case 2 : gosub blankit : ROW_1 = _0F ;Set to Pre-defined value of "$0F"
case 3 : gosub blankit : ROW_2 = _F0
case 4 : gosub blankit : ROW_2 = _0F
case 5 : gosub blankit : ROW_3 = _F0
case 6 : gosub blankit : ROW_3 = _0F
case 7 : gosub blankit : ROW_4 = _F0
case 8 : gosub blankit : ROW_4 = _0F
case 9 : gosub blankit : ROW_5 = _F0
case 10 : gosub blankit : ROW_5 = _0F
case 11 : gosub blankit : ROW_6 = _F0
case 12 : gosub blankit : ROW_6 = _0F
case 13 : gosub blankit : ROW_7 = _F0
case 14 : gosub blankit : ROW_7 = _0F
case 15 : gosub blankit : ROW_8 = _F0
case 16 : gosub blankit : ROW_8 = _0F
endselect
;##################################################################
lookup countA,($30,$6D,$79,$33,$5B,$5F,$70,$7F,$7B,$7E,$30,$6D,$79,$33,$5B,$5F,$70),SEG7_2 ;Load 7-SEG values onto 7-seg Display(s)
if countA => 9 then ; when 'counter'(lookup) becomes greater then the 9th digit (0 to 8, is 9 counts)...bring on the 10's digit for numbers 10 to 16.
SEG7_1 = $30 ; Turn on the 10's digit (1) for numbers 10 to 16 on the LEFT 7-seg display.
else seg7_1 = $00 ; if 'counter' is 9 or less, then turn OFF thge `10's digit (1) again, for numbers 1-9 in the RIGHT 7-seg display.
endif
; SEND_TO_MATRIX: ;#######
; | | | | | | | |
; A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 | A0..A7 A8..A15 |
; | | | | | | | |
Hi2cOUT $00, (ROW_1, SEG7_1, ROW_2, SEG7_2, ROW_3, $00, ROW_4, $00, ROW_5, $00, ROW_6, $00, ROW_7, $00, ROW_8, $00)
Hi2cOUT ($81) ; turn on the display
Loop
Interrupt:
b0 = pinsD
If bit4 <> 0 Then
CountA = CountA + bit5 Min 1 + bit5 - 1 Max 16
End If
If bit6 <> 0 Then
countB = CountB + bit7 Min 1 + bit7 - 1 Max 16
End If
b0 = b0 And MASK
SetInt Not b0, MASK, D
Return
Interrupt_Enable:
b0 = pinsD And MASK
SetInt Not b0, MASK, D
Return
blankit:
ROW_1 = $00 : ROW_2 = $00 : ROW_3 = $00 : ROW_4 = $00 : ROW_5 = $00 : ROW_6 = $00 : ROW_7 = $00 : ROW_8 = $00
return