Witam
Zrobiłem ten termometr: http://mirley.firlej.org/termometr_domowy?page=1#comment-12504
Jednak programowanie AT89C2051 nie należy do najłatwiejszych, więc chciałbym prosić o pomoc w "przerobieniu" tego kodu pod kontroler ATTINY2313. Zrobiłem już programator pod ATTINY2313 więc to byłaby najprostsza droga.
Proszę o pomoc.
Oto kod pod AT89C2051:
Spróbowałem własnymi siłami zmienić ten kod, ale nie dałem rady(błędy kompilacji). Wklejam jeszcze ten kod po błędnym poprawieniu(błędy zaznaczone strzałkami). Proszę o sprawdzenie.
Zrobiłem ten termometr: http://mirley.firlej.org/termometr_domowy?page=1#comment-12504
Jednak programowanie AT89C2051 nie należy do najłatwiejszych, więc chciałbym prosić o pomoc w "przerobieniu" tego kodu pod kontroler ATTINY2313. Zrobiłem już programator pod ATTINY2313 więc to byłaby najprostsza droga.
Proszę o pomoc.
Oto kod pod AT89C2051:
Config Timer0 = Timer , Gate = Internal , Mode = 2 'okres Timera0 250*12*Tosc=250us
Load Timer0 , 250
On Timer0 Przerwanie
Enable Interrupts
Enable Timer0
Start Timer0
P1 = 255
P3 = 255
Config 1wire = P3.5
'*******************************************************************************
'Zmienne
'*******************************************************************************
Dim Lsb As Byte
Dim Msb As Byte
Dim Co4ms As Byte , Co100ms As Byte , Co1s As Byte
Dim Wysw As Byte , Wysw1 As Byte , Wysw10 As Byte
Dim Tempa As Byte
Dim Mux As Byte
Dim Autooff As Word
Dim Przycisk As Byte
Dim Zezw_przyc As Bit , Zezw_wysw As Bit
Dim Pomiar_odczyt As Bit
Dim Minus As Bit
Dim Pokaz As Bit
Dim Przyc As Bit
'*******************************************************************************
'wartosci
'*******************************************************************************
Reset Pomiar_odczyt
Set Pokaz
Autooff = 1500
'*******************************************************************************
'Petla glowna
'*******************************************************************************
Do
If Zezw_wysw = 1 Then 'wyswietlanie
Reset Zezw_wysw
'***************************************** 'co 4ms
If P3.4 = 0 Then
Incr Przycisk
If Przycisk = 200 Then
Przycisk = 0
Set Przyc
End If
Else
Przycisk = 180
Reset Przyc
End If
If P3.7 = 0 Then
If Przyc = 1 Then
Reset Przyc
Pokaz = Not Pokaz
End If
Else
If Przyc = 1 Then
Reset Przyc
Set Pokaz
Autooff = 1500
End If
If Autooff > 0 Then
Decr Autooff
Else
Reset Pokaz
End If
End If
If Pokaz = 1 Then
Wysw = Tempa
Gosub Przelicz
Gosub Wyswietl
Else
P1 = 255
End If
'*****************************************
End If
Loop
End
'*******************************************************************************
'Przerwanie Timera
'*******************************************************************************
Przerwanie: 'co 250us
Incr Co4ms
If Co4ms = 16 Then
Co4ms = 0
'*************************************** co 4ms
Set Zezw_wysw
Incr Co100ms
If Co100ms = 25 Then
Co100ms = 0
'*************************************** co 100 ms
Set Zezw_przyc
Incr Co1s
If Co1s = 10 Then
Co1s = 0
'*************************************** co 1s
Pomiar_odczyt = Not Pomiar_odczyt
Disable Interrupts
1wreset
If Pomiar_odczyt = 1 Then
1wwrite &HCC
1wwrite &H44
Else
If Err = 0 Then
1wwrite &HCC
1wwrite &HBE
Lsb = 1wread():
Msb = 1wread():
If Msb = 0 Then
Reset Minus
Tempa = Lsb / 2
Else
Set Minus
Lsb = Not Lsb
Tempa = Lsb / 2
Tempa = Tempa + 1
End If
Else
Tempa = 255 'Er wyswietli wyswietlacz potem
End If
End If
Enable Interrupts
'***************************************
End If
'***************************************
End If
'***************************************
End If
Return
'*******************************************************************************
Przelicz:
If Wysw < 100 Then
Wysw1 = Wysw Mod 10
Wysw1 = Lookup(wysw1 , Tabela)
If Wysw > 9 Then
Wysw10 = Wysw / 10
Wysw10 = Lookup(wysw10 , Tabela)
Else
Wysw10 = 255 ' znika 0 na pierwszym miejscu
End If
Else
Wysw1 = 175 'r
Wysw10 = 134 'E
End If
Return
'*******************************************************************************
Wyswietl:
Incr Mux
If Mux = 4 Then Mux = 0
Select Case Mux
Case 0:
Set P3.0
If Minus = 1 Then
If Wysw10 = 255 Then
P1 = 255
Else
P1 = 191
End If
Else
P1 = 255
End If
Reset P3.3
Case 1:
Set P3.3
If Minus = 1 Then
If Wysw10 = 255 Then
P1 = 191
Else
P1 = Wysw10
End If
Else
P1 = Wysw10
End If
Reset P3.2
Case 2:
Set P3.2
P1 = Wysw1
Reset P3.1
Case 3:
Set P3.1
P1 = 70
Reset P3.0
End Select
Return
'*******************************************************************************
'Tabela do wyswietlania na wyswietlaczu
'*******************************************************************************
Tabela:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144
'znak: 0 1 2 3 4 5 6 7 8 9
'*******************************************************************************Spróbowałem własnymi siłami zmienić ten kod, ale nie dałem rady(błędy kompilacji). Wklejam jeszcze ten kod po błędnym poprawieniu(błędy zaznaczone strzałkami). Proszę o sprawdzenie.
$regfile = "attiny2313.dat"
$crystal = 12000000
Config Portb = &B11111111 : Portb = &B11111111
Config Portd = &B11111111 : Portd = &B11111111
Config Timer0 = Timer , Prescale = 64 'okres Timera0 250*12*Tosc=250us
Load Timer0 , 250
Enable Interrupts
Enable Timer0 : On Timer0 Przerwanie
Start Timer0
P1 = 255
P3 = 255
Config 1wire = Pind.5
'*******************************************************************************
'Zmienne
'*******************************************************************************
Dim Lsb As Byte
Dim Msb As Byte
Dim Co4ms As Byte , Co100ms As Byte , Co1s As Byte
Dim Wysw As Byte , Wysw1 As Byte , Wysw10 As Byte
Dim Tempa As Byte
Dim Mux As Byte
Dim Autooff As Word
Dim Przycisk As Byte
Dim Zezw_przyc As Bit , Zezw_wysw As Bit
Dim Pomiar_odczyt As Bit
Dim Minus As Bit
Dim Pokaz As Bit
Dim Przyc As Bit
'*******************************************************************************
'wartosci
'*******************************************************************************
Reset Pomiar_odczyt
Set Pokaz
Autooff = 1500
'*******************************************************************************
'Petla glowna
'*******************************************************************************
Do
If Zezw_wysw = 1 Then 'wyswietlanie
Reset Zezw_wysw
'***************************************** 'co 4ms
If Portd.4 = 0 Then
Incr Przycisk
If Przycisk = 200 Then
Przycisk = 0
Set Przyc
End If
Else
Przycisk = 180
Reset Przyc
End If
If Portd.6 = 0 Then
If Przyc = 1 Then
Reset Przyc
Pokaz = Not Pokaz
End If
Else
If Przyc = 1 Then
Reset Przyc
Set Pokaz
Autooff = 1500
End If
If Autooff > 0 Then
Decr Autooff
Else
Reset Pokaz
End If
End If
If Pokaz = 1 Then
Wysw = Tempa
Gosub Przelicz
Gosub Wyswietl
Else
P1 = 255
End If
'*****************************************
End If
Loop
End
'*******************************************************************************
'Przerwanie Timera
'*******************************************************************************
Przerwanie: 'co 250us
Incr Co4ms
If Co4ms = 16 Then
Co4ms = 0
'*************************************** co 4ms
Set Zezw_wysw
Incr Co100ms
If Co100ms = 25 Then
Co100ms = 0
'*************************************** co 100 ms
Set Zezw_przyc
Incr Co1s
If Co1s = 10 Then
Co1s = 0
'*************************************** co 1s
Pomiar_odczyt = Not Pomiar_odczyt
Disable Interrupts
1wreset
If Pomiar_odczyt = 1 Then
1wwrite &HCC
1wwrite &H44
Else
If Err = 0 Then
1wwrite &HCC
1wwrite &HBE
Lsb = 1wread():
Msb = 1wread():
If Msb = 0 Then
Reset Minus
Tempa = Lsb / 2
Else
Set Minus
Lsb = Not Lsb
Tempa = Lsb / 2
Tempa = Tempa + 1
End If
Else
Tempa = 255 'Er wyswietli wyswietlacz potem
End If
End If
Enable Interrupts
'***************************************
End If
'***************************************
End If
'***************************************
End If
Return
'*******************************************************************************
Przelicz:
If Wysw < 100 Then
Wysw1 = Wysw Mod 10
Wysw1 = Lookup(wysw1 , Tabela)
If Wysw > 9 Then
Wysw10 = Wysw / 10
Wysw10 = Lookup(wysw10 , Tabela)
Else
Wysw10 = 255 ' znika 0 na pierwszym miejscu
End If
Else
Wysw1 = 175 'r
Wysw10 = 134 'E
End If
Return
'*******************************************************************************
Wyswietl:
Incr Mux
If Mux = 4 Then Mux = 0
Select Case Mux
Case 0:
Set Portd.0
If Minus = 1 Then
If Wysw10 = 255 Then
P1 = 255
Else
P1 = 191
End If
Else
P1 = 255
End If
Reset Portd.3
Case 1:
Set Portd.3
If Minus = 1 Then
If Wysw10 = 255 Then
P1 = 191
Else
P1 = Wysw10
End If
Else
P1 = Wysw10
End If
Reset Portd.2
Case 2:
Set Portd.2
P1 = Wysw1
Reset Portd.1
Case 3:
Set Portd.1
P1 = 70
Reset Portd.0
End Select
Return
'*******************************************************************************
'Tabela do wyswietlania na wyswietlaczu
'*******************************************************************************
Tabela:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144
'znak: 0 1 2 3 4 5 6 7 8 9
'*******************************************************************************