ich betreibe das display per TWI mit einem PCA9555. die negative kontrastspannung erzeuge ich mit einem MAX202
Code
Import SysTick, TWIMaster;
LCDGraphic = 128, 32, 8;
LCDgraphMode = column, iData;
DefCharSet = 'Graphchars.pchr';
GViewports = 1, iData;
TGraphStr = 8;
Const
PCA9555 : Byte = $20;
Var
CtrlPortSave : Byte;
Col : Byte; { column counter }
CurRow : Byte; { storage for 2. controller }
IsCtrlTwo : Boolean;
Procedure WriteLCD(Arg: Byte; IsData: Boolean);
Var Mask : Byte;
Begin
If IsData
then
Mask:=$14; // Daten
else
Mask:=$10; // Befehl
EndIf;
TWIOut(PCA9555,$02,Arg); // Output arg
If IsCtrlTwo
then
TWIOut(PCA9555,$03,(Mask or $08)); // Controller 2
else
TWIOut(PCA9555,$03,(Mask or $01)); // Controller 1
EndIf;
TWIOut(PCA9555,$03,Mask);
End WriteLCD;
Procedure GraphInit;
Begin
IsCtrlTwo := false; // controller 1
WriteLCD(%10101111,false); // display on
WriteLCD(%11000000,false); // start line 0
WriteLCD(%10111000,false); // page 0
WriteLCD(%00000000,false); // address 0
IsCtrlTwo := true; // controller 2
WriteLCD(%10101111,false); // display on
WriteLCD(%11000000,false); // start line 0
WriteLCD(%10111000,false); // page 0
WriteLCD(%00000000,false); // address 0
gClrScr(0);
gDispRefresh;
End GraphInit;
{$D-}
UserDevice GraphIOS(Cmd: Byte; Arg: byte);
Begin
If Cmd=0 then // set row addr
CurRow:=arg;
IsCtrlTwo:=false; // controller 1
WriteLCD(%10111000+CurRow,false); // page
WriteLCD(%00000000,false); // address 0
Col:= 0;
else
If Col=61 // if column = 61 then switch to controller 2
then
IsCtrlTwo:=true; // controller 2
WriteLCD(%10111000+CurRow,false); // page
WriteLCD(%00000000,false); // address 0
WriteLCD(Arg,true);
Inc(Col);
else
If Col<122
then // only column 0..121 are valid
WriteLCD(Arg,true);
Inc(Col);
Endif;
EndIf;
EndIf;
End GraphIOS;
{$D+}
Procedure Init9555;
Begin
TWIout(PCA9555,$02,0); // all pins null - Datenport
TWIout(PCA9555,$03,0); // all pins null - Controlport
TWIout(PCA9555,$06,0); // all pins output
TWIout(PCA9555,$07,0); // all pins output
MDelay(10);
TWIout(PCA9555,$03,$10); // remove reset
End Init9555;