Hallo Lukky,
ich verwende folgende Skript von HJH unter IPS 2.1
/*
*******************************
IP-SYMCON Event Scripting
*******************************
File : LCD_Functions.ips.php
Trigger :
Interval :
Author : HJH
Project : Utilities
Date : 03.07.08
*/
//==============================================================================
//============================== Include File ==================================
//================= Dieses Skript ist allein nicht lauffhig! ==================
//==== Die Funktionen mssen von einem Hauptprogramm aus aufgerufen werden =====
//==============================================================================
//******************************************************************************
// Class OneWireLCD
//******************************************************************************
class OneWireLCD
{
private static $Stndrd = "\x33\x32\x20\x0c\x01\x06"; // InitString fr Standard 1-zeilig
private static $KS0073 = "\x33\x32\x24\x00\x20\x0c\x01\x06"; // InitString fr KS0073 1-zeilig
private static $ST7036 = "\x33\x32\x21\x1c\x52\x69\x74\x20\x0c\x01\x06"; // InitString fr ST7036 1-zeilig
private static $sol1 = array(0, 64, 20, 84); // Zeilenstartadressen fr Standard
private static $sol2 = array(0, 32, 64, 96); // Zeilenstartadressen fr KS0073
private static $sol3 = array(0, 16, 32, 0); // Zeilenstartadressen fr ST7036
private static $ctab1 = array(''=>0x01, ''=>0x03, ''=>0x05,
''=>0x02, ''=>0x04, ''=>0x06, ''=>0x07); // Umlaut-bersetzungstabelle fr Standard
private static $ctab2 = array(''=>0x7b, ''=>0x7c, ''=>0x7e,
''=>0x5b, ''=>0x5c, ''=>0x5e, ''=>0xbe); // Umlaut-bersetzungstabelle fr KS0073
private static $ctab3 = array(''=>0x84, ''=>0x94, ''=>0x81,
''=>0x8e, ''=>0x99, ''=>0x9a, ''=>0x07); // Umlaut-bersetzungstabelle fr ST7036
private static $asumlt = "\x0a\x00\x0e\x01\x0f\x11\x0f\x00"; // Zeichendefinition ''
private static $acumlt = "\x11\x04\x0a\x11\x1f\x11\x11\x00"; // Zeichendefinition ''
private static $osumlt = "\x0a\x00\x0e\x11\x11\x11\x0e\x00"; // Zeichendefinition ''
private static $ocumlt = "\x11\x0e\x11\x11\x11\x11\x0e\x00"; // Zeichendefinition ''
private static $usumlt = "\x0a\x00\x11\x11\x11\x13\x0d\x00"; // Zeichendefinition ''
private static $ucumlt = "\x11\x00\x11\x11\x11\x11\x0e\x00"; // Zeichendefinition ''
private static $ssharp = "\x06\x09\x11\x12\x11\x11\x16\x10"; // Zeichendefinition ''
private $Controller;
private $InitString;
private $InstanceID;
private $rows;
private $cols;
// public functions ===========================================================
// Constructor ----------------------------------------------------------------
public function __construct($InstanceID, $ControllerType, $rows, $cols)
{
$this->InstanceID = $InstanceID;
$this->rows = $rows;
$this->cols = $cols;
$this->Controller = $ControllerType;
switch ($this->Controller)
{
case "KS0073":
$this->InitString = self::$KS0073;
if ($rows > 1)
{
$this->InitString[2] = chr(0x2c); // InitString-Ergnzung fr 2-zeilige Displays
$this->InitString[4] = chr(0x28);
}
if ($rows == 4) $this->InitString[3] = chr(0x09); // InitString-Ergnzung fr 4-zeilige Displays
break;
case "ST7036":
$this->InitString = self::$ST7036;
if ($rows > 1)
{
$this->InitString[2] = chr(0x29); // InitString-Ergnzung fr 2-zeilige Displays
$this->InitString[7] = chr(0x28);
}
if ($rows == 3) $this->InitString[3] = chr(0x1d); // InitString-Ergnzung fr 3-zeilige Displays
break;
case "Standard":
default:
$this->InitString = self::$Stndrd;
if ($rows > 1) $this->InitString[2] = chr(0x28); // InitString-Ergnzung fr mehrzeilige Displays
break;
}
}
// LCD-Initialisierung --------------------------------------------------------
public function SendLCDInit()
{
TMEX_F29_SetStrobe($this->InstanceID, TRUE);
IPS_Sleep(100);
$sendbuf = $this->MakeCmd($this->InitString);
// Init-String ausgeben
$this->WriteLCDData($sendbuf);
// deutsche Sonderzeichen definieren
switch ($this->Controller)
{
case "KS0073":
// keine Definition erforderlich
break;
case "ST7036":
$this->SendLCDCharDef(7, self::$ssharp); //
break;
default:
$this->SendLCDCharDef(1, self::$asumlt); //
$this->SendLCDCharDef(2, self::$acumlt); //
$this->SendLCDCharDef(3, self::$osumlt); //
$this->SendLCDCharDef(4, self::$ocumlt); //
$this->SendLCDCharDef(5, self::$usumlt); //
$this->SendLCDCharDef(6, self::$ucumlt); //
$this->SendLCDCharDef(7, self::$ssharp); //
}
}
// Display lschen ------------------------------------------------------------
public function SendLCDClear()
{
$sendbuf = $this->ClearDisplay();
// Befehl ausgeben
$this->WriteLCDData($sendbuf);
}
// Cursor ein-/ausschalten ----------------------------------------------------
public function SendLCDCursor($cstate)
{
$sendbuf = $this->SwitchCursor($cstate);
// Befehl ausgeben
$this->WriteLCDData($sendbuf);
}
// Cursor positionieren -------------------------------------------------------
public function SendLCDCpos($row, $col)
{
if (($row >= $this->rows) || ($col >= $this->cols)) return;
$sendbuf = $this->CalcCursorPos($row, $col);
// Befehl ausgeben
$this->WriteLCDData($sendbuf);
}
// Text an bestimmter Cursor-Position ausgeben --------------------------------
// Zeilenberlauf wird nicht bercksichtigt!
public function SendLCDText($row, $col, $text)
{
if (($row >= $this->rows) || ($col >= $this->cols)) return;
$sendbuf = "";
// Cursor-Position setzen
$sendbuf .= $this->CalcCursorPos($row, $col);
// Text-String erzeugen
$sendbuf .= $this->MakeTxt($text);
// Text-String ausgeben
$this->WriteLCDData($sendbuf);
}
// Ausgabe auf das gesamte LCD ------------------------------------------------
public function SendLCDScreen($text)
{
$sendbuf = "";
$currentline = 0;
$lines = explode("|", $text);
// Display lschen
$sendbuf .= $this->ClearDisplay();
// Cursor ausschalten
$sendbuf .= $this->SwitchCursor(false);
foreach($lines as $line)
{
// Cursor positionieren
$sendbuf .= $this->CalcCursorPos($currentline, 0);
// Text-String erzeugen
$line = substr($line, 0, $this->cols);
$sendbuf .= $this->MakeTxt($line);
$currentline++;
if ($currentline >= $this->rows) break;
}
// Text-String ausgeben
$this->WriteLCDData($sendbuf);
}
// eigene Zeichen definieren --------------------------------------------------
public function SendLCDCharDef($num, $data)
{
$str = "";
if ($this->Controller == "ST7036") $str .= chr(0x28);// instruction table 0
// Speicherposition setzen (0...7)
$str .= chr((($num & 0x07) << 3) | 0x40);
$sendbuf = $this->MakeCmd($str);
// Zeichendaten erzeugen
$sendbuf .= $this->MakeTxt($data);
// Command-String ausgeben
$this->WriteLCDData($sendbuf);
}
// Kontrasteinstellung beim ST7036-Controller ---------------------------------
function SendLCDContrast($ContrastValue)
{
// Diese Funktion ist nur bei diesem Controller verfgbar!
if ($this->Controller != "ST7036") return;
$contrast = $ContrastValue & 0x3f;
$byte1 = ($this->rows == 1) ? 0x21 : 0x29; // umschalten auf Befehlstabelle 1
$byte2 = ($contrast >> 4) | 0x50;
$byte3 = ($contrast & 0x0f) | 0x70;
$byte4 = ($this->rows == 1) ? 0x20 : 0x28; // zurckschalten auf Befehlstabelle 0
$cstrg = chr($byte1). chr($byte2). chr($byte3). chr($byte4);
$sendbuf = $this->MakeCmd($cstrg);
// Command-String ausgeben
$this->WriteLCDData($sendbuf);
}
// private functions ==========================================================
// interne Funktionen
// nicht fr externe Aufrufe verfgbar ========================================
// Cursor-Position berechnen --------------------------------------------------
private function CalcCursorPos($row, $col)
{
switch ($this->Controller) // Auswahl der Zeilenstartadressen
{
case "KS0073":
if ($this->rows > 2)
$la = self::$sol2; // Sonderadressen bei 4 Zeilen
else
$la = self::$sol1; // sonst Standardadressen
break;
case "ST7036":
if ($this->rows > 2) // Sonderadressen bei 3 Zeilen
$la = self::$sol3;
else
$la = self::$sol1; // sonst Standardadressen
break;
default:
$la = self::$sol1; // sonst Standardadressen
break;
}
$adr = $la[$row] + $col;
$cpos = chr($adr | 0x80);
$sendbuf = $this->MakeNibbles($cpos, true);
return $sendbuf;
}
// Cursor ein-/ausschalten ----------------------------------------------------
private function SwitchCursor($cstate)
{
$cmd = ($cstate) ? chr(0x0f) : chr(0x0c);
return $this->MakeNibbles($cmd, true);
}
// Display lschen ------------------------------------------------------------
private function ClearDisplay()
{
return $this->MakeNibbles(chr(0x01), true);
}
// Command-String erzeugen ----------------------------------------------------
private function MakeCmd($string)
{
return $this->MakeNibbles($string, true);
}
// Text-String erzeugen -------------------------------------------------------
private function MakeTxt($string)
{
return $this->MakeNibbles($string, false);
}
// Bytes in Nibbles (Halb-Bytes) umwandeln -------------------------------------------------
// R/S-Bit fr Text setzen, fr Befehle lschen
private function MakeNibbles($string, $cmd)
{
$rs = ($cmd) ? 0 : 0x10;
$sendbuf = "";
for ($i=0; $i<strlen($string); $i++)
{
$s = ord($string[$i]);
if (!$cmd && ($s >= 0xc0))
switch ($this->Controller)
{
case "KS0073":
$s = self::$ctab2[chr($s)];
break;
case "ST7036":
$s = self::$ctab3[chr($s)];
break;
default:
$s = self::$ctab1[chr($s)];
}
$sendbuf .= chr(($s >> 4) | $rs);
$sendbuf .= chr(($s & 0x0f) | $rs);
}
return $sendbuf;
}
// Ausgabe der Befehls- oder Text-Sequenz -------------------------------------
private function WriteLCDData($string)
{
if ($string != "")
TMEX_F29_WriteBytesMasked($this->InstanceID, $string, 0x1f);
}
}
?>
…und das als Testskrip
/*
*******************************
IP-SYMCON Event Scripting
*******************************
File : LCD_Test.ips.php
Trigger :
Interval :
*/
$InstanceID = 33836; hier deine ID des DS2408 eingeben
$ControllerType = "Standard";
$Zeilen = 2;
$Spalten = 16;
$includeFile = IPS_GetScriptFile("LCD_Functions");
require_once "LCD_Functions.ips.php";
$lcd = new OneWireLCD($InstanceID, $ControllerType, $Zeilen, $Spalten);
//$lcd = new OneWireLCD($id, $ControllerType, $Zeilen, $Spalten);
$lcd->SendLCDInit();
$t1 = "Hallo ";
$t2 = "Andi";
$t3 = "Haussteuerung/";
$t4 = "IP-Symcom";
$text = $t1.$t2."|".$t3.$t4;
Echo " $text";
// | ist der Trenner 1. und 2. Zeile
$lcd->SendLCDScreen($text);