Ich verwende die Demo "XGraph_OLED128x64" so wie sie von E-Lab zum Avrco dazu gegeben wurde.
Habe dann nur mal testweise ein paar Linien aufs Display gemalt, sonst alles gleich gelassen.
Code
{******************************************************************************}
{* Demo for SSD1306-OLED-Controller with LCDGraphic *}
{* Resolution: 128x64 Pixel 0.96" and 1.3" sizes *}
{* Interface: I²C on Port E *}
{* Terminal: Port D0 *}
{* ELAB XMega Evaluation Board A3/A4 *}
{******************************************************************************}
{ $DEFINE OLED13} // 1.3"OLED !!!!!!!!!!!!!!!!
program XGraph_OLED128x64;
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = XMega256A3U, VCC = 3.3;
{ $BOOTRST $20000} {Reset Jump to $20000}
import SysTick, TWI_E, LCDGraphic, BeepPort, SerPortC0, SysLEDblink;
from LCDGraphic import CharSet; {block CharSet, pixels}
define
// The XMegas don't provide any Oscillator fuses.
// So the application must setup the desired values
// possible OSC types: extXTAL, extClock, ext32kHz, int32Khz, int2MHz, int32MHz
//>> CPU=32MHz, PeripherX4=32MHz, PeripherX2=32MHz
OSCtype = int32MHz,
PLLmul = 4,
prescB = 1,
prescC = 1;
SysTick = 10; // msec
StackSize = $0064, iData;
FrameSize = $0100, iData;
BeepPort = PortR.0;
SysLEDblink = mSec300; // 10..1000 msec
SysLEDBlink0 = PortR.1, low;
SerPortC0 = 19200, ParNone, Stop1, Databit8;
TxBufferC0 = 16, iData;
RxBufferC0 = 8, iData;
TWIPrescE = TWI_BR800;
LCDGraphic = 128, 64, 8; {x-pix, y-pix, accesswidth}
LCDgraphMode = column, iData;
DefCharSet = 'Graphchars.pchr'; {FileName}
GViewports = 1, iData; {logical ViewPorts, scalings}
TGraphStr = 16; {Graphic Text String Length}
implementation
{$IDATA}
const
// definitions for 2 bitmap types
BmpSize8x8 : byte = (8 * 8 div 8) + 2;
BmpSize16x32 : byte = (16 * 32 div 8) + 2;
BmpSize32x32 : byte = (32 * 32 div 8) + 2;
{--------------------------------------------------------------}
{ Type Declarations }
type
// we need a few array types where we can insert the bitmaps
tBMP8 = array[1..BmpSize8x8] of byte;
tBMP32 = array[1..BmpSize32x32] of byte;
tArrows = array[0..3, 1..BmpSize8x8] of byte;
tChips = array[0..15, 1..BmpSize16x32] of byte;
{--------------------------------------------------------------}
const
// constant which contain the bitmaps
ELABbmp : tBMP32 = 'E-LAB.pbmp';
Arrows : tArrows = 'Arr_N.pbmp', 'Arr_W.pbmp', 'Arr_S.pbmp', 'Arr_E.pbmp';
ChipsV : tChips = 'ChipV0.pbmp', 'ChipV1.pbmp', 'ChipV2.pbmp', 'ChipV3.pbmp',
'ChipV4.pbmp', 'ChipV5.pbmp', 'ChipV6.pbmp', 'ChipV7.pbmp',
'ChipV8.pbmp', 'ChipV9.pbmp', 'ChipV10.pbmp', 'ChipV11.pbmp',
'ChipV12.pbmp', 'ChipV13.pbmp', 'ChipV14.pbmp', 'ChipV15.pbmp';
ChipsH : tChips = 'ChipH0.pbmp', 'ChipH1.pbmp', 'ChipH2.pbmp', 'ChipH3.pbmp',
'ChipH4.pbmp', 'ChipH5.pbmp', 'ChipH6.pbmp', 'ChipH7.pbmp',
'ChipH8.pbmp', 'ChipH9.pbmp', 'ChipH10.pbmp', 'ChipH11.pbmp',
'ChipH12.pbmp', 'ChipH13.pbmp', 'ChipH14.pbmp', 'ChipH15.pbmp';
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
bb, idx,
bright, co : byte;
i : integer;
ch : char;
{--------------------------------------------------------------}
{ functions }
{$NOFRAME}
procedure WriteLCDCmd(Arg : byte);
begin
TWIOutE($3C, $80, Arg); // cmd
end;
{$NOFRAME}
procedure WriteLCD(Arg : byte);
begin
TWIOutE($3C, $40, Arg); // data
end WriteLCD;
procedure GraphInit;
begin
WriteLCDCmd($AE); // display off
WriteLCDCmd($D5); // set osc division
WriteLCDCmd($80); //
WriteLCDCmd($A8); // multiplex ratio
WriteLCDCmd($3F); // duty=1/32
WriteLCDCmd($D3); // set vertical shift by COM
WriteLCDCmd($00); //
WriteLCDCmd($8D); // set charge pump enable
WriteLCDCmd($14); // $10=disable
WriteLCDCmd($20); // set memory addressing mode
WriteLCDCmd($02); // page addressing mode
WriteLCDCmd($C8); // COM scan direction/vertical mirror
WriteLCDCmd($DA); // set COM pins
WriteLCDCmd($12); //
WriteLCDCmd($81); // contrast control
WriteLCDCmd($8F); // 0-255
WriteLCDCmd($21); // set column address
WriteLCDCmd($00); // start
WriteLCDCmd($7F); // end
WriteLCDCmd($40); // set display start line
WriteLCDCmd($00); // set lower column address
WriteLCDCmd($10); // set higher column address
WriteLCDCmd($B0); // set page address
WriteLCDCmd($A1); // set segment remap/horizontal mirror
WriteLCDCmd($A6); // normal/$A7=inverse
WriteLCDCmd($D9); // set pre-charge period
WriteLCDCmd($1F); //
WriteLCDCmd($DB); // set vcomh
WriteLCDCmd($20); //
WriteLCDCmd($AF); // display on
MDelay(50);
end GraphInit;
{$D-}
userdevice GraphIOS(Cmd : byte; Arg : byte);
begin
if Cmd = 0 then
{$IFDEF OLED13} // 1.3"OLED
WriteLCDCmd($02); // set lower 4 bit of the col adr to 2
{$ELSE}
WriteLCDCmd($00); // set lower 4 bit of the col adr to 0
{$ENDIF}
WriteLCDCmd($10);
WriteLCDCmd($B0 + Arg);
else
WriteLCD(Arg);
endif;
end GraphIOS;
{$D+}
procedure SetBrightness(br : byte);
begin
WriteLCDCmd($81); // brightness control
WriteLCDCmd(br); // 0-255
end SetBrightness;
procedure SetInverse(inv : boolean);
begin
if inv = true then
WriteLCDCmd($A7); // inverse
else
WriteLCDCmd($A6); // normal
endif;
end SetInverse;
procedure MirrorH(mir : boolean); // mirror horizontal
begin
if mir = true then
WriteLCDCmd($A0); // mirrored
else
WriteLCDCmd($A1); // normal
endif;
end MirrorH;
procedure MirrorV(mir : boolean); // mirror vertical
begin
if mir = true then
WriteLCDCmd($C0); // mirrored
else
WriteLCDCmd($C8); // normal
endif;
end MirrorV;
procedure CheckSerPort;
begin
if SerStatC0 then
ch:= SerInpC0;
case ch of
'+' :
IncToLim(bright);
SetBrightness(bright);
BeepClick;
|
'-' :
DecToLim(bright);
SetBrightness(bright);
BeepClick;
|
'H' :
MirrorH(true);
BeepClick;
|
'h' :
MirrorH(false);
BeepClick;
|
'V' :
MirrorV(true);
BeepClick;
|
'v' :
MirrorV(false);
BeepClick;
|
'I' :
SetInverse(true);
BeepClick;
|
'i' :
SetInverse(false);
BeepClick;
|
else
BeepOut(2000, 5);
endcase;
gSetTextMode(wmSetPix);
gSetTextBkGnd(bkNormal);
gDrawString(30, 40, 1, 1, TxtRot0, ByteToStr(bright : 3));
gSetTextBkGnd(bkTransp);
gSetTextMode(wmXorPix);
endif;
end CheckSerPort;
procedure GraphTest;
begin
bright:= 140;
gClrScr($00);
gDrawRect(1, 1, 127, 63, $FF);
gSetTextJustify(alHorLeft, alVertTop);
gDrawString(2, 2, 1, 2, TxtRot0, 'Test1');
gDrawString(2, 20, 1, 2, TxtRot0, Test2');
gDrawString(2, 40, 1, 2, TxtRot0, 'Test3');
gDispRefresh;
MDelay(100);
end GraphTest;
procedure GraphTest2;
begin
bright:= 140;
gDrawRect(0, 0, 127, 63, $AA);
gDrawRect(49, 6, 125, 56, $FF);
gDispRefresh;
MDelay(100);
gDrawBitMap(10, 10, @ELABbmp, wmSetPix);
gDispRefresh;
MDelay(100);
gFillRect(10, 10, 42, 42, 0);
gDispRefresh;
gSetTextJustify(alHorCenter, alVertBottom);
gSetTextBkGnd(bkTransp);
gSetTextMode(wmSetPix);
gDrawString(30, 40, 1, 1, TxtRot0, ByteToStr(bright : 3));
gDrawString(62, 54, 1, 1, TxtRot0, 'Test');
gSetTextMode(wmXorPix);
gDrawString(90, 33, 2, 2, TxtRot0, 'E-LAB');
gDrawString(90, 42, 1, 1, TxtRot0, 'Computers');
gDrawString(62, 27, 1, 1, TxtRot90, 'AVRco');
gDispRefresh;
MDelay(5);
loop
for i:= 1 to 44 do
gDrawString(61 + i, 54, 1, 1, TxtRot0, 'Test');
gDrawString(62 + i, 54, 1, 1, TxtRot0, 'Test');
gDispRefresh;
CheckSerPort;
MDelay(30);
endfor;
for i:= 44 downto 1 do
gDrawString(62 + i, 54, 1, 1, TxtRot0, 'Test');
gDrawString(61 + i, 54, 1, 1, TxtRot0, 'Test');
gDispRefresh;
CheckSerPort;
MDelay(30);
endfor;
Inc(bb);
if bb > 3 then
bb:= 0;
endif;
gDrawBitMapN(29, 16, @Arrows[bb, 1], wmSetPix);
for idx:= 0 to 15 do
gDrawBitMapN(2, 3, @ChipsV[idx, 1], wmSetPix);
gDrawBitMapN(15, 45, @ChipsH[idx, 1], wmSetPix);
gDrawString(30, 58, 1, 1, TxtRot0, 'ABC');
gDispRefresh;
CheckSerPort;
MDelay(30);
endfor;
MDelay(100);
Inc(bb);
if bb > 3 then
bb:= 0;
endif;
gDrawBitMapN(29, 16, @Arrows[bb, 1], wmSetPix);
for idx:= 15 downto 0 do
gDrawBitMapN(2, 3, @ChipsV[idx, 1], wmSetPix);
gDrawBitMapN(15, 45, @ChipsH[idx, 1], wmSetPix);
gDrawString(30, 58, 1, 1, TxtRot0, 'ABC');
gDispRefresh;
CheckSerPort;
MDelay(30);
endfor;
MDelay(100);
endloop;
end GraphTest2;
{------------------------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
EnableInts($87);
//BeepChirpL(3);
SysLEDflashAllOn;
beepout(1200,10);
Writeln(SerOutC0, 'AVRco LCD-Graphic Test');
Writeln(SerOutC0, '+ & - contrast/Brightness');
Writeln(SerOutC0, 'H & h horizontal mirror on/off');
Writeln(SerOutC0, 'V & v vertical mirror on/off');
Writeln(SerOutC0, 'I & i display inverse/normal');
GraphInit;
gClrScr(0);
gSetTextJustify(alHorCenter, alVertTop);
GraphTest;
loop
endloop;
end XGraph_OLED128x64.