$crystal = 8000000
$regfile = "m16def.dat"
$hwstack = 64 '64 for the hardware stack
$swstack = 8 '8 for the SW stack
$framesize = 16 'use 16 for the frame space
Config Clock = Soft , Gosub = Sectic
Config Timer0 = Timer , Prescale = 1024 ' Configure timer for Setup Blinking
Config Debounce = 2
On Ovf0 Blinkisr 'Setup Blinking Routine
Time$ = "12:34:00"
Enable Interrupts ' Enable Interupts
Dim Columnword As Word ' column word value, 1,2,4,8,16,32,64,128,256
Dim Random As Integer 'random value
Dim Cport(9) As Integer ' port output
Dim Oldport(9) As Integer
Dim Columncount As Integer 'actual column count
Dim Delaycount As Integer 'change time counter
Dim Delayvalue As Integer 'change time
Dim H1$ As String * 1 ' hours
Dim H2$ As String * 1 'hours
Dim M1$ As String * 1 'mins
Dim M2$ As String * 1 'mins
Dim Tijd As String * 8 'time holder
Dim N As Integer ' general counter
Dim Prtb As Byte ' portB value Counter
Dim Key As Byte ' Key Press
Dim Setup As Byte ' Setup Mode
Dim Blinkcount As Byte ' Blinking Delay
Dim _delay As Byte 'Delay counter
Dim H1 As Byte
Dim H2 As Byte
Dim M1 As Byte
Dim M2 As Byte
Dim 3x3_1(100) As Byte
Dim 3x3_2(100) As Byte
Dim 3x3_3(100) As Byte
Dim 2x3_1(100) As Byte
Dim 2x3_2(100) As Byte
Dim 1x3_1(100) As Byte
'define 3x3 PATTERN 1
3x3_1(1) = 0 : 3x3_2(1) = 0 : 3x3_3(1) = 0 'zero
3x3_1(2) = 1 : 3x3_2(2) = 0 : 3x3_3(2) = 0 'one
3x3_1(3) = 1 : 3x3_2(3) = 1 : 3x3_3(3) = 0 'two
3x3_1(4) = 2 : 3x3_2(4) = 1 : 3x3_3(4) = 1 'three
3x3_1(5) = 5 : 3x3_2(5) = 0 : 3x3_3(5) = 5 'four
3x3_1(6) = 5 : 3x3_2(6) = 2 : 3x3_3(6) = 5 'five
3x3_1(7) = 7 : 3x3_2(7) = 0 : 3x3_3(7) = 7 'six
3x3_1(8) = 7 : 3x3_2(8) = 3 : 3x3_3(8) = 3 'seven
3x3_1(9) = 6 : 3x3_2(9) = 7 : 3x3_3(9) = 7 'eight
3x3_1(10) = 7 : 3x3_2(10) = 7 : 3x3_3(10) = 7 'nine
'define 3x3 PATTERN 2
3x3_1(11) = 0 : 3x3_2(11) = 0 : 3x3_3(11) = 0 'zero
3x3_1(12) = 0 : 3x3_2(12) = 1 : 3x3_3(12) = 0 'one
3x3_1(13) = 2 : 3x3_2(13) = 0 : 3x3_3(13) = 1 'two
3x3_1(14) = 2 : 3x3_2(14) = 2 : 3x3_3(14) = 2 'three
3x3_1(15) = 2 : 3x3_2(15) = 5 : 3x3_3(15) = 2 'four
3x3_1(16) = 2 : 3x3_2(16) = 7 : 3x3_3(16) = 2 'five
3x3_1(17) = 5 : 3x3_2(17) = 5 : 3x3_3(17) = 5 'six
3x3_1(18) = 5 : 3x3_2(18) = 5 : 3x3_3(18) = 7 'seven
3x3_1(19) = 7 : 3x3_2(19) = 6 : 3x3_3(19) = 7 'eight
3x3_1(20) = 7 : 3x3_2(20) = 7 : 3x3_3(20) = 7 'nine
'define 3x3 PATTERN 3
3x3_1(21) = 0 : 3x3_2(21) = 0 : 3x3_3(21) = 0 'zero
3x3_1(22) = 0 : 3x3_2(22) = 0 : 3x3_3(22) = 1 'one
3x3_1(23) = 4 : 3x3_2(23) = 0 : 3x3_3(23) = 2 'two
3x3_1(24) = 1 : 3x3_2(24) = 0 : 3x3_3(24) = 5 'three
3x3_1(25) = 2 : 3x3_2(25) = 3 : 3x3_3(25) = 1 'four
3x3_1(26) = 4 : 3x3_2(26) = 4 : 3x3_3(26) = 7 'five
3x3_1(27) = 6 : 3x3_2(27) = 6 : 3x3_3(27) = 6 'six
3x3_1(28) = 7 : 3x3_2(28) = 6 : 3x3_3(28) = 6 'seven
3x3_1(29) = 7 : 3x3_2(29) = 7 : 3x3_3(29) = 6 'eight
3x3_1(30) = 7 : 3x3_2(30) = 7 : 3x3_3(30) = 7 'nine
'define 3x3 PATTERN 4
3x3_1(31) = 0 : 3x3_2(31) = 0 : 3x3_3(31) = 0 'zero
3x3_1(32) = 2 : 3x3_2(32) = 0 : 3x3_3(32) = 0 'one
3x3_1(33) = 1 : 3x3_2(33) = 0 : 3x3_3(33) = 1 'two
3x3_1(34) = 0 : 3x3_2(34) = 0 : 3x3_3(34) = 7 'three
3x3_1(35) = 6 : 3x3_2(35) = 2 : 3x3_3(35) = 2 'four
3x3_1(36) = 7 : 3x3_2(36) = 5 : 3x3_3(36) = 0 'five
3x3_1(37) = 7 : 3x3_2(37) = 7 : 3x3_3(37) = 0 'six
3x3_1(38) = 7 : 3x3_2(38) = 4 : 3x3_3(38) = 7 'seven
3x3_1(39) = 5 : 3x3_2(39) = 7 : 3x3_3(39) = 7 'eight
3x3_1(40) = 7 : 3x3_2(40) = 7 : 3x3_3(40) = 7 'nine
'define 3x3 PATTERN 5
3x3_1(41) = 0 : 3x3_2(41) = 0 : 3x3_3(41) = 0 'zero
3x3_1(42) = 0 : 3x3_2(42) = 2 : 3x3_3(42) = 0 'one
3x3_1(43) = 2 : 3x3_2(43) = 1 : 3x3_3(43) = 0 'two
3x3_1(44) = 4 : 3x3_2(44) = 3 : 3x3_3(44) = 0 'three
3x3_1(45) = 5 : 3x3_2(45) = 4 : 3x3_3(45) = 4 'four
3x3_1(46) = 7 : 3x3_2(46) = 4 : 3x3_3(46) = 2 'five
3x3_1(47) = 7 : 3x3_2(47) = 2 : 3x3_3(47) = 5 'six
3x3_1(48) = 6 : 3x3_2(48) = 7 : 3x3_3(48) = 3 'seven
3x3_1(49) = 7 : 3x3_2(49) = 5 : 3x3_3(49) = 7 'eight
3x3_1(50) = 7 : 3x3_2(50) = 7 : 3x3_3(50) = 7 'nine
'define 3x3 PATTERN 6
3x3_1(51) = 0 : 3x3_2(51) = 0 : 3x3_3(51) = 0 'zero
3x3_1(52) = 0 : 3x3_2(52) = 0 : 3x3_3(52) = 2 'one
3x3_1(53) = 2 : 3x3_2(53) = 0 : 3x3_3(53) = 2 'two
3x3_1(54) = 1 : 3x3_2(54) = 2 : 3x3_3(54) = 4 'three
3x3_1(55) = 6 : 3x3_2(55) = 3 : 3x3_3(55) = 0 'four
3x3_1(56) = 6 : 3x3_2(56) = 6 : 3x3_3(56) = 1 'five
3x3_1(57) = 1 : 3x3_2(57) = 3 : 3x3_3(57) = 7 'six
3x3_1(58) = 3 : 3x3_2(58) = 7 : 3x3_3(58) = 6 'seven
3x3_1(59) = 7 : 3x3_2(59) = 7 : 3x3_3(59) = 5 'eight
3x3_1(60) = 7 : 3x3_2(60) = 7 : 3x3_3(60) = 7 'nine
'define 3x3 PATTERN 7
3x3_1(61) = 0 : 3x3_2(61) = 0 : 3x3_3(61) = 0 'zero
3x3_1(62) = 4 : 3x3_2(62) = 0 : 3x3_3(62) = 0 'one
3x3_1(63) = 0 : 3x3_2(63) = 3 : 3x3_3(63) = 0 'two
3x3_1(64) = 4 : 3x3_2(64) = 2 : 3x3_3(64) = 1 'three
3x3_1(65) = 0 : 3x3_2(65) = 7 : 3x3_3(65) = 1 'four
3x3_1(66) = 2 : 3x3_2(66) = 5 : 3x3_3(66) = 3 'five
3x3_1(67) = 6 : 3x3_2(67) = 7 : 3x3_3(67) = 1 'six
3x3_1(68) = 5 : 3x3_2(68) = 7 : 3x3_3(68) = 5 'seven
3x3_1(69) = 3 : 3x3_2(69) = 7 : 3x3_3(69) = 7 'eight
3x3_1(70) = 7 : 3x3_2(70) = 7 : 3x3_3(70) = 7 'nine
'define 3x3 PATTERN 8
3x3_1(71) = 0 : 3x3_2(71) = 0 : 3x3_3(71) = 0 'zero
3x3_1(72) = 0 : 3x3_2(72) = 4 : 3x3_3(72) = 0 'one
3x3_1(73) = 1 : 3x3_2(73) = 0 : 3x3_3(73) = 2 'two
3x3_1(74) = 2 : 3x3_2(74) = 4 : 3x3_3(74) = 2 'three
3x3_1(75) = 3 : 3x3_2(75) = 0 : 3x3_3(75) = 6 'four
3x3_1(76) = 2 : 3x3_2(76) = 3 : 3x3_3(76) = 6 'five
3x3_1(77) = 4 : 3x3_2(77) = 7 : 3x3_3(77) = 5 'six
3x3_1(78) = 7 : 3x3_2(78) = 2 : 3x3_3(78) = 7 'seven
3x3_1(79) = 7 : 3x3_2(79) = 3 : 3x3_3(79) = 7 'eight
3x3_1(80) = 7 : 3x3_2(80) = 7 : 3x3_3(80) = 7 'nine
'define 3x3 PATTERN 9
3x3_1(81) = 0 : 3x3_2(81) = 0 : 3x3_3(81) = 0 'zero
3x3_1(82) = 0 : 3x3_2(82) = 0 : 3x3_3(82) = 4 'one
3x3_1(83) = 0 : 3x3_2(83) = 5 : 3x3_3(83) = 0 'two
3x3_1(84) = 4 : 3x3_2(84) = 1 : 3x3_3(84) = 4 'three
3x3_1(85) = 1 : 3x3_2(85) = 3 : 3x3_3(85) = 1 'four
3x3_1(86) = 1 : 3x3_2(86) = 5 : 3x3_3(86) = 5 'five
3x3_1(87) = 5 : 3x3_2(87) = 1 : 3x3_3(87) = 7 'six
3x3_1(88) = 3 : 3x3_2(88) = 5 : 3x3_3(88) = 7 'seven
3x3_1(89) = 7 : 3x3_2(89) = 7 : 3x3_3(89) = 3 'eight
3x3_1(90) = 7 : 3x3_2(90) = 7 : 3x3_3(90) = 7 'nine
'define 3x3 PATTERN 10
3x3_1(91) = 0 : 3x3_2(91) = 0 : 3x3_3(91) = 0 'zero
3x3_1(92) = 0 : 3x3_2(92) = 2 : 3x3_3(92) = 0 'one
3x3_1(93) = 1 : 3x3_2(93) = 2 : 3x3_3(93) = 0 'two
3x3_1(94) = 0 : 3x3_2(94) = 3 : 3x3_3(94) = 2 'three
3x3_1(95) = 4 : 3x3_2(95) = 5 : 3x3_3(95) = 4 'four
3x3_1(96) = 6 : 3x3_2(96) = 0 : 3x3_3(96) = 7 'five
3x3_1(97) = 5 : 3x3_2(97) = 7 : 3x3_3(97) = 2 'six
3x3_1(98) = 6 : 3x3_2(98) = 5 : 3x3_3(98) = 7 'seven
3x3_1(99) = 7 : 3x3_2(99) = 5 : 3x3_3(99) = 7 'eight
3x3_1(100) = 7 : 3x3_2(100) = 7 : 3x3_3(100) = 7 'nine
'define 2x3 PATTERN 1
2x3_1(1) = 0 : 2x3_2(1) = 0 'zero
2x3_1(2) = 1 : 2x3_2(2) = 0 'one
2x3_1(3) = 1 : 2x3_2(3) = 1 'two
2x3_1(4) = 7 : 2x3_2(4) = 0 'three
2x3_1(5) = 6 : 2x3_2(5) = 3 'four
2x3_1(6) = 7 : 2x3_2(6) = 5 'five
2x3_1(7) = 7 : 2x3_2(7) = 7 'six
'define 2x3 PATTERN 2
2x3_1(11) = 0 : 2x3_2(11) = 0 'zero
2x3_1(12) = 0 : 2x3_2(12) = 1 'one
2x3_1(13) = 2 : 2x3_2(13) = 1 'two
2x3_1(14) = 2 : 2x3_2(14) = 5 'three
2x3_1(15) = 7 : 2x3_2(15) = 1 'four
2x3_1(16) = 5 : 2x3_2(16) = 7 'five
2x3_1(17) = 7 : 2x3_2(17) = 7 'six
'define 2x3 PATTERN 3
2x3_1(21) = 0 : 2x3_2(21) = 0 'zero
2x3_1(22) = 2 : 2x3_2(22) = 0 'one
2x3_1(23) = 4 : 2x3_2(23) = 2 'two
2x3_1(24) = 5 : 2x3_2(24) = 2 'three
2x3_1(25) = 4 : 2x3_2(25) = 7 'four
2x3_1(26) = 7 : 2x3_2(26) = 3 'five
2x3_1(27) = 7 : 2x3_2(27) = 7 'six
'define 2x3 PATTERN 4
2x3_1(31) = 0 : 2x3_2(31) = 0 'zero
2x3_1(32) = 0 : 2x3_2(32) = 2 'one
2x3_1(33) = 5 : 2x3_2(33) = 0 'two
2x3_1(34) = 1 : 2x3_2(34) = 3 'three
2x3_1(35) = 5 : 2x3_2(35) = 5 'four
2x3_1(36) = 6 : 2x3_2(36) = 7 'five
2x3_1(37) = 7 : 2x3_2(37) = 7 'six
'define 2x3 PATTERN 5
2x3_1(41) = 0 : 2x3_2(41) = 0 'zero
2x3_1(42) = 4 : 2x3_2(42) = 0 'one
2x3_1(43) = 3 : 2x3_2(43) = 0 'two
2x3_1(44) = 6 : 2x3_2(44) = 1 'three
2x3_1(45) = 7 : 2x3_2(45) = 2 'four
2x3_1(46) = 3 : 2x3_2(46) = 7 'five
2x3_1(47) = 7 : 2x3_2(47) = 7 'six
'define 2x3 PATTERN 6
2x3_1(51) = 0 : 2x3_2(51) = 0 'zero
2x3_1(52) = 0 : 2x3_2(52) = 4 'one
2x3_1(53) = 4 : 2x3_2(53) = 4 'two
2x3_1(54) = 1 : 2x3_2(54) = 5 'three
2x3_1(55) = 6 : 2x3_2(55) = 6 'four
2x3_1(56) = 7 : 2x3_2(56) = 3 'five
2x3_1(57) = 7 : 2x3_2(57) = 7 'six
'define 1x3
'Patern 1
1x3_1(1) = 0 'zero
1x3_1(2) = 1 'one
1x3_1(3) = 3 'two
1x3_1(4) = 7 'three
'patern 2
1x3_1(11) = 0 'zero
1x3_1(12) = 2 'one
1x3_1(13) = 5 'two
1x3_1(14) = 7 'three
'patern 3
1x3_1(21) = 0 'zero
1x3_1(22) = 4 'one
1x3_1(23) = 6 'two
1x3_1(24) = 7 'three
Ddra = 255
Ddrb = &B00000000
Ddrc = &B00001111
Porta = 0
Delaycount = 4
Columnword = 1
Columncount = 1
Delayvalue = 5
Setup = 0
_delay = 2
Gosub Sectic
Main:
If Columnword < 256 Then
Portc = 8
Porta = Not Columnword
Portc = Cport(columncount) + 8
Else
Portc = 0
Porta = 255
Portc = Cport(columncount)
End If
Shift Columnword , Left
Incr Columncount
If Columnword = 512 Then
Columnword = 1
Columncount = 1
End If
Debounce Pinb.1 , 1 , Key1 , Sub ' Setup
Debounce Pinb.2 , 1 , Key2 , Sub ' Up
Debounce Pinb.0 , 1 , Key3 , Sub ' Down
Goto Main
'-Blinking Interupt ------------------------------------------------------------
Blinkisr:
Incr Blinkcount
If Blinkcount < 9 Then
Select Case Setup
Case 1 :
Cport(1) = 0 ' blank Hours
Cport(2) = 0
Cport(3) = 0
Cport(4) = 0
Case 2 :
Cport(5) = 0
Cport(6) = 0 ' Blank Minutes
Cport(7) = 0
Cport(8) = 0
Cport(9) = 0
Case 3
Cport(1) = 2 ' Delay
Cport(7) = 0
Cport(8) = 0
Cport(9) = 0
End Select
Else
Cport(1) = 1x3_1(h1)
Cport(2) = 3x3_1(h2)
Cport(3) = 3x3_2(h2)
Cport(4) = 3x3_3(h2)
Cport(5) = 2x3_1(m1)
Cport(6) = 2x3_2(m1)
Cport(7) = 3x3_1(m2)
Cport(8) = 3x3_2(m2)
Cport(9) = 3x3_3(m2)
End If
If Blinkcount = 16 Then Blinkcount = 0
Return
'-To Do On the Second-----------------------------------------------------------
Sectic:
Incr Delaycount
If Delaycount = Delayvalue Then
Update:
' Portc = 0
If Setup < 3 Then
Tijd = Time$
H1$ = Left(tijd , 1)
H2$ = Mid(tijd , 2 , 1)
M1$ = Mid(tijd , 4 , 1)
M2$ = Mid(tijd , 5 , 1)
H1 = Val(h1$)
H2 = Val(h2$)
M1 = Val(m1$)
M2 = Val(m2$)
Random = Rnd(3) * 10
H1 = H1 + Random
Random = Rnd(10) * 10
H2 = H2 + Random
Random = Rnd(6) * 10
M1 = M1 + Random
Random = Rnd(10) * 10
M2 = M2 + Random
H1 = H1 + 1
H2 = H2 + 1
M1 = M1 + 1
M2 = M2 + 1
Else
Tijd = Str(delayvalue)
Tijd = Format(tijd , "00")
M1$ = Left(tijd , 1 )
M2$ = Right(tijd , 1)
H1 = 12
H2 = 0
M1 = Val(m1$)
M2 = Val(m2$)
H1 = H1 + 1
H2 = H2 + 1
M1 = M1 + 1
M2 = M2 + 1
End If
Cport(1) = 1x3_1(h1)
Cport(2) = 3x3_1(h2)
Cport(3) = 3x3_2(h2)
Cport(4) = 3x3_3(h2)
Cport(5) = 2x3_1(m1)
Cport(6) = 2x3_2(m1)
Cport(7) = 3x3_1(m2)
Cport(8) = 3x3_2(m2)
Cport(9) = 3x3_3(m2)
Delaycount = 0
End If
Return
'-Setup Key Pressed-------------------------------------------------------------
Key1:
Enable Timer0 ' enable the Blink timer
Delaycount = Delayvalue - 1 ' Ensure Update is immediate
'Portc = 0
Incr Setup
If Setup > 3 Then
Setup = 0
Disable Timer0 ' Disable the Blink timer
End If
Return
'-Up Key Pressed----------------------------------------------------------------
Key2:
'Portc = 0
Select Case Setup
Case 1
Incr _hour
Case 2
Incr _min
Case 3
Incr _delay
End Select
If _hour > 23 Then _hour = 0
If _min > 59 Then _min = 0
If _delay = 1 Then Delayvalue = 1
If _delay = 2 Then Delayvalue = 5
If _delay = 3 Then Delayvalue = 10
If _delay = 4 Then Delayvalue = 15
If _delay = 5 Then Delayvalue = 30
If _delay = 6 Then Delayvalue = 60
If _delay > 6 Then
_delay = 1
Delayvalue = 1
End If
Gosub Update
Return
'-Down Key Pressed -----------------------------------------------------------
Key3:
'Portc = 0
Select Case Setup
Case 1
Decr _hour
Case 2
Decr _min
Case 3
Decr _delay
End Select
If _hour = 255 Then _hour = 23
If _min = 255 Then _min = 59
If _delay = 1 Then Delayvalue = 1
If _delay = 2 Then Delayvalue = 5
If _delay = 3 Then Delayvalue = 10
If _delay = 4 Then Delayvalue = 15
If _delay = 5 Then Delayvalue = 30
If _delay = 6 Then Delayvalue = 60
If _delay = 255 Then
_delay = 6
Delayvalue = 60
End If
Gosub Update
Return