summaryrefslogtreecommitdiff
path: root/libraries/MultiLCD
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2013-04-02 16:24:09 +0800
committerStanley Huang <stanleyhuangyc@gmail.com>2013-04-02 16:24:09 +0800
commitb59be2fb6f05f43e93ce70bd140ab7149fa18c40 (patch)
tree5984c4c3c8ea7618ed478ff3deece05d4045ff17 /libraries/MultiLCD
parent509f7a67724bca9a3222a41c870da747df97f720 (diff)
download2021-arduino-obd-b59be2fb6f05f43e93ce70bd140ab7149fa18c40.tar.gz
2021-arduino-obd-b59be2fb6f05f43e93ce70bd140ab7149fa18c40.tar.bz2
2021-arduino-obd-b59be2fb6f05f43e93ce70bd140ab7149fa18c40.zip
add MultiLCD library
Diffstat (limited to 'libraries/MultiLCD')
-rw-r--r--libraries/MultiLCD/LCD4Bit_mod.cpp209
-rw-r--r--libraries/MultiLCD/LCD4Bit_mod.h47
-rw-r--r--libraries/MultiLCD/MultiLCD.cpp170
-rw-r--r--libraries/MultiLCD/MultiLCD.h44
-rw-r--r--libraries/MultiLCD/PCD8544.cpp318
-rw-r--r--libraries/MultiLCD/PCD8544.h119
-rw-r--r--libraries/MultiLCD/ZtLib.cpp601
-rw-r--r--libraries/MultiLCD/ZtLib.h127
-rw-r--r--libraries/MultiLCD/examples/lcdhello/lcdhello.ino20
9 files changed, 1655 insertions, 0 deletions
diff --git a/libraries/MultiLCD/LCD4Bit_mod.cpp b/libraries/MultiLCD/LCD4Bit_mod.cpp
new file mode 100644
index 0000000..c100c19
--- /dev/null
+++ b/libraries/MultiLCD/LCD4Bit_mod.cpp
@@ -0,0 +1,209 @@
+/*
+LCD4Bit v0.1 16/Oct/2006 neillzero http://abstractplain.net
+
+What is this?
+An arduino library for comms with HD44780-compatible LCD, in 4-bit mode (saves pins)
+
+Sources:
+- The original "LiquidCrystal" 8-bit library and tutorial
+ http://www.arduino.cc/en/uploads/Tutorial/LiquidCrystal.zip
+ http://www.arduino.cc/en/Tutorial/LCDLibrary
+- DEM 16216 datasheet http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf
+- Massimo's suggested 4-bit code (I took initialization from here) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1144924220/8
+See also:
+- glasspusher's code (probably more correct): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160586800/0#0
+
+Tested only with a DEM 16216 (maplin "N27AZ" - http://www.maplin.co.uk/Search.aspx?criteria=N27AZ)
+If you use this successfully, consider feeding back to the arduino wiki with a note of which LCD it worked on.
+
+Usage:
+see the examples folder of this library distribution.
+
+*/
+
+#if defined(ARDUINO) && ARDUINO >= 100
+#include "Arduino.h"
+#else
+#include "WProgram.h"
+#endif
+
+#include "LCD4Bit_mod.h"
+
+//command bytes for LCD
+#define CMD_CLR 0x01
+#define CMD_RIGHT 0x1C
+#define CMD_LEFT 0x18
+#define CMD_HOME 0x02
+
+//pulse the Enable pin high (for a microsecond).
+//This clocks whatever command or data is in DB4~7 into the LCD controller.
+void LCD4Bit_mod::pulseEnablePin(){
+ digitalWrite(Enable,LOW);
+ delayMicroseconds(1);
+ // send a pulse to enable
+ digitalWrite(Enable,HIGH);
+ delayMicroseconds(1);
+ digitalWrite(Enable,LOW);
+ delay(1); // pause 1 ms. TODO: what delay, if any, is necessary here?
+}
+
+//push a nibble of data through the the LCD's DB4~7 pins, clocking with the Enable pin.
+//We don't care what RS and RW are, here.
+void LCD4Bit_mod::pushNibble(byte value)
+{
+ byte val_nibble= value & 0x0F; //clean the value. (unnecessary)
+
+ for (byte i=DB[0]; i <= DB[3]; i++) {
+ digitalWrite(i,val_nibble & 01);
+ val_nibble >>= 1;
+ }
+ pulseEnablePin();
+}
+
+//push a byte of data through the LCD's DB4~7 pins, in two steps, clocking each with the enable pin.
+void LCD4Bit_mod::pushByte(byte value)
+{
+ byte val_lower = value & 0x0F;
+ byte val_upper = value >> 4;
+ pushNibble(val_upper);
+ pushNibble(val_lower);
+}
+
+void LCD4Bit_mod::commandWriteNibble(byte nibble)
+{
+ digitalWrite(RS, LOW);
+ if (USING_RW) { digitalWrite(RW, LOW); }
+ pushNibble(nibble);
+}
+
+
+void LCD4Bit_mod::commandWrite(byte value)
+{
+ digitalWrite(RS, LOW);
+ if (USING_RW) { digitalWrite(RW, LOW); }
+ pushByte(value);
+ //TODO: perhaps better to add a delay after EVERY command, here. many need a delay, apparently.
+}
+
+
+
+
+//print the given character at the current cursor position. overwrites, doesn't insert.
+void LCD4Bit_mod::write(byte c)
+{
+ //set the RS and RW pins to show we're writing data
+ digitalWrite(RS, HIGH);
+ if (USING_RW) { digitalWrite(RW, LOW); }
+
+ //let pushByte worry about the intricacies of Enable, nibble order.
+ pushByte(c);
+}
+
+
+//print the given string to the LCD at the current cursor position. overwrites, doesn't insert.
+//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library, I've preserved it here to maintain the interchangeability of the two libraries.
+void LCD4Bit_mod::print(const char* msg)
+{
+ byte i; //fancy int. avoids compiler warning when comparing i with strlen()'s uint8_t
+ byte l = strlen(msg);
+ for (i=0; i < l; i++){
+ if (msg[i] >= 20) write(msg[i]);
+ }
+}
+
+
+//send the clear screen command to the LCD
+void LCD4Bit_mod::clear()
+{
+ commandWrite(CMD_CLR);
+ delay(1);
+}
+
+
+// initiatize lcd after a short pause
+//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
+void LCD4Bit_mod::begin ()
+{
+ pinMode(Enable,OUTPUT);
+ pinMode(RS,OUTPUT);
+ if (USING_RW) { pinMode(RW,OUTPUT); }
+ pinMode(DB[0],OUTPUT);
+ pinMode(DB[1],OUTPUT);
+ pinMode(DB[2],OUTPUT);
+ pinMode(DB[3],OUTPUT);
+
+ delay(50);
+
+ //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
+ commandWriteNibble(0x03);
+ delay(5);
+ commandWriteNibble(0x03);
+ delayMicroseconds(100);
+ commandWriteNibble(0x03);
+ delay(5);
+
+ // needed by the LCDs controller
+ //this being 2 sets up 4-bit mode.
+ commandWriteNibble(0x02);
+ commandWriteNibble(0x02);
+ //todo: make configurable by the user of this library.
+ //NFXX where
+ //N = num lines (0=1 line or 1=2 lines).
+ //F= format (number of dots (0=5x7 or 1=5x10)).
+ //X=don't care
+
+ byte num_lines_ptn = (num_lines - 1) << 3;
+ byte dot_format_ptn = 0x00; //5x7 dots. 0x04 is 5x10
+
+ commandWriteNibble(num_lines_ptn | dot_format_ptn);
+ delayMicroseconds(60);
+
+ //The rest of the init is not specific to 4-bit mode.
+ //NOTE: we're writing full bytes now, not nibbles.
+
+ // display control:
+ // turn display on, cursor off, no blinking
+ commandWrite(0x0C);
+ delayMicroseconds(60);
+
+ //clear display
+ commandWrite(0x01);
+ delay(3);
+
+ // entry mode set: 06
+ // increment automatically, display shift, entire shift off
+ commandWrite(0x06);
+
+ delay(1);//TODO: remove unnecessary delays
+}
+
+
+//non-core stuff --------------------------------------
+//move the cursor to the given absolute position. line numbers start at 1.
+//if this is not a 2-line LCD4Bit_mod instance, will always position on first line.
+void LCD4Bit_mod::setCursor(byte x, byte line)
+{
+ //first, put cursor home
+ commandWrite(CMD_HOME);
+ //offset 40 chars in if second line requested
+ x += line * 40;
+
+ //advance the cursor to the right according to position. (second line starts at position 40).
+ for (byte i=0; i<x; i++) {
+ commandWrite(0x14);
+ }
+}
+
+//scroll whole display to left
+void LCD4Bit_mod::leftScroll(byte num_chars, unsigned int delay_time)
+{
+ for (byte i=0; i<num_chars; i++) {
+ commandWrite(CMD_LEFT);
+ delay(delay_time);
+ }
+}
+
+//Improvements ------------------------------------------------
+//Remove the unnecessary delays (e.g. from the end of pulseEnablePin()).
+//Allow the user to pass the pins to be used by the LCD in the constructor, and store them as member variables of the class instance.
+//-------------------------------------------------------------
diff --git a/libraries/MultiLCD/LCD4Bit_mod.h b/libraries/MultiLCD/LCD4Bit_mod.h
new file mode 100644
index 0000000..7cd5115
--- /dev/null
+++ b/libraries/MultiLCD/LCD4Bit_mod.h
@@ -0,0 +1,47 @@
+#ifndef LCD4Bit_mod_h
+#define LCD4Bit_mod_h
+
+#include <inttypes.h>
+
+class LCD4Bit_mod {
+public:
+ LCD4Bit_mod(byte num_lines = 2):USING_RW(false),RS(8),RW(11),Enable(9)
+ {
+ DB[0] = 4;
+ DB[1] = 5;
+ DB[2] = 6;
+ DB[3] = 7;
+ this->num_lines = num_lines;
+ }
+ void commandWrite(byte value);
+ void begin();
+ void write(byte value);
+ void print(const char* string);
+ void clear();
+ //non-core---------------
+ void setCursor(byte x, byte line);
+ void leftScroll(byte chars, unsigned int delay_time);
+ //end of non-core--------
+
+ //4bit only, therefore ideally private but may be needed by user
+ void commandWriteNibble(byte nibble);
+private:
+ void pulseEnablePin();
+ void pushNibble(byte nibble);
+ void pushByte(byte value);
+ // --------- PINS -------------------------------------
+ //is the RW pin of the LCD under our control? If we're only ever going to write to the LCD, we can use one less microcontroller pin, and just tie the LCD pin to the necessary signal, high or low.
+ //this stops us sending signals to the RW pin if it isn't being used.
+ bool USING_RW;
+ //RS, RW and Enable can be set to whatever you like
+ byte RS;
+ byte RW;
+ byte Enable;
+ //DB should be an unseparated group of pins - because of lazy coding in pushNibble()
+ byte DB[4]; //wire these to DB4~7 on LCD.
+ //how many lines has the LCD? (don't change here - specify on calling constructor)
+ int num_lines;
+
+};
+
+#endif
diff --git a/libraries/MultiLCD/MultiLCD.cpp b/libraries/MultiLCD/MultiLCD.cpp
new file mode 100644
index 0000000..06500fa
--- /dev/null
+++ b/libraries/MultiLCD/MultiLCD.cpp
@@ -0,0 +1,170 @@
+#include <Arduino.h>
+#include "MultiLCD.h"
+
+const PROGMEM unsigned char font16x16[][32] = {
+{0x00,0xE0,0xF8,0xFC,0xFE,0x1E,0x07,0x07,0x07,0x07,0x1E,0xFE,0xFC,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x3F,0x3F,0x7C,0x70,0x70,0x70,0x70,0x7C,0x3F,0x1F,0x1F,0x07,0x00},/*0*/
+{0x00,0x00,0x00,0x06,0x07,0x07,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00},/*1*/
+{0x00,0x38,0x3C,0x3E,0x3E,0x0F,0x07,0x07,0x07,0xCF,0xFF,0xFE,0xFE,0x38,0x00,0x00,0x00,0x40,0x40,0x60,0x70,0x78,0x7C,0x7E,0x7F,0x77,0x73,0x71,0x70,0x70,0x00,0x00},/*2*/
+{0x00,0x18,0x1C,0x1E,0x1E,0x0F,0xC7,0xC7,0xE7,0xFF,0xFE,0xBE,0x9C,0x00,0x00,0x00,0x00,0x0C,0x1C,0x3C,0x3C,0x78,0x70,0x70,0x70,0x79,0x7F,0x3F,0x1F,0x0F,0x00,0x00},/*3*/
+{0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x1E,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x06,0x07,0x07,0x07,0x06,0x06,0x06,0x06,0x06,0x7F,0x7F,0x7F,0x7F,0x06,0x06,0x00},/*4*/
+{0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xE7,0xE7,0xE7,0xE7,0xC7,0x87,0x00,0x00,0x00,0x00,0x38,0x78,0x71,0x70,0x70,0x70,0x70,0x70,0x39,0x3F,0x3F,0x1F,0x0F,0x00},/*5*/
+{0x00,0x80,0xE0,0xF0,0xF8,0xFC,0x7F,0x7F,0x6F,0x67,0xE1,0xE1,0xC0,0x80,0x00,0x00,0x00,0x0F,0x1F,0x3F,0x3F,0x78,0x70,0x70,0x70,0x70,0x78,0x3F,0x3F,0x1F,0x0F,0x00},/*6*/
+{0x00,0x07,0x07,0x07,0x07,0x07,0xC7,0xE7,0xF7,0xFF,0x7F,0x3F,0x1F,0x07,0x03,0x01,0x00,0x20,0x38,0x7C,0x7E,0x3F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*7*/
+{0x00,0x00,0x00,0x1C,0xBE,0xFE,0xFF,0xE7,0xC3,0xC3,0xE7,0xFF,0xFE,0xBE,0x1C,0x00,0x00,0x00,0x0E,0x3F,0x3F,0x7F,0x71,0x60,0x60,0x60,0x71,0x7F,0x3F,0x3F,0x0F,0x00},/*8*/
+{0x00,0x78,0xFC,0xFE,0xFE,0x8F,0x07,0x07,0x07,0x07,0x8F,0xFE,0xFE,0xFC,0xF8,0x00,0x00,0x00,0x00,0x01,0x43,0x43,0x73,0x7B,0x7F,0x7F,0x1F,0x0F,0x07,0x03,0x00,0x00},/*9*/
+};
+
+// The 7-bit ASCII character set...
+const PROGMEM unsigned char font5x8[][5] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00 }, // 20 space
+ { 0x00, 0x00, 0x5f, 0x00, 0x00 }, // 21 !
+ { 0x00, 0x07, 0x00, 0x07, 0x00 }, // 22 "
+ { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // 23 #
+ { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // 24 $
+ { 0x23, 0x13, 0x08, 0x64, 0x62 }, // 25 %
+ { 0x36, 0x49, 0x55, 0x22, 0x50 }, // 26 &
+ { 0x00, 0x05, 0x03, 0x00, 0x00 }, // 27 '
+ { 0x00, 0x1c, 0x22, 0x41, 0x00 }, // 28 (
+ { 0x00, 0x41, 0x22, 0x1c, 0x00 }, // 29 )
+ { 0x14, 0x08, 0x3e, 0x08, 0x14 }, // 2a *
+ { 0x08, 0x08, 0x3e, 0x08, 0x08 }, // 2b +
+ { 0x00, 0x50, 0x30, 0x00, 0x00 }, // 2c ,
+ { 0x08, 0x08, 0x08, 0x08, 0x08 }, // 2d -
+ { 0x00, 0x60, 0x60, 0x00, 0x00 }, // 2e .
+ { 0x20, 0x10, 0x08, 0x04, 0x02 }, // 2f /
+ { 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 30 0
+ { 0x00, 0x42, 0x7f, 0x40, 0x00 }, // 31 1
+ { 0x42, 0x61, 0x51, 0x49, 0x46 }, // 32 2
+ { 0x21, 0x41, 0x45, 0x4b, 0x31 }, // 33 3
+ { 0x18, 0x14, 0x12, 0x7f, 0x10 }, // 34 4
+ { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 35 5
+ { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 36 6
+ { 0x01, 0x71, 0x09, 0x05, 0x03 }, // 37 7
+ { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 38 8
+ { 0x06, 0x49, 0x49, 0x29, 0x1e }, // 39 9
+ { 0x00, 0x36, 0x36, 0x00, 0x00 }, // 3a :
+ { 0x00, 0x56, 0x36, 0x00, 0x00 }, // 3b ;
+ { 0x08, 0x14, 0x22, 0x41, 0x00 }, // 3c <
+ { 0x14, 0x14, 0x14, 0x14, 0x14 }, // 3d =
+ { 0x00, 0x41, 0x22, 0x14, 0x08 }, // 3e >
+ { 0x02, 0x01, 0x51, 0x09, 0x06 }, // 3f ?
+ { 0x32, 0x49, 0x79, 0x41, 0x3e }, // 40 @
+ { 0x7e, 0x11, 0x11, 0x11, 0x7e }, // 41 A
+ { 0x7f, 0x49, 0x49, 0x49, 0x36 }, // 42 B
+ { 0x3e, 0x41, 0x41, 0x41, 0x22 }, // 43 C
+ { 0x7f, 0x41, 0x41, 0x22, 0x1c }, // 44 D
+ { 0x7f, 0x49, 0x49, 0x49, 0x41 }, // 45 E
+ { 0x7f, 0x09, 0x09, 0x09, 0x01 }, // 46 F
+ { 0x3e, 0x41, 0x49, 0x49, 0x7a }, // 47 G
+ { 0x7f, 0x08, 0x08, 0x08, 0x7f }, // 48 H
+ { 0x00, 0x41, 0x7f, 0x41, 0x00 }, // 49 I
+ { 0x20, 0x40, 0x41, 0x3f, 0x01 }, // 4a J
+ { 0x7f, 0x08, 0x14, 0x22, 0x41 }, // 4b K
+ { 0x7f, 0x40, 0x40, 0x40, 0x40 }, // 4c L
+ { 0x7f, 0x02, 0x0c, 0x02, 0x7f }, // 4d M
+ { 0x7f, 0x04, 0x08, 0x10, 0x7f }, // 4e N
+ { 0x3e, 0x41, 0x41, 0x41, 0x3e }, // 4f O
+ { 0x7f, 0x09, 0x09, 0x09, 0x06 }, // 50 P
+ { 0x3e, 0x41, 0x51, 0x21, 0x5e }, // 51 Q
+ { 0x7f, 0x09, 0x19, 0x29, 0x46 }, // 52 R
+ { 0x46, 0x49, 0x49, 0x49, 0x31 }, // 53 S
+ { 0x01, 0x01, 0x7f, 0x01, 0x01 }, // 54 T
+ { 0x3f, 0x40, 0x40, 0x40, 0x3f }, // 55 U
+ { 0x1f, 0x20, 0x40, 0x20, 0x1f }, // 56 V
+ { 0x3f, 0x40, 0x38, 0x40, 0x3f }, // 57 W
+ { 0x63, 0x14, 0x08, 0x14, 0x63 }, // 58 X
+ { 0x07, 0x08, 0x70, 0x08, 0x07 }, // 59 Y
+ { 0x61, 0x51, 0x49, 0x45, 0x43 }, // 5a Z
+ { 0x00, 0x7f, 0x41, 0x41, 0x00 }, // 5b [
+ { 0x02, 0x04, 0x08, 0x10, 0x20 }, // 5c backslash
+ { 0x00, 0x41, 0x41, 0x7f, 0x00 }, // 5d ]
+ { 0x04, 0x02, 0x01, 0x02, 0x04 }, // 5e ^
+ { 0x40, 0x40, 0x40, 0x40, 0x40 }, // 5f _
+ { 0x00, 0x01, 0x02, 0x04, 0x00 }, // 60 `
+ { 0x20, 0x54, 0x54, 0x54, 0x78 }, // 61 a
+ { 0x7f, 0x48, 0x44, 0x44, 0x38 }, // 62 b
+ { 0x38, 0x44, 0x44, 0x44, 0x20 }, // 63 c
+ { 0x38, 0x44, 0x44, 0x48, 0x7f }, // 64 d
+ { 0x38, 0x54, 0x54, 0x54, 0x18 }, // 65 e
+ { 0x08, 0x7e, 0x09, 0x01, 0x02 }, // 66 f
+ { 0x0c, 0x52, 0x52, 0x52, 0x3e }, // 67 g
+ { 0x7f, 0x08, 0x04, 0x04, 0x78 }, // 68 h
+ { 0x00, 0x44, 0x7d, 0x40, 0x00 }, // 69 i
+ { 0x20, 0x40, 0x44, 0x3d, 0x00 }, // 6a j
+ { 0x7f, 0x10, 0x28, 0x44, 0x00 }, // 6b k
+ { 0x00, 0x41, 0x7f, 0x40, 0x00 }, // 6c l
+ { 0x7c, 0x04, 0x18, 0x04, 0x78 }, // 6d m
+ { 0x7c, 0x08, 0x04, 0x04, 0x78 }, // 6e n
+ { 0x38, 0x44, 0x44, 0x44, 0x38 }, // 6f o
+ { 0x7c, 0x14, 0x14, 0x14, 0x08 }, // 70 p
+ { 0x08, 0x14, 0x14, 0x18, 0x7c }, // 71 q
+ { 0x7c, 0x08, 0x04, 0x04, 0x08 }, // 72 r
+ { 0x48, 0x54, 0x54, 0x54, 0x20 }, // 73 s
+ { 0x04, 0x3f, 0x44, 0x40, 0x20 }, // 74 t
+ { 0x3c, 0x40, 0x40, 0x20, 0x7c }, // 75 u
+ { 0x1c, 0x20, 0x40, 0x20, 0x1c }, // 76 v
+ { 0x3c, 0x40, 0x30, 0x40, 0x3c }, // 77 w
+ { 0x44, 0x28, 0x10, 0x28, 0x44 }, // 78 x
+ { 0x0c, 0x50, 0x50, 0x50, 0x3c }, // 79 y
+ { 0x44, 0x64, 0x54, 0x4c, 0x44 }, // 7a z
+ { 0x00, 0x08, 0x36, 0x41, 0x00 }, // 7b {
+ { 0x00, 0x00, 0x7f, 0x00, 0x00 }, // 7c |
+ { 0x00, 0x41, 0x36, 0x08, 0x00 }, // 7d }
+ { 0x10, 0x08, 0x08, 0x10, 0x08 }, // 7e ~
+ { 0x00, 0x00, 0x00, 0x00, 0x00 } // 7f
+};
+
+void LCD_OLED::write(char c)
+{
+ char s[2] = {c};
+ ScI2cMxDisplay8x16Str(OLED_ADDRESS, m_line, m_column, s);
+}
+
+void LCD_OLED::print(const char* s)
+{
+ ScI2cMxDisplay8x16Str(OLED_ADDRESS, m_line, m_column, s);
+}
+
+void LCD_OLED::printLarge(const char* s)
+{
+ delay(5);
+ while (*s) {
+ if (*s >= '0' && *s <= '9') {
+ char data[32];
+ memcpy_P(data, font16x16[*s - '0'], 32);
+ ScI2cMxDisplayDot16x16(OLED_ADDRESS, m_line, m_column, data);
+ } else {
+ ScI2cMxFillArea(OLED_ADDRESS, m_line, m_line + 1, m_column, m_column + 16, 0);
+ }
+ m_column = (m_column + 16) & 0x7f;
+ s++;
+ }
+}
+
+void LCD_OLED::clear()
+{
+ ScI2cMxFillArea(OLED_ADDRESS, 0, 7, 0, 127, 0);
+ delay(10);
+ setCursor(0, 0);
+}
+
+void LCD_OLED::begin()
+{
+ I2cInit();
+ ScI2cMxReset(OLED_ADDRESS);
+ delay(10);
+}
+
+void LCD_PCD8544::printLarge(const char* s)
+{
+ while (*s) {
+ if (*s >= '0' && *s <= '9') {
+ unsigned char data[32];
+ memcpy_P(data, font16x16[*s - '0'], 32);
+ drawBitmap(data, 16, 16);
+ } else {
+ column = (column + 16) % 84;
+ }
+ s++;
+ }
+}
diff --git a/libraries/MultiLCD/MultiLCD.h b/libraries/MultiLCD/MultiLCD.h
new file mode 100644
index 0000000..2a10356
--- /dev/null
+++ b/libraries/MultiLCD/MultiLCD.h
@@ -0,0 +1,44 @@
+extern const PROGMEM unsigned char font16x32[][32];
+extern const PROGMEM unsigned char font5x8[][5];
+
+#include "PCD8544.h"
+
+class LCD_PCD8544 : public PCD8544 {
+public:
+ void printLarge(const char* s);
+ void backlight(bool on)
+ {
+ pinMode(7, OUTPUT);
+ digitalWrite(7, on ? HIGH : LOW);
+ }
+};
+
+#include "ZtLib.h"
+
+#define OLED_ADDRESS 0x27
+
+class LCD_OLED : public ZtLib {
+public:
+ void setCursor(unsigned char column, unsigned char line)
+ {
+ m_column = column << 3;
+ m_line = line << 1;
+ }
+ void write(char c);
+ void print(const char* s);
+ void printLarge(const char* s);
+ void clear();
+ void begin();
+ void backlight(bool on) {}
+private:
+ unsigned char m_column;
+ unsigned char m_line;
+};
+
+#include "LCD4Bit_mod.h"
+class LCD_1602 : public LCD4Bit_mod {
+public:
+ void printLarge(const char* s) { print(s); }
+ void backlight(bool on) {}
+};
+
diff --git a/libraries/MultiLCD/PCD8544.cpp b/libraries/MultiLCD/PCD8544.cpp
new file mode 100644
index 0000000..9c85662
--- /dev/null
+++ b/libraries/MultiLCD/PCD8544.cpp
@@ -0,0 +1,318 @@
+/*
+ * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
+ *
+ * Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "PCD8544.h"
+
+#if ARDUINO < 100
+#include <WProgram.h>
+#else
+#include <Arduino.h>
+#endif
+
+#include <avr/pgmspace.h>
+
+
+#define PCD8544_CMD LOW
+#define PCD8544_DATA HIGH
+
+extern const PROGMEM unsigned char font5x8[][5];
+
+/*
+ * If this was a ".h", it would get added to sketches when using
+ * the "Sketch -> Import Library..." menu on the Arduino IDE...
+ */
+
+PCD8544::PCD8544(unsigned char sclk, unsigned char sdin,
+ unsigned char dc, unsigned char reset,
+ unsigned char sce):
+ pin_sclk(sclk),
+ pin_sdin(sdin),
+ pin_dc(dc),
+ pin_reset(reset),
+ pin_sce(sce)
+{}
+
+
+void PCD8544::begin(unsigned char width, unsigned char height, unsigned char model)
+{
+ this->width = width;
+ this->height = height;
+
+ this->column = 0;
+ this->line = 0;
+
+ // Sanitize the custom glyphs...
+ memset(this->custom, 0, sizeof(this->custom));
+
+ // All pins are outputs (these displays cannot be read)...
+ pinMode(this->pin_sclk, OUTPUT);
+ pinMode(this->pin_sdin, OUTPUT);
+ pinMode(this->pin_dc, OUTPUT);
+ pinMode(this->pin_reset, OUTPUT);
+ pinMode(this->pin_sce, OUTPUT);
+
+ // Reset the controller state...
+ digitalWrite(this->pin_reset, HIGH);
+ digitalWrite(this->pin_sce, HIGH);
+ digitalWrite(this->pin_reset, LOW);
+ delay(100);
+ digitalWrite(this->pin_reset, HIGH);
+
+ // Set the LCD parameters...
+ this->send(PCD8544_CMD, 0x21); // extended instruction set control (H=1)
+ this->send(PCD8544_CMD, 0x13); // bias system (1:48)
+
+ if (model == CHIP_ST7576) {
+ this->send(PCD8544_CMD, 0xe0); // higher Vop, too faint at default
+ this->send(PCD8544_CMD, 0x05); // partial display mode
+ } else {
+ this->send(PCD8544_CMD, 0xc2); // default Vop (3.06 + 66 * 0.06 = 7V)
+ }
+
+ this->send(PCD8544_CMD, 0x20); // extended instruction set control (H=0)
+ this->send(PCD8544_CMD, 0x09); // all display segments on
+
+ // Clear RAM contents...
+ this->clear();
+
+ // Activate LCD...
+ this->send(PCD8544_CMD, 0x08); // display blank
+ this->send(PCD8544_CMD, 0x0c); // normal mode (0x0d = inverse mode)
+ delay(100);
+
+ // Place the cursor at the origin...
+ this->send(PCD8544_CMD, 0x80);
+ this->send(PCD8544_CMD, 0x40);
+}
+
+
+void PCD8544::stop()
+{
+ this->clear();
+ this->setPower(false);
+}
+
+
+void PCD8544::clear()
+{
+ this->setCursor(0, 0);
+
+ for (unsigned short i = 0; i < this->width * (this->height/8); i++) {
+ this->send(PCD8544_DATA, 0x00);
+ }
+
+ this->setCursor(0, 0);
+}
+
+
+void PCD8544::clearLine()
+{
+ this->setCursor(0, this->line);
+
+ for (unsigned char i = 0; i < this->width; i++) {
+ this->send(PCD8544_DATA, 0x00);
+ }
+
+ this->setCursor(0, this->line);
+}
+
+
+void PCD8544::setPower(bool on)
+{
+ this->send(PCD8544_CMD, on ? 0x20 : 0x24);
+}
+
+
+inline void PCD8544::display()
+{
+ this->setPower(true);
+}
+
+
+inline void PCD8544::noDisplay()
+{
+ this->setPower(false);
+}
+
+
+void PCD8544::setInverse(bool inverse)
+{
+ this->send(PCD8544_CMD, inverse ? 0x0d : 0x0c);
+}
+
+
+void PCD8544::home()
+{
+ this->setCursor(0, this->line);
+}
+
+
+void PCD8544::setCursor(unsigned char column, unsigned char line)
+{
+ this->column = (column % this->width);
+ this->line = (line % (this->height/9 + 1));
+
+ this->send(PCD8544_CMD, 0x80 | this->column);
+ this->send(PCD8544_CMD, 0x40 | this->line);
+}
+
+
+void PCD8544::createChar(unsigned char chr, const unsigned char *glyph)
+{
+ // ASCII 0-31 only...
+ if (chr >= ' ') {
+ return;
+ }
+
+ this->custom[chr] = glyph;
+}
+
+
+#if ARDUINO < 100
+void PCD8544::write(uint8_t chr)
+#else
+size_t PCD8544::write(uint8_t chr)
+#endif
+{
+ // ASCII 7-bit only...
+ if (chr >= 0x80) {
+#if ARDUINO < 100
+ return;
+#else
+ return 0;
+#endif
+ }
+
+ const unsigned char *glyph;
+ unsigned char pgm_buffer[5];
+
+ if (chr >= ' ') {
+ // Regular ASCII characters are kept in flash to save RAM...
+ memcpy_P(pgm_buffer, &font5x8[chr - ' '], sizeof(pgm_buffer));
+ glyph = pgm_buffer;
+ } else {
+ // Custom glyphs, on the other hand, are stored in RAM...
+ if (custom[chr]) {
+ glyph = custom[chr];
+ } else {
+ // Default to a space character if unset...
+ memcpy_P(pgm_buffer, &font5x8[0], sizeof(pgm_buffer));
+ glyph = pgm_buffer;
+ }
+ }
+
+ // Output one column at a time...
+ for (unsigned char i = 0; i < 5; i++) {
+ this->send(PCD8544_DATA, glyph[i]);
+ }
+
+ // One column between characters...
+ this->send(PCD8544_DATA, 0x00);
+
+ // Update the cursor position...
+ this->column = (this->column + 6) % this->width;
+
+ if (this->column == 0) {
+ this->line = (this->line + 1) % (this->height/9 + 1);
+ }
+
+#if ARDUINO >= 100
+ return 1;
+#endif
+}
+
+
+void PCD8544::drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines)
+{
+ unsigned char scolumn = this->column;
+ unsigned char sline = this->line;
+
+ // The bitmap will be clipped at the right/bottom edge of the display...
+ unsigned char mx = (scolumn + columns > this->width) ? (this->width - scolumn) : columns;
+ unsigned char my = (sline + lines > this->height/8) ? (this->height/8 - sline) : lines;
+
+ for (unsigned char y = 0; y < my; y++) {
+ this->setCursor(scolumn, sline + y);
+
+ for (unsigned char x = 0; x < mx; x++) {
+ this->send(PCD8544_DATA, data[y * columns + x]);
+ }
+ }
+
+ // Leave the cursor in a consistent position...
+ this->setCursor(scolumn + columns, sline);
+}
+
+
+void PCD8544::drawColumn(unsigned char lines, unsigned char value)
+{
+ unsigned char scolumn = this->column;
+ unsigned char sline = this->line;
+
+ // Keep "value" within range...
+ if (value > lines*8) {
+ value = lines*8;
+ }
+
+ // Find the line where "value" resides...
+ unsigned char mark = (lines*8 - 1 - value)/8;
+
+ // Clear the lines above the mark...
+ for (unsigned char line = 0; line < mark; line++) {
+ this->setCursor(scolumn, sline + line);
+ this->send(PCD8544_DATA, 0x00);
+ }
+
+ // Compute the byte to draw at the "mark" line...
+ unsigned char b = 0xff;
+ for (unsigned char i = 0; i < lines*8 - mark*8 - value; i++) {
+ b <<= 1;
+ }
+
+ this->setCursor(scolumn, sline + mark);
+ this->send(PCD8544_DATA, b);
+
+ // Fill the lines below the mark...
+ for (unsigned char line = mark + 1; line < lines; line++) {
+ this->setCursor(scolumn, sline + line);
+ this->send(PCD8544_DATA, 0xff);
+ }
+
+ // Leave the cursor in a consistent position...
+ this->setCursor(scolumn + 1, sline);
+}
+
+
+void PCD8544::send(unsigned char type, unsigned char data)
+{
+ digitalWrite(this->pin_dc, type);
+
+ digitalWrite(this->pin_sce, LOW);
+ shiftOut(this->pin_sdin, this->pin_sclk, MSBFIRST, data);
+ digitalWrite(this->pin_sce, HIGH);
+}
+
+
+/* vim: set expandtab ts=4 sw=4: */
diff --git a/libraries/MultiLCD/PCD8544.h b/libraries/MultiLCD/PCD8544.h
new file mode 100644
index 0000000..927ec47
--- /dev/null
+++ b/libraries/MultiLCD/PCD8544.h
@@ -0,0 +1,119 @@
+/*
+ * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
+ *
+ * Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#ifndef PCD8544_H
+#define PCD8544_H
+
+
+#if ARDUINO < 100
+#include <WProgram.h>
+#else
+#include <Arduino.h>
+#endif
+
+
+// Chip variants supported...
+#define CHIP_PCD8544 0
+#define CHIP_ST7576 1
+
+
+class PCD8544: public Print {
+ public:
+ // All the pins can be changed from the default values...
+ PCD8544(unsigned char sclk = 2, /* clock (display pin 2) */
+ unsigned char sdin = 3, /* data-in (display pin 3) */
+ unsigned char dc = 4, /* data select (display pin 4) */
+ unsigned char reset = 6, /* reset (display pin 8) */
+ unsigned char sce = 5); /* enable (display pin 5) */
+
+ // Display initialization (dimensions in pixels)...
+ void begin(unsigned char width=84, unsigned char height=48, unsigned char model=CHIP_PCD8544);
+ void stop();
+
+ // Erase everything on the display...
+ void clear();
+ void clearLine(); // ...or just the current line
+
+ // Control the display's power state...
+ void setPower(bool on);
+
+ // For compatibility with the LiquidCrystal library...
+ void display();
+ void noDisplay();
+
+ // Activate white-on-black mode (whole display)...
+ void setInverse(bool inverse);
+
+ // Place the cursor at the start of the current line...
+ void home();
+
+ // Place the cursor at position (column, line)...
+ void setCursor(unsigned char column, unsigned char line);
+
+ // Assign a user-defined glyph (5x8) to an ASCII character (0-31)...
+ void createChar(unsigned char chr, const unsigned char *glyph);
+
+ // Write an ASCII character at the current cursor position (7-bit)...
+#if ARDUINO < 100
+ virtual void write(uint8_t chr);
+#else
+ virtual size_t write(uint8_t chr);
+#endif
+
+ // Draw a bitmap at the current cursor position...
+ void drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines);
+
+ // Draw a chart element at the current cursor position...
+ void drawColumn(unsigned char lines, unsigned char value);
+
+ protected:
+ // Current cursor position...
+ unsigned char column;
+ unsigned char line;
+
+ private:
+ unsigned char pin_sclk;
+ unsigned char pin_sdin;
+ unsigned char pin_dc;
+ unsigned char pin_reset;
+ unsigned char pin_sce;
+
+ // The size of the display, in pixels...
+ unsigned char width;
+ unsigned char height;
+
+
+ // User-defined glyphs (below the ASCII space character)...
+ const unsigned char *custom[' '];
+
+ // Send a command or data to the display...
+ void send(unsigned char type, unsigned char data);
+};
+
+
+#endif /* PCD8544_H */
+
+
+/* vim: set expandtab ts=4 sw=4: */
diff --git a/libraries/MultiLCD/ZtLib.cpp b/libraries/MultiLCD/ZtLib.cpp
new file mode 100644
index 0000000..f8b55df
--- /dev/null
+++ b/libraries/MultiLCD/ZtLib.cpp
@@ -0,0 +1,601 @@
+/*
+ ZtLib.cpp - ZT module Drive Library for Wiring & Arduino
+ Copyright (c) 2012 Alvin Li(Kozig/www.kozig.com). All right reserved.
+ This library is free software;
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ Version:V1.1
+*/
+
+extern "C" {
+ #include <stdlib.h>
+ #include <string.h>
+ #include <inttypes.h>
+ #include "../Wire/utility/twi.h"
+}
+
+#include "ZtLib.h"
+
+///ZT.SEG8B4A036A PART///-------------------------------------------------------------------s
+unsigned char codetable[] =
+{
+ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F, 0x77, 0x7C,0x39,0x5E,0x79,0x71,0x00
+};
+
+// Public Methods //////////////////////////////////////////////////////////////
+/*
+ * Function I2cInit
+ * Desc TWI/I2C init
+ * Input none
+ * Output none
+ */
+void ZtLib::I2cInit(void)
+{
+ twi_init();
+}
+/*
+ * Function Seg8b4a036aSleep
+ * Desc Set ZT.SEG8B4A036A Go to Sleep
+ * Input addr:ZT.SEG8B4A036A Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aSleep(uint8_t addr)
+{
+ uint8_t buff[5]={REG_SLEEP, SLEEP_ON, 0, 0, 0};
+
+ return twi_writeTo(addr, buff, 5, 1, 1);
+}
+/*
+ * Function Seg8b4a036aUnSleep
+ * Desc Set ZT.SEG8B4A036A Wait Up From Sleep
+ * Input addr:ZT.SEG8B4A036A Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aUnSleep(uint8_t addr)
+{
+ uint8_t buff[5]={REG_SLEEP, SLEEP_OFF, 0, 0, 0};
+
+ return twi_writeTo(addr, buff, 5, 1, 1);
+}
+/*
+ * Function Seg8b4a036aReadState
+ * Desc Read ZT.SEG8B4A036A Status
+ * Input addr:ZT.SEG8B4A036A Address
+ * Output !=0xFF ZT.SC-I2CMx Status
+ * 0xFF .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aReadState(uint8_t addr)
+{
+ uint8_t state = 0xFF;
+ uint8_t temp;
+ uint8_t buff[1] = {REG_STATUS};
+ temp = twi_writeTo(addr, buff, 1, 1, 0); // no stop
+ if (temp ==0)
+ {
+ temp = twi_readFrom(addr, buff, 1, 1);
+ }
+ if (temp==1)
+ {
+ state = buff[0];
+ }
+
+ return state;
+}
+/*
+ * Function Seg8b4a036aReadVersion
+ * Desc Read ZT.SEG8B4A036A Fireware Version
+ * Input addr:ZT.SEG8B4A036A Address
+ *buf:Version Buffer
+ * Output .. number bytes of Version Read out
+ */
+int ZtLib::Seg8b4a036aReadVersion(uint8_t addr, uint8_t *buf)
+{
+ uint8_t state = 0xFF;
+ uint8_t temp;
+ uint8_t regv[1] = {REG_VERSION};
+ temp = twi_writeTo(addr, regv, 1, 1, 0); // no stop
+ if (temp ==0)
+ {
+ temp = twi_readFrom(addr, &(*buf), 19, 1);
+ }
+ return temp;
+}
+/*
+ * Function Seg8b4a036aDisplayDec
+ * Desc ZT.SEG8B4A036A Display decimal numeral
+ * Input addr:ZT.SEG8B4A036A Address
+ val: Display Val
+ bitnum:Display Bit Number
+ dotbit: Dot Display
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aDisplayDec(uint8_t addr,unsigned short val, uint8_t bitnum, uint8_t dotbit)
+{
+ uint8_t i;
+ uint8_t segnum[5];
+ if (val>9999) return 0xFF;
+
+ segnum[0] = REG_DAT;
+ segnum[1] = val%10;
+ segnum[2] = (val%100)/10;
+ segnum[3] = (val/100)%10;
+ segnum[4] = val/1000;
+ for (i=1; i<5; i++)
+ {
+ segnum[i] = codetable[segnum[i]];
+ if (dotbit&0x01)
+ {
+ segnum[i] |= 0x80;
+ }
+ dotbit >>= 1;
+ }
+
+ if (bitnum==DISP_0BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;segnum[1] = 0;}
+ else if (bitnum==DISP_1BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
+ else if (bitnum==DISP_2BIT) {segnum[4] = 0;segnum[3] = 0;}
+ else if (bitnum==DISP_3BIT) {segnum[4] = 0;}
+ else if (bitnum==DISP_AUTO)
+ {
+ if (val<10) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
+ else if (val<100) {segnum[4] = 0;segnum[3] = 0;}
+ else if (val<1000) {segnum[4] = 0;}
+ }
+
+ return twi_writeTo(addr, segnum, 5, 1, 1);
+}
+/*
+ * Function Seg8b4a036aDisplayHex
+ * Desc Read ZT.SEG8B4A036A Display hexadecimal number
+ * Input addr:ZT.SEG8B4A036A Address
+ val: Display Val
+ bitnum:Display Bit Number
+ dotbit: Dot Display
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aDisplayHex(uint8_t addr,unsigned short val, uint8_t bitnum, uint8_t dotbit)
+{
+ uint8_t i;
+ unsigned short temp;
+ uint8_t segnum[5];
+ segnum[0] = REG_DAT;
+ temp = val;
+ for (i=1; i<5; i++)
+ {
+ segnum[i] = temp&0x000F;
+ temp >>= 4;
+ segnum[i] = codetable[segnum[i]];
+ if (dotbit&0x01)
+ {
+ segnum[i] |= 0x80;
+ }
+ dotbit >>= 1;
+ }
+
+ if (bitnum==DISP_0BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;segnum[1] = 0;}
+ else if (bitnum==DISP_1BIT) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
+ else if (bitnum==DISP_2BIT) {segnum[4] = 0;segnum[3] = 0;}
+ else if (bitnum==DISP_3BIT) {segnum[4] = 0;}
+ else if (bitnum==DISP_AUTO)
+ {
+ if (!(val&0xFFF0)) {segnum[4] = 0;segnum[3] = 0;segnum[2] = 0;}
+ else if (!(val&0xFF00)) {segnum[4] = 0;segnum[3] = 0;}
+ else if (!(val&0xF000)) {segnum[4] = 0;}
+ }
+
+ return twi_writeTo(addr, segnum, 5, 1, 1);
+}
+/*
+ * Function Seg8b4a036aSetBrightness
+ * Desc Set ZT.SEG8B4A036A Brightness
+ * Input addr:ZT.SEG8B4A036A Address
+ OnDelay:
+ OffDelay:
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aSetBrightness(uint8_t addr, uint8_t OnDelay, uint8_t OffDelay)
+{
+ uint8_t buff[5] = {REG_BRIGHTNESS, OnDelay, OffDelay, 0, 0};
+ return twi_writeTo(addr, buff, 5, 1, 1);
+}
+/*
+ * Function Seg8b4a036aSetAddress
+ * Desc Set ZT.SEG8B4A036A New Address
+ * Input val:ZT.SEG8B4A036A Address New Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aSetAddress(uint8_t val)
+{
+ uint8_t buff[2] = {REG_ADDRESS, val};
+ return twi_writeTo(ZTSEG8B4A036A_DADDR, buff, 2, 1, 1);
+}
+/*
+ * Function Seg8b4a036aDisplayBuff
+ * Desc Set ZT.SEG8B4A036A Brightness
+ * Input addr:ZT.SEG8B4A036A Address
+ *buf: Display buffer
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::Seg8b4a036aDisplayBuff(uint8_t addr,uint8_t *buf)
+{
+ uint8_t buff[5]={REG_DAT, buf[0], buf[1], buf[2], buf[3]};
+
+ return twi_writeTo(addr, buff, 5, 1, 1);
+}
+
+
+///ZT.ScI2cMx PART///-------------------------------------------------------------------
+/*
+ * Function ScI2cMxReadState
+ * Desc Read ZT.SC-I2CMx Status
+ * Input addr:ZT.SC-I2CMx Address
+ * Output !=0xFF ZT.SC-I2CMx Status
+ * 0xFF .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxReadState(uint8_t addr)
+{
+ uint8_t state = 0xFF;
+ uint8_t temp;
+ uint8_t buff[1] = {REG_STATUS};
+ temp = twi_writeTo(addr, buff, 1, 1, 0); // no stop
+ if (temp ==0)
+ {
+ temp = twi_readFrom(addr, buff, 1, 1);
+ }
+ if (temp==1)
+ {
+ state = buff[0];
+ }
+
+ return state;
+}
+
+/*
+ * Function ScI2cMxReadVersion
+ * Desc Read ZT.SC-I2CMx Fireware Version
+ * Input addr:ZT.SC-I2CMx Address
+ *buf:Version Buffer
+ * Output !=0xFF ZT.SC-I2CMx Status
+ * othe .. number bytes of Version Read out
+ */
+int ZtLib::ScI2cMxReadVersion(uint8_t addr, uint8_t *buf)
+{
+ uint8_t state = 0xFF;
+ uint8_t temp;
+ uint8_t regv[1] = {REG_VERSION};
+ temp = twi_writeTo(addr, regv, 1, 1, 0); // no stop
+ if (temp ==0)
+ {
+ temp = twi_readFrom(addr, &(*buf), 16, 1);
+ }
+ return temp;
+}
+/*
+ * Function ScI2cMxSetAddress
+ * Desc Set ZT.SC-I2CMx New Address
+ * Input val:ZT.SC-I2CMx Address New Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxSetAddress(uint8_t newaddr)
+{
+ uint8_t buff[2] = {REG_ADDRESS, newaddr};
+ return twi_writeTo(ZTSCI2CMX_DADDRESS, buff, 2, 1, 1);
+}
+
+/*
+ * Function ScI2cMxSetBrightness
+ * Desc Set ZT.SC-I2CMx Brightness
+ * Input addr:ZT.SC-I2CMx Address
+ val: Brightness 0~0xFF
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxSetBrightness(uint8_t addr, uint8_t val)
+{
+ uint8_t buff[2] = {REG_BRIGHTNESS, val};
+ return twi_writeTo(addr, buff, 2, 1, 1);
+}
+/*
+ * Function ScI2cMxSetVcomH
+ * Desc Set ZT.SC-I2CMx VcomH
+ * Input addr:ZT.SC-I2CMx Address
+ val: Brightness 0~7
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxSetVcomH(uint8_t addr, uint8_t val)
+{
+ uint8_t buff[2] = {REG_VCOMH, val};
+ return twi_writeTo(addr, buff, 2, 1, 1);
+}
+
+/*
+ * Function ScI2cMxDisplay8x16Str
+ * Desc ZT.SC-I2CMx Display 8x16 English String
+ * Input addr:ZT.SC-I2CMx Address
+ page: location page
+ column: location column
+ *str: 8X16 English String
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxDisplay8x16Str(uint8_t addr, uint8_t page, uint8_t column, const char *str)
+{
+ uint8_t i=0;
+ uint8_t buff[19];
+ buff[0] = REG_8X16STR;
+ buff[1] = page;
+ buff[2] = column;
+ i=0;
+ while ((*str != '\0') && (i<16))
+ {
+ buff[i+3] = (uint8_t)*str++;
+ i++;
+ }
+ return twi_writeTo(addr, buff, i+3, 1, 1);
+}
+/*
+ * Function ScI2cMxFillArea
+ * Desc ZT.SC-I2CMx Fill Area
+ * Input addr:ZT.SC-I2CMx Address
+ spage: start page
+ epage: end page
+ scolumn: start column
+ ecolumn: end column
+ filldata: fill data
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxFillArea(uint8_t addr, uint8_t spage, uint8_t epage,uint8_t scolumn, uint8_t ecolumn,uint8_t filldata)
+{
+ uint8_t buff[6] = {REG_FILL_AREA, spage, epage, scolumn, ecolumn, filldata};
+ return twi_writeTo(addr, buff, 6, 1, 1);
+}
+/*
+ * Function ScI2cMxScrollingHorizontal
+ * Desc ZT.SC-I2CMx Scrolling Horizontal
+ * Input addr:ZT.SC-I2CMx Address
+ lr: Scroll direction
+ spage: start page
+ epage: end page
+ frames: Scroll fram
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxScrollingHorizontal(uint8_t addr, uint8_t lr, uint8_t spage, uint8_t epage,uint8_t frames)
+{
+ uint8_t buff[9] = {REG_CMD, 0x2E, 0x00, spage, frames, epage, 0x00, 0xFF, 0x2F};
+ twi_writeTo(addr, buff, 2, 1, 1);
+ buff[0] = REG_CMD;
+ buff[1] = lr;
+ for (int i=0; i<10; i++);
+ return twi_writeTo(addr, buff, 9, 1, 1);
+}
+/*
+ * Function ScI2cMxScrollingHorizontal
+ * Desc ZT.SC-I2CMx Scrolling Vertical
+ * Input addr:ZT.SC-I2CMx Address
+ lr: Scroll direction
+ rowsfixed: rows fixed
+ rowsscroll: rows scroll
+ scrollstep: scroll step
+ stepdelay: step delay
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxScrollingVertical(uint8_t addr, uint8_t scrollupdown, uint8_t rowsfixed, uint8_t rowsscroll, uint8_t scrollstep, uint8_t stepdelay)
+{
+ uint8_t buff[6] = {REG_SCROVER, scrollupdown, rowsfixed, rowsscroll, scrollstep, stepdelay};
+ return twi_writeTo(addr, buff, 6, 1, 1);
+}
+/*
+ * function ScI2cMxScrollingVerticalHorizontal
+ * Desc Continuous Vertical / Horizontal / Diagonal Scrolling (Partial or Full Screen)
+ * input :
+ Sdirection: Scrolling Direction
+ "0x00" (Vertical & Rightward)
+ "0x01" (Vertical & Leftward)
+ spage: Define Start Page Address (Horizontal / Diagonal Scrolling)
+ epage: Define End Page Address (Horizontal / Diagonal Scrolling)
+ fixedarea: Set Top Fixed Area (Vertical Scrolling)
+ scrollarea: Set Vertical Scroll Area (Vertical Scrolling)
+ frames: Set Time Interval between Each Scroll Step in Terms of Frame Frequency
+ offset: Set Numbers of Row Scroll per Step (Vertical / Diagonal Scrolling)
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxScrollingVerticalHorizontal(uint8_t addr, uint8_t Sdirection, uint8_t spage, uint8_t epage, uint8_t fixedarea, uint8_t scrollarea, uint8_t offset, uint8_t frames)
+{
+ uint8_t buff[8] = {REG_SCROVERHOR, Sdirection, spage, epage, fixedarea, scrollarea, offset, frames};
+ return twi_writeTo(addr, buff, 8, 1, 1);
+}
+/*
+ * Function ScI2cMxDeactivateScroll
+ * Desc ZT.SC-I2CMx Deactivate Scroll
+ * Input addr:ZT.SC-I2CMx Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxDeactivateScroll(uint8_t addr)
+{
+ uint8_t buff[2] = {REG_CMD, 0x2E};
+ return twi_writeTo(addr, buff, 2, 1, 1);
+}
+
+/*
+ * Function ScI2cMxReset
+ * Desc ZT.SC-I2CMx Reset OLED
+ * Input addr:ZT.SC-I2CMx Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxReset(uint8_t addr)
+{
+ uint8_t buff[2] = {REG_RESET,RESET_OLED};
+ return twi_writeTo(addr, buff, 2, 1, 1);
+}
+
+/*
+ * Function ScI2cMxSetLocation
+ * Desc Set ZT.SC-I2CMx SetLocation
+ * Input addr:ZT.SC-I2CMx Address
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+int ZtLib::ScI2cMxSetLocation(uint8_t addr, uint8_t page,uint8_t column)
+{
+ uint8_t buff[4] = {REG_CMD, (0xB0|page), (column%16), (column/16+0x10)};
+ return twi_writeTo(addr, buff, 4, 1, 1);
+}
+/*
+ * Function ScI2cMxDisplayDot16x16
+ * Desc Set ZT.SC-I2CMx Display 16*16 Dot
+ * Input addr:ZT.SC-I2CMx Address
+ page:page
+ column:column
+ *str:16*16 Dot Data
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+void ZtLib::ScI2cMxDisplayDot16x16(uint8_t addr, uint8_t page, uint8_t column, const char *str)
+{
+ uint8_t buff[17];
+ buff[0] = REG_DAT;
+ ScI2cMxSetLocation(addr, page, column);
+ for (int i=0; i<16; i++)
+ {
+ buff[i+1] = str[i];
+ }
+ twi_writeTo(addr, buff, 17, 1, 1);
+ ScI2cMxSetLocation(addr, page+1, column);
+ for (int i=0; i<16; i++)
+ {
+ buff[i+1] = str[i+16];
+ }
+ twi_writeTo(addr, buff, 17, 1, 1);
+}
+/*
+ * Function ScI2cMxDisplayArea
+ * Desc Set ZT.SC-I2CMx Display Area
+ * Input addr:ZT.SC-I2CMx Address
+ spage: start page
+ epage: end page
+ scolumn: start column
+ ecolumn: end column
+ *pt: Data
+ * Output 0 .. success
+ * 1 .. length to long for buffer
+ * 2 .. address send, NACK received
+ * 3 .. data send, NACK received
+ * 4 .. other twi error (lost bus arbitration, bus error, ..)
+ */
+void ZtLib::ScI2cMxDisplayArea(uint8_t addr, uint8_t spage, uint8_t epage, uint8_t scolumn, uint8_t ecolumn, const char *pt)
+{
+ uint8_t i = 0;
+ uint8_t j = 0;
+ uint8_t h = 0;
+ uint8_t w = 0;
+ uint16_t cnt = 0;
+ uint8_t buff[32];
+ buff[0] = REG_DAT;
+
+ h = epage - spage;
+ w = ecolumn - scolumn;
+
+ while ( j<h )
+ {
+ ScI2cMxSetLocation(addr, spage + j, scolumn);
+ uint8_t p=w;
+ while(p)
+ {
+ if(p>=31)
+ {
+ for (int n=0; n<31; n++)
+ {
+ buff[1+n] = pt[cnt++];
+ }
+ twi_writeTo(addr, buff, 32, 1, 1);
+ p -= 31;
+ }
+ else
+ {
+ int n;
+ for (n=0; n<p; n++)
+ {
+ buff[1+n] = pt[cnt++];
+ }
+ twi_writeTo(addr, buff, n+1, 1, 1);
+ p -= n;
+ }
+ }
+ j++;
+ }
+}
+
+// Preinstantiate Objects //////////////////////////////////////////////////////
+
diff --git a/libraries/MultiLCD/ZtLib.h b/libraries/MultiLCD/ZtLib.h
new file mode 100644
index 0000000..b93ccc1
--- /dev/null
+++ b/libraries/MultiLCD/ZtLib.h
@@ -0,0 +1,127 @@
+/*
+ ZtLib.cpp - ZT module Drive Library for Wiring & Arduino
+ Copyright (c) 2012 Alvin Li(Kozig/www.kozig.com). All right reserved.
+ This library is free software;
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ Version:V1.1
+*/
+
+#ifndef __ZTLIB_H__
+#define __ZTLIB_H__
+
+#include <inttypes.h>
+
+//////////////////
+#define ZTSEG8B4A036A_DADDR 0x51
+#define SET_ADDR 0x61
+#define WRITE_CODE 0xAA
+#define WRITE_CMD 0x55
+
+#define DOT_NONE (0)
+#define DOT_BIT1 (1<<0)
+#define DOT_BIT2 (1<<1)
+#define DOT_BIT3 (1<<2)
+#define DOT_BIT4 (1<<3)
+
+#define DISP_0BIT (0)
+#define DISP_1BIT (1)
+#define DISP_2BIT (2)
+#define DISP_3BIT (3)
+#define DISP_4BIT (4)
+#define DISP_AUTO (5)
+///////////////////////////////////
+
+#define ZTSCI2CMX_DADDRESS 0x51
+// Ä£¿é¼Ä´æÆ÷µØÖ·
+#define REG_CMD 0x01
+#define REG_DAT 0x02
+#define REG_RESET 0x03
+ #define RESET_OLED 0x06
+#define REG_VERSION 0x1F
+#define REG_SLEEP 0x04
+ #define SLEEP_ON 0xA5
+ #define SLEEP_OFF 0xA1
+#define REG_VCOMH 0x05
+#define REG_STATUS 0x06
+ #define STATUS_RUN 0x00
+ #define STATUS_RUN 0x00
+ #define STATUS_SLEEP 0x01
+ #define STATUS_SET_ADDRESS 0x02
+ #define STATUS_TEST 0x04
+ #define STATUS_BUSY 0x10
+
+#define REG_ADDRESS 0x08
+#define REG_BRIGHTNESS 0x0A
+#define REG_8X16STR 0x52
+#define REG_OLED_XY 0x60
+#define REG_FILL_AREA 0x61
+#define REG_SCROHOR 0x62
+#define REG_SCROVER 0x63
+#define REG_SCROVERHOR 0x64
+
+#define PAGE0 0x00
+#define PAGE1 0x01
+#define PAGE2 0x02
+#define PAGE3 0x03
+#define PAGE4 0x04
+#define PAGE5 0x05
+#define PAGE6 0x06
+#define PAGE7 0x07
+
+#define SCROLL_UP 0x01
+#define SCROLL_DOWN 0x00
+#define SCROLL_RIGHT 0x26
+#define SCROLL_LEFT 0x27
+#define SCROLL_VR 0x29
+#define SCROLL_VL 0x2A
+
+#define FRAMS_2 0x07
+#define FRAMS_3 0x04
+#define FRAMS_4 0x05
+#define FRAMS_5 0x00
+#define FRAMS_25 0x06
+#define FRAMS_64 0x01
+#define FRAMS_128 0x02
+#define FRAMS_256 0x03
+
+class ZtLib
+{
+ private:
+
+ public:
+ void I2cInit(void);
+// Module ZT.SEG8B4A036A FUNCTION
+ int Seg8b4a036aSleep(uint8_t);
+ int Seg8b4a036aUnSleep(uint8_t);
+ int Seg8b4a036aReadState(uint8_t addr);
+ int Seg8b4a036aReadVersion(uint8_t addr, uint8_t *buf);
+ int Seg8b4a036aDisplayDec(uint8_t,unsigned short, uint8_t, uint8_t);
+ int Seg8b4a036aDisplayHex(uint8_t,unsigned short, uint8_t, uint8_t);
+ int Seg8b4a036aSetBrightness(uint8_t, uint8_t, uint8_t);
+ int Seg8b4a036aSetAddress(uint8_t);
+ int Seg8b4a036aDisplayBuff(uint8_t,uint8_t *);
+// Module ZT.SC-I2CMx
+ int ScI2cMxReadState(uint8_t);
+ int ScI2cMxReadVersion(uint8_t, uint8_t *);
+ int ScI2cMxSetAddress(uint8_t);
+ int ScI2cMxSetBrightness(uint8_t, uint8_t);
+ int ScI2cMxSetVcomH(uint8_t, uint8_t);
+ int ScI2cMxDisplay8x16Str(uint8_t, uint8_t, uint8_t, const char *);
+ int ScI2cMxFillArea(uint8_t, uint8_t, uint8_t,uint8_t, uint8_t,uint8_t);
+ int ScI2cMxScrollingHorizontal(uint8_t, uint8_t, uint8_t, uint8_t,uint8_t);
+ int ScI2cMxScrollingVertical(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
+ int ScI2cMxScrollingVerticalHorizontal(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
+ int ScI2cMxDeactivateScroll(uint8_t);
+ int ScI2cMxReset(uint8_t);
+ int ScI2cMxSetLocation(uint8_t, uint8_t, uint8_t);
+ void ScI2cMxDisplayDot16x16(uint8_t, uint8_t, uint8_t, const char *);
+ void ScI2cMxDisplayArea(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, const char *);
+};
+
+
+extern ZtLib ZT;
+
+#endif
+
diff --git a/libraries/MultiLCD/examples/lcdhello/lcdhello.ino b/libraries/MultiLCD/examples/lcdhello/lcdhello.ino
new file mode 100644
index 0000000..55f07e5
--- /dev/null
+++ b/libraries/MultiLCD/examples/lcdhello/lcdhello.ino
@@ -0,0 +1,20 @@
+#include <Arduino.h>
+#include <Wire.h>
+#include <MultiLCD.h>
+
+//LCD_OLED lcd; /* for I2C OLED module */
+//LCD_PCD8544 lcd; /* for LCD4884 shield or Nokia 5100 screen module */
+LCD_1602 lcd; /* for LCD1602 shield */
+
+void setup()
+{
+ lcd.begin();
+ lcd.setCursor(0, 0);
+ lcd.print("Hello, World");
+ lcd.setCursor(0, 1);
+ lcd.printLarge("12345");
+}
+
+void loop()
+{
+}