Witam, mam mały problem, jak w temacie. Mianowie chciałbym zaprogramować m8def tak, aby wskazywał mi on temperaturę otoczenia,czujnik jakiego używam to DS18B20, do atmegi wgrałem program taki jak poniżej lecz migają się tylko kropki na trzech z czterech wyświetlaczy i temperatury nie poazuje
'f u s e b i t A987 0100:0100 osc
'ds niebieski masa, biały sygnał, pomarańczowy 5V
'nie wgrane do focusa 03-01-2009
$regfile = "m8def.dat"
$crystal = 8000000
'Config Pind.1 = Input
'Config Portb.0 = Output ' cyfra1
'Config Portb.1 = Output ' cyfra2
'Config Portb.2 = Output ' cyfra3
Config Portb = Output
Portb = 255
Config Portc = Input
Portc = &B11011111
Config Portd = Output
Portd = 255 ' anody cyfr
Config 1wire = Portc.5
Config Timer1 = Timer , Prescale = 8
Cyfra1 Alias Portd.6
Cyfra2 Alias Portd.5
Cyfra3 Alias Portd.4
'Portd =&Bdc.gebfa
Dim Ds_1 As Byte
Dim Ds_2 As Byte
Dim C As Word
Dim D As Byte
Dim E As Byte
Dim T1 As Single
Dim T2 As Single
Dim Temperatura As Word
Dim Status_temp As Bit
Dim Wartosc_c1 As Word
Dim Wartosc_c2 As Word
Dim Wartosc_c3 As Word
Dim Wartosc As Word
Dim Wartosc_przel As Word
D = 4
E = 250
Do
Gosub Aktywuj_ds
For C = 0 To 65
' pętla trwa około 750 ms
Cyfra1 = 0
Portb = Wartosc_c1
Waitms D
Gosub Zerowanie
Cyfra2 = 0
Portb = Wartosc_c2
Waitms D
Gosub Zerowanie
Cyfra3 = 0
Portb = Wartosc_c3
Waitms D
Gosub Zerowanie
Next C
Gosub Odczytaj_ds
Gosub Zerowanie
Waitms E
For C = 0 To 30
' pętla trwa około 10 s
Cyfra1 = 0
Portb = Wartosc_c1
Waitms D
Gosub Zerowanie
Cyfra2 = 0
Portb = Wartosc_c2
Waitms D
Gosub Zerowanie
Cyfra3 = 0
Portb = Wartosc_c3
Waitms D
Gosub Zerowanie
Next C
Waitms E
For C = 0 To 30
' pętla trwa około 10 s
Cyfra1 = 0
Portb = Wartosc_c1
Waitms D
Gosub Zerowanie
Cyfra2 = 0
Portb = Wartosc_c2
Waitms D
Gosub Zerowanie
Cyfra3 = 0
Portb = Wartosc_c3
Waitms D
Gosub Zerowanie
Next C
Waitms E
For C = 0 To 700
' pętla trwa około 10 s
Cyfra1 = 0
Portb = Wartosc_c1
Waitms D
Gosub Zerowanie
Cyfra2 = 0
Portb = Wartosc_c2
Waitms D
Gosub Zerowanie
Cyfra3 = 0
Portb = Wartosc_c3
Waitms D
Gosub Zerowanie
Next C
Loop
Zerowanie:
Cyfra1 = 1
Cyfra2 = 1
Cyfra3 = 1
Return
'Tabela:
'Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144
Okresl_wartosc:
Select Case Wartosc
'Portd =&B.gfedcba
Case 0
Wartosc_przel = 192
Case 1
Wartosc_przel = 249
Case 2
Wartosc_przel = 164
Case 3
Wartosc_przel = 176
Case 4
Wartosc_przel = 153
Case 5
Wartosc_przel = 146
Case 6
Wartosc_przel = 130
Case 7
Wartosc_przel = 248
Case 8
Wartosc_przel = 128
Case 9
Wartosc_przel = 144
Case 10
Wartosc_przel = 255
End Select
Return
Aktywuj_ds:
1wreset
If Err = 0 Then
1wwrite &HCC
1wwrite &H44
Else
Wartosc_c1 = 127
Wartosc_c2 = 127
Wartosc_c3 = 127
End If
Return
Odczytaj_ds:
1wreset
If Err = 0 Then
1wwrite &HCC
1wwrite &HBE
Ds_1 = 1wread()
Ds_2 = 1wread()
Status_temp = 1
If Ds_2 >= 248 Then 'warto?ć ujemna
Ds_1 = 255 - Ds_1
Ds_2 = 255 - Ds_2
Status_temp = 0
End If
T1 = Ds_1 / 16
T2 = Ds_2 * 16
T1 = T1 + T2
T1 = T1 + 0.05
'T1 warto?ć temperatury xx.xx
T1 = T1 * 10
'warto?ć całkowita XXX
Temperatura = T1 \ 1
If Temperatura = 0 Then
' po to aby nie było -0.0
Status_temp = 1
End If
If Temperatura <= 15 Then
E = 250
Else
E = 0
End If
If Status_temp = 1 Then
Wartosc_c3 = Temperatura Mod 10
Temperatura = Temperatura \ 10
Wartosc_c2 = Temperatura Mod 10
Temperatura = Temperatura \ 10
Wartosc_c1 = Temperatura Mod 10
Wartosc = Wartosc_c3 'obliczenie czę?ci dziesiętnej
Gosub Okresl_wartosc 'warto?ć 3 cyfry
Wartosc_c3 = Wartosc_przel
Wartosc = Wartosc_c2 'obliczenie jedno?ci
Gosub Okresl_wartosc 'warto?ć 2 cyfry
Wartosc_c2 = Wartosc_przel
Wartosc_c2 = Wartosc_c2 And &B01111111
If Wartosc_c1 = 0 Then 'wyczyszczenie zera nieznaczšcego
Wartosc_c1 = 10
End If
Wartosc = Wartosc_c1 'obliczenie dziesištek
Gosub Okresl_wartosc 'warto?ć 1 cyfry
Wartosc_c1 = Wartosc_przel
Else
'Portd =&Bdc.gebfa
Wartosc_c1 = 127 'znak minus na 1 cyfrze
If Temperatura < 100 Then 'mniej niż 10 stopni
Wartosc_c3 = Temperatura Mod 10
Temperatura = Temperatura \ 10
Wartosc_c2 = Temperatura Mod 10
Wartosc = Wartosc_c3 'obliczenie czę?ci dziesiętnej
Gosub Okresl_wartosc 'warto?ć 3 cyfry
Wartosc_c3 = Wartosc_przel
Wartosc = Wartosc_c2 'obliczenie jedno?ci
Gosub Okresl_wartosc 'warto?ć 2 cyfry
Wartosc_c2 = Wartosc_przel
Wartosc_c2 = Wartosc_c2 And &B01111111
Else
Temperatura = Temperatura + 5 'aby liczył ?redniš przy >10 stopni
Temperatura = Temperatura \ 10
Wartosc_c3 = Temperatura Mod 10
Temperatura = Temperatura \ 10
Wartosc_c2 = Temperatura Mod 10
Wartosc = Wartosc_c3 'obliczenie jedno?ci
Gosub Okresl_wartosc 'warto?ć 3 cyfry
Wartosc_c3 = Wartosc_przel
Wartosc = Wartosc_c2 'obliczenie dziesištek
Gosub Okresl_wartosc 'warto?ć 2 cyfry
Wartosc_c2 = Wartosc_przel
End If
End If
End If
Return