Has anyone ran a PCF8833 LCD display from the maple's SPI port? I would like to add a Nokia 6100 Display to my project but most off the code from arduino sites use bit banging and I would prefer to use the built in SPI port.
Nokia 6100 Display
(11 posts) (4 voices)-
Posted 5 years ago #
-
Do you have a link to the code?
Posted 5 years ago # -
the examples i have seen are here.
http://www.arduino.cc/playground/Code/LCDPCF8833
and there is come code here tat i think looks useful.
http://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdfPosted 5 years ago # -
I need to send a 9 bit code out the spi port. The 9th bit selects between the control register and memory in the LCD. Using the Spi.send() command how can i send 9 bits? would this work?
void writeSPI( byte data){
byte temp[2]={0b0001,data};
digitalWrite(CS, LOW);
Spi.send(temp,sizeof(temp));
digitalWrite(CS, HIGH);}It seems that this would send all the leading zeros as well, and I'm not sure of the effect that would have.
Posted 5 years ago # -
Have a look here: http://github.com/leaflabs/libmaple/blob/master/wirish/comm/HardwareSPI.h
SPI got pushed out in 0.0.6, but it was undocumented because it wasnt adequately stress tested. The docs package for this (and other hidden features) are part of the 0.0.7 IDE ticket bundle.
Would love to see some pictures of driving the LCD! Weve done OLED's here before to great effect, graphics are just the best.
Posted 5 years ago # -
I am almost finished porting over a small arduino library for the PCF8833 created by Markos Kyritsis. I am stuck on one line.
pgm_read_word_near
this command seems to be in the <avr/pgmspace.h> file but I'm not sure of the maple equivalent.
the code it comes from is given below....
void PhilipsLCD::DrawBitmap(int xpos, int ypos) {
int count = 0;
for (int j = 0; j < sheight; j++) {
for (int i = 0; i < swidth; i++) {
DrawPixel(pgm_read_word_near(header_data + count),xpos+i,ypos+j);
count++;
}
}}
Posted 5 years ago # -
here is the code so far..
///----------------------------------------------------------------------------
// PhilipsLCD.cpp
//------------------------------------------------------------------------------// This library has been created by Markos Kyritsis. The stuff is all copyleft, so go ahead and do whatever you like
// with it. Please contribute to the community and upload all changes to the arduino playground for everyone else to
// use. Enjoy!#include "PhilipsLCD.h"
#include "Image.h"
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include "WProgram.h"HardwareSPI Spi(2);
PhilipsLCD::PhilipsLCD() {
}
void PhilipsLCD::LCDClear(int color) // Clear the whole screen with the specified colour
{LCDCommand(0x2B);
LCDData(0);
LCDData(132);
LCDCommand(0x2A);
LCDData(0);
LCDData(132);
LCDCommand(0x2C);
for(int i=0; i < (132*132)/2; i++)
{
LCDData((color>>4)&0x00FF);
LCDData(((color&0x0F)<<4)|(color>>8));
LCDData(color&0x0FF);
}
}void PhilipsLCD::LCDInit(void) // Initialise the screen
{
LCDCommand(0x11);
LCDCommand(0x03);
LCDCommand(0x21);
LCDCommand(0x36);
LCDData(0xC8);
LCDCommand(0x3A);
LCDCommand(0x25);
LCDData(0x30);
LCDCommand(0x00);LCDCommand(0x29);
}
void PhilipsLCD::LCDCommand(unsigned char data) // Send a hex command through the serial port (MOSI 0 first)
{unsigned char temp[2]={0b0000,data}; //
digitalWrite(CS, LOW); // disable CS
Spi.send(temp,sizeof(temp));
digitalWrite(CS, HIGH);}
void PhilipsLCD::LCDData(unsigned char data) // Send hex data through the serial port (MOSI 1 first)
{unsigned char temp[2]={0b0001,data};
digitalWrite(CS, LOW); // disable CS
Spi.send(temp,sizeof(temp));
digitalWrite(CS, HIGH);}
void PhilipsLCD::DrawPixel(int color, unsigned char x, unsigned char y) // 12bit pixel information FORMAT: RGB, four bits for each. MAX = FFF MIN = 000
{
LCDCommand(0x2B); // x start
LCDData(x);
LCDData(132);LCDCommand(0x2A); // y start
LCDData(y);
LCDData(132);LCDCommand(0x2C); // write
LCDData((unsigned char)((color>>4)&0x00FF));
LCDData((unsigned char)(((color&0x0F)<<4)|0x00));
}void PhilipsLCD::DrawCircle(int colour, uint8_t x0, uint8_t y0, uint8_t radius) //Midpoint circle algorithm
{
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;DrawPixel(colour,x0, y0 + radius);
DrawPixel(colour,x0, y0 - radius);
DrawPixel(colour,x0 + radius, y0);
DrawPixel(colour,x0 - radius, y0);while(x < y)
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
DrawPixel(colour,x0 + x, y0 + y);
DrawPixel(colour,x0 - x, y0 + y);
DrawPixel(colour,x0 + x, y0 - y);
DrawPixel(colour,x0 - x, y0 - y);
DrawPixel(colour,x0 + y, y0 + x);
DrawPixel(colour,x0 - y, y0 + x);
DrawPixel(colour,x0 + y, y0 - x);
DrawPixel(colour,x0 - y, y0 - x);
}
}void PhilipsLCD::DrawBrLine(int colour, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) { // Bresenham Line Algorithm
int Dx = x1 - x0;
int Dy = y1 - y0;
int steep = (abs(Dy) >= abs(Dx));
if (steep) {int a = x0;
int b = y0;
x0=b;
y0=a;a = x1;
b = y1;
x1=b;
y1=a;// recompute Dx, Dy after swap
Dx = x1 - x0;
Dy = y1 - y0;
}
int xstep = 1;
if (Dx < 0) {
xstep = -1;
Dx = -Dx;
}
int ystep = 1;
if (Dy < 0) {
ystep = -1;
Dy = -Dy;
}
int TwoDy = 2*Dy;
int TwoDyTwoDx = TwoDy - 2*Dx; // 2*Dy - 2*Dx
int E = TwoDy - Dx; //2*Dy - Dx
int y = y0;
int xDraw, yDraw;
for (int x = x0; x != x1; x += xstep) {
if (steep) {
xDraw = y;
yDraw = x;
} else {
xDraw = x;
yDraw = y;
}
// plot
DrawPixel(colour,xDraw, yDraw);
// next
if (E > 0) {
E += TwoDyTwoDx; //E += 2*Dy - 2*Dx;
y = y + ystep;
} else {
E += TwoDy; //E += 2*Dy;
}
}
}void PhilipsLCD::FillRectangle(int colour, uint8_t x0, uint8_t y0, uint8_t width, uint8_t height)
{
for (uint8_t i = y0+1; i < y0+height; i++) {
DrawBrLine(colour, x0, i, x0+width, i);
}}
void PhilipsLCD::DrawRectangle(int colour, uint8_t x0, uint8_t y0, uint8_t width, uint8_t height)
{
// Draw Top side
DrawBrLine(colour,x0, y0, x0+width+1, y0);// Draw Bottom side
DrawBrLine(colour,x0, y0+height, x0+width+1, y0+height);// Now the sides
for (uint8_t i = y0+1; i < y0+height; i++) {
DrawPixel(colour,x0,i);
DrawPixel(colour,x0+width,i);
}
}void PhilipsLCD::DrawBitmap(int xpos, int ypos) {
int count = 0;
for (int j = 0; j < sheight; j++) {
for (int i = 0; i < swidth; i++) {
DrawPixel(pgm_read_word_near(header_data + count),xpos+i,ypos+j);
count++;
}
}}
PhilipsLCD LCDP = PhilipsLCD();
///----------------------------------------------------------------------------
// philipsLCD.h
///----------------------------------------------------------------------------// This library has been created by Markos Kyritsis. The stuff is all copyleft, so go ahead and do whatever you like
// with it. Please contribute to the community and upload all changes to the arduino playground for everyone else to
// use. Enjoy!
#ifndef PhilipsLCD_h#define PhilipsLCD_h
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>class PhilipsLCD {
private:
typedef unsigned char byte;
public:
PhilipsLCD();
void LCDCommand(unsigned char data);
void LCDData(unsigned char data);
void LCDInit(void);
void LCDClear(int color);
void DrawPixel(int color, unsigned char x, unsigned char y);
void DrawCircle(int colour, uint8_t x0, uint8_t y0, uint8_t radius);
void DrawBrLine(int colour, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void FillRectangle(int colour, uint8_t x0, uint8_t y0, uint8_t width, uint8_t height);
void DrawRectangle(int colour, uint8_t x0, uint8_t y0, uint8_t width, uint8_t height);
void DrawBitmap(int xpos, int ypos);// old stuff
//static const byte CS = 9;
//static const byte SCLK = 7;
//static const byte SDATA = 5;// LCD display IO pins
static const byte pinRST ;// = 1; // used to reset the lcd display
static const byte CS ;// = 31; // chip select
static const byte MISO ;// = 33; // data out
static const byte MOSI ;// = 34; // data in
static const byte SCLK ;// = 32; // system clock//extern PhilipsLCD LCDP;
};
#endif
///----------------------------------------------------------------------------
// image.h
///----------------------------------------------------------------------------
static int swidth = 24; // change these
static int sheight = 29; // change thesestatic const int header_data[] = { // add data here
0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee9
,0x997
,0x777
,0x77b
,0xbbe
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffc
,0xcc1
,0x110
,0x000
,0x000
,0x002
,0x225
,0x55e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee4
,0x440
,0x000
,0x000
,0x000
,0x004
,0x442
,0x226
,0x66f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee0
,0x001
,0x110
,0x000
,0x000
,0x001
,0x110
,0x000
,0x00e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffd
,0xdd0
,0x004
,0x441
,0x110
,0x003
,0x334
,0x441
,0x110
,0x00b
,0xbbf
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee3
,0x337
,0x774
,0x443
,0x33a
,0xaa9
,0x992
,0x220
,0x009
,0x99f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee4
,0x441
,0x119
,0x857
,0x745
,0x555
,0x554
,0x440
,0x009
,0x99f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfe2
,0x21b
,0x94d
,0xb3d
,0xb3c
,0xa3c
,0xa71
,0x110
,0x007
,0x77f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee6
,0x53c
,0x92d
,0xb3d
,0xb5c
,0xa3c
,0xa34
,0x310
,0x115
,0x55f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfe4
,0x44a
,0x94b
,0xa4b
,0xa3b
,0xa4c
,0xb84
,0x434
,0x442
,0x22d
,0xddf
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffc
,0xcc3
,0x33c
,0xcbc
,0xb7c
,0xb7c
,0xcbe
,0xeeb
,0xbb0
,0x000
,0x005
,0x55e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee3
,0x339
,0x99e
,0xeed
,0xdcd
,0xdde
,0xeee
,0xeee
,0xee3
,0x330
,0x000
,0x00a
,0xaaf
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee7
,0x773
,0x33e
,0xeee
,0xeee
,0xeee
,0xeee
,0xeef
,0xffe
,0xee8
,0x880
,0x000
,0x001
,0x11d
,0xddf
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffb
,0xbb0
,0x006
,0x66e
,0xeee
,0xeed
,0xdde
,0xeef
,0xffe
,0xeed
,0xddc
,0xcc0
,0x000
,0x000
,0x004
,0x44f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xff4
,0x440
,0x00c
,0xcce
,0xeef
,0xffe
,0xeef
,0xfff
,0xfff
,0xffe
,0xeed
,0xdd6
,0x661
,0x110
,0x000
,0x00b
,0xbbf
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xffd
,0xdd1
,0x115
,0x55e
,0xeef
,0xffe
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xeed
,0xdd1
,0x111
,0x110
,0x005
,0x55f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xff8
,0x880
,0x00b
,0xbbf
,0xfff
,0xffe
,0xeee
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee2
,0x220
,0x000
,0x001
,0x11e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee3
,0x332
,0x22e
,0xeef
,0xfff
,0xffe
,0xeee
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xee3
,0x330
,0x000
,0x000
,0x00b
,0xbbf
,0xfff
,0xfff
,0xfff
,0xfff
,0xff8
,0x881
,0x114
,0x44e
,0xeef
,0xfff
,0xffe
,0xeee
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xff4
,0x440
,0x000
,0x000
,0x009
,0x99f
,0xfff
,0xfff
,0xfff
,0xfff
,0xfe7
,0x663
,0x206
,0x66f
,0xfff
,0xfff
,0xffe
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xfee
,0xee4
,0x441
,0x111
,0x110
,0x009
,0x99f
,0xfff
,0xfff
,0xfff
,0xffe
,0xeec
,0xb5d
,0xa07
,0x62b
,0xbbe
,0xfef
,0xffe
,0xeee
,0xeef
,0xfff
,0xfff
,0xfff
,0xffe
,0xeee
,0xc54
,0x410
,0x000
,0x003
,0x31d
,0xcaf
,0xfff
,0xfff
,0xeee
,0xedb
,0xb8b
,0x91d
,0xa0d
,0xa04
,0x318
,0x88e
,0xeee
,0xeee
,0xeef
,0xfff
,0xfff
,0xfff
,0xffd
,0xddd
,0xa06
,0x500
,0x000
,0x00a
,0x80e
,0xc7f
,0xfff
,0xffd
,0xc7c
,0xa1b
,0x90c
,0xa0d
,0xa0d
,0xa0a
,0x800
,0x006
,0x66e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffb
,0xbbc
,0xa0a
,0x807
,0x619
,0x80d
,0xa0d
,0xb2e
,0xedf
,0xffd
,0xb5d
,0xa0d
,0xa0d
,0xa0d
,0xa0d
,0xa0c
,0xa05
,0x400
,0x00c
,0xccf
,0xfff
,0xfff
,0xfff
,0xfff
,0xffa
,0xa9c
,0x91d
,0xa0c
,0xa0d
,0xa0d
,0xb0d
,0xa0d
,0xb3e
,0xedb
,0xa6c
,0xa0d
,0xb0d
,0xb0d
,0xb0d
,0xb0d
,0xa0c
,0x90a
,0xa8e
,0xeef
,0xfff
,0xfff
,0xffe
,0xeea
,0xaa3
,0x21c
,0x90d
,0xb0d
,0xb0d
,0xa0d
,0xa0d
,0xb0d
,0xb0d
,0xc5b
,0xa5c
,0x90d
,0xa0d
,0xa0d
,0xb0d
,0xb0d
,0xb0d
,0xa0a
,0x82a
,0xaad
,0xddc
,0xcca
,0xaa5
,0x550
,0x003
,0x20c
,0xa0d
,0xb0d
,0xa0d
,0xa0c
,0xa0c
,0xa0d
,0xb4e
,0xecc
,0xb6a
,0x81a
,0x80b
,0x91b
,0x90d
,0xa0d
,0xa0d
,0xa0a
,0x811
,0x100
,0x000
,0x000
,0x000
,0x000
,0x004
,0x30c
,0xa0d
,0xa0c
,0xa0c
,0x90c
,0xa3e
,0xdbf
,0xeef
,0xffe
,0xeee
,0xedd
,0xcab
,0xa79
,0x839
,0x71a
,0x81a
,0x818
,0x727
,0x77a
,0xaab
,0xbbb
,0xbbb
,0xbba
,0xaa8
,0x86a
,0x80c
,0x90b
,0x90c
,0xa5e
,0xeef
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
,0xfff
,0xeee
,0xeed
,0xdca
,0xa7a
,0x96d
,0xccf
,0xfef
,0xfff
,0xfff
,0xfff
,0xfff
,0xffe
,0xeea
,0xa7a
,0x95c
,0xb8e
,0xeef
,0xfff
,0xfff
,0xfff
,0xfff
};//--------------------------------------------------------------------------------
// main program
//------------------------------------------------------------------------------
#include "WProgram.h"
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>HardwareSPI Spi(2); // this has to appear here
#include <PhilipsLCD.h>
pinRST = 1; // used to reset the lcd display
CS = 31; // chip select
MISO = 33; // data out
MOSI = 34; // data in
SCLK = 32;more code to come........................
I welcome any and all constructive criticism. :)
Posted 5 years ago # -
Hey, great post! I still see a pgm_read_near line there, is it working?
I am not an AVR expert, but there are various convenience macros and function for reading and writing the non volatile flash memory and fuse bits. I suspect pgm_read_word_near is just "read from non volatile memory." Assuming this is true (I could be way off here), then you shouldnt need pgm_read_word_near at all. Everything on Maple is one continuous address space (including all the non memory stuff like peripherals an GPIO), so you can read from anywhere just via pointers and such, or array indexing.Without going out of your way to try and write to the flash (not recommended - see: http://forums.leaflabs.com/topic.php?id=146#post-916), you can only get your large ROM buffers into your sketch at compile time via this trick described above.
Then just read from the array as you would a regular array.
Feel free to branch off of our maple-ide repository at github.com/leaflabs - the libraries go in maple-ide/libraries by pushing your completed libraries into your own branch (on your own repository...get a github account!) and link to it! We DO track user patches, and are excited to start seeing our codebase see more and more contributed content. Dont forget to put the license in your files!
I should mention, and this goes for anyone considering submitting patches, etc. LeafLabs code is licensed under the permissive MIT license, which is incompatible with GPL (GPL code added to an MIT project makes the whole project GPL). We havnt figured out all the nitty gritty details yet, but for now we wont be pushing GPL code into the libmaple and wirish codebases, but we will happily link to it and promote it. Its very likely that an exception will be made for "libraries" since it can be considered an library built on TOP of a platform, thus licenses dont affect the lower level platform...blah blah.
I dont mean to suggest or coerce in any way that you should use a different license. I am just saying we are careful about what we push into the codebase that we distribute, and we havnt sorted out the details of what is permissible and not permissible.
Thanks!
Posted 5 years ago # -
Unfortunately it doesn't work yet. This posted code still has problems with compiling and I'm unsure if i handled the "static const byte" variables for the LCD display IO pins correctly and I'm still waiting for the actual LCD to test it. any day now. :)
Posted 5 years ago # -
I got it working. I think it's working but without the lcd display, I have on order, I can't be sure. But I can see a clock signal at the clock pin and data at the data pin, so I am hope full. There is still a little bit of work i need to do before I can call it complete but it should work for most people. I'll have to add a page on how to use it but for now here it is
http://github.com/wilsonjc/PhilipsLCD_PCF8833_Maplecheers
Posted 5 years ago # -
wilsonjc: Fantastic! It's great to see the open source spirit at work. And it's icing on the cake that you've used github, where we can keep our eyes on your code.
I've added your repo to my watch list, and am looking forward to your updates.
Posted 5 years ago #
Reply
You must log in to post.