Translate

Mengakses OLED DISPLAY SSD1306 0.96 i2C

Mengakses OLED DISPLAY SSD1306 0.96 i2C


              Di tengah malam yang gelap  ini saya akan menjelaskan bagaimana cara mengakses OLED Display dengan controller SSD1306, oled ini berbentuk kecil namun tampilannya luar biasa, jadi kalau lcd biasa yang terang backlightnya, namun kalau oled ini justru sebaliknya, yang terang adalah character / huruf-nya, sehingga mudah untuk dilihat dan dibaca orang.  disini saya akan membahas cara mengakses oled dengan bascom AVR dengan komunikasi I2C. berikut adalah penjelasan tentang hardware dan programnya. 


a. Minimum System 




b. Program Bascom AVR

'SSD1306 oled 0.96 i2C
'created by Theo Kleijn & Ben Zijlstra

$regfile = "m32def.dat"
$crystal = 11059200
$hwstack = 64
$swstack = 64
$framesize = 64

Dim Resetflag As Bit


Const Kontrast = &HFF                                       '00-FF Kontrast


Config Scl = Portc.0
Config Sda = Portc.1
Config Twi = 400000

Declare Sub Rstoled
Declare Sub Oled(byval Text As String * 16 , Byval Col As Integer , Byval Page As Integer)
Declare Sub Oled_init

I2cinit

Call Oled_init

Do
   If Resetflag < 1 Then
      Call Rstoled
      Resetflag = 1
     Do
      Call Oled( "     YANUAR     " , 0 , 9)
      Call Oled( "    MUKHAMMAD   " , 0 , 2)
      Call Oled( "                " , 0 , 3)
      Call Oled( "  OLED DISPLAY  " , 0 , 4)
      Call Oled( "                " , 0 , 5)
      Call Oled( "   BASCOM AVR   " , 0 , 6)
      Call Oled( "                " , 0 , 7)
      Call Oled( "    OK BOSS     " , 0 , 8)
    Wait 3
      Call Oled( "    DEMO LCD    " , 0 , 9)
      Call Oled( "   OLED DISPLAY " , 0 , 2)
      Call Oled( "                " , 0 , 3)
      Call Oled( "       OK       " , 0 , 4)
      Call Oled( "                " , 0 , 5)
      Call Oled( "     GIMANA ?   " , 0 , 6)
      Call Oled( "                " , 0 , 7)
      Call Oled( "     LANJUT ?   " , 0 , 8)
    Wait 3

     Loop
   End If

Loop

End

Sub Oled(byval Text As String * 16 , Byval Col As Integer , Byval Page As Integer)
   Dim Buchstabe As String * 1

   Dim Q As Integer
   Dim H As Integer
   Dim Temp As Integer
   Dim Senden As Byte
   Col = Col + 16
   Page = Page + 175
   I2cstart
   I2cwbyte &H78
   I2cwbyte &H80
   I2cwbyte Page
   I2cstop

   I2cstart
   I2cwbyte &H78
   I2cwbyte &H80
   I2cwbyte &H00
   I2cstop

   I2cstart
   I2cwbyte &H78
   I2cwbyte &H80
   I2cwbyte Col
   I2cstop

   I2cstart
   I2cwbyte &H78
   I2cwbyte &H80
   I2cstop

   I2cstart
   I2cwbyte &H78
   I2cwbyte &H40


   For Q = 1 To 16
      Temp = 0
      Buchstabe = Mid(text , Q , 1)
      Temp = Asc(buchstabe)
      Temp = Temp - 32
      Temp = Temp * 8
      For H = 1 To 8
         Senden = Lookup(temp , Asciitab)
         I2cwbyte Senden
         Incr Temp
      Next H
   Next Q
   I2cstop
End Sub


Sub Rstoled                                                 'OLED RESET
   Dim I As Byte
   Dim J As Integer
   Dim Page As Byte
   Page = 176

   I2cstart
   I2cwbyte &H78
   I2cwbyte &H40
   For J = 0 To 1023
      I2cwbyte &H00
   Next J
   I2cstop
End Sub

