Danke an Harry der mir dabei geholfen hat.
das einzige was ich noch nicht hinbekommen habe ist das ich $B0 LCD Adr vorher setzen muss
LCD_Adr:= $B0; // immer vor gDispRefresh setzen
gDispRefresh; // senden
program gOLed;
{ $BOOTRST $03800} {Reset Jump to $03800}
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = mega32, VCC=5;
Import SysTick, LCDGraphic, I2Cport;
From System Import ;
From LCDGraphic Import CharSet; {block CharSet, pixels}
Define
ProcClock = 14745600; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
LCDGraphic = 128, 64, 8; {x-pix, y-pix, accesswidth}
GViewports = 1, iData; {logical ViewPorts, scalings}
DefCharSet = 'Graphchars.pchr'; {FileName}
TGraphStr = 21; {Graphic Text String Length}
LCDgraphMode = column, iData; // linear, column, readonly
I2Cport = PortB;
I2Cdat = 4;
I2Cclk = 3,0;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
Const
SCREEN_HOR_SIZE : byte = 128;
SCREEN_VER_SIZE : byte = 64;
SSD1306_SETCONTRAST : byte = $81;
SSD1306_DISPLAYALLON_RESUME : byte = $A4;
SSD1306_DISPLAYALLON : byte = $A5;
SSD1306_NORMALDISPLAY : byte = $A6;
SSD1306_INVERTDISPLAY : byte = $A7;
SSD1306_DISPLAYOFF : byte = $AE;
SSD1306_DISPLAYON : byte = $AF;
SSD1306_SETDISPLAYOFFSET : byte = $D3;
SSD1306_SETCOMPINS : byte = $DA;
SSD1306_SETVCOMDETECT : byte = $DB;
SSD1306_SETDISPLAYCLOCKDIV : byte = $D5;
SSD1306_SETPRECHARGE : byte = $D9;
SSD1306_SETMULTIPLEX : byte = $A8;
SSD1306_SETLOWCOLUMN : byte = $00;
SSD1306_SETHIGHCOLUMN : byte = $10;
SSD1306_SETSTARTLINE : byte = $40;
SSD1306_MEMORYMODE : byte = $20;
SSD1306_COLUMNADDR : byte = $21;
SSD1306_PAGEADDR : byte = $22;
SSD1306_COMSCANINC : byte = $C0;
SSD1306_COMSCANDEC : byte = $C8;
SSD1306_SEGREMAP : byte = $A1;
SSD1306_CHARGEPUMP : byte = $8D;
SSD1306_EXTERNALVCC : byte = $1;
SSD1306_SWITCHCAPVCC : byte = $2;
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
ii : word;
LCD_Adr : byte;
procedure InitPorts;
begin
PortA := %00000111;
DDRA := %00000000;
PortB := %00011000;
DDRB := %00011000;
PortC := %00000011;
DDRC := %00000011;
PortD := %00110000;
DDRD := %00110000;
end InitPorts;
//$80 = Command
//$C0 = ein Datenbyte
//$40 = kontinuierlich Datenbytes
//------------------------------------------------------------------------------
// Sende Command Oled
//------------------------------------------------------------------------------
Procedure ssd1306_command(cmd1 : byte);
Begin
I2Cout($3C,$80,cmd1);
end ssd1306_command;
//------------------------------------------------------------------------------
// Sende Data Oled
//------------------------------------------------------------------------------
Procedure ssd1306_data(cmd1 : byte);
Begin
I2Cout($3C,$40,cmd1);
end ssd1306_data;
//------------------------------------------------------------------------------
// Setze Oled Adresse
//------------------------------------------------------------------------------
Procedure SetAddress(page, lowerAddr, higherAddr : Byte);
Begin
ssd1306_command(page);
ssd1306_command(lowerAddr);
ssd1306_command(higherAddr);
End SetAddress;
//------------------------------------------------------------------------------
// // 0111100 = $3C I2C Adresse
//------------------------------------------------------------------------------
Procedure Init_OLED;
Begin
if I2Cstat($3C) then
// Init sequence for 128x64 OLED module
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_command($80); // the suggested ratio 0x80
// Multiplex Ratio
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_command($3F); // alt 3F
// Display Offset
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_command($0); // no offset
//Display Startline
ssd1306_command(SSD1306_SETSTARTLINE); // $40
// Set Charge Pump
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
ssd1306_command($14);
// Re-map
ssd1306_command(SSD1306_SEGREMAP); // A1
// COM Output Scan Direction
ssd1306_command(SSD1306_COMSCANDEC); // C8
// COM Pins Hardware Configuration
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
ssd1306_command($12);
// Contrast Control Register
ssd1306_command(SSD1306_SETCONTRAST); // 0x81 Contrast
ssd1306_command($CF);
// Set Pre Charge Period
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
ssd1306_command($F1); // alt 22 // $22 - External, $F1 - Internal
// Set VCOMH Deselect level
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_command($40); // $40 $20
// Display OFF
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
//--turn on oled panel
ssd1306_command(SSD1306_DISPLAYON); // 0xAF
endif;
end Init_OLED;
{$D-}
UserDevice GraphIOS(cmd : byte; arg : byte);
// cmd=0 bedeutet RAM-Adresse auf oben links stellen
// cmd=1 bedeutet Datenausgabe
begin
if cmd = 0 then
SetAddress(LCD_Adr, $00, $10);
ii:=0;
else
If ii < 128 then
ssd1306_data(arg);
Inc(ii);
if ii > 127 then
inc(LCD_Adr);
SetAddress(LCD_Adr, $00, $10);
ii:= 0;
endif;
EndIf;
EndIf;
end;
{$D+}
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
EnableInts;
InitPorts;
mDelay(50);
Init_OLED;
mDelay(350); // Muss rein sonst Display dunkel
gClrScr(0);
gDrawRect(0,0,127,63,$FF);
gDrawString(10,30,2,2,TxtRot0,'Hello');
gDrawString(10,50,1,1,TxtRot0,'hello !!!');
LCD_Adr:= $B0; // immer vor gDispRefresh setzen
gDispRefresh; // senden
loop
endloop;
end gOLed.
das einzige was ich noch nicht hinbekommen habe ist das ich $B0 LCD Adr vorher setzen muss
LCD_Adr:= $B0; // immer vor gDispRefresh setzen
gDispRefresh; // senden
Code
program gOLed;
{ $BOOTRST $03800} {Reset Jump to $03800}
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = mega32, VCC=5;
Import SysTick, LCDGraphic, I2Cport;
From System Import ;
From LCDGraphic Import CharSet; {block CharSet, pixels}
Define
ProcClock = 14745600; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
LCDGraphic = 128, 64, 8; {x-pix, y-pix, accesswidth}
GViewports = 1, iData; {logical ViewPorts, scalings}
DefCharSet = 'Graphchars.pchr'; {FileName}
TGraphStr = 21; {Graphic Text String Length}
LCDgraphMode = column, iData; // linear, column, readonly
I2Cport = PortB;
I2Cdat = 4;
I2Cclk = 3,0;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
Const
SCREEN_HOR_SIZE : byte = 128;
SCREEN_VER_SIZE : byte = 64;
SSD1306_SETCONTRAST : byte = $81;
SSD1306_DISPLAYALLON_RESUME : byte = $A4;
SSD1306_DISPLAYALLON : byte = $A5;
SSD1306_NORMALDISPLAY : byte = $A6;
SSD1306_INVERTDISPLAY : byte = $A7;
SSD1306_DISPLAYOFF : byte = $AE;
SSD1306_DISPLAYON : byte = $AF;
SSD1306_SETDISPLAYOFFSET : byte = $D3;
SSD1306_SETCOMPINS : byte = $DA;
SSD1306_SETVCOMDETECT : byte = $DB;
SSD1306_SETDISPLAYCLOCKDIV : byte = $D5;
SSD1306_SETPRECHARGE : byte = $D9;
SSD1306_SETMULTIPLEX : byte = $A8;
SSD1306_SETLOWCOLUMN : byte = $00;
SSD1306_SETHIGHCOLUMN : byte = $10;
SSD1306_SETSTARTLINE : byte = $40;
SSD1306_MEMORYMODE : byte = $20;
SSD1306_COLUMNADDR : byte = $21;
SSD1306_PAGEADDR : byte = $22;
SSD1306_COMSCANINC : byte = $C0;
SSD1306_COMSCANDEC : byte = $C8;
SSD1306_SEGREMAP : byte = $A1;
SSD1306_CHARGEPUMP : byte = $8D;
SSD1306_EXTERNALVCC : byte = $1;
SSD1306_SWITCHCAPVCC : byte = $2;
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
ii : word;
LCD_Adr : byte;
procedure InitPorts;
begin
PortA := %00000111;
DDRA := %00000000;
PortB := %00011000;
DDRB := %00011000;
PortC := %00000011;
DDRC := %00000011;
PortD := %00110000;
DDRD := %00110000;
end InitPorts;
//$80 = Command
//$C0 = ein Datenbyte
//$40 = kontinuierlich Datenbytes
//------------------------------------------------------------------------------
// Sende Command Oled
//------------------------------------------------------------------------------
Procedure ssd1306_command(cmd1 : byte);
Begin
I2Cout($3C,$80,cmd1);
end ssd1306_command;
//------------------------------------------------------------------------------
// Sende Data Oled
//------------------------------------------------------------------------------
Procedure ssd1306_data(cmd1 : byte);
Begin
I2Cout($3C,$40,cmd1);
end ssd1306_data;
//------------------------------------------------------------------------------
// Setze Oled Adresse
//------------------------------------------------------------------------------
Procedure SetAddress(page, lowerAddr, higherAddr : Byte);
Begin
ssd1306_command(page);
ssd1306_command(lowerAddr);
ssd1306_command(higherAddr);
End SetAddress;
//------------------------------------------------------------------------------
// // 0111100 = $3C I2C Adresse
//------------------------------------------------------------------------------
Procedure Init_OLED;
Begin
if I2Cstat($3C) then
// Init sequence for 128x64 OLED module
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_command($80); // the suggested ratio 0x80
// Multiplex Ratio
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_command($3F); // alt 3F
// Display Offset
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_command($0); // no offset
//Display Startline
ssd1306_command(SSD1306_SETSTARTLINE); // $40
// Set Charge Pump
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
ssd1306_command($14);
// Re-map
ssd1306_command(SSD1306_SEGREMAP); // A1
// COM Output Scan Direction
ssd1306_command(SSD1306_COMSCANDEC); // C8
// COM Pins Hardware Configuration
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
ssd1306_command($12);
// Contrast Control Register
ssd1306_command(SSD1306_SETCONTRAST); // 0x81 Contrast
ssd1306_command($CF);
// Set Pre Charge Period
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
ssd1306_command($F1); // alt 22 // $22 - External, $F1 - Internal
// Set VCOMH Deselect level
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_command($40); // $40 $20
// Display OFF
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
//--turn on oled panel
ssd1306_command(SSD1306_DISPLAYON); // 0xAF
endif;
end Init_OLED;
{$D-}
UserDevice GraphIOS(cmd : byte; arg : byte);
// cmd=0 bedeutet RAM-Adresse auf oben links stellen
// cmd=1 bedeutet Datenausgabe
begin
if cmd = 0 then
SetAddress(LCD_Adr, $00, $10);
ii:=0;
else
If ii < 128 then
ssd1306_data(arg);
Inc(ii);
if ii > 127 then
inc(LCD_Adr);
SetAddress(LCD_Adr, $00, $10);
ii:= 0;
endif;
EndIf;
EndIf;
end;
{$D+}
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
EnableInts;
InitPorts;
mDelay(50);
Init_OLED;
mDelay(350); // Muss rein sonst Display dunkel
gClrScr(0);
gDrawRect(0,0,127,63,$FF);
gDrawString(10,30,2,2,TxtRot0,'Hello');
gDrawString(10,50,1,1,TxtRot0,'hello !!!');
LCD_Adr:= $B0; // immer vor gDispRefresh setzen
gDispRefresh; // senden
loop
endloop;
end gOLed.
You must be logged in or your permissions are to low to see this Attachment(s).