Hallo, es ist kein Problem mehr. Aber hier ist es so ruhig das vielleicht jemand rätseln möchte. (Natürlich sind auch Kritik und Verbesserungsvorschläge gern gehört).
Folgende kleine Steuerung verhielt sich wunschgemäß bis zu dem Zeitpunkt als die Heizung eingeschaltet werden sollte. Dann sprang die Anzeige auf Sollwerte und schaltete im viertel Sekunden takt an und ab auch die Sollwerte änderten sich um 2-3 ohne die Potis zu bewegen.
(Im Simulator tritt der Fehler nicht auf)
Alles anzeigen
Folgende kleine Steuerung verhielt sich wunschgemäß bis zu dem Zeitpunkt als die Heizung eingeschaltet werden sollte. Dann sprang die Anzeige auf Sollwerte und schaltete im viertel Sekunden takt an und ab auch die Sollwerte änderten sich um 2-3 ohne die Potis zu bewegen.
(Im Simulator tritt der Fehler nicht auf)
Quellcode
- $regfile = "attiny24.dat"
- $crystal = 1000000
- $hwstack = $16
- $swstack = $16
- $framesize = $20
- '$sim
- $lib "I2c_usi44.lib"
- Config Base = 0
- Config Watchdog = 2048
- Config Scl = Porta.4 'Platne außen: Gnd,Vdd, SDA,SCL
- Config Sda = Porta.6 'Isp 1-a4,2-Vcc,3-Sc(l),4-Mo(Sda),5-/R,6-Gnd
- Config Usi = Twimaster , Mode = Normal
- 'a0=temp/d7, a1=Feu/d6, a2=d5, a3=d4, a4=Sc(l), a5=Miso,a6=Mo/Sda a7=Rs
- 'b0=Temp , b1=Feucht, b2=E
- I2cinit
- Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.2 , Db6 = Porta.1 , Db7 = Porta.0 , E = Portb.2 , Rs = Porta.7
- Config Lcd = 16 * 2
- Initlcd
- cursor off noblink
- Deflcdchar 1 , 14 , 31 , 31 , 31 , 31 , 31 , 14 , 32 ' replace [x] with number (0-7)
- 'Deflcdchar 1 , 14 , 31 , 31 , 31 , 31 , 31 , 31 , 14
- Cls
- Enable Interrupts
- Ddrb = $f
- Config Timer0 = Timer , Prescale = 1024
- Config Adc = Single , Prescaler = Auto , Reference = Avcc
- Dim I2cbuf(8) As Byte
- Dim A As Byte ' , V As Byte , Z As Byte 'a=Schleifenzähler,V=länge,Z=EEpromaddresse
- Dim Tist As Integer , Talt As Word , Tsoll As Word , Thy As Byte ' , T_h As Byte , T_l As Byte
- Dim Fist As Word , Falt As Word , Fsoll As Word , Fhy As Byte ', F_h As Byte , F_l As Byte
- Dim Ti As Byte , Fi As Byte , Tand As Byte , Fand As Byte ', Er As Byte
- Dim Temp As Byte , Tempw As Word , Tempi As Integer ' , Tempstr As String * 6
- Thy = 1
- Fhy = 1
- Start Watchdog
- Do
- Ddra = $dc
- Tempw = Getadc(0) 'Tempsoll
- Shift Tempw , Right , 5
- Tsoll = Tempw + 20
- If Tsoll <> Talt Then Tand = 10
- Talt = Tsoll
- Tempw = Getadc(1) 'Feuchtsoll
- Shift Tempw , Right , 4
- Fsoll = Tempw + 36
- If Fsoll <> Falt Then Fand = 10
- Falt = Fsoll
- Ddra = $df
- Gosub Lese_am
- If I2cbuf(0) = 3 Then
- Tempi = I2cbuf(2)
- Shift Tempi , Left , 8
- Tempi = Tempi + I2cbuf(3)
- If Tempi < 1000 Then
- Fist = Tempi / 10
- End If
- Tempi = I2cbuf(4)
- Shift Tempi , Left , 8
- Tempi = Tempi + I2cbuf(5)
- Tempi = Tempi + 5
- If Tempi < 1000 Then
- Tist = Tempi / 10
- End If
- If Fist >= Fsoll Then
- Reset Portb.1
- Fi = 79
- End If
- If Tist >= Tsoll Then
- Reset Portb.0
- Ti = 79
- End If
- Temp = Fist + Fhy
- If Temp < Fsoll Then
- Set Portb.1
- Fi = 1
- End If
- Temp = Tist + Thy
- If Temp < Tsoll Then
- Set Portb.0
- Ti = 1
- End If
- Else
- Fi = $45
- Ti = $45
- End If
- Locate 1 , 1
- If Fand > 0 Then
- Lcd "Feu.Soll: " ; Fsoll
- Decr Fand
- Else
- Lcd "Feuchte : " ; Fist
- End If
- Lcd "%r "
- Lcd Chr(fi)
- Locate 2 , 1
- If Tand > 0 Then
- Lcd "Raumsoll: " ; Tsoll
- Decr Tand
- Else
- Tempi = Tempi Mod 10
- Lcd "Raum : " ; Tist ; "," ; Tempi
- End If
- Lcd Chr(223) ; "C " ; Chr(ti)
- #if _sim = 0
- Do
- Loop Until Timer0 > 250
- #endif
- Timer0 = 0
- Reset Watchdog
- Loop
- Lese_am:
- #if _sim = 0
- I2cstart
- I2cwbyte &HB8 'Schreibadresse
- Waitms 1
- I2cstop
- I2cstart
- I2cwbyte &HB8 'Schreibadresse 184 ($B8)
- I2cwbyte 3 'Registerlesen
- I2cwbyte 0 'beginne Bei Reg 0
- I2cwbyte 4 'lese 4 Register
- I2cstop
- Waitms 2
- I2cstart
- I2cwbyte &HB9 'Leseadresse 185 ($B9)
- For A = 0 To 6 '0=funktion code(3), 1=Registeranzahl(4)
- I2crbyte I2cbuf(a) , Ack '2-3=Feuchte*10 (LB,HB)
- Next '4-5=Temperatur*10 (LB,HB)
- I2crbyte I2cbuf(7) , Nack '6-7=CRC
- I2cstop
- #else
- I2cbuf(0) = 3
- Tempw = Getadc(2)
- I2cbuf(4) = Adch
- I2cbuf(5) = Adcl
- Tempw = Getadc(3)
- I2cbuf(2) = Adch
- I2cbuf(3) = Adcl
- #endif
- Return