Sub Oled_init
'OLED initialisation ***********************************************************

   I2cstart
   I2cwbyte &H78
    I2cwbyte &HAE                                       'DISPLAYOFF
    I2cwbyte &HD5                                       'SETDISPLAYCLOCKDIV
    I2cwbyte &H80                                       'ratio 0x80
    I2cwbyte &H00                                       'SETMULTIPLEX
    I2cwbyte &H3F                                       '   1f 128x32
    I2cwbyte &HD3                                       'SETDISPLAYOFFSET
    I2cwbyte &H00

    I2cwbyte &H40                                       'SETSTARTLINE
    I2cwbyte &H8D                                       'CHARGEPUMP
    I2cwbyte &H14                                       'vccstate 14
    I2cwbyte &H20                                       'MEMORYMODE
    I2cwbyte &H00                                       '
    I2cwbyte &HA1                                       'A0 upside down SEGREMAP
    I2cwbyte &HC8                                       'COMSCANDEC

    I2cwbyte &HDA                                       'SETCOMPINS
    I2cwbyte &H12                                       ' 02 128x32  12
    I2cwbyte &H81                                       'SETCONTRAST
    I2cwbyte Kontrast                                   'value 1-->256
    I2cwbyte &HD9                                       'SETPRECHARGE
    I2cwbyte &HF1                                       'vccstate  f1
    I2cwbyte &HDB                                       'SETVCOMDETECT

    I2cwbyte &H40
    I2cwbyte &HA4                                       'DISPLAYALLON_RESUME
    I2cwbyte &HA6                                       'NORMALDISPLAY

    I2cwbyte &HAF
I2cstop

End Sub



