Code: Select all
'****************************
'Konfiguracija
'****************************
$crystal = 12000000 ' 12MHz
$regfile = "89C2051.DAT" ' Kontroler
Config 1wire = P3.7 ' 1Wire port
'-------------------------------------------------------------------------------
'****************************
'Postavljanje interrupta
'****************************
Config Timer0 = Timer , Gate = Internal , Mode = 2 ' Konfiguracija timera
Load Timer0 , 250 ' Početna vrijednost timera
On Timer0 T0int ' Skok na interrupt podprogram
Enable Timer0 ' Dopusti interrupt timera
Start Timer0 ' Pokreni timer
Enable Interrupts ' Globalno dopusti interrupte
'-------------------------------------------------------------------------------
'****************************
'Varijable
'****************************
Dim Brojac_4ms As Byte , Brojac_100ms As Byte , Brojac_1s As Byte
Dim Vrijednost As Word , Jedinice As Byte , Desetice As Byte , Stotice As Byte
Dim Bd(9) As Byte
Dim T1 As Integer
Dim T2 As Integer
Dim Temp As Word
Dim Mux As Byte
Dim Nova_temperatura As Bit
Dim Procitaj_senzor As Bit
Dim Minus As Bit
Dim Senzor_procitan As Bit
'-------------------------------------------------------------------------------
'****************************
'Početne vrednosti
'****************************
Reset Procitaj_senzor
Reset Senzor_procitan
Jedinice = 191
Desetice = 191
Stotice = 191
'-------------------------------------------------------------------------------
'****************************
'Glavna petlja
'****************************
Do
If Nova_temperatura = 1 Then
Reset Nova_temperatura
Vrijednost = Temp
If Senzor_procitan = 1 Then Gosub Pretvorba
Gosub Prikaz
End If
Loop
End
'-------------------------------------------------------------------------------
'****************************
'TIMER0 INTERRUPT
'****************************
T0int:
Incr Brojac_4ms
If Brojac_4ms = 16 Then
Brojac_4ms = 0
Incr Brojac_100ms
Set Nova_temperatura
If Brojac_100ms = 25 Then
Brojac_100ms = 0
Incr Brojac_1s
If Brojac_1s = 7 Then
Brojac_1s = 0
Disable Interrupts
1wreset
1wwrite &HCC
1wwrite &H44
If Err = 0 Then
1wreset
1wwrite &HCC
1wwrite &HBE
Bd(1) = 1wread(9)
1wreset
Bd(1) = Bd(1) And &HFE
T1 = Makeint(bd(1) , Bd(2))
T1 = T1 * 50
T1 = T1 - 25
T2 = Bd(8) - Bd(7)
T2 = T2 * 100
T2 = T2 / Bd(8)
T1 = T1 + T2
Temp = T1 / 10
Else
Temp = 10000 'Prikazuje se greška - Err
End If
Senzor_procitan = 1
Enable Interrupts
End If
End If
End If
Return
'-------------------------------------------------------------------------------
'****************************
'PODPROGRAMI
'****************************
Pretvorba:
If Vrijednost < 1000 Then
Jedinice = Vrijednost Mod 10
Vrijednost = Vrijednost / 10
Desetice = Vrijednost Mod 10
Vrijednost = Vrijednost / 10
Stotice = Vrijednost Mod 10
If Stotice = 0 Then Stotice = 10 'gašenje nule na stoticama
Jedinice = Lookup(jedinice , Tabela)
Desetice = Lookup(desetice , Tabela)
Stotice = Lookup(stotice , Tabela)
Else
Stotice = 134 'E
Desetice = 175 'r
Jedinice = 175 'r
End If
Return
'-------------------------------------------------------------------------------
Prikaz:
Incr Mux
If Mux = 3 Then Mux = 0
Select Case Mux
Case 0:
Set P3.5 ' Ugasi stotice
P1 = Jedinice ' Uzmi jedinice
Reset P3.3 ' Prikaži jedinice
Case 1:
Set P3.3 ' Ugasi jedinice
P1 = Desetice And &B01111111 ' Uzmi desetice i upali točkicu
Reset P3.4 ' Prikaži desetice
Case 2:
Set P3.4 ' Ugasi desetice
P1 = Stotice ' Uzmi stotice
Reset P3.5 ' Prikaži stotice
End Select
Return
'-------------------------------------------------------------------------------
'****************************
'Tabela za prikaz brojeva
'****************************
Tabela:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144 , 255
'BROJ: 0 1 2 3 4 5 6 7 8 9 PRAZNO