$regfile = "m32def.dat" : $crystal = 8000000
Config Adc = Single , Prescaler = Auto , Reference = Internal
Ddra.3 = 0 : Ddra.4 = 0 : Ddra.5 = 0 : Ddra.6 = 0 : Ddra.7 = 0
Ddrc = 63 : Ddrd = 255 : Ddrb = &B11111101
Dim B As Byte , F As Byte , Sectic As Byte , Ff As Byte
Dim Out_1 As Byte , Out_2 As Byte , Out_3 As Byte , Out_4 As Byte
Dim Out_5 As Byte , Out_6 As Byte , Out_7 As Byte , Out_8 As Byte
Dim Out_9 As Byte , Out_10 As Byte , Fff As Byte , Ww As Word
Dim Ol As Byte , Frq As Long , W As Word , L As Long , E As Word , C As Word
Dim Cornometr_ms As Word , Cornometr_s As Byte , Cornometr_m As Byte , Cornometr_h As Word
Dim Dama As Word , Car As Word
Dim Cc As Byte , Mm As Byte , Ss As Byte
Config Timer2 = Timer , Async = On , Prescale = 1
On Timer2 Sectic : Enable Interrupts : Enable Timer2
Config Timer1 = Counter , Edge = Rising : On Timer1 Ol : Enable Timer1
Config Timer0 = Timer , Prescale = 8 : On Timer0 Scan : Enable Timer0
Start Timer0 : Start Timer2 : F = 2 : Gosub Res_data : Gosub Sectic : Sectic = 126
'###############################################################################
Star:
Do
Debounce Pina.3 , 1 , Set1
Loop
Set1:
If F = 7 Then :
F = 2 : Start Timer2
L = Frq / 100000 : Out_8 = L + 1 : L = L * 100000 : Frq = Frq - L
L = Frq / 10000 : Out_7 = L + 1 : L = L * 10000 : Frq = Frq - L
L = Frq / 1000 : Out_6 = L + 1 : L = L * 1000 : Frq = Frq - L
L = Frq / 100 : Out_5 = L + 1 : L = L * 100 : Frq = Frq - L
L = Frq / 10 : Out_4 = L + 1 : L = L * 10 : Frq = Frq - L
Out_3 = Frq + 1 : Out_10 = 11 : Out_9 = 12 : Out_2 = 13 : Out_1 = 14
Elseif F = 2 Then :
F = 3 : Stop Timer2 : Stop Timer1 : Gosub Res_data
Do
Debounce Pina.3 , 1 , Set2
Debounce Pina.4 , 1 , Set3 , Gosub
Debounce Pina.5 , 1 , Set4 , Gosub
Loop
Set2:
Stop Timer2 : Gosub Res_data : Goto Set1
Set3:
Start Timer2 : Return
Set4:
Stop Timer2
For C = 0 To 50000
If Pina.5 = 0 Then Return
Next
Gosub Res_data : Return
Elseif F = 3 Then :
F = 4 : Gosub Res_data : Start Timer2
Elseif F = 4 Then :
F = 5 : Stop Timer2 : Gosub Res_data
Do
Debounce Pina.3 , 1 , Set1
Debounce Pina.4 , 1 , Set6 , Gosub
Debounce Pina.5 , 1 , Set7 , Gosub
Debounce Pina.6 , 1 , In_car , Gosub
Debounce Pina.7 , 1 , Out_car , Gosub
Loop
Set6:
Incr Out_1
If Out_1 > 10 Then :
Out_1 = 1 : Incr Out_2
End If
If Out_2 > 10 Then :
Out_2 = 1 : Incr Out_3
End If
If Out_3 > 10 Then :
Out_3 = 1 : Incr Out_4
End If
If Out_4 > 10 Then :
Out_4 = 1 : Incr Out_5
End If
If Out_5 > 10 Then :
Out_5 = 1 : Incr Out_6
End If
If Out_6 > 10 Then :
Out_6 = 1 : Incr Out_7
End If
If Out_7 > 10 Then :
Out_7 = 1 : Incr Out_8
End If
If Out_8 > 10 Then :
Out_8 = 1 : Incr Out_9
End If
If Out_9 > 10 Then :
Out_9 = 1 : Incr Out_10
End If
If Out_10 > 10 Then Out_10 = 1
For C = 0 To 30000
If Pina.4 = 0 Then Return
Next
Do
Incr Out_1
If Out_1 > 10 Then :
Out_1 = 1 : Incr Out_2
End If
If Out_2 > 10 Then :
Out_2 = 1 : Incr Out_3
End If
If Out_3 > 10 Then :
Out_3 = 1 : Incr Out_4
End If
If Out_4 > 10 Then :
Out_4 = 1 : Incr Out_5
End If
If Out_5 > 10 Then :
Out_5 = 1 : Incr Out_6
End If
If Out_6 > 10 Then :
Out_6 = 1 : Incr Out_7
End If
If Out_7 > 10 Then :
Out_7 = 1 : Incr Out_8
End If
If Out_8 > 10 Then :
Out_8 = 1 : Incr Out_9
End If
If Out_9 > 10 Then :
Out_9 = 1 : Incr Out_10
End If
If Out_10 > 10 Then Out_10 = 1
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Loop
Set7:
Decr Out_1
If Out_1 = 0 Then :
Out_1 = 10 : Decr Out_2
End If
If Out_2 = 0 Then :
Out_2 = 10 : Decr Out_3
End If
If Out_3 = 0 Then :
Out_3 = 10 : Decr Out_4
End If
If Out_4 = 0 Then :
Out_4 = 10 : Decr Out_5
End If
If Out_5 = 0 Then :
Out_5 = 10 : Decr Out_6
End If
If Out_6 = 0 Then :
Out_6 = 10 : Decr Out_7
End If
If Out_7 = 0 Then :
Out_7 = 10 : Decr Out_8
End If
If Out_8 = 0 Then :
Out_8 = 10 : Decr Out_9
End If
If Out_9 = 0 Then :
Out_9 = 10 : Decr Out_10
End If
If Out_10 = 0 Then Out_10 = 10
For C = 0 To 30000
If Pina.5 = 0 Then Return
Next
Do
Decr Out_1
If Out_1 = 0 Then :
Out_1 = 10 : Decr Out_2
End If
If Out_2 = 0 Then :
Out_2 = 10 : Decr Out_3
End If
If Out_3 = 0 Then :
Out_3 = 10 : Decr Out_4
End If
If Out_4 = 0 Then :
Out_4 = 10 : Decr Out_5
End If
If Out_5 = 0 Then :
Out_5 = 10 : Decr Out_6
End If
If Out_6 = 0 Then :
Out_6 = 10 : Decr Out_7
End If
If Out_7 = 0 Then :
Out_7 = 10 : Decr Out_8
End If
If Out_8 = 0 Then :
Out_8 = 10 : Decr Out_9
End If
If Out_9 = 0 Then :
Out_9 = 10 : Decr Out_10
End If
If Out_10 = 0 Then Out_10 = 10
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Loop
In_car:
If Pina.7 = 0 Then :
For W = 0 To 60000
Debounce Pina.7 , 1 , In_car2
If Pina.6 = 0 Then Return
Next
Return
Else :
Return
End If
In_car2:
Gosub Set6 : Return
Out_car:
If Pina.6 = 0 Then :
For W = 0 To 60000
Debounce Pina.6 , 1 , Out_car2
If Pina.7 = 0 Then Return
Next
Return
Else :
Return
End If
Out_car2:
Gosub Set7 : Return
Elseif F = 5 Then : 'DAMASANJ
F = 6 : Gosub Res_data : Start Timer2
Elseif F = 6 Then :
F = 7 : Gosub Res_data : Start Timer2
Saat:
Ff = 0 : Waitms 100
Do
Debounce Pina.3 , 1 , Set_time
Loop
Set_time:
For C = 0 To 50000
If Pina.3 = 0 Then Goto Set1
Next
Ff = 1
Do
Debounce Pina.3 , 1 , Set_mm
Debounce Pina.4 , 1 , Incr_cc , Gosub
Debounce Pina.5 , 1 , Decr_cc , Gosub
Loop
Incr_cc:
Incr Cc
If Cc > 23 Then Cc = 0
C = Cc : Ww = C / 10 : Out_9 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_8 = C + 1
For C = 0 To 30000
If Pina.4 = 0 Then Return
Next
Do
Incr Cc
If Cc > 23 Then Cc = 0
C = Cc : Ww = C / 10 : Out_9 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_8 = C + 1
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Loop
Decr_cc:
Decr Cc
If Cc > 23 Then Cc = 23
C = Cc : Ww = C / 10 : Out_9 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_8 = C + 1
For C = 0 To 30000
If Pina.5 = 0 Then Return
Next
Do
Decr Cc
If Cc > 23 Then Cc = 23
C = Cc : Ww = C / 10 : Out_9 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_8 = C + 1
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Loop
Set_mm:
Ff = 2
Do
Debounce Pina.3 , 1 , Saat
Debounce Pina.4 , 1 , Incr_mm , Gosub
Debounce Pina.5 , 1 , Decr_mm , Gosub
Loop
Incr_mm:
Incr Mm
If Mm > 59 Then Mm = 0
C = Mm : Ww = C / 10 : Out_6 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_5 = C + 1
For C = 0 To 30000
If Pina.4 = 0 Then Return
Next
Do
Incr Mm
If Mm > 59 Then Mm = 0
C = Mm : Ww = C / 10 : Out_6 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_5 = C + 1
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Waitms 50
If Pina.4 = 0 Then Return
Loop
Decr_mm:
Decr Mm
If Mm > 59 Then Mm = 59
C = Mm : Ww = C / 10 : Out_6 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_5 = C + 1
For C = 0 To 30000
If Pina.5 = 0 Then Return
Next
Do
Decr Mm
If Mm > 59 Then Mm = 59
C = Mm : Ww = C / 10 : Out_6 = Ww + 1 : Ww = Ww * 10 : C = C - Ww : Out_5 = C + 1
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Waitms 50
If Pina.5 = 0 Then Return
Loop
End If
Goto Star
Res_data:
Out_1 = 1 : Out_2 = 1 : Out_3 = 1 : Out_4 = 1 : Out_5 = 1 : Out_6 = 1
Out_7 = 1 : Out_8 = 1 : Out_9 = 1 : Out_10 = 1 : Sectic = 255
Cornometr_ms = 0 : Cornometr_s = 0 : Cornometr_m = 0 : Cornometr_h = 0
If F = 3 Then :
Out_4 = 16 : Out_6 = 16 : Out_8 = 16
End If
Return
'###############################################################################
Sectic:
Incr Sectic
If F = 2 Then :
If Sectic = 127 Then :
Stop Timer1 : W = Timer1 : Timer1 = 0 : Start Timer1
Frq = Ol * 65536 : Frq = Frq + W : Ol = 0 : If Frq > 999999 Then Frq = 999999
L = Frq / 100000 : Out_8 = L + 1 : L = L * 100000 : Frq = Frq - L
L = Frq / 10000 : Out_7 = L + 1 : L = L * 10000 : Frq = Frq - L
L = Frq / 1000 : Out_6 = L + 1 : L = L * 1000 : Frq = Frq - L
L = Frq / 100 : Out_5 = L + 1 : L = L * 100 : Frq = Frq - L
L = Frq / 10 : Out_4 = L + 1 : L = L * 10 : Frq = Frq - L
Out_3 = Frq + 1 : Out_10 = 11 : Out_9 = 12 : Out_2 = 13 : Out_1 = 14
End If
Elseif F = 3 Then :
Cornometr_ms = Sectic * 8 : W = Cornometr_ms / 59
Cornometr_ms = Cornometr_ms - W : If Cornometr_ms > 999 Then Cornometr_ms = 0
If Sectic = 127 Then :
Incr Cornometr_s
If Cornometr_s > 59 Then :
Cornometr_s = 0 : Incr Cornometr_m
End If
If Cornometr_m > 59 Then :
Cornometr_m = 0 : Incr Cornometr_h
End If
End If
E = Cornometr_ms : W = E / 100 : Out_3 = W + 1 : W = W * 100 : E = E - W
W = E / 10 : Out_2 = W + 1 : W = W * 10 : E = E - W : Out_1 = E + 1
E = Cornometr_s : W = E / 10 : Out_5 = W + 1 : W = W * 10 : E = E - W : Out_4 = E + 16
E = Cornometr_m : W = E / 10 : Out_7 = W + 1 : W = W * 10 : E = E - W : Out_6 = E + 16
E = Cornometr_h : W = E / 100 : Out_10 = W + 1 : W = W * 100 : E = E - W
W = E / 9 : Out_9 = W + 1 : W = W * 10 : E = E - W : Out_8 = E + 16
Elseif F = 4 Then :
If Sectic = 127 Then :
Incr Fff : If Fff = 21 Then Fff = 0
Select Case Fff
Case 0 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 1 :
Out_10 = 1 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 2 :
Out_10 = 2 : Out_9 = 1 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 3 :
Out_10 = 3 : Out_9 = 2 : Out_8 = 1 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 4 :
Out_10 = 4 : Out_9 = 3 : Out_8 = 2 : Out_7 = 1 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 5 :
Out_10 = 5 : Out_9 = 4 : Out_8 = 3 : Out_7 = 2 : Out_6 = 1
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 6 :
Out_10 = 6 : Out_9 = 5 : Out_8 = 4 : Out_7 = 3 : Out_6 = 2
Out_5 = 1 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 7 :
Out_10 = 7 : Out_9 = 6 : Out_8 = 5 : Out_7 = 4 : Out_6 = 3
Out_5 = 2 : Out_4 = 1 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
Case 8 :
Out_10 = 8 : Out_9 = 7 : Out_8 = 6 : Out_7 = 5 : Out_6 = 4
Out_5 = 3 : Out_4 = 2 : Out_3 = 1 : Out_2 = 0 : Out_1 = 0
Case 9 :
Out_10 = 9 : Out_9 = 8 : Out_8 = 7 : Out_7 = 6 : Out_6 = 5
Out_5 = 4 : Out_4 = 3 : Out_3 = 2 : Out_2 = 1 : Out_1 = 0
Case 10 :
Out_10 = 10 : Out_9 = 9 : Out_8 = 8 : Out_7 = 7 : Out_6 = 6
Out_5 = 5 : Out_4 = 4 : Out_3 = 3 : Out_2 = 2 : Out_1 = 1
Case 11 :
Out_10 = 0 : Out_9 = 10 : Out_8 = 9 : Out_7 = 8 : Out_6 = 7
Out_5 = 6 : Out_4 = 5 : Out_3 = 4 : Out_2 = 3 : Out_1 = 2
Case 12 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 10 : Out_7 = 9 : Out_6 = 8
Out_5 = 7 : Out_4 = 6 : Out_3 = 5 : Out_2 = 4 : Out_1 = 3
Case 13 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 10 : Out_6 = 9
Out_5 = 8 : Out_4 = 7 : Out_3 = 6 : Out_2 = 5 : Out_1 = 4
Case 14 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 10
Out_5 = 9 : Out_4 = 8 : Out_3 = 7 : Out_2 = 6 : Out_1 = 5
Case 15 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 10 : Out_4 = 9 : Out_3 = 8 : Out_2 = 7 : Out_1 = 6
Case 16 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 10 : Out_3 = 9 : Out_2 = 8 : Out_1 = 7
Case 17 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 10 : Out_2 = 9 : Out_1 = 8
Case 18 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 10 : Out_1 = 9
Case 19 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 10
Case 20 :
Out_10 = 0 : Out_9 = 0 : Out_8 = 0 : Out_7 = 0 : Out_6 = 0
Out_5 = 0 : Out_4 = 0 : Out_3 = 0 : Out_2 = 0 : Out_1 = 0
End Select
End If
Elseif F = 6 Then :
If Sectic = 127 Then :
Start Adc : Dama = Getadc(0) : Stop Adc : Dama = Dama * 25
L = Dama / 100000 : Out_8 = L + 1 : L = L * 100000 : Dama = Dama - L
L = Dama / 10000 : Out_7 = L + 1 : L = L * 10000 : Dama = Dama - L
L = Dama / 1000 : Out_6 = L + 1 : L = L * 1000 : Dama = Dama - L
L = Dama / 100 : Out_5 = L + 16 : L = L * 100 : Dama = Dama - L
L = Dama / 10 : Out_4 = L + 1 : L = L * 10 : Dama = Dama - L
Out_3 = Dama + 1 : Out_10 = 27 : Out_9 = 28 : Out_8 = 12 : Out_2 = 29 : Out_1 = 30
End If
Elseif F = 7 Then :
If Sectic = 127 Then :
Ss = Ss + 1
If Ss > 59 Then :
Ss = 0 : Mm = Mm + 1
End If
If Mm > 59 Then :
Mm = 0 : Cc = Cc + 1
End If
If Cc > 23 Then :
Cc = 0
End If
E = Ss : W = E / 10 : Out_3 = W + 1 : W = W * 10 : E = E - W : Out_2 = E + 1
E = Mm : W = E / 10 : Out_6 = W + 1 : W = W * 10 : E = E - W : Out_5 = E + 1
E = Cc : W = E / 10 : Out_9 = W + 1 : W = W * 10 : E = E - W : Out_8 = E + 1
Out_4 = 12 : Out_7 = 12 : Out_1 = 0 : Out_10 = 0
Elseif Sectic = 63 Then :
Out_4 = 0 : Out_7 = 0
E = Mm : W = E / 10 : Out_6 = W + 1 : W = W * 10 : E = E - W : Out_5 = E + 1
E = Cc : W = E / 10 : Out_9 = W + 1 : W = W * 10 : E = E - W : Out_8 = E + 1
Elseif Sectic = 31 Then :
If Ff = 1 Then : Out_8 = 0 : Out_9 = 0
Elseif Ff = 2 Then : Out_6 = 0 : Out_5 = 0
End If
Elseif Sectic = 95 Then :
If Ff = 1 Then : Out_8 = 0 : Out_9 = 0
Elseif Ff = 2 Then : Out_6 = 0 : Out_5 = 0
End If
End If
End If
If Sectic > 126 Then Sectic = 255
Return
Ol:
Incr Ol
Return
'###############################################################################
Scan:
Incr B : If B = 11 Then B = 1
Reset Portb.4 : Reset Portb.5 : Reset Portb.6 : Reset Portb.7 : Reset Portc.0
Reset Portc.1 : Reset Portc.2 : Reset Portc.3 : Reset Portc.4 : Reset Portc.5
Select Case B
Case 1 :
Portd = Lookup(out_1 , Number) : Set Portb.7
Case 2 :
Portd = Lookup(out_2 , Number) : Set Portb.6
Case 3 :
Portd = Lookup(out_3 , Number) : Set Portb.5
Case 4 :
Portd = Lookup(out_4 , Number) : Set Portb.4
Case 5 :
Portd = Lookup(out_5 , Number) : Set Portc.5
Case 6 :
Portd = Lookup(out_6 , Number) : Set Portc.4
Case 7 :
Portd = Lookup(out_7 , Number) : Set Portc.3
Case 8 :
Portd = Lookup(out_8 , Number) : Set Portc.2
Case 9 :
Portd = Lookup(out_9 , Number) : Set Portc.1
Case 10 :
Portd = Lookup(out_10 , Number) : Set Portc.0
End Select
Return
'###############################################################################
Number:
Data 0 , &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110 , &B01101101 _
, &B01111101 , &B00000111 , &B01111111 , &B01101111 , &B01110001 , &B01001000 , &B01110110 _
, &B01001001 , 0 , &B10111111 , &B10000110 , &B11011011 , &B11001111 , &B11100110 , &B11101101_
, &B11111101 , &B10000111 , &B11111111 , &B01101111 , 26 , &B00110001 , &B01111001 , &B00000001 , &B01011000