Kod: Zaznacz cały
$crystal = 12000000
$regfile = "89C2051.DAT"
Config Timer0 = Timer , Gate = Internal , Mode = 1
Tmod.3 = 1
Tmod.7 = 0
Gate_alias P3.7
Booz_alias P3.0
Ledy Alias P1
Dim Temp As Long
Dim Error As Byte
Dim B1 As Byte
Dim B2 As Byte
Declare Sub Ledy_(nled As Byte , Gd As Byte)
Dim Nled As Byte
Dim Gd As Byte
On Timer0 Timer0_int
On Int0 Int0_int
Tcon.0 = 0
Priority Set Int0
Enable Interrupts
Enable Timer0
Disable Int0
// Początek programu ? //
Booz_ = 0
Gate_ = 1
Call Ledy_(8 , 0)
// Początek pętli głównej //
Do
Error = 0
Th0 = 0
Tl0 = 0
Gate_ = 0
Delay
Delay
Delay
Delay
Delay
Gate_ = 1
Tcon.4 = 1
Waitms 1
Delay
Delay
Delay
Delay
Delay
Tcon.1 = 0
Enable Int0
Do
Error.1 = Tcon.5
Loop Until Error > 0
If Error.0 = 1 Then
Call Ledy_(0 , 0)
Booz_ = 0
Print "T"
Elseif Error.1 = 1 Then
B1 = Tl0
B2 = Th0
Temp = B2 * 256
Temp = Temp + B1
// w zależności od odległości zapalane są ledy,
wraz z włączeniem 5 leda, włącza się buzer //
If Temp < 860 Then
Call Ledy_(8 , 0)
Booz_ = 1
Elseif Temp > 859 And Temp < 2109 Then
Call Ledy_(7 , 0)
Booz_ = 1
Elseif Temp > 2108 And Temp < 3359 Then
Call Ledy_(6 , 0)
Booz_ = 1
Elseif Temp > 3358 And Temp < 4609 Then
Call Ledy_(5 , 0)
Booz_ = 1
Elseif Temp > 4608 And Temp < 5859 Then
Call Ledy_(4 , 0)
Booz_ = 0
Elseif Temp > 5858 And Temp < 7109 Then
Call Ledy_(3 , 0)
Booz_ = 0
Elseif Temp > 7108 And Temp < 8359 Then
Call Ledy_(2 , 0)
Booz_ = 0
Elseif Temp > 8358 And Temp < 10000 Then
Call Ledy_(1 , 0)
Booz_ = 0
Elseif Temp > 9999 Then
Call Ledy_(0 , 0)
Booz_ = 0
End If
End If
Waitms 200
Loop
// Koniec pętli głównej //
Sub Ledy_(nled As Byte , Gd As Byte)
Select Case Gd
Case 0 :
Select Case Nled
Case 0 : Ledy = 255
Case 1 : Ledy = 254
Case 2 : Ledy = 252
Case 3 : Ledy = 248
Case 4 : Ledy = 240
Case 5 : Ledy = 224
Case 6 : Ledy = 192
Case 7 : Ledy = 128
Case 8 : Ledy = 0
End Select
Case 1 :
Select Case Nled
Case 0 : Ledy = 255
Case 1 : Ledy = 127
Case 2 : Ledy = 63
Case 3 : Ledy = 31
Case 4 : Ledy = 15
Case 5 : Ledy = 7
Case 6 : Ledy = 3
Case 7 : Ledy = 1
Case 8 : Ledy = 0
End Select
End Select
B2 = Ledy
End Sub
Timer0_int:
' Incr Over_count
' If Over_count > 9 Then
' Tcon.4 = 0
Disable Int0
Error.0 = 1
' End If
Return
Int0_int:
Tcon.4 = 0
Disable Int0
Error.1 = 1
Return
End