Cannot drive I2C Oled :(


Results 1 to 22 of 22

Threaded View

  1. #6
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    Here is some code. It fills the screen with 8 lines of vertical bars then clears it.
    If the screen does not start up correctly dissconnect and wait or discharge with a resistor and try again. Apparently this is normal.
    The 'INIT' routine was arrived at by trial and error, if you can improve on it let me know.
    The 'RESET' routine makes no difference and is included for you to experiment.
    Not an easy display to work with.

    Phil

    Code:
    '****************************************************************
    '*  Name    : CRIUS_OLED_Test.pbp                               *
    '*  Author  : Philtronix                                        *
    '*  Notice  : Copyright (c) 2015 Philtronix                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 15/06/2015                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC18F2550 int osc @ 4mHz   3.3v                  *
    '*          : CRIUS OLED display   3.3v                         *
    '****************************************************************
    osccon = %01100010          'Int OSC @ 4mHz
    adcon1 = %00001111          'All ports digital
    ucon.3 = 0                  'Disable USB port
    ucfg.3 = 1                  'Digital in RC4 & RC5
    cmcon  = 7                  'Comparators off
    
    led     var LatC.0
    scl     var PortC.1
    sda     var PortC.2
    dat     var byte
    counter var word
    
    control con %01111000       'I2C slave address (write mode)
    
    trisb = %11000000
    PortB = %00000000
    pause 500
    
    trisc = %11111000           'PortC 0, 1, 2 outputs
    PortC = %00000110           'scl & sda high to start
    
        pause 2000
    '    gosub RESET:
        gosub init_oled:
        i2cwrite sda,scl,control,[$80,$AF]  'Display ON
        pause 10
    
    Start:
        led = 1                             'Code running
        i2cwrite sda,scl,control,[$80,$A7]  'Inverse Display 
        pause 500
        i2cwrite sda,scl,control,[$80,$A6]  'Normal Display
        pause 20
    '    i2cwrite sda,scl,control,[$80,$21,$00,$40] 'Set columns
        pause 20
    '    i2cwrite sda,scl,control,[$80,$22,$00,$04]  'Set pages
        pause 500     
        for counter = 0 to 1023
        i2cwrite sda,scl,control,[$40,$FF]
        next
        led = 0                             'Code running
        for counter = 0 to 1023
        i2cwrite sda,scl,control,[$40,$00]
        next
    GOTO Start:
    
    INIT_OLED:
        i2cwrite sda,scl,control,[$80,$AE]          'Display OFF               ****
        pause 1
        i2cwrite sda,scl,control,[$80,$2E]          'Deactivate scrolling
        pause 1
        i2cwrite sda,scl,control,[$80,$20,$10]      'Page addressing mode      ****
        pause 1
        i2cwrite sda,scl,control,[$80,$A0]          '                          ****
    '    i2cwrite sda,scl,control,[$80,$A1]          '                          ****
        pause 1
        i2cwrite sda,scl,control,[$80,$A6]          'WHITE chars BLACK backround
    '    i2cwrite sda,scl,control,[$80,$A7]         'BLACK chars WHITE backround
        pause 1
        i2cwrite sda,scl,control,[$80,$81,$7F]      'Setup contrast            XXXX
        pause 1
        i2cwrite sda,scl,control,[$80,$AF]          'Display on                **** 
        pause 1
        i2cwrite sda,scl,control,[$80,$40]
        pause 1
    '    i2cwrite sda,scl,control,[$80,$C0]          'Flip display vertically   ****
        i2cwrite sda,scl,control,[$80,$C8]          'Flip display vertically   ****
        pause 1
    '    i2cwrite sda,scl,control,[$80,$A0]          '                          ****
        i2cwrite sda,scl,control,[$80,$A1]          '                          ****
        pause 1
        i2cwrite sda,scl,control,[$80,$00,$80,$10]  'Set column start address  ****
        pause 1
        i2cwrite sda,scl,control,[$80,$B0]          'Set page start address    ****
        pause 1
        return
        
    RESET:
        i2cwrite sda,scl,control,[$80,$AE]          'Display OFF
        pause 10
        I2Cwrite sda,scl,control,[$80,$20,$02]      'Page addressing mode
        pause 10
        i2cwrite sda,scl,control,[$80,$B0]          'Page start address
        pause 10
        i2cwrite sda,scl,control,[$80,$00,$80,$10]  'Set column start address
        pause 10
        i2cwrite sda,scl,control,[$80,$A0]          'Address 0 mapped to SEG 0
        pause 10
     '   i2cwrite sda,scl,control,[$80,$A1]          'Address 0 mapped to SEG 127
        pause 10
        i2cwrite sda,scl,control,[$80,$D3,$00]      'Display offset
        pause 10
    
        pause 10
        i2cwrite sda,scl,control,[$80,$40]          'Display start line
        Pause 10
        i2cwrite sda,scl,control,[$80,$C0]          'Output scan direction
        pause 10
        i2cwrite sda,scl,control,[$80,$A6]          'WHITE chars BLACK backround
        pause 10
        i2cwrite sda,scl,control,[$80,$81,$7F]      'Contrast control
        pause 10
        i2cwrite sda,scl,control,[$80,$A4]          'Entire display OFF
        pause 10
        i2cwrite sda,scl,control,[$80,$A6]          'Normal display
        pause 10
        i2cwrite sda,scl,control,[$80,$A3,$00,$40]  'Set vertical scroll
        pause 10
        i2cwrite sda,scl,control,[$80,$20,$00]      'Horizontal addressing mode
    '    i2cwrite sda,scl,control,[$80,$20,$01]      'Vertical addressing mode
        RETURN
    Last edited by Demon; - 15th June 2015 at 13:13. Reason: Fixed tags

Similar Threads

  1. OLED 128X96 cheap china lcd
    By starwick in forum Code Examples
    Replies: 10
    Last Post: - 19th June 2017, 05:23
  2. Help With OLED Display / 128X64 SSD1306
    By Denner in forum General
    Replies: 6
    Last Post: - 25th May 2013, 15:40
  3. SEROUT + SERIN, OLED + PICAXE coding help required
    By SeanHowson in forum mel PIC BASIC
    Replies: 4
    Last Post: - 15th October 2012, 16:11
  4. Master SPI interface to LCD/OLED??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2009, 23:44
  5. OLED 128x128 color display
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st May 2007, 01:45

Members who have read this thread : 3

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts