CHIPRAM DATALOG.bpp
(c) Dierk Schmid
Weitere Infos im C-Control I Info
Download Download
'//////////////////////////////////////
'//
'//  Basic++ 2006
'//  Für C-Control I M2.0 / Station2
'//  Autor: Dierk Schmid
'// 
'//  Name: ChipRam-Datenlogger
'//
'//  Beschreibung:
'//  Kleines Demo-Programm, in Form eines einfachen Datenloggers, 
'//  welches die ChipRam() Funktion bzw. Zuweisung nutzt
'//
'//  Chipram ist mit der M-Unit2.0 und Station2 ab OS 2.05 bzw. 2.06 
'//  nutzbar. 
'//  In diesem Beispiel ist ein 8k EEProm (24C64 oder 24C65) an den IIC-Bus 
'//  der C-Control angeschlossen.
'//  Es werden rollierend Tag, Stunde, Minute, Sekunde und ein Temperaturwert als 
'//  Datensatz abgespeichert. Für den Temperaturwert wird ein Zufallswert erzeugt.
'//  Die aktuelle geschriebene Position im EEProm wird ständig auf 
'//  Byte-Zelle 0 und 1 als Wordwert hinterlegt. So ist die aktuelle 
'//  Schreibe-Position im EEProm auch nach einem Reset verfügbar.
'//  Mit der Taste F2 wird diese Position auf den Anfang Chipram(5) gesetzt.
'//  Mit der Taste F1 werden die Daten auf die serielle Schnittstelle ausgegeben.     
'//
'//////////////////////////////////////
 
OPTION CC2.0  'Zielplattform

define i as Word
define RamPointer as Word
define RamPointerByte1 ref RamPointer at byte[1]
define RamPointerByte2 ref RamPointer at byte[2]

Const DataMax = 8191   'Maximaler Speicher 8K bei EEprom 24C64 bzw. 24C65 
Const Key_F1 = 12
Const Key_F2 = 13

Import "GET_KEY.blib"

Randomize Timer          'Zufallszahl

#StartLoop
Select Case Get_Key

Case Key_F1   'Ausgabe der Daten auf serielle Schnittstelle
   Print "**** C-Control Chipram-Demostration *****"
   For i = 5 to RamPointer Step 5
     Print "Tag " & ChipRam(i) & " um " & ChipRam(i+1) & ":" & ChipRam(i+2) & ":" & ChipRam(i+3) ;
     Print " Wert: " ; 
     PrintTemperature(ChipRam(i+4), true)
   Next
  
Case Key_F2   'Pointer Reset mit Taste F2
   RamPointer = 5
   Beep 3, 100, 20 
   ChipRam(0)=RamPointerByte1  '1.Byte von RamPointer auf Speicherzelle 0 legen
   ChipRam(1)=RamPointerByte2  '2.Byte von RamPointer auf Speicherzelle 1 legen
End Select

If (Second Mod 10)=0 Then         'Jede 10. Sekunde Wert wegschreiben
  WriteTemperature()
  Do                              'Schleife bis aktuelle Sekunde wieder vorüber
  Loop Until (Second Mod 10) <> 0 
End If

Goto StartLoop    'Ende Hauptschleife


Function WriteTemperature()
  RamPointerByte1 = ChipRam(0)
  RamPointerByte2 = ChipRam(1)
  RamPointer=RamPointer+5
  If RamPointer > DataMax then RamPointer = 5
  
  ChipRam(RamPointer)   = day
  ChipRam(RamPointer+1) = hour  
  ChipRam(RamPointer+2) = minute  
  ChipRam(RamPointer+3) = second
  ChipRam(RamPointer+4) = GetTemperature
  
  ChipRam(0)=RamPointerByte1  '1.Byte von RamPointer auf Speicherzelle 0 legen
  ChipRam(1)=RamPointerByte2  '2.Byte von RamPointer auf Speicherzelle 1 legen
    
  LCD.Init 
  LCD.Print "Zelle:" & Rampointer
  LCD.Pos 2,1
  LCD.Print "Wert: "  
  PrintTemperature(ChipRam(RamPointer+4), false)
  LCD.Print "  "      
  LCD.Off

End Function    

Function GetTemperature()
   Return Abs(Rand and 25)+ 180    'Hier wird ein Zufallswert 
                                   'für die Temperatur zurückgegeben 
End Function

Function PrintTemperature(iValue as byte, ToCommport as Bit)
  'Ausgabe Wert mit Kommastellen
  define TmpByte as Byte

  TmpByte=0

  ' Hunderter-Dezimalstelle 
  if iValue >= 100 then
    TmpByte = (ivalue/100)
    if ToCommport then
      Print TmpByte;
    else
      LCD.Print TmpByte
    end if
    iValue=iValue -(TmpByte * 100)
  else
    If TmpByte<>0 then
      If ToCommport then 
        Print 0;
      else
        LCD.Print 0
      end if
    end if      
  end if
  
  ' Zehner-Dezimalstelle 
  if iValue >= 10 then
    TmpByte = (Ivalue/10)
    If ToCommPort then
      Print TmpByte;
    else
      LCD.Print TmpByte
    end if    
    iValue=iValue -(TmpByte * 10)
  else
    If TmpByte<>0 then
      If ToCommport then 
        Print 0;
      else
        LCD.Print 0
      end if 
    end if     
  end if

  If ToCommport then 
    Print "," & Ivalue & "°"  ' Nachkommastelle
  else
    LCD.Print "," & Ivalue  
  end if    

End Function
Powered by C-Control I Info