Asciitab:
   Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
   Data 0 , 0 , 6 , 95 , 6 , 0 , 0 , 0,
   Data 0 , 7 , 3 , 0 , 7 , 3 , 0 , 0,
   Data 0 , 36 , 126 , 36 , 126 , 36 , 0 , 0,
   Data 0 , 36 , 43 , 106 , 18 , 0 , 0 , 0,
   Data 0 , 99 , 19 , 8 , 100 , 99 , 0 , 0,
   Data 0 , 54 , 73 , 86 , 32 , 80 , 0 , 0,
   Data 0 , 0 , 7 , 3 , 0 , 0 , 0 , 0,
   Data 0 , 0 , 62 , 65 , 0 , 0 , 0 , 0,
   Data 0 , 0 , 65 , 62 , 0 , 0 , 0 , 0,
   Data 0 , 8 , 62 , 28 , 62 , 8 , 0 , 0,
   Data 0 , 8 , 8 , 62 , 8 , 8 , 0 , 0,
   Data 0 , 0 , 224 , 96 , 0 , 0 , 0 , 0,
   Data 0 , 8 , 8 , 8 , 8 , 8 , 0 , 0,
   Data 0 , 0 , 96 , 96 , 0 , 0 , 0 , 0,
   Data 0 , 32 , 16 , 8 , 4 , 2 , 0 , 0,
   Data 0 , 62 , 81 , 73 , 69 , 62 , 0 , 0,
   Data 0 , 0 , 66 , 127 , 64 , 0 , 0 , 0,
   Data 0 , 98 , 81 , 73 , 73 , 70 , 0 , 0,
   Data 0 , 34 , 73 , 73 , 73 , 54 , 0 , 0,
   Data 0 , 24 , 20 , 18 , 127 , 16 , 0 , 0,
   Data 0 , 47 , 73 , 73 , 73 , 49 , 0 , 0,
   Data 0 , 60 , 74 , 73 , 73 , 48 , 0 , 0,
   Data 0 , 1 , 113 , 9 , 5 , 3 , 0 , 0,
   Data 0 , 54 , 73 , 73 , 73 , 54 , 0 , 0,
   Data 0 , 6 , 73 , 73 , 41 , 30 , 0 , 0,
   Data 0 , 0 , 108 , 108 , 0 , 0 , 0 , 0,
   Data 0 , 0 , 236 , 108 , 0 , 0 , 0 , 0,
   Data 0 , 8 , 20 , 4 , 65 , 0 , 0 , 0,
   Data 0 , 36 , 36 , 36 , 36 , 36 , 0 , 0,
   Data 0 , 0 , 65 , 34 , 20 , 8 , 0 , 0,
   Data 0 , 2 , 1 , 89 , 9 , 6 , 0 , 0,
   Data 0 , 62 , 65 , 93 , 85 , 30 , 0 , 0,
   Data 0 , 126 , 17 , 17 , 17 , 126 , 0 , 0,
   Data 0 , 127 , 73 , 73 , 73 , 54 , 0 , 0,
   Data 0 , 62 , 65 , 65 , 65 , 34 , 0 , 0,
   Data 0 , 127 , 65 , 65 , 65 , 62 , 0 , 0,
   Data 0 , 127 , 73 , 73 , 73 , 65 , 0 , 0,
   Data 0 , 127 , 9 , 9 , 9 , 1 , 0 , 0,
   Data 0 , 62 , 65 , 73 , 73 , 122 , 0 , 0,
   Data 0 , 127 , 8 , 8 , 8 , 127 , 0 , 0,
   Data 0 , 0 , 65 , 127 , 65 , 0 , 0 , 0,
   Data 0 , 48 , 64 , 64 , 64 , 63 , 0 , 0,
   Data 0 , 127 , 8 , 20 , 34 , 65 , 0 , 0,
   Data 0 , 127 , 64 , 64 , 64 , 64 , 0 , 0,
   Data 0 , 127 , 2 , 4 , 2 , 127 , 0 , 0,
   Data 0 , 127 , 2 , 4 , 8 , 127 , 0 , 0,
   Data 0 , 62 , 65 , 65 , 65 , 62 , 0 , 0,
   Data 0 , 127 , 9 , 9 , 9 , 6 , 0 , 0,
   Data 0 , 62 , 65 , 81 , 33 , 94 , 0 , 0,
   Data 0 , 127 , 9 , 9 , 25 , 102 , 0 , 0,
   Data 0 , 38 , 73 , 73 , 73 , 50 , 0 , 0,
   Data 0 , 1 , 1 , 127 , 1 , 1 , 0 , 0,
   Data 0 , 63 , 64 , 64 , 64 , 63 , 0 , 0,
   Data 0 , 31 , 32 , 64 , 32 , 31 , 0 , 0,
   Data 0 , 63 , 64 , 60 , 64 , 63 , 0 , 0,
   Data 0 , 99 , 20 , 8 , 20 , 99 , 0 , 0,
   Data 0 , 7 , 8 , 112 , 8 , 7 , 0 , 0,
   Data 0 , 113 , 73 , 69 , 67 , 0 , 0 , 0,
   Data 0 , 0 , 127 , 65 , 65 , 0 , 0 , 0,
   Data 0 , 2 , 4 , 8 , 16 , 32 , 0 , 0,
   Data 0 , 0 , 65 , 65 , 127 , 0 , 0 , 0,
   Data 0 , 4 , 2 , 1 , 2 , 4 , 0 , 0,
   Data 128 , 128 , 128 , 128 , 128 , 128 , 128 , 128,
   Data 0 , 0 , 3 , 7 , 0 , 0 , 0 , 0,
   Data 0 , 32 , 84 , 84 , 84 , 120 , 0 , 0,
   Data 0 , 127 , 68 , 68 , 68 , 56 , 0 , 0,
   Data 0 , 56 , 68 , 68 , 68 , 40 , 0 , 0,
   Data 0 , 56 , 68 , 68 , 68 , 127 , 0 , 0,
   Data 0 , 56 , 84 , 84 , 84 , 8 , 0 , 0,
   Data 0 , 8 , 126 , 9 , 9 , 0 , 0 , 0,
   Data 0 , 24 , 164 , 164 , 164 , 124 , 0 , 0,
   Data 0 , 127 , 4 , 4 , 120 , 0 , 0 , 0,
   Data 0 , 0 , 0 , 125 , 64 , 0 , 0 , 0,
   Data 0 , 64 , 128 , 132 , 125 , 0 , 0 , 0,
   Data 0 , 127 , 16 , 40 , 68 , 0 , 0 , 0,
   Data 0 , 0 , 0 , 127 , 64 , 0 , 0 , 0,
   Data 0 , 124 , 4 , 24 , 4 , 120 , 0 , 0,
   Data 0 , 124 , 4 , 4 , 120 , 0 , 0 , 0,
   Data 0 , 56 , 68 , 68 , 68 , 56 , 0 , 0,
   Data 0 , 252 , 68 , 68 , 68 , 56 , 0 , 0,
   Data 0 , 56 , 68 , 68 , 68 , 252 , 0 , 0,
   Data 0 , 68 , 120 , 68 , 4 , 8 , 0 , 0,
   Data 0 , 8 , 84 , 84 , 84 , 32 , 0 , 0,
   Data 0 , 4 , 62 , 68 , 36 , 0 , 0 , 0,
   Data 0 , 60 , 64 , 32 , 124 , 0 , 0 , 0,
   Data 0 , 28 , 32 , 64 , 32 , 28 , 0 , 0,
   Data 0 , 60 , 96 , 48 , 96 , 60 , 0 , 0,
   Data 0 , 108 , 16 , 16 , 108 , 0 , 0 , 0,
   Data 0 , 156 , 160 , 96 , 60 , 0 , 0 , 0,
   Data 0 , 100 , 84 , 84 , 76 , 0 , 0 , 0,
   Data 0 , 8 , 62 , 65 , 65 , 0 , 0 , 0,
   Data 0 , 0 , 0 , 119 , 0 , 0 , 0 , 0,
   Data 0 , 0 , 65 , 65 , 62 , 8 , 0 , 0,
   Data 0 , 2 , 1 , 2 , 1 , 0 , 0 , 0,
   Data 0 , 60 , 38 , 35 , 38 , 60 , 0 , 0



c. VIDEO HASILNYA







No comments:

Post a Comment