




$regfile = "2313def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32

Dim T As Byte
Dim T1 As Byte
Dim T2 As Byte
Dim Count As Byte
Dim Number(2) As Byte
Dim Byte0 As Byte
Dim Byte1 As Byte
Dim Tust As Byte                                            '  
Dim Tust_ee As Eram Byte                                    '    Eeprom
Dim Tmin As Byte                                            '  
Dim Tmax As Byte                                            '  
Dim A As Byte
Dim F As Bit                                                '  INT0
Dim K As Bit                                                '  T   

Const Gist = 2                                              '

Config 1wire = Port D.0
Config Portb = Output                                       '7-   
Config Portd.4 = Output                                     '1  
Config Portd.5 = Output                                     '2  
Config Portd.6 = Output                                     '  
Config Pind.1 = Input                                       ' 
Config Pind.3 = Input                                       ' 

Config Int0 = Falling
Config Timer0 = Timer , Prescale = 256
On Ovf0 Indic                                               '
On Int0 Flag                                                '  

Dig1 Alias Portd.4
Dig2 Alias Portd.5
'Button Alias Pind.2
Plus Alias Pind.3
Minus Alias Pind.1
Ten Alias Portd.6

Enable Interrupts
Enable Int0
Enable Timer0

Tust_ee = 10                                                '  
F = 0 : K = 0 : A = 0
Start Timer0

Do

If F = 1 Then Goto Metka

1wreset                                                     '  
1wwrite &HCC
1wwrite &H44
Wait 1
'Stop Timer0
1wreset
1wwrite &HCC
1wwrite &HBE
Byte0 = 1wread()
Byte1 = 1wread()
'Start Timer0
T1 = Byte0 / 16
T2 = Byte1 * 16
T = T1 + T2                                                 ' 
Gosub Nagrev                                                '  .  

Metka:
'If F = 1 Then
  If K = 0 Then                                             '    
     T = Tust_ee : A = T                                    '   
  End If
  Wait 2
  Gosub Nastr
'End If
If T <> A And K = 0 Then Tust_ee = T                        '   Tust  

Loop

Flag:                                                       ' INT0
F = 1                                                       '    
If K = 1 Then                                               '    
   F = 0 : K = 0
End If
If T = A Then F = 0
Return

Indic:                                                      ' 
Reset Dig1 : Reset Dig2 : A = T
Number(1) = A / 10                                          '  
Number(2) = A Mod 10
Incr Count : If Count > 2 Then Count = 1
Portb = Lookup(number(count) , Digits)
Select Case Count
Case 1 : Set Dig1
Case 2 : Set Dig2
End Select
Return

Nagrev:                                                     ' 
Tust = Tust_ee                                              ' .   
Tmin = Tust - Gist                                          '  
Tmax = Tust + Gist
If T < Tmin Then Set Ten                                    '   
If T > Tmax Then Reset Ten
Return

Nastr:                                                      ' 
If Plus = 0 Then                                            '   
  Waitms 500
  Incr T : If T = 99 Then T = 0                             '  .
End If

If Minus = 0 Then                                           '   
  Waitms 500
  Decr T : If T = 0 Then T = 99                             '  .
End If
K = 1                                                       '  
Return

End

Digits:
Data &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110
Data &B01101101 , &B01111101 , &B00000111 , &B01111111 , &B01101111