What is required to convert this code to run it the IDE so it can be added to a sketch (or, a sketch buit up around it)?
It auto-formats, but won’t compile.
OLED datasheet top level
Specifics with the sample code below
Carrier board that simplifies the interfacing
I could see this part requiring a uC with more SRAM (i.e. '1284):
//This is the display memory.
volatile unsigned char display[6144]; //12288 bytes
“SOURCES FOR DRIVER LIBRARIES
Graphic driver libraries may save a lot of time and help you develop a more professional product. Possible library sources
are easyGUI, en.radzio.dxp.pl, Gwentech, Micri?m, RAMTEX, and Segger emWin.
SAMPLE CODE
This code will initialize the display and show the boot screen. You can download the complete source from this link: http:/
/www.crystalfontz.com/product/CFAL9664BFB1.html#docs.”
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "9664_isaac.h"
// all on PORTC
#define OLED_CDPC7
#define OLED_WR PC6// WR in 8080 mode
#define OLED_RD PC5// RD in 8080 mode
#define OLED_CSPC4
#define OLED_RESPC2
#define CLR_CD PORTC &= ~(1<<OLED_CD);
#define SET_CD PORTC |= (1<<OLED_CD);
#define CLR_CS PORTC &= ~(1<<OLED_CS);
#define SET_CS PORTC |= (1<<OLED_CS);
#define CLR_RESET PORTC &= ~(1<<OLED_RES);
#define SET_RESET PORTC |= (1<<OLED_RES);
#define CLR_WR PORTC &= ~(1 << OLED_WR); // 8080 mode
#define SET_WR PORTC |= (1 << OLED_WR); // 8080 mode
#define CLR_RD PORTC &= ~(1 << OLED_RD); // 8080 mode
#define SET_RD PORTC |= (1 << OLED_RD); // 8080 mode
//This is the display memory.
volatile unsigned char display[6144]; //12288 bytes
void delay(uint32_t twait)
{
while (twait--)
asm volatile ("nop");
}
void oled_cmd(unsigned command)
{
PORTA = command;// set up data on bus
CLR_CS; // chip selected
CLR_CD; // command mode
SET_RD;
// clock WR
CLR_WR;
SET_WR;
SET_CS; // deselect chip
}
void oled_data(unsigned data)
{
PORTA = data;// set up data on bus
SET_CD; // data mode
CLR_CS; // chip selected
SET_RD;
// clock WR
CLR_WR;
SET_WR;
SET_CS; // deselect chip
}
void reset_display(void)
{
CLR_RESET;
delay(10000);
SET_RESET;
}
void oled_clr(uint8_t color)
{
int i,p;
oled_cmd(0x40);
for (p=0;p<8;p++) // pages
{
oled_cmd(0xB0 + p); // set page address
oled_cmd(0x10); // set high column address
oled_cmd(0x00); // set low column address
for (i=0;i<132;i++)
{
oled_data(color);
}
}
}
void show_bitmap()
{
int i;
memcpy_P(display, boot_example_bottom, sizeof(display));
for(i=0;i<6144;i++)
{
oled_data(display[i]);
delay(10);
}
memcpy_P(display, boot_example_top, sizeof(display));
for(i=0;i<6144;i++)
{
oled_data(display[i]);
delay(10);
}
delay(2500000L);
}
/********************************************************************************/
void init_OLED(void)
{
PORTD = 0; // all off
DDRD |= (1<<3);// VPP output
DDRA = 0xFF; // set PORTA for output
PORTC = 0b11111110;
DDRC = 0xFE;
DDRD |= 0x06;// OLED pins output
delay(20000L);
oled_cmd(0xAF); //10101111: set display on
oled_cmd(0xA4); //10100100: set nomal display(POR)
//oled_cmd(0xA5); //entire display on, all pixels turn on at GS level 63
//oled_cmd(0xA6); //entire display off, all pixels turns off
//oled_cmd(0xA7); //inverse display
oled_cmd(0x81); // 10000001: set contrast control for color A
oled_cmd(0xF0); //11111111: contrast set(select from 1 to 256)
oled_cmd(0x82); // 10000010: set contrast control for color B
oled_cmd(0xF0); //11111111: contrast set(select from 1 to 256)
oled_cmd(0x83); // 10000011: set contrast control for color C
oled_cmd(0xF0); //11111111: contrast set(select from 1 to 256)
oled_cmd(0x87); // 10000111: adjust the master current attenuation factor from 1/
16,2/16...16/16
oled_cmd(0x08); //00001111: (POR)
oled_cmd(0xA0); //10100000: set re-map & data format
oled_cmd(0x70); //01100000: a[7,6]:01:65k color format(por)CCCCCBBBBBBAAAAA 00:256
color formatCCCBBBAA
oled_cmd(0xA1); //set display start line
oled_cmd(0x00);
oled_cmd(0xA2); //set display offset
oled_cmd(0x00);
oled_cmd(0xA8); //set multiplex ratio
oled_cmd(0x3F);
oled_cmd(0xAD); //set master configuration
oled_cmd(0x8A);
oled_cmd(0xB0); //set power save
oled_cmd(0x12); //0x12:power saving mode
oled_cmd(0xB1);//phase 1 and period adjustment(discharge,charge)
oled_cmd(0xF1);
oled_cmd(0xB3);//display clock divider/oscillator frequency
oled_cmd(0xF0);
oled_cmd(0xBB);//set vpa
oled_cmd(0x7F);
oled_cmd(0xBC);//set vpb
oled_cmd(0x7F);
oled_cmd(0xBD); //set vpc
oled_cmd(0x7F);
oled_cmd(0xBE);//set vcomh
oled_cmd(0x7F);
}
int main()
{
init_OLED(); // initialize OLED module
while(1)
{
delay(5000L);
show_bitmap(); // display image
}
return 0;
}