Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 07.02.2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
Include "modedefs.bas" ' Include serial modes
TRISA = %11111111 ' Set PORTA to all input
TRISC = %00000000 ' Sets all PortB pins to output
ADCON1 = %10001001 ' Set PORTA analog and right justify result
ADCON0=%00000000
low portc.4
low portc.5
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44
DEFINE OSC 4
'==========================MCU SETUP============================================
'DEFINE I2C_SLOW 1 'Used to work with 100KHz devicez when using over 4MHz (my screen working without this too)
'DEFINE I2C_HOLD 1 'Holding Lines low when not sending data (not necessary)
OPTION_REG=0
ADCON0=0
ADCON1=7
TRISB=%00000001
trisc = %11111111 'PortC 0, 1, 2 outputs
PortC = %00110000 'scl & sda high to start
led var portC.0
scl var PortC.4
sda var PortC.5
dat var byte
counter var word
control con %01111000 'I2C slave address (write mode)
pause 500
pause 2000
gosub RESET:
gosub init_oled:
i2cwrite sda,scl,control,[$78,$AF] 'Display ON
pause 10
Start:
led = 1 'Code running
i2cwrite sda,scl,control,[$78,$A7] 'Inverse Display
pause 500
i2cwrite sda,scl,control,[$78,$A6] 'Normal Display
pause 20
' i2cwrite sda,scl,control,[$78,$21,$00,$40] 'Set columns
pause 20
' i2cwrite sda,scl,control,[$78,$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
lcdout $fe,$C0, #counter, " main "
i2cwrite sda,scl,control,[$40,$00]
next
GOTO Start:
INIT_OLED:
lcdout $fe,$C0, "init "
i2cwrite sda,scl,control,[$78,$AE] 'Display OFF ****
pause 1
i2cwrite sda,scl,control,[$78,$2E] 'Deactivate scrolling
pause 1
i2cwrite sda,scl,control,[$78,$20,$10] 'Page addressing mode ****
pause 1
i2cwrite sda,scl,control,[$78,$A0] ' ****
' i2cwrite sda,scl,control,[$78,$A1] ' ****
pause 1
i2cwrite sda,scl,control,[$78,$A6] 'WHITE chars BLACK backround
' i2cwrite sda,scl,control,[$78,$A7] 'BLACK chars WHITE backround
pause 1
i2cwrite sda,scl,control,[$78,$81,$7F] 'Setup contrast XXXX
pause 1
i2cwrite sda,scl,control,[$78,$AF] 'Display on ****
pause 1
i2cwrite sda,scl,control,[$78,$40]
pause 1
' i2cwrite sda,scl,control,[$78,$C0] 'Flip display vertically ****
i2cwrite sda,scl,control,[$78,$C8] 'Flip display vertically ****
pause 1
' i2cwrite sda,scl,control,[$78,$A0] ' ****
i2cwrite sda,scl,control,[$78,$A1] ' ****
pause 1
i2cwrite sda,scl,control,[$78,$00,$78,$10] 'Set column start address ****
pause 1
i2cwrite sda,scl,control,[$78,$B0] 'Set page start address ****
pause 1
return
RESET:
i2cwrite sda,scl,control,[$78,$AE] 'Display OFF
pause 10
I2Cwrite sda,scl,control,[$78,$20,$02] 'Page addressing mode
pause 10
i2cwrite sda,scl,control,[$78,$B0] 'Page start address
pause 10
i2cwrite sda,scl,control,[$78,$00,$78,$10] 'Set column start address
pause 10
i2cwrite sda,scl,control,[$78,$A0] 'Address 0 mapped to SEG 0
pause 10
' i2cwrite sda,scl,control,[$78,$A1] 'Address 0 mapped to SEG 127
pause 10
i2cwrite sda,scl,control,[$78,$D3,$00] 'Display offset
pause 10
pause 10
i2cwrite sda,scl,control,[$78,$40] 'Display start line
Pause 10
i2cwrite sda,scl,control,[$78,$C0] 'Output scan direction
pause 10
i2cwrite sda,scl,control,[$78,$A6] 'WHITE chars BLACK backround
pause 10
i2cwrite sda,scl,control,[$78,$81,$7F] 'Contrast control
pause 10
i2cwrite sda,scl,control,[$78,$A4] 'Entire display OFF
pause 10
i2cwrite sda,scl,control,[$78,$A6] 'Normal display
pause 10
i2cwrite sda,scl,control,[$78,$A3,$00,$40] 'Set vertical scroll
pause 10
i2cwrite sda,scl,control,[$78,$20,$00] 'Horizontal addressing mode
' i2cwrite sda,scl,control,[$78,$20,$01] 'Vertical addressing mode
RETURN
The initial address was $80, so I've changed it to $78, as shown on picture of the OLED itself.
Bookmarks