Souce Codenya :
'****************************************************************
'* Name : 59sec_Counter.BAS *
'* Author : Likno *
'* Date : 25.03.2012 *
'* Version : 1.0.1 *
'* Notes : *
'* : *
'****************************************************************
@ Device Xt_osc , Wdt_off , Pwrt_on , Protect_off
Display Var Word
Counter Var Byte
Doonce Var Bit
Pbup Var Porta.0
Pbdn Var Porta.1
Trisa = 011
Trisb = 000000
Porta = 0
Portb = 0
Doonce = 0
Counter = 0
Hours Var Byte
Minutes Var Byte
Seconds Var Byte
Ticks Var Byte
U_flag Var Byte
T0ie Var Intcon.5
T0if Var Intcon.2
Gie Var Intcon.7
Ps0 Var Option_reg.0
Ps1 Var Option_reg.1
Ps2 Var Option_reg.2
Psa Var Option_reg.3
' (0= assigned to oscillator)
T0cs Var Option_reg.5
' (1=External PORTA.4)
Hours = 0
Minutes = 0
Seconds = 0
Ticks = 0
U_flag = 1
Gie = 0
While Gie = 1 : Gie = 0 : Wend
Psa = 0
Ps0 = 1
Ps1 = 0
Ps2 = 1
T0cs = 0
Tmr0 = 0
T0ie = 1
Gie = 1
On Interrupt Goto Clock_int
Main:
If U_flag = 1 Then
U_flag = 0
Counter = Seconds
Display.byte0 =(counter Dig 1) << 4
Display.byte1 =(counter Dig 0)
Display = Display >> 4
Portb = Display.byte0
End If
Goto Main
Disable
Clock_int:
Ticks = Ticks + 1
If Ticks <= 61 Then Clock_exit
' One second has elasped so update the time variables
Ticks = 0
Seconds = Seconds + 1
If Seconds >= 60 Then
Seconds = 0
Minutes = Minutes + 1
If Minutes >= 60 Then
Minutes = 0
Hours = Hours + 1
If Hours >= 23 Then
Hours = 0
End If
End If
End If
U_flag = 1
Clock_exit:
T0if = 0
Resume
Enable
End