'*******************************************************************************
'* *
'* Grundprogramm mit PWM-Ausgabe Timer 1 und 2 Teperaturmessungen mit DS1820 *
'* Es wird mit Timer Interupts Programmiert *
'* Mit GLCD JHD240128D *
'* Ralf Neubert Dinslaken *
'* www.AVR-Praxis.de *
'* Version vom 12.04.2012 *
'* *
'*******************************************************************************
$regfile = "m32def.dat"
$crystal = 16000000
'$baud = 19200
$hwstack = 128 ' default use 32 for the hardware stack
$swstack = 128 'default use 8 for the SW stack
$framesize = 128 'default use 24 for the frame space
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 6
Cursor Off
Cls
Config Timer0 = Timer , Prescale = 64
Config Timer1 = Pwm , Prescale = 8 , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down
'*******************************************************************************
Locate 2 , 1
Lcd " Ralf Neubert,Logger @ AVR-Praxis Forum"
Locate 4 , 10
Lcd "Hallo AVR-Praxis Forum"
Locate 6 , 3
Lcd "TEST GLCD JHD240128D LED erfolgreich "
Start Timer0
On Ovf0 Timer0isr
'*******************************************************************************
Enable Timer0
Enable Interrupts
'*******************************************************************************
S1 Alias Pind.2 'Taster 0 Eingabe Pwm up
S2 Alias Pind.3 'Taster 1 Eingabe Pwm down
S3 Alias Pind.6 'Taster 2 Eingabe LED 1 Start/Stop
S4 Alias Pind.7 'Taster 3 Eingabe LCD Clear screen
Out1 Alias Portb.2 'LED 0 Ausgabe Dauerlicht
Out2 Alias Portb.3 'LED 1 Ausgabe Blinkt
' Pin für 1wire Schnittstelle festlegen
Config 1wire = Portb.0 'Belegung aussenfühler,pin1=Weiß-GND,pin2=Grün-Data,pin3=Grau-VDD
Config Portd = &B00110000 'PortD. = 0,1,2,3,6,7 Eingang = 4,5 PWM Ausgang
Config Portb = &B00001100 'PortB. = 0,1,4,5,6,7 Eingang = 2,3 Ausgang für LED's
'*******************************************************************************
Dim Pwma As Integer
Dim Pwmb As Integer
Dim Ticks As Byte
Dim Sw1 As Byte
Dim Sw2 As Byte
Dim Sw3 As Byte
Dim Sw4 As Byte
Dim Pwm1 As Integer
Dim Pwm1old As Integer
Dim Ledtimer As Byte
Dim Ledblink As Byte
'*******************************************************************************
'PWM1 wert aus EEprom lesen
Readeeprom Pwm1 , &H20
'*******************************************************************************
'Für die Temperaturmessung
Dim T1 As Integer 'hilfs Variable für die berechnung Temp1
Dim T2 As Integer 'hilfs Variable für die berechnung Temp1
Dim T3 As Integer 'hilfs Variable für die berechnung Temp2
Dim T4 As Integer 'hilfs Variable für die berechnung Temp2
Dim T5 As String * 5 'Variable für Temp1 zur anzeige auf dem LCD
Dim T6 As String * 5 'Variable für Temp2 zur anzeige auf dem LCD
Dim T7 As Single 'hilfs Variable für die berechnung Temp1
Dim T8 As Single 'hilfs Variable für die berechnung Temp2
Dim Id1(8) As Byte 'für die adresse Sensor 1
Dim Id2(8) As Byte 'für die adresse Sensor 2
Dim Ar1(9) As Byte
Dim Ar2(9) As Byte
Dim I As Byte , Tmp1 As Byte , Tmp2 As Byte
Dim W As Byte
'*******************************************************************************
'
Dim Tx As Integer
Dim Txold As Integer
Dim Ty As Integer
Dim Tyold As Integer
Dim Xold As Integer
Dim Pwmx As Integer
'*******************************************************************************
'Constanten festlegen
'Constante1 = 506 '479
'Con2 = 0.0978 '0.0978
Const Timer0_reload = 224 'Wert für 1ms
'*******************************************************************************
'1wire Bus absuchen
W = 1wirecount()
Id1(1) = 1wsearchfirst()
Id2(1) = 1wsearchnext()
'Print W
For W = 1 To 8
'Print Hex(id1(w));
Next
'Print
For W = 1 To 8
'Print Hex(id2(w));
Next
'Print
'*******************************************************************************
Portd.2 = 1
Portd.3 = 1
Portd.6 = 1
Portd.7 = 1
Ledblink = 1
Boxfill(0 , 64) -(201 , 74) , 1
Boxfill(0 , 88) -(201 , 98) , 1
Boxfill(0 , 112) -(201 , 122) , 1
'*******************************************************************************
'Hauptschleife
Do
'Temperaturen Convertieren
1wreset
1wwrite &HCC
1wwrite &H44
Ddrb.0 = 1
Waitms 800
Ddrb.0 = 0
'*******************************************************************************
'Innen-Temperatur Berechnen
1wreset
1wwrite &H55
1wwrite Id1(1) , 8
1wwrite &HBE
Ar1(1) = 1wread(9)
1wreset
Tmp1 = Ar1(1) And 1
If Tmp1 = 1 Then Decr Ar1(1)
T1 = Makeint(ar1(1) , Ar1(2))
T1 = T1 * 50
T1 = T1 - 25
T2 = Ar1(8) - Ar1(7)
T2 = T2 * 100
T2 = T2 / Ar1(8)
T1 = T1 + T2
T1 = T1 / 10
Tx = T1
T7 = T1 / 10
T5 = Fusing(t7 , "###.#" )
Tx = Tx / 5
Tx = Tx + 50
If Tx < 1 Then Tx = 0
If Tx > 200 Then Tx = 200
Boxfill(0 , 89) -(tx , 97) , 1
Boxfill(tx , 89) -(200 , 97) , 0
'*******************************************************************************
'Außen-Temperatur Berechnen
1wreset
1wwrite &H55
1wwrite Id2(1) , 8
1wwrite &HBE
Ar2(1) = 1wread(9)
1wreset
Tmp2 = Ar2(1) And 1
If Tmp2 = 1 Then Decr Ar2(1)
T3 = Makeint(ar2(1) , Ar2(2))
T3 = T3 * 50
T3 = T3 - 25
T4 = Ar2(8) - Ar2(7)
T4 = T4 * 100
T4 = T4 / Ar2(8)
T3 = T3 + T4
T3 = T3 / 10
Ty = T3
T8 = T3 / 10
T6 = Fusing(t8 , "###.0" )
Ty = Ty / 5
Ty = Ty + 50
If Ty < 1 Then Tx = 0
If Ty > 200 Then Tx = 200
Boxfill(0 , 113) -(ty , 121) , 1
Boxfill(ty , 113) -(200 , 121) , 0
'*******************************************************************************
Pwmx = Pwm1 / 5
If Pwmx < 1 Then Pwmx = 0
If Pwmx > 200 Then Pwmx = 200
Boxfill(0 , 65) -(pwmx , 73) , 1
Boxfill(pwmx , 65) -(200 , 73) , 0
Xold = Pwmx
'*******************************************************************************
Locate 8 , 1
Lcd "PWM:"
Locate 8 , 5
If Pwm1 < 1000 Then Lcd " ";
If Pwm1 < 100 Then Lcd " ";
If Pwm1 < 10 Then Lcd " ";
Lcd Pwm1
'*******************************************************************************
Locate 11 , 1
Lcd "Innen: " ; T5 ; "'C"
Locate 14 , 1
Lcd "Aussen: " ; T6 ; "'C"
If Ticks = 1 Then Out1 = 1
If Ticks = 5 Then Out1 = 0
Loop
End
'*******************************************************************************
'Timer Intrupt auswertung
Timer0isr:
Ticks = Ticks + 1
'*******************************************************************************
If Ticks = 1 Then
If S1 = 0 Then Sw1 = Sw1 + 1 Else Sw1 = 0
If Sw1 > 100 Then Sw1 = 100
If S2 = 0 Then Sw2 = Sw2 + 1 Else Sw2 = 0
If Sw2 > 100 Then Sw2 = 100
If S3 = 0 Then Sw3 = Sw3 + 1 Else Sw3 = 0
If Sw3 > 100 Then Sw3 = 100
If S4 = 0 Then Sw4 = Sw4 + 1 Else Sw4 = 0
If Sw4 > 100 Then Sw4 = 100
End If
'*******************************************************************************
If Ticks = 2 Then
If Sw1 = 3 Then
Pwm1 = Pwm1 + 10
If Pwm1 > 1020 Then Pwm1 = 1020
End If
If Sw1 = 100 Then
Pwm1 = Pwm1 + 10
If Pwm1 > 1020 Then Pwm1 = 1020
End If
If Sw2 = 3 Then
Pwm1 = Pwm1 - 10
If Pwm1 < 0 Then Pwm1 = 0
End If
If Sw2 = 100 Then
Pwm1 = Pwm1 - 10
If Pwm1 < 0 Then Pwm1 = 0
End If
If Pwm1 <> Pwm1old Then
Writeeeprom Pwm1 , &H20
End If
Pwm1a = Pwm1
Pwm1old = Pwm1
End If
'*******************************************************************************
If Ticks = 3 Then
If Sw3 = 3 Then
If Ledblink = 1 Then
Ledblink = 0
'Print W
Else
Ledblink = 1
End If
End If
End If
'*******************************************************************************
If Ticks = 4 Then
Ledtimer = Ledtimer + 1
If Ledtimer > 100 Then Ledtimer = 0
If Ledtimer = 1 Then
If Ledblink = 1 Then Out2 = 1
End If
If Ledtimer = 50 Then Out2 = 0
End If
'*******************************************************************************
If Ticks = 5 Then
End If
'*******************************************************************************
If Ticks = 6 Then
If Sw4 = 3 Then Cls
End If
'*******************************************************************************
If Ticks = 10 Then Ticks = 0
Return
End