new SSD1306S Library
Posted: Sun Sep 13, 2020 9:12 am
Is there any example code for the new SSD1306S.bas Module just added to the compiler library?...
Structured BASIC for PICĀ® Microcontrollers
https://sfcompiler.co.uk/phpBB3/
Code: Select all
Device = 18F26K22
Clock = 64
// OLED I2C 128x64
// 4 SDA mssp SDA
// 3 SCL mssp SCL
// 2 5V VCC
// 1 GND GND
Include "intosc.bas" // setup intosc based on 'clock='
#option DIGITALIO_INIT = true // automatically call setalldigital at startup
Include "setdigitalio.bas"
// select SSD1306 serial mode driver
#option GLCD_MODEL = SSD1306S
// interface selection... I2C, I2C2, SI2C, SPI, SPI2, or SSPI
#option GLCD_INTERFACE = I2C 'I2C2 'SPI2
// set any #options required by the selected interface .bas module.
#if (GLCD_INTERFACE = I2C)
#option I2C_BAUD = 400
'include "i2c.bas" // module name shown for ref only
#elseif (GLCD_INTERFACE = I2C2)
#option I2C2_SCL = PORTB.1 // K22 SCL2
#option I2C2_SDA = PORTB.2 // K22 SDA2
#option I2C2_BAUD = 400
'include "i2c2.bas"
#elseif (GLCD_INTERFACE = SI2C)
#option SI2C_SCL = PORTB.1 // K22 SCL2
#option SI2C_SDA = PORTB.2 // K22 SDA2
#option SI2C_BAUD = 400
'include "si2c.bas"
#elseif (GLCD_INTERFACE = SPI)
'include "spi.bas"
#elseif (GLCD_INTERFACE = SPI2)
#option SPI2_SCK = PORTB.1 // SPI clock
#option SPI2_SDO = PORTB.3 // SPI data out
#option SPI2_SDI = PORTB.2 // SPI data in (not used, remap as GLCD_DC below)
#option SPI2_DEFAULT_CLOCK = %1010 // use SPI CLK = FOSC/8 **NOT SUPPORTED BY ALL DEVICES**
'include "spi2.bas"
#elseif (GLCD_INTERFACE = SSPI)
#option SSPI_SCK = PORTB.1 // SPI clock
#option SSPI_SDO = PORTB.3 // SPI data out
#option SSPI_SDI = PORTB.2 // SPI data in (not used, remap as GLCD_DC below)
'include "sspi.bas"
#endif
// addtl SPI control pins (unused pins will not be initialized)
#option GLCD_DC = PORTB.2 // D/C data/command pin: data=1, command=0
#option GLCD_CS = PORTB.0 // SPI CS chip select pin (active-low)
#option GLCD_RST = PORTA.0 // reset pin (either mode, optional)
// addtl I2C settings
#option GLCD_I2C_ADDR = $78 // ssd1306 DC_SA0 GND (note: this seems to be the default)
'#option GLCD_I2C_ADDR = $7A // ssd1306 DC_SA0 high, floating (unconnected)
// we'll call GLCD.Initialize (allows for PPS setup)
#option GLCD_INITIALIZE = false
// we're already setting digitalio pin mode here, so it's not required in GLCD
#option GLCD_SETALLDIGITAL = false
#option GLCD_WIDTH = 128 // SSD1306 max 128
#option GLCD_HEIGHT = 64 // SSD1306 max 64
Include "math.bas"
Include "GLCD.bas"
Include "graphics.bas"
Dim i As Byte
Dim x As Byte
Dim c As Byte
Dim y As Float
// start of prog...
GLCD.Initialize()
GLCD.SetContrast() // default
GLCD.Cls()
// main Loop...
While True
// lines
GLCD.Cls()
For i = 0 To 63 Step 2
GLCD.Line(0, i, 127, 63-i)
Next
For i = 127 To 0 Step -2
GLCD.Line(i, 0, 127-i, 63)
Next
DelayMS(2000)
// cross lines
GLCD.Cls()
GLCD.Rectangle(0, 0, 127, 63)
For i = 0 To 63 Step +4
GLCD.Line(0, i, i*2, 63)
Next
For i = 0 To 63 Step +4
GLCD.Line(127, 63-i, 127-(i*2), 0)
Next
DelayMS(2000)
// squares
GLCD.Cls()
For i = 0 To 9
GLCD.Rectangle(i*3, i*3, 127-(i*3), 63-(i*3))
Next
DelayMS(2000)
// circles
GLCD.Cls()
x = 0
For i = 0 To 24
x = x + 3
GLCD.Circle(64, 32, x)
DelayMS(1)
Next
DelayMS(2000)
// sin wave
GLCD.Cls()
GLCD.Rectangle(0, 0, 127, 63)
GLCD.Line(0, 31, 127, 31)
GLCD.Line(63, 0, 63, 63)
For c = 0 To 3
For i = 0 To 127
y=i*0.04974188368183839294232518690191
GLCD.SetPixel(i, (sin(y)*28)+31)
DelayMS(10)
Next
Next
DelayMS(2000)
Wend
Code: Select all
Device = 18F26K22
Clock = 64
Include "intosc.bas" // setup intosc based on 'clock='
// select SSD1306 serial mode driver
#option GLCD_MODEL = SSD1306S
// interface selection... I2C, I2C2, SI2C, SPI, SPI2, or SSPI
#option GLCD_INTERFACE = I2C
#option I2C_BAUD = 400
#option GLCD_I2C_ADDR = $78 // ssd1306 DC_SA0 GND (note: this seems to be the default)
#option GLCD_WIDTH = 128 // SSD1306 max 128
#option GLCD_HEIGHT = 64 // SSD1306 max 64
Include "GLCD.bas"
Include "graphics.bas"
Include "math.bas"