Graphic LCD Display ST7565R
This is a nice 128 by 64 pixel LCD Display, available from RS
RS-564416
RS-564393 a bit smaller
and from DOGM Graphics (nice data-sheet)
Note: there is no built in Alphabet
The display is divided into 8 lines, of 8 pixels, by 128.
This does mean that for graphics, you are bound by an 8, 16, 24 .. pixel high stripe.
I have used SPI, as the MBED is plenty fast enough, and only ends up needing 5 wires, plus 2 power.
CODE:
#include "GLCD-ST7565R.h" #include "char.h" #include "mbed.h" // pin remapping GLCD_ST7565R::GLCD_ST7565R (PinName mosi , PinName miso, PinName sclk, PinName GLCD_CS, PinName GLCD_DC, PinName GLCD_Reset) : // mosi, miso, clk, CS, DC, Reset _spi (mosi, miso, sclk), _GLCD_CS (GLCD_CS), _GLCD_DC (GLCD_DC), _GLCD_Reset (GLCD_Reset) { // Default constructor .. _normal = 1; Init_GLCD(); } /* //SPI spi(p11, p12, p13); // mosi, miso, sclk //DigitalOut n_OLED_Reset (p24); //DigitalOut n_OLED_CS (p25); //DigitalOut n_OLED_DC (p26); */ // ------------------------------------------------------ void GLCD_ST7565R::comm_out (unsigned char command) { _GLCD_DC = 0; _GLCD_CS = 0; _spi.write (command); _GLCD_CS = 1; } // ********************************************************** // void GLCD_ST7565R::data_out (unsigned char data) { _GLCD_DC = 1; _GLCD_CS = 0; if (_normal) { _spi.write (data); } else // _invert { _spi.write (~data); } _GLCD_CS = 1; } // ********************************************************** // void GLCD_ST7565R::Init_GLCD(void) { _spi.format(8,0); _spi.frequency(200000); // send some dummy packets .. comm_out(0x00); comm_out(0x00); // force Hardware reset .. _GLCD_Reset = 0; _GLCD_CS = 1; // reset wait_ms(200); _GLCD_Reset = 0; wait_ms(500); _GLCD_Reset = 1; wait_ms(500); #define RotDisplay comm_out(0x40); //set command unlock #ifdef RotDisplay comm_out(0xa1); //$A0=Normal $A1=Invert akkow sensiable X:Y mapping comm_out(0xc0 | 0x00); //Select COM output scan direction #else comm_out(0xa0); //$A0=Normal $A1=Invert akkow sensiable X:Y mapping comm_out(0xc0 | 0x08); //Select COM output scan direction #endif comm_out(0xa7); // comm_out(0xa2); //LCD Bias comm_out(0x2f); //set multiplex ratio comm_out(0xf8); //Booster Ratio comm_out(0x00); // 0=2x,3x,4x 1=5x, 3=6x comm_out(0x27); //V0 (Rb/Ra) ? Contrast comm_out(0x81); //Electronic VOLUME ($16) comm_out(0x05); //..value comm_out(0xac); //Sleep mode ? comm_out(0x00); //second byte #ifdef invert comm_out(0xa4 | 0); //$A0=Normal $A1=Invert(9) 1 = black screen ?? no writing #else comm_out(0xa6 | 0); //$A0=Normal $A1=Invert(9) #endif cleanDDRAM(0x00); comm_out(0xaf); //Display = ON comm_out(0xb0); // page (0..16) comm_out(0x40); // display start line ($40..$7f) comm_out(0x10); // Column Address ($10 | MSB) (4-bits) comm_out(0x00); // ...............($00 | LSB) (4-bits) } // ********************************************************** // void GLCD_ST7565R::GLCD_String (char Coll, char Line, char *Phrase) { _col = Coll; _row = Line; Line = Line & 0x07; #ifdef RotDisplay Coll += 4; // adjust for rotated display .. #endif // select ln, coll .. comm_out(0xb0 | Line); // display start line ($40..$7f) roll ? comm_out(0x10 | (Coll >> 4) ); comm_out(0x00 | (Coll & 0x0f)); while (*Phrase) { GLCDCharC_GEN(*Phrase++); } } /* ******************************************************* */ /* ******************************************************* */ // locate .. void GLCD_ST7565R::GLCD_Locate (char Coll, char Line) { _col = Coll; _row = Line; Line = Line & 0x07; #ifdef RotDisplay Coll += 4; // adjust for rotated display .. #endif // select ln, coll .. comm_out(0xb0 | Line); // display start line ($40..$7f) roll ? comm_out(0x10 | (Coll >> 4) ); comm_out(0x00 | (Coll & 0x0f)); } /* ******************************************************* */ /* ******************************************************* */ // printf .. int GLCD_ST7565R::_putc (int c) { GLCDCharC_GEN(c); return c; } int GLCD_ST7565R::_getc() { return -1; } /* ******************************************************* */ void GLCD_ST7565R::GLCDCharC_GEN (unsigned char Alph) { unsigned char line, BitsOut; int pt; if (Alph < 0x20) Alph = 0x20; // canot display .. Alph -= 0x20; // array of data starts @ "space" ~ $20 ! //Alph = Alph << 3; pt = Alph; pt = pt<< 3; for (line = 0; line<8; line++) { BitsOut = Character8x7[pt | line]; data_out(BitsOut); _col ++; // catch for over printing .. if (_col > 127) { _col = 0; _row++; _row &= 0x07; GLCD_Locate(_col, _row); } } // detect if width is low, eg 'i' as opposed to 'H', // .... only a few char's are shorter, no gain is not high enough. } /* ************************************************************** */ void GLCD_ST7565R::GLCD_Bargraph (char Line, char Percent) { Line = Line & 0x07; char Coll; // adjust for rotated display .. #ifdef RotDisplay Coll = 4; #else Coll = 0; #endif char Len,ch; // select ln, coll .. comm_out(0xb0 | Line); // display start line ($40..$7f) roll ? comm_out(0x10 | (Coll >> 4) ); comm_out(0x00 | (Coll & 0x0f)); data_out(0x00); data_out(0x00); data_out(0x00); data_out(0x00); data_out(0x3e); for (Len = 0; Len < 120; Len++) { ch = 0x41; if (Len < Percent) ch |= 0x3e; data_out(ch); } data_out(0x3e); } /* ************************************************************** */ void GLCD_ST7565R::GLCD_Draw_Box (char x, char y, char xx, char yy) { } // ********************************************************** // void GLCD_ST7565R::cleanDDRAM(int pattern) { int Ln,Col; for (Ln=0;Ln<8;Ln++) { comm_out(0xb0|Ln); // display start line ($40..$7f) roll ? comm_out(0x10); #ifdef RotDisplay comm_out(0x04); #else comm_out(0x00); #endif for (Col=0;Col<128;Col++) { //data_out(j); wait_ms (30); data_out(pattern); //data_out(0x81); } } } // ----------------------------------------------------------------- void GLCD_ST7565R::DrawBitMap (void) { } // ---------------------------------------------------------------- void GLCD_ST7565R::FatalFileWarning(char *Message) { cleanDDRAM(0x00); GLCD_Locate (0,0); printf(" ** WARNING ** "); GLCD_Locate (0,2); printf(" Could not open"); GLCD_Locate (0,4); printf(" file! "); GLCD_Locate (0,6); printf (Message); }
#ifndef _GLCD_h_ #define _GLCD_h_ #include "mbed.h" /* class TextLCD : public Stream { public: */ class GLCD_ST7565R :public Stream { public: GLCD_ST7565R (PinName mosi , PinName miso, PinName sclk, PinName GLCD_CS, PinName GLCD_DC, PinName GLCD_Reset); void cleanDDRAM(int); void Init_GLCD(void); void comm_out (unsigned char command); void data_out (unsigned char data); void GLCD_String (char px, char py, char *Phrase); //void (unsigned char Alph); void GLCDCharC_GEN (unsigned char Alph); void DrawBitMap (void); void GLCD_Bargraph (char Line, char Percent); void GLCD_Draw_Box (char x, char y, char xx, char yy); void GLCD_Locate (char Coll, char Line); void FatalFileWarning(char *Message); protected: // Stream implementation functions virtual int _putc (int); virtual int _getc (void); int _col; int _row; int _normal; // int printf(const char* format, ...); //private: // ?? SPI _spi; DigitalOut _GLCD_CS; DigitalOut _GLCD_DC; DigitalOut _GLCD_Reset; }; #endif
Additional code:
sprintf (String, "/sd/mydir/sdtest.txt" );
FILE *fp = fopen (String, "r");
if(!fp)
{
glcd.FatalFileWarning(String);
}
else
{
// normal operation
}
Pictures as well.
I used a 40 way IDC Cable (e.g. an old Hard Disk Drive cable)
cut down, and the centor 28 conductors soldered to the LCD Leads.
with the outside 4 connectors, (2 each side) going to the LED pins.
Not too clear from the photo, but the capacitors are soldered DIAGONALLY across the pins.
Connections etc., and
EAGLE schematics after that
1 comment
You need to log in to post a comment
I have some code for it here.