Witam.
Mam taki oto program do pomiaru temperatury przez DS18B20 i wyświetleniu jej na 14-sto pozycyjnym wyświetlaczu 14-sto segmentowym:
Problem w tym że program nie działa jak należy, niby pokazuje prawidłową temperaturę ale pokazuje też mnóstwo innych głupot. Problem jest pewnie w tym że obsługa wyświetlacza jest w przerwaniu. Nie potrafię się z tym uporać. Wiecie może co jest źle w tym programie?
Mam taki oto program do pomiaru temperatury przez DS18B20 i wyświetleniu jej na 14-sto pozycyjnym wyświetlaczu 14-sto segmentowym:
'-------------Zegar Kalendarz 14-segment LED-"
'opis złącza ISP
'czerwony - "+"
'zielony - RESET
'biały - MISO
'niebieski - SCK
'brązowy - MOSI
'czarny - "-"
'------------dyrektywy dla kompilatora--------"
$regfile = "m16def.dat"
$crystal = 8000000
'------------konfiguracja timera--------------"
Config Timer2 = Timer , Prescale = 8 : Enable Interrupts : Enable Timer2
On Timer2 Co4ms
'------------zmienne--------------------------"
Dim Ktorywysw As Byte
Dim W1 As Byte
Dim W2 As Byte
Dim W3 As Byte
Dim W4 As Byte
Dim W5 As Byte
Dim W6 As Byte
Dim W7 As Byte
Dim W8 As Byte
Dim W9 As Byte
Dim W10 As Byte
Dim W11 As Byte
Dim W12 As Byte
Dim W13 As Byte
Dim W14 As Byte
'Termometr'
Dim Odczyt(2) As Byte
Dim T As Integer
Dim T1 As Single
Dim Temp As Byte
'------------konfiguracja portów--------------"
Config Portb = &B11111111
Portb = &B00000000
Config Portd = &B1111111
Portb = &B11111111
Config Porta = &B11111111
Porta = &B11111111
Config Pinc.0 = Output
Portc.0 = 0
Config 1wire = Portc.7
'-----------program główny--------------------"
Do
1wreset : 1wwrite &HCC : 1wwrite &H44 'SKIP ROM + dokonaj konwersji
Waitms 750
1wreset : 1wwrite &HCC : 1wwrite &HBE 'odczytaj DS18x20
Odczyt(1) = 1wread(2) 'odczytaj dwa pierwsze bajty
T = Odczyt(2) : Shift T , Left , 8 'przepisz, przesuń
T1 = T + Odczyt(1) 'wynik do zmiennej typu Single
T1 = T1 * 0.0625 'wyrażenie w stopniach celsjusza
Temp = Round(t1)
W1 = Temp / 10
W2 = Temp Mod 10
W3 = 36
W4 = 12
W5 = 35
W6 = 35
W7 = 35
W8 = 35
W9 = 35
W10 = 35
W11 = 35
W12 = 35
W13 = 35
W14 = 35
Loop
End
'-----------obsługa wyświetlacza------"
Co4ms:
Portd = &B00000000
Portb = &B000000
Incr Ktorywysw : If Ktorywysw = 14 Then Ktorywysw = 0
Select Case Ktorywysw
Case 0:
Portb.6 = 1
Porta = Lookup(w1 , Tabela1)
Portb.6 = 0
Porta = Lookup(w1 , Tabela2) : Portd.0 = 1
Case 1:
Portb.6 = 1
Porta = Lookup(w2 , Tabela1)
Portb.6 = 0
Porta = Lookup(w2 , Tabela2) : Portd.1 = 1
Case 2:
Portb.6 = 1
Porta = Lookup(w3 , Tabela1)
Portb.6 = 0
Porta = Lookup(w3 , Tabela2) : Portd.2 = 1
Case 3:
Portb.6 = 1
Porta = Lookup(w4 , Tabela1)
Portb.6 = 0
Porta = Lookup(w4 , Tabela2) : Portd.3 = 1
Case 4:
Portb.6 = 1
Porta = Lookup(w5 , Tabela1)
Portb.6 = 0
Porta = Lookup(w5 , Tabela2) : Portd.4 = 1
Case 5:
Portb.6 = 1
Porta = Lookup(w6 , Tabela1)
Portb.6 = 0
Porta = Lookup(w6 , Tabela2) : Portd.5 = 1
Case 6:
Portb.6 = 1
Porta = Lookup(w7 , Tabela1)
Portb.6 = 0
Porta = Lookup(w7 , Tabela2) : Portd.6 = 1
Case 7:
Portb.6 = 1
Porta = Lookup(w8 , Tabela1)
Portb.6 = 0
Porta = Lookup(w8 , Tabela2) : Portb.7 = 1
Case 8:
Portb.6 = 1
Porta = Lookup(w9 , Tabela1)
Portb.6 = 0
Porta = Lookup(w9 , Tabela2) : Portb.0 = 1
Case 9:
Portb.6 = 1
Porta = Lookup(w10 , Tabela1)
Portb.6 = 0
Porta = Lookup(w10 , Tabela2) : Portb.1 = 1
Case 10:
Portb.6 = 1
Porta = Lookup(w11 , Tabela1)
Portb.6 = 0
Porta = Lookup(w11 , Tabela2) : Portb.2 = 1
Case 11:
Portb.6 = 1
Porta = Lookup(w12 , Tabela1)
Portb.6 = 0
Porta = Lookup(w12 , Tabela2) : Portb.3 = 1
Case 12:
Portb.6 = 1
Porta = Lookup(w13 , Tabela1)
Portb.6 = 0
Porta = Lookup(w13 , Tabela2) : Portb.4 = 1
Case 13:
Portb.6 = 1
Porta = Lookup(w14 , Tabela1)
Portb.6 = 0
Porta = Lookup(w14 , Tabela2) : Portb.5 = 1
End Select
Return
Tabela1: 'TABELA DLA PORTU A
Data 63 , 6 , 219 , 207 , 230 , 237 , 253 , 7 , 255 , 239 , 247 , 143 , 57 , 15 , 249 , 241 , 189 , 246 , 0 , 30 , 112 , 56 , 54 , 54 , 63 , 243 , 243 , 237 , 1 , 62 , 54 , 0 , 0 , 9 , 0 , 0 , 227 , 192 , 48
Tabela2: 'TABELA DLA PORTU A-dodatkowe segmenty
Data 12 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 18 , 0 , 18 , 0 , 0 , 0 , 0 , 18 , 0 , 36 , 0 , 5 , 33 , 0 , 0 , 32 , 0 , 18 , 0 , 40 , 45 , 21 , 12 , 8 , 0 , 0 , 0 , 12
Problem w tym że program nie działa jak należy, niby pokazuje prawidłową temperaturę ale pokazuje też mnóstwo innych głupot. Problem jest pewnie w tym że obsługa wyświetlacza jest w przerwaniu. Nie potrafię się z tym uporać. Wiecie może co jest źle w tym programie?
