Pages: [1]   Go Down
Author Topic: Thinking about an OLED display  (Read 843 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://www.crystalfontz.com/product/CFAL9664BFB1
Specifics with the sample code below
http://www.crystalfontz.com/products/document/2354/CFAL9664B-F-B1_Data_Sheet_v1.2.pdf

Carrier board that simplifies the interfacing
http://www.crystalfontz.com/product/CFAL9664BFB1CB

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."

Code:
#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;
}
« Last Edit: April 22, 2012, 11:24:54 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What errors did you get? Did they start with this?

Code:
sketch_apr23c.cpp:5:24: error: 9664_isaac.h: No such file or directory

Have you located the file 9664_isaac.h? If so, can you tell me where? Thanks.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that's the first one of several.

There are 4 files here:
http://www.crystalfontz.com/products/document/2016/CFAL9664B.zip
9664_isaac.h is one of them.
CFAL9664b.aps
cfal9664b.aws
CFAL9664b.c

I put them in the same directory as the sketch. Didn't help.
Do they need to be copied into tabs in the sketch?
Not really sure how this multiple file thing works.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't make it work. First you have to make extra tabs for the files CFAL9664b.c and 9664_isaac.h. The IDE will create empty files of that name, except it doesn't like the leading numbers so it makes a tab _9664_isaac.h. Save and close the sketch, copy in those files on top of the empty ones, renaming 9664_isaac.h as _9664_isaac.h.

Change the include in two files to read:

Code:
#include "_9664_isaac.h"

(Add the underscore in other words).



Then there's a compile error on this line:

Code:
  oled_cmd(0x87); // 10000111: adjust the master current attenuation factor from 1/
16,2/16...16/16

Join those two lines together to get rid of that.

Then I get these errors:

Code:
foo_102516.cpp: In function 'void oled_cmd(unsigned int)':
foo_102516:32: error: 'OLED_CS' was not declared in this scope
foo_102516:33: error: 'OLED_CD' was not declared in this scope

I can see where they are used, like here:

Code:
#define CLR_CD PORTC &= ~(1<<OLED_CD);
#define SET_CD PORTC |= (1<<OLED_CD);

But I can't see where they are defined.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That makes two of us.  I tried the same kind of things. Renamed the file to just isaac.h, tried copying it on, tried Sketch:add file to bring it in.

Do these all need to be rewritten as voids?

#define CLR_CD PORTC &= ~(1<<OLED_CD);

void CLR_CD(){
PORTC &= ~(1<<OLED_CD);
}

Tried changing the bottom of the file too, that didn't help:
Code:
/*int main()
{
  init_OLED(); // initialize OLED module
  while(1)
  {
    delay(5000L);
    show_bitmap(); // display image
  }
  return 0;
}
*/
void setup (){
  init_OLED();
  delay (5000UL);
  show_bitmap();
}
void loop(){}

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do these all need to be rewritten as voids?

Functions is the correct term. For example:

Code:
void loop ()
  {
  // do whatever
  }

That is a function called loop, that doesn't return anything. Hence the word void, meaning "no return value".

Do these all need to be rewritten ... ?

That would look better certainly, the code is a mess. I am giving him the benefit of the doubt in that his method is probably marginally faster.

Quote
Tried changing the bottom of the file too ...

You will have to find the definition of OLED_CD, maybe can work out from the datasheet.

Code:
(1<<OLED_CD)

That's basically a bit position. So for example if OLED_CD was 4 it would be the 4th bit across (starting at zero).

You might be able to deduce it. Since this is referring to PORTC, then if OLED_CD (whatever that is) is plugged into A0, then it is 0, if it is A1 then it is 1, if it is A2 it is 2 and so on (check out the pin-outs for the Atmega).

Ditto for OLED_CS (chip select I presume).

So really, you work it out from where you plug the wires in.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

why are functions called void?
If I were going to rewrite, I think I would do it this way:

// clear a bit
PORTC = PINC & B11101111;

// set a bit
PORTC = PINC | B00010000;

Think I'll see about a Serial/I2C/SPI interface part instead.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why are functions called void?

Well, they aren't. The word void is the return type. So for example:

Code:
int foo (int a, int b)
  {
  return a + b;
  }

That is a function (not an int) that adds two things together. The original word int is the return type.



Code:
float foo (float a, float b)
  {
  return a + b;
  }

That is a function (not an float) that adds two things together. The original word float is the return type.



Code:
void foo (int a)
  {
  Serial.println (a);
  }

That is a function (not an void) that prints its argument. The original word void indicates there is no returned value.



The word "function" is implied. In some languages it is spelt out. Like in VB:

Code:
Public Function GetPi() As Double
    ' Calculate the value of pi.
    Return 4.0 * Math.Atan(1.0)
End Function

There they explicitly use the word "function".

In C that would be:

Code:
double GetPi()
  {
   // Calculate the value of pi.
    return 4.0 * atan (1.0);
  }

See how in C the word "function" just gets assumed? But it's still a function. Not a double.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick. Guess I missed those subtleties by not actually using any of those except for setup & loop.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No worries, Bob. And I must admit, when you look at setup and loop, the look like they must be "void"s.
Logged

Pages: [1]   Go Up
Jump to: