Program MatrixKlok
Dim DigCount As Byte
Digit As Byte[4]
Seccount As Byte
MinCount As Byte
KeyCount As Byte
Flags As Byte
fKeyRpt As sBit At Flags.0
fUpdate As sBit At Flags.1
Button As sBit At PORTC.2
Const Maxdigits = 4
Keytime = 120
Keydebounce = 10
Keyrpttime = 10
Dim ClockPin as sbit at PORTC.3
Dim Latch as sbit at PORTC.7
Dim Datapin as sbit at PORTC.5
Dim Kolom as Byte
const font as byte[80] =
(
0x3c, 0x66, 0x6e, 0x76, 0x66, 0x66, 0x3c, 0x00,
0x7e, 0x18, 0x18, 0x18, 0x1c, 0x18, 0x18, 0x00,
0x7e, 0x06, 0x0c, 0x30, 0x60, 0x66, 0x3c, 0x00,
0x3c, 0x66, 0x60, 0x38, 0x60, 0x66, 0x3c, 0x00,
0x30, 0x30, 0x7e, 0x32, 0x34, 0x38, 0x30, 0x00,
0x3c, 0x66, 0x60, 0x60, 0x3e, 0x06, 0x7e, 0x00,
0x3c, 0x66, 0x66, 0x3e, 0x06, 0x66, 0x3c, 0x00,
0x18, 0x18, 0x18, 0x30, 0x30, 0x66, 0x7e, 0x00,
0x3c, 0x66, 0x66, 0x3c, 0x66, 0x66, 0x3c, 0x00,
0x3c, 0x66, 0x60, 0x7c, 0x66, 0x66, 0x3c, 0x00
)
Sub Procedure Max_Write(Dim pCol, pDig0, pDig1, pDig2, pDig3 As Byte)
Latch = 0
SPI1_Write(pCol)
SPI1_Write(pDig0)
SPI1_Write(pCol)
SPI1_Write(pDig1)
SPI1_Write(pCol)
SPI1_Write(pDig2)
SPI1_Write(pCol)
SPI1_Write(pDig3)
Latch = 1
delay_ms(1)
End sub
Sub Procedure Max7219_Init()
Max_Write(0x09,0x00,0x00,0x00,0x00)
Max_Write(0x0B,0x07,0x07,0x07,0x07)
Max_Write(0x0C,0x01,0x01,0x01,0x01)
Max_Write(0x0A,0x01,0x01,0x01,0x01)
End sub
Sub Procedure Display_Testen()
Max_Write(0x0F,0x01,0x01,0x01,0x01)
DELAY_MS(500)
Max_Write(0x0F,0x00,0x00,0x00,0x00)
DELAY_MS(500)
end sub
Sub Procedure Uitzetten_Leds()
FOR Kolom = 1 TO 8
Max_Write(Kolom,0x00,0x00,0x00,0x00)
delay_ms(50)
NEXT Kolom
end sub
Sub Procedure Aanzetten_Leds()
For Kolom = 1 TO 8
Max_Write(Kolom,0xFF,0xFF,0xFF,0xFF)
delay_ms(50)
Next Kolom
end sub
Sub Procedure Update_LED
For Kolom = 1 to 8
Max_write(Kolom,
Font[(Digit[0]<<3)+(Kolom-1)],
Font[(Digit[1]<<3)+(Kolom-1)],
Font[(Digit[2]<<3)+(Kolom-1)],
Font[(Digit[3]<<3)+(Kolom-1)])
Next Kolom
end sub
sub procedure Interrupt() iv 0x0004 ics ICS_AUTO
If TMR2IF_bit Then
Inc(Seccount)
If Seccount = 250 Then
Seccount = 0
Inc(MinCount)
If MinCount = 60 Then
MinCount = 0
fUpdate = 1
End If
End If
TMR2IF_bit = 0
End If
end sub
Main:
T2CON = %00100110
PR2 = 124
ANSEL = %00000000
ANSELh = %00000000
TRISC = %00011101
TRISB = %00000000
fUpdate = 0
GIE_bit = 1
PEIE_bit = 1
TMR2IE_bit = 1
DigCount = 0
Digit[0] = 0
Digit[1] = 0
Digit[2] = 0
Digit[3] = 0
SPI1_Init()
Max7219_Init()
Display_Testen()
Uitzetten_Leds()
Update_LED()
While True
if fUpdate = 1 then
Inc(Digit[0])
If Digit[0] = 10 Then
Digit[0] = 0
Inc (Digit[1])
If Digit[1] = 6 Then
Digit[1] = 0
Inc (Digit[2])
If Digit[2] = 10 Then
Digit[2] = 0
Inc(Digit[3])
End If
End If
End If
If (Digit[3] = 2) And (Digit[2] = 4) Then
Digit[0]=0 Digit[1]=0 Digit[2]=0 Digit[3]=0
End If
Update_LED()
fUpdate = 0
End if
Wend
End.