Hi All, I am very new to arduino. So far I have managed to hook up an accelerometer and get it running with the values appearing in the monitor. I then went and bought a display made by DF Robot.
I went and got the particular library and was able to compile the sketch example for the parallel method of operating.
So far so good.
I also got the sketch example to run the display in serial [it can do both serial and parallel mode]. This is when I got compile errors.
Here is a list of the errors I got. I have no idea what to do now and hope someone can help me.
Rob [Sydney Australia]
Note: I have also copied the example sketch at the bottom of this message in case this can be of use. And further down the header file and .cpp file.
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp: In member function 'void LCD12864RSPI::delayns()':
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:28: error: 'delayMicroseconds' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp: In member function 'void LCD12864RSPI::WriteByte(int)':
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:34: error: 'HIGH' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:34: error: 'digitalWrite' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:36: error: 'MSBFIRST' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:36: error: 'shiftOut' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:37: error: 'LOW' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp: In member function 'void LCD12864RSPI::Initialise()':
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:72: error: 'OUTPUT' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:72: error: 'pinMode' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:75: error: 'LOW' was not declared in this scope
/Users/robmeyer/Documents/Arduino/libraries/LCD12864RSPI/LCD12864RSPI.cpp:75: error: 'digitalWrite' was not declared in this scope
Example sketch that produced the errors:
/*
LCD Arduino
PIN1 = GND
PIN2 = 5V
RS(CS) = 8;
RW(SID)= 9;
EN(CLK) = 3;
PIN15 PSB = GND;
*/
#include "LCD12864RSPI.h"
#include "DFrobot_bmp.h"
#include "DFrobot_char.h"
#define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] )
unsigned char wangzhi[]=" www.DFRobot.cn ";//
unsigned char en_char1[]="ST7920 LCD12864 ";//
unsigned char en_char2[]="Test, Copyright ";//
unsigned char en_char3[]="by DFRobot ---> ";//
void setup()
{
LCDA.Initialise(); // INIT SCREEN
delay(100);
LCDA.DrawFullScreen(logo);//LOGO
delay(5000);
}
void loop()
{
LCDA.CLEAR();//????
delay(100);
LCDA.DisplayString(0,0,en_char1,16);//
delay(10);
LCDA.DisplayString(1,0,en_char2,16);//
delay(10);
LCDA.DisplayString(2,0,en_char3,16);//
delay(10);
LCDA.DisplayString(3,0,wangzhi,16);//
delay(5000);
LCDA.CLEAR();//????
delay(100);
LCDA.DisplayString(0,0,show1,16);//
delay(10);
LCDA.DisplayString(1,0,show2,16);//
delay(10);
LCDA.DisplayString(2,0,show3,16);//
delay(10);
LCDA.DisplayString(3,0,wangzhi,16);//LOGO
delay(5000);
}
HEADER File from Library "LCD12864RSPI.h"
//Demo LCD12864 spi
//www.dfrobot.com
#ifndef LCD12864RSPI_h
#define LCD12864RSPI_h
#include <avr/pgmspace.h>
#include <inttypes.h>
class LCD12864RSPI {
typedef unsigned char uchar;
public:
LCD12864RSPI();
void Initialise(void);
void delayns(void);
void WriteByte(int dat);
void WriteCommand(int CMD);
void WriteData(int CMD);
void CLEAR(void);
void DisplayString(int X,int Y,uchar *ptr,int dat);
void DisplaySig(int M,int N,int sig);
void DrawFullScreen(uchar *p);
void img1(uchar img[]);
void img2(uchar img[]);
int delaytime;
int DEFAULTTIME;
static const int latchPin = 8;
static const int clockPin = 3;
static const int dataPin = 9;
};
extern LCD12864RSPI LCDA;
#endif
CPP File from Library
//Demo LCD12864 spi
//www.dfrobot.com
#include "LCD12864RSPI.h"
extern "C"
{
#include <wiring.h>
#include <inttypes.h>
#include <stdio.h> //not needed yet
#include <string.h> //needed for strlen()
#include <avr/pgmspace.h>
}
LCD12864RSPI::LCD12864RSPI()
{
this->DEFAULTTIME = 80; // 80 ms default time
this->delaytime = DEFAULTTIME;
}
//—” ±?Ø ?***//
void LCD12864RSPI::delayns(void)
{
delayMicroseconds(delaytime);
}
void LCD12864RSPI::WriteByte(int dat)
{
digitalWrite(latchPin, HIGH);
delayns();
shiftOut(dataPin, clockPin, MSBFIRST, dat);
digitalWrite(latchPin, LOW);
}
void LCD12864RSPI::WriteCommand(int CMD)
{
int H_data,L_data;
H_data = CMD;
H_data &= 0xf0; //?¡±ŒµÕ4Œªµƒ ?æ›
L_data = CMD; //xxxx0000?Ò ?
L_data &= 0x0f; //?¡±Œ??4Œªµƒ ?æ›
L_data <<= 4; //xxxx0000?Ò ?
WriteByte(0xf8); //RS=0£¨–¥»Îµƒ «÷?¡Ó£ª
WriteByte(H_data);
WriteByte(L_data);
}
void LCD12864RSPI::WriteData(int CMD)
{
int H_data,L_data;
H_data = CMD;
H_data &= 0xf0; //?¡±ŒµÕ4Œªµƒ ?æ›
L_data = CMD; //xxxx0000?Ò ?
L_data &= 0x0f; //?¡±Œ??4Œªµƒ ?æ›
L_data <<= 4; //xxxx0000?Ò ?
WriteByte(0xfa); //RS=1£¨–¥»Îµƒ « ?æ›
WriteByte(H_data);
WriteByte(L_data);
}
void LCD12864RSPI::Initialise()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(latchPin, LOW);
delayns();
WriteCommand(0x30); //?¶ƒ‹…Ë?®øÿ÷??÷
WriteCommand(0x0c); //œ‘ æø™?ÿøÿ÷??÷
WriteCommand(0x01); //«Â???¡ƒªøÿ÷??÷
WriteCommand(0x06); //?¯»Î…Ë?®µ„øÿ÷??÷
}
void LCD12864RSPI::CLEAR(void)
{
WriteCommand(0x30);//
WriteCommand(0x01);//«Â??œ‘ æ
}
void LCD12864RSPI::DisplayString(int X,int Y,uchar *ptr,int dat)
{
int i;
switch(X)
{
case 0: Y|=0x80;break;
case 1: Y|=0x90;break;
case 2: Y|=0x88;break;
case 3: Y|=0x98;break;
default: break;
}
WriteCommand(Y); // ?®Œªœ‘ æ?? ºµÿ÷?
for(i=0;i<dat;i++)
{
WriteData(ptr*);//œ‘ æ???÷ ±?¢“‚¬Î÷µ£¨¡¨–¯¡??ˆ¬Î±Ì 擪?ˆ???÷*
-
}*
}
void LCD12864RSPI::DisplaySig(int M,int N,int sig)
{ -
switch(M)*
-
{*
-
case 0: N|=0x80;break;*
-
case 1: N|=0x90;break;*
-
case 2: N|=0x88;break;*
-
case 3: N|=0x98;break;*
-
default: break;*
-
}*
-
WriteCommand(N); // ?®Œªœ‘ æ?? ºµÿ÷?*
-
WriteData(sig); // ‰?ˆµ•?ˆ?÷??*
}
void LCD12864RSPI::DrawFullScreen(uchar *p)
{ -
int ygroup,x,y,i;*
-
int temp;*
-
int tmp;*
-
for(ygroup=0;ygroup<64;ygroup++) //–¥»Î“?æß…œ?ÎÕºœÛ?ø?÷*
-
{ //–¥»Î?¯±Í*
-
if(ygroup<32)*
-
{*
-
x=0x80;*
-
y=ygroup+0x80;*
-
}*
-
else*
-
{*
-
x=0x88;*
-
y=ygroup-32+0x80; *
-
} *
-
WriteCommand(0x34); //–¥»Î¿©?‰÷?¡Ó?¸¡Ó*
-
WriteCommand(y); //–¥»Îy÷·?¯±Í*
-
WriteCommand(x); //–¥»Îx÷·?¯±Í*
-
WriteCommand(0x30); //–¥»Îª?±æ÷?¡Ó?¸¡Ó*
_ tmp=ygroup*16;_ -
for(i=0;i<16;i++)*
-
{*
-
temp=p[tmp++];*
-
WriteData(temp);*
-
}*
-
}*
-
WriteCommand(0x34); //–¥»Î¿©?‰÷?¡Ó?¸¡Ó*
-
WriteCommand(0x36); //œ‘ æÕºœÛ*
}
void LCD12864RSPI::img1(uchar img[])
{ -
unsigned int i;*
-
unsigned char page,column; *
-
for(page=0xB0;page<0xB4;page++) *
-
{ *
-
WriteCommand(page); //set page address *
-
WriteCommand(0x10); //set Column address MSB *
-
WriteCommand(0x04); //set column address LSB*
_ i = (0xB3-page)*128;_
- for(column=0;column<128;column++) *
- { *
- WriteData(~img[i+column]); *
- }*
- }*
- WriteCommand(0x34); //–¥»Î¿©?‰÷?¡Ó?¸¡Ó*
- WriteCommand(0x36); //œ‘ æÕºœÛ*
}
void LCD12864RSPI::img2(uchar img[])
{ - unsigned int i;*
- unsigned char page,column; *
- for(page=0xB4;page<0xB8;page++) *
- { *
- WriteCommand(page); //set page address *
- WriteCommand(0x10); //set Column address MSB *
- WriteCommand(0x04); //set column address LSB*
_ i = (0xB7-page)*128;_
- for(column=0;column<128;column++) *
- { *
- WriteData(~img[i+column]); *
- }*
- } *
- WriteCommand(0x34); //–¥»Î¿©?‰÷?¡Ó?¸¡Ó*
- WriteCommand(0x36); //œ‘ æÕºœÛ*
}
LCD12864RSPI LCDA = LCD12864RSPI();