'TRX-Lüfter Regelung mit ATtiny26L
'---------------------------------- '
' Stand 21.07.2004 17:51 Uhr

$regfile = "at26def.dat"
$crystal = 1000000

'Ein- und Ausgänge definieren
' 0 = Eingang, 1 = Ausgang
'Eingänge--------------------------
Ddra.0 = 0                                                  'Taster PTT TX/RX

'PullUp´s -------------------------
Porta.0 = 1                                                 'PullUp

'Ausgänge---------------------------
Ddrb.1 = 1

' Ports beim µC Start Ein-oder-Ausschalten
Portb.1 = 1
Tccr1a = &B01000011
Tccr1b = &B10000001
'Tccr1b = &B10000011

'Variablen Temp
Dim Ad As Word
Dim Ad0 As Word
Dim Ad1 As Word
Dim V As Bit
Dim W As Bit
'Ocr1c = 254
Ocr1c = 255

'Config Sda = Porta.1                                        'I²C Bus
'Config Scl = Porta.2

'Dim Lm75write As Byte
'Dim Lm75read As Byte
'Dim Lm75high As Word
''Dim Lm75low As Byte
'Dim Lm75da As Byte
'Dim Adout As Byte
' LM75 Addresse definieren, AD0 - AD2 auf Masse !!
'Lm75write = &B10010000                                      'DA-Write Addy
'Lm75read = &B10010001                                       'DA-Read Addy
'Lm75da = &B01000000                                         'DA-Modus
'Lm75high = 180                                              'Spannungswert

'--- LCD und A/D Wander configurieren -----------------------------------------
'
' AD-Wandler konfigurieren
Config Adc = Single , Prescaler = Auto                      ', Reference = Avcc

'                                 |----------------------------|
'---------------------------------| Ab hier das ganze Programm |-------------------------
'                                 |----------------------------|
Ocr1a = 254
Wait 1
Ocr1a = 0
Waitms 200
Ocr1a = 254
Waitms 200
Ocr1a = 0
Waitms 200
 Ocr1a = 254
Waitms 200
Ocr1a = 0
Waitms 200
Main:

Do
 'Ocr1a = 100

  '---- Hier Röhren-Temp auswerten für Sperre Anfang--------
   Temptube1:
    Start Adc                                               'A/D starten
    Ad = Getadc(3)                                          'Hole Wert vom AD3 und schreibe in Ad0
    Stop Adc
   Ad0 = Ad - 682                                           'RX
   Ad1 = Ad - 682                                           'TX
   Ad1 = Ad1 * 1

    'If Pina.0 = 1 Then
    '   Ad0 = Ad0 - 575                                      ' RX- 31°C
    '  Else
    '   Ad0 = Ad0 - 575                                      ' TX  31°X
    '   End If

    ' RX!
 '''If Pina.0 = 1 Then Ocr1a = 0

    If Ad0 < 62 And V = 1 And Pina.0 = 1 Or Ad0 < 55 And Pina.0 = 1 Then       '150 = 36°C
         V = 1
         Ocr1a = 0                                          'Hyst
       Else
         If Pina.0 = 1 And Ad0 < 80 Then
         V = 0
         Ocr1a = Ad0 - 10
         Else
         End If
         'V = 0
     End If

     'TX
     If Ad1 < 50 And W = 1 And Pina.0 = 0 Or Ad1 < 45 And Pina.0 = 0 Then       '150 = 36°C
        W = 1
        Ocr1a = 0                                           'Hyst
       Else
         If Pina.0 = 0 And Ad1 < 70 Then
         W = 0
         'Ad1 = Ad1                                          '* 2.5
         Ocr1a = Ad1 + 5
        ' Ocr1a = 0                                          '+ 12
         Else
         End If
         'V = 0
     End If

 'Ocr1a = Ad1

     ' Wann ist an:
 '    If Pina.0 = 0 Then                                     'RX
 '    Ocr1a = Ad0 * 2.6
 '    Else
     'Ocr1a = Ad0 * 2.5
 '    End If

     If Ad0 => 79 And Pina.0 = 1 Then                       'RX 50°C
        Ocr1a = 254
       Else
     End If

       If Ad1 => 70 And Pina.0 = 0 Then                     'TX 45°C                                         'A/D stoppen
        Ocr1a = 254                                         ' 254
        Else
        End If

     'I2cstart
     '     I2cwbyte Lm75write                                'I2C Gerät auswählen
     '     I2cwbyte Lm75da                                   ', Ack                                      ' Auf D/A Modus schalten
     '     I2cwbyte Lm75high                                 ', Nack                                   'Wert Volt schreiben Ack
     '    I2cstop
     '     Waitms 20

Goto Main

'##########################################################################################

 ' decrease

 Loop
End                                                         'end program