Code:
Declare Sub Oledinit()
Declare Sub Cleardisplay()
Declare Sub Filldisplay()
Declare Sub Hline(byval Xpos As Byte , Byval Ypos As Byte , Byval Laenge As Byte)
Declare Sub Vline(byval Xpos As Byte , Byval Ypos As Byte , Byval Laenge As Byte)
Declare Sub Write_byte(byval Dat_or_cmd As Byte)
Declare Sub Write_cmd(byval Command As Byte)
Declare Sub Write_dat(byval Daten As Byte)
Declare Sub Write_chars(byval Xpos As Byte , Byval Ypos As Byte , Byval Text As String)
Declare Sub Write_pic_bw(byval Xpos As Byte , Byval Ypos As Byte)
Declare Sub Write_pic_grey
Declare Sub Array_erstellen(byval Text As String)
Dim A As Integer
Dim B As Byte
Dim C As Byte
Dim D As Word
Dim E As Byte
Dim G As Byte
Dim Y As Byte
Dim X As Byte
Dim Z As Byte
Dim Ziel As Byte
Dim Xpos As Byte
Dim Xpos_temp As Byte
Dim Ypos As Byte
Dim Pos As Integer
Dim Tmp As Byte
Dim Laenge As Byte
Dim Zeile As Byte
Dim Bitmode As Byte
Dim Hoehe As Byte
Dim Breite As Byte
Dim Erg As Byte
Dim Erg1 As Byte
Dim Pic_daten_1 As Byte
Dim Pic_daten_2 As Byte
Dim Beginn_zeichen As Word
Dim Ende_zeichen As Word
Dim Db_zeiger As Word
Dim Bz As Word
Dim Ez As Byte
Dim Ti As Byte
Dim Tl As Byte
Dim Tl2 As Word
Dim Dat(102) As Byte ' max. Stringlänge (=17) * 6 Bytes
Dim Text As String * 17
Dim Einzelzeichen As String * 1
Waitms 100
Call Oledinit
Oled_12v = 1
Waitms 100
Do
Call Cleardisplay
Call Filldisplay
Wait 3
Call Cleardisplay
Call Write_chars(0 , 0 , "*****************")
Call Write_chars(0 , 1 , "* 102x80 Pixel *")
Call Write_chars(0 , 2 , "* *")
Call Write_chars(0 , 3 , "* - SSD1325 - *")
Call Write_chars(0 , 4 , "* *")
Call Write_chars(0 , 5 , "* 16 Graustufen *")
Call Write_chars(0 , 6 , "* *")
Call Write_chars(0 , 7 , "* 0123456789ABC *")
Call Write_chars(0 , 8 , "* *")
Call Write_chars(0 , 9 , "*****************")
Wait 3
Call Cleardisplay
Call Hline(7 , 12 , 100)
Call Write_chars(0 , 3 , " Jetzt auch in ")
Call Write_chars(0 , 5 , "BASCOM anwendbar ")
Call Hline(7 , 60 , 100)
Wait 3
Call Cleardisplay
Call Write_pic_bw(2 , 2)
Wait 3
Call Cleardisplay
Call Write_pic_grey
Wait 3
Loop
End
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Sendet die Initialisierungs Bytes zum Oled Controller
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Oledinit
Oled_res = 0
Waitms 100
Oled_res = 1
Waitms 200
Call Write_cmd(&H15) ' / / Set Column Address
Call Write_cmd(&H07) ' / / Begin 7 Offset!
Call Write_cmd(&H39) ' / / End 57
Call Write_cmd(&H75) ' / / Set Row Address
Call Write_cmd(&H00) ' / / Begin 0
Call Write_cmd(&H4f) ' / / End 79
Call Write_cmd(&H86) ' / / Set Current Range 84h : Quarter , 85h : Half , 86h : Full
Call Write_cmd(&H81) ' / / Set Contrast Control
Call Write_cmd(&H2d)
Call Write_cmd(&Hbe) ' / / Set Vcomh Voltage
Call Write_cmd(&H00)
Call Write_cmd(&Hbc) ' / / Set Precharge Voltage
Call Write_cmd(&H0f)
Call Write_cmd(&Ha0) ' / / Set Re -map
Call Write_cmd(&H41) ' / / Od. &H43
Call Write_cmd(&Ha6) ' / / Entire Display Off , All Pixels Turns Off
Call Write_cmd(&Ha8) ' / / Set Multiplex Ratio
Call Write_cmd(&H4f) ' / / Multiplex Ratio N From 16mux -80mux / / 80!
Call Write_cmd(&Hb1) ' / / Set Phase Length
Call Write_cmd(&H22)
Call Write_cmd(&Hb2) ' / / Set Row Period
Call Write_cmd(&H46)
Call Write_cmd(&Hb0) ' / / Set Pre -charge Compensation Enable
Call Write_cmd(&H08) '
Call Write_cmd(&Hb4) ' / / Set Pre -charge Compensation Level
Call Write_cmd(&H00) '
Call Write_cmd(&Hb3) ' / / Set Display Clock
Call Write_cmd(&Ha0)
Call Write_cmd(&Hbf) ' / / Set Segment Low Voltage(vsl)
Call Write_cmd(&H0d) '
Call Write_cmd(&Hb8) ' / / Set Gray Scale Table
Call Write_cmd(&H01)
Call Write_cmd(&H11)
Call Write_cmd(&H22)
Call Write_cmd(&H32)
Call Write_cmd(&H43)
Call Write_cmd(&H54)
Call Write_cmd(&H65)
Call Write_cmd(&H76)
Call Write_cmd(&Hae) ' / / Set Display On
Call Write_cmd(&Had) ' / / Set Master Configuration
Call Write_cmd(&H02)
Waitms 75 '; / / Dannach 75ms Pause!Print 7365us
Call Write_cmd(&Ha4) ' / / Normal Display
Call Write_cmd(&Haf) ' / / Set Display Off
Call Write_cmd(&He3) ' / / Nop
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' übergibt Daten für eine 1 Bit Grafik
' 1 Byte für 8 Pixel --> 1 Byte für 2 Pixel zum Display
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_pic_bw(byval Xpos As Byte , Byval Ypos As Byte)
D = 3
Xpos_temp = Xpos
Hoehe = Lookup(1 , Schiff)
Breite = Lookup(2 , Schiff)
Hoehe = Hoehe / 8
Decr Hoehe
Breite = Breite / 2
Decr Breite
For C = 0 To Hoehe
For B = 0 To Breite
Call Write_cmd(&H15)
Erg = Xpos + 7
Call Write_cmd(erg)
Call Write_cmd(erg)
Call Write_cmd(&H75)
Erg = Ypos * 8
Call Write_cmd(erg)
Erg = Erg + 7
Call Write_cmd(erg)
Db_zeiger = D
Pic_daten_1 = Lookup(db_zeiger , Schiff)
Db_zeiger = D + 1
Pic_daten_2 = Lookup(db_zeiger , Schiff)
For Zeile = 0 To 7
G = &H00
If Pic_daten_1.zeile = 1 And Pic_daten_2.zeile = 1 Then G = &HFF
If Pic_daten_1.zeile = 0 And Pic_daten_2.zeile = 1 Then G = &H0F
If Pic_daten_1.zeile = 1 And Pic_daten_2.zeile = 0 Then G = &HF0
Call Write_dat(g)
Next
Incr Xpos
D = D + 2
Next
Xpos = Xpos_temp
Incr Ypos
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' übergibt Daten für eine Graustufen Grafik
' 1 Byte für 8 Pixel --> 1 Byte für 2 Pixel zum Display
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_pic_grey
Hoehe = Lookup(1 , Python)
Breite = Lookup(2 , Python)
Pos = Hoehe * Breite
Pos = Pos / 2
Pos = Pos - 1
Pos = Pos + 2
Hoehe = Hoehe - 1
For Z = 0 To Hoehe
Call Write_cmd(&H15)
Call Write_cmd(7)
Erg = Breite / 2
Erg = Erg - 1
Erg = Erg + 7
Call Write_cmd(erg)
Call Write_cmd(&H75)
Call Write_cmd(z)
Call Write_cmd(z)
Erg = Breite / 2
Erg = Erg - 1
For Y = 0 To Erg
Tmp = Lookup(pos , Python)
Erg1 = Tmp
Shift Erg1 , Right , 4
X = Erg1
Shift Tmp , Left , 4
Tmp = Tmp + X
Call Write_dat(tmp)
Pos = Pos - 1
Next
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' übergibt Daten für max 17 5x7 Zeichen
' 8 Zeilen a 3 Bytes für ein Buchstabe
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_chars(byval Xpos As Byte , Byval Ypos As Byte , Byval Text As String)
Call Array_erstellen(text)
Pos = 1
B = 1
Ypos = Ypos * 8
Xpos = Xpos + 6
For C = 1 To Tl
Call Write_cmd(&H15)
Erg = Xpos + B
Call Write_cmd(erg)
Erg = Erg + 2
Call Write_cmd(erg)
Call Write_cmd(&H75)
Erg = Ypos
Call Write_cmd(erg)
Erg = Ypos + 7
Call Write_cmd(erg)
For Zeile = 0 To 7
G = &H00
If Dat(pos).zeile = 1 And Dat(pos + 1).zeile = 1 Then G = &HFF
If Dat(pos).zeile = 0 And Dat(pos + 1).zeile = 1 Then G = &H0F
If Dat(pos).zeile = 1 And Dat(pos + 1).zeile = 0 Then G = &HF0
Call Write_dat(g)
G = &H00
If Dat(pos + 2).zeile = 1 And Dat(pos + 3).zeile = 1 Then G = &HFF
If Dat(pos + 2).zeile = 0 And Dat(pos + 3).zeile = 1 Then G = &H0F
If Dat(pos + 2).zeile = 1 And Dat(pos + 3).zeile = 0 Then G = &HF0
Call Write_dat(g)
G = &H00
If Dat(pos + 4).zeile = 1 And Dat(pos + 5).zeile = 1 Then G = &HFF
If Dat(pos + 4).zeile = 0 And Dat(pos + 5).zeile = 1 Then G = &H0F
If Dat(pos + 4).zeile = 1 And Dat(pos + 5).zeile = 0 Then G = &HF0
Call Write_dat(g)
Next
B = B + 3
Pos = Pos + 6
Next C
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Sendet ein Daten Byte zum Oled Controller
' DC Auswahl
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_dat(byval Daten As Byte)
Oled_dc = 1
Call Write_byte(daten)
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Sendet ein Kommando Byte zum Oled Controller
' DC Auswahl
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_cmd(byval Command As Byte)
Oled_dc = 0
Call Write_byte(command)
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Sendet seriell ein Daten oder Kommando Byte zum Oled Controller
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Write_byte(byval Dat_or_cmd As Byte)
Disable Interrupts
Reset Oled_cs
Reset Oled_sdin
Reset Oled_sclk
Shiftout Oled_sdin , Oled_sclk , Dat_or_cmd , 1
Enable Interrupts
Reset Oled_sdin
Set Oled_cs
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Display löschen
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Cleardisplay
Call Write_cmd(&H15)
Call Write_cmd(7)
Call Write_cmd(57)
Call Write_cmd(&H75)
Call Write_cmd(0)
Call Write_cmd(79)
For A = 0 To 4080
Call Write_dat(0)
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Display mit Muster füllen
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Filldisplay
Call Write_cmd(&H15)
Call Write_cmd(7)
Call Write_cmd(57)
Call Write_cmd(&H75)
Call Write_cmd(0)
Call Write_cmd(79)
For A = 0 To 4080
Call Write_dat(&Hf0)
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' zeichnet eine horizontale Linie
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Hline(byval Xpos As Byte , Byval Ypos As Byte , Byval Laenge As Byte)
Call Write_cmd(&H15)
Call Write_cmd(xpos)
Laenge = Laenge / 2
Ziel = Xpos + Laenge
Call Write_cmd(ziel)
Call Write_cmd(&H75)
Call Write_cmd(ypos)
Call Write_cmd(ypos)
For A = 0 To Laenge
Call Write_dat(&Hff)
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' zeichnet eine vertikale Linie
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Vline(byval Xpos As Byte , Byval Ypos As Byte , Byval Laenge As Byte)
Call Write_cmd(&H15)
Call Write_cmd(xpos)
Call Write_cmd(xpos)
Call Write_cmd(&H75)
Call Write_cmd(ypos)
Ziel = Ypos + Laenge
Call Write_cmd(ziel)
For A = 0 To Laenge
Call Write_dat(&Hf0)
Next
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Schreibt die Bytes für den Text in ein Array
'Pro Zeichen 6 Bytes, max 17 Zeichen
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub Array_erstellen(byval Text As String)
Tl = Len(text)
B = 1
For C = 1 To Tl
Tl2 = Tl * 6
Einzelzeichen = Mid(text , C , 1)
Ez = Asc(einzelzeichen)
Bz = Ez - 32
Beginn_zeichen = Bz * 6
Ende_zeichen = Beginn_zeichen + 5
For Db_zeiger = Beginn_zeichen To Ende_zeichen
Dat(b) = Lookup(db_zeiger , Zeichensatz)
Incr B
Next Db_zeiger
Next C
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Zeichensatz in der Reihenfolge des ASCII Codes
' 6 Bytes pro Zeichen, erste Spalte immer leer
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Zeichensatz:
Data 0 , 0 , 0 , 0 , 0 , 0 'Leerzeichen
Hier der C-Code Schnipsel:
Code:
void PaintChar2(BYTE sign, BYTE column, BYTE row);
...
//-------------------------------------------------------------------------------------------------
// Zeichendarstellung im Display-Hochformat
//
// Hoehe x Breite: 102x80 Pixel
//
// row: 0..11 = 12 Zeilen
// column: 0..12 = 13 Spalten
//
//-------------------------------------------------------------------------------------------------
void PaintChar2(BYTE sign, BYTE row, BYTE column)
{
unsigned int pos;
BYTE tmp, twopix, y;
if (row>12) { row = 12; }
if (column>11) { column = 11; }
write_cmd(0x15);
write_cmd(10+4*(11-column));
write_cmd(10+4*(11-column)+3); // 8 Spalten a 2 Pixel
write_cmd(0x75);
write_cmd(6*row);
write_cmd(6*row+5); // 6 Zeilen
if ((sign<0x20) || (sign>0x7F)) { sign = 0x20; }
pos = 5*(sign-0x20);
for (y=0; y<6; y++)
{
twopix = 0;
tmp = pgm_read_byte(&code5x7[pos++]);
if (y>4) { tmp = 0; } // leere Pixelspalte: sonst steht Zeichen an Zeichen!
if (tmp & 0x80) { twopix |= 0xF0; }
if (tmp & 0x40) { twopix |= 0x0F; }
write_dat(twopix); twopix = 0;
if (tmp & 0x20) { twopix |= 0xF0; }
if (tmp & 0x10) { twopix |= 0x0F; }
write_dat(twopix); twopix = 0;
if (tmp & 0x08) { twopix |= 0xF0; }
if (tmp & 0x04) { twopix |= 0x0F; }
write_dat(twopix); twopix = 0;
if (tmp & 0x02) { twopix |= 0xF0; }
if (tmp & 0x01) { twopix |= 0x0F; }
write_dat(twopix);
}
}
Danke und Gruß BlaueLed
Lesezeichen