Cannot drive I2C Oled :(


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    Hi all, I did use the Timc code to drive a 0.96 '' oled display and it works fine (thank you Timc)
    The only doubt now I have is the warning message I get compiling the code:

    "ASM WARNING Argument out of range. Last significant bits used. (0) : Warninig [202]"

    What does it mean?
    How can I remove it?

    Alberto

  2. #2
    Join Date
    Feb 2007
    Posts
    55


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    I bought a OLED display on ebay saying it had a SSD1306 chip, trying running some code from here and I got a display full of noise

    Turns out it has SH1106 driver

    I modified the code here to work with it on 18F877
    this draws a box around the display


    <code>

    'OLED driver 16F877
    'SH1106 driver
    'NOT SSD1306

    '==========================MCU SETUP============================================
    Include "modedefs.bas"

    DEFINE OSC 8


    ADCON0=0
    ADCON1=7
    TRISA=%00111111
    TRISB=%00000001
    TRISC=0
    TRISD=0
    TRISE=0
    PORTC=$FF

    '==============================Variables========== =============================

    I2CDevice var byte
    SCL var PortC.3 ' I2C Clock PortC.3
    SDA var PortC.4 ' I2C Data PortC.4
    DC VAR byte' "DATA OR COMMAND", $40=DATA; $0=COMMAND
    LCD_DATA VAR BYTE
    COM VAR BYTE' COMMAND


    I VAR BYTE
    J VAR BYTE
    X VAR BYTE' LCD Column POSITION (0 TO 127)
    Y VAR BYTE'LCD Line POSITION FOR PAGE MODE(0 TO 7)
    Xlow VAR BYTE 'Low 4 bits of X
    Xhigh VAR BYTE 'High 4 bits of X
    CLEAR
    '================================================= ============================
    I2CDevice = $78 ' Display = $78,
    PAUSE 500
    '=========================lcd initialization====================================
    DC = 0
    INIT:
    I2CWrite SDA,SCL,I2CDevice,[DC,$AE]'Display Off
    pause 10
    I2CWrite SDA,SCL,I2CDevice,[DC,$D3,$00]' Set offset to 0
    I2CWrite SDA,SCL,I2CDevice,[DC,$40]' Set display start line 0
    I2CWrite SDA,SCL,I2CDevice,[DC,$8D,$14]' Set Charge Pump Internal, usually needed
    'I2CWrite SDA,SCL,I2CDevice,[DC,$20,$10]' Page adressing mode
    I2CWrite SDA,SCL,I2CDevice,[DC,$A1]' set column 0 as start
    i2cwrite sda,scl,I2CDevice,[DC,$C8]'
    I2CWrite SDA,SCL,I2CDevice,[DC,$DA,$12]' set COM pins = 128x64=$12 128x32=$02'
    I2CWrite SDA,SCL,I2CDevice,[DC,$81,$01]' Set contrast to low
    I2CWrite SDA,SCL,I2CDevice,[DC,$A4]' display on continue
    I2CWrite SDA,SCL,I2CDevice,[DC,$A6]' $A6=NORMAL MODE;$A7=INVERSE MODE

    I2CWrite SDA,SCL,I2CDevice,[DC,$AF]'Display On
    pause 500




    '================================================= ==============================
    GOSUB CLEAR_LCD
    pause 500



    MAIN:

    gosub CLEAR_LCD
    pause 1000
    gosub BOX1
    pause 1000

    GOTO MAIN

    '======================Send data============================================== =
    SEND_DATA:
    DC=$40
    I2CWrite SDA,SCL,I2CDevice,[DC,LCD_DATA]
    RETURN
    '================================================= ==============================
    '======================Send Command=========================================== ==
    SEND_COMMAND:
    DC=0
    I2CWrite SDA,SCL,I2CDevice,[DC,COM]
    RETURN
    '================================================= ==============================

    '==============================clear lcd========================================
    CLEAR_LCD:
    X=2
    Y=0
    LCD_DATA=$00
    'Send 0 to every column in every line
    FOR Y=0 TO 7
    gosub SET_XY
    FOR I=0 TO 127
    GOSUB SEND_DATA
    NEXT I
    NEXT Y
    RETURN

    '================================================= ==============================
    BOX1:
    FOR Y = 0 TO 7
    X=2
    GOSUB SET_XY
    LCD_DATA=%11111111
    GOSUB SEND_DATA
    X=129
    GOSUB SET_XY
    GOSUB SEND_DATA
    NEXT Y
    FOR X = 3 TO 128
    Y=0
    GOSUB SET_XY
    LCD_DATA=%00000001
    GOSUB SEND_DATA
    Y=7
    GOSUB SET_XY
    LCD_DATA=%10000000
    GOSUB SEND_DATA
    NEXT


    RETURN

    '===========================================SET X AND Y=========================
    SET_XY:
    COM = $B0
    COM = COM + Y '<<<--- SET PAGE ADDRESS %1011DDDD
    GOSUB SEND_COMMAND

    Xhigh = X >> 4
    Xlow = X &$0F
    COM=Xlow '<<<--- SET COL ADDRESS LOW bits %0000DDDD
    GOSUB SEND_COMMAND
    Xhigh.4 = 1
    COM = Xhigh '<<<--- SET COL ADDRESS HIGH bits %0001DDDD
    GOSUB SEND_COMMAND

    RETURN
    '================================================= ==============================


    END

    </code>

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    Probably this:
    Code:
    chartmp = charset - 295
    char temp is a byte who’s maximum value is 255.
    It will probably also break it if it was working, to fix it,
    you’d probably have to rotate the values in the lookup table by some amount.


    Quote Originally Posted by Alberto View Post
    Hi all, I did use the Timc code to drive a 0.96 '' oled display and it works fine (thank you Timc)
    The only doubt now I have is the warning message I get compiling the code:

    "ASM WARNING Argument out of range. Last significant bits used. (0) : Warninig [202]"

    What does it mean?
    How can I remove it?

    Alberto

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