/***************************************************************** METP0000_lib Arduino library Structure based on standard Arduino LiquidCrystal.h library Much of the Print routine code is based on code developed and maintanied by MCUdude https://github.com/MCUdude/KTMS1201 Based on Tronixstruff's work tronixstuff.com/2013/03/11/arduino-and-ktm-s1201-lcd-modules (Jeff Albertson, Robert W. Mech, John Boxall) Also incorporating font/code ideas from all over Conversion to supporting METP0000 module by Tony Wills 2018-11-24 v 1.00 initial version 2018-11-27 v 1.30 print.h version based on LiquidCrystal.h 2018-11-29 v 1.40 back to using custom print routines 2018-12-01 v 1.50 new character set *****************************************************************/ #ifndef METP0000_lib_h #define METP0000_lib_h #include "Arduino.h" //#include //#include "Print.h" // --- 0x4 0x0 0x0 // 0x0 0x0 0x4 | | 0x0 0x4 0x0 // 0x1 0x0 0x0 --- // 0x0 0x0 0x1 | | 0x0 0x1 0x0 // 0x2 0x0 0x0 --- o 0x0 0x0 0x2 // ' 0x0 0x2 0x0 // These are the pins on the connector to the METP0000 // // pin 1 Busy // pin 2 Reset // pin 3 Si // pin 4 NSCk // pin 5 CS // pin 6 CD // pin 7 GND // pin 8 +5V /* LCD characters */ static const uint16_t sevenSegHex[96] = {0x000/* */, 0x070/*!*/, 0x044/*"*/, 0x720/*#*/, 0x700/*$*/, 0x161/*%*/, 0x775/*&*/, 0x040/*'*/, 0x605/*(*/, 0x650/*)*/, 0x544/***/, 0x150/*+*/, 0x200/*,*/, 0x100/*-*/, 0x002/*.*/, 0x141/*/*/, \ 0x655/*0*/, 0x050/*1*/, 0x741/*2*/, 0x750/*3*/, 0x154/*4*/, 0x714/*5*/, 0x715/*6*/, 0x450/*7*/, 0x755/*8*/, 0x754/*9*/, 0x300/*:*/, 0x320/*:*/, 0x504/*<*/, 0x500/*=*/, 0x540/*>*/, 0x541/*?*/, \ 0x771/*@*/, 0x555/*A*/, 0x755/*B*/, 0x605/*C*/, 0x675/*D*/, 0x705/*E*/, 0x505/*F*/, 0x615/*G*/, 0x155/*H*/, 0x005/*I*/, 0x251/*J*/, 0x105/*K*/, 0x205/*L*/, 0x475/*M*/, 0x455/*N*/, 0x655/*O*/, \ 0x545/*P*/, 0x675/*Q*/, 0x405/*R*/, 0x714/*S*/, 0x450/*T*/, 0x275/*U*/, 0x255/*V*/, 0x355/*W*/, 0x175/*X*/, 0x354/*Y*/, 0x761/*Z*/, 0x605/*[*/, 0x114/*\\*/,0x650/*]*/, 0x444/*^*/, 0x200/*_*/, \ 0x004/*`*/, 0x331/*a*/, 0x315/*b*/, 0x301/*c*/, 0x351/*d*/, 0x321/*e*/, 0x505/*f*/, 0x754/*g*/, 0x115/*h*/, 0x001/*i*/, 0x210/*j*/, 0x105/*k*/, 0x201/*l*/, 0x131/*m*/, 0x111/*n*/, 0x311/*o*/, \ 0x545/*p*/, 0x554/*q*/, 0x101/*r*/, 0x714/*s*/, 0x305/*t*/, 0x231/*u*/, 0x211/*v*/, 0x355/*w*/, 0x175/*x*/, 0x354/*y*/, 0x761/*z*/, 0x605/*{*/, 0x005/*|*/, 0x650/*}*/, 0x400/*~*/, 0x000/**/}; const uint16_t _SetDp = 0x002; // "Decimal point" (Dp) segment definition const uint16_t _SetComma = 0x020; // "Comma" segment definition //const uint16_t _SetBar0 = 0x0002; // Set Bar 0, first char, segment dp //const uint16_t _SetBar1 = 0x6100; // Set Bar 1, seventh char, segment g //const uint16_t _SetBar2 = 0x6200; // Set Bar 2, seventh char, segment d //const uint16_t _SetBar3 = 0x6400; // Set Bar 3, seventh char, segment a //const uint16_t _SetBar4 = 0x5020; // Set Bar 4, sixth char, segment comma static const uint16_t barArray[5] = {0x0002, 0x6100, 0x6200, 0x6400, 0x5020}; /* LCD modes */ const uint8_t _Mode = 0x48; // LCD speed. See uPD7225 datasheet for more info const uint8_t _Sync = 0x31; // Synchronized transfer const uint8_t _USync = 0x30; // Unsynchronized transfer const uint8_t _PXfer = 0x38; // Pause data transfer const uint8_t _FFlash = 0x1b; // Blink fast (~2 Hz) const uint8_t _SFlash = 0x1a; // Blink slow (~1 Hz) const uint8_t _NoFlash = 0x18; // No blink const uint8_t _DispOn = 0x11; // Display on const uint8_t _DispOff = 0x10; // Display off const uint8_t _Decode = 0x15; // Turn on segment decoding const uint8_t _NoDecode = 0x14; // Turn off segment decoding const uint8_t _LoadPtr = 0xe0; // Load data pointer const uint8_t _WriteMem = 0xd0; // Write immediate data to display memory const uint8_t _OrDspMem = 0xb0; // OR display memory with immediate data const uint8_t _AndDspMem = 0x90;// AND display memory with immediate data const uint8_t _ClearDsp = 0x20; // Clear display memory const uint8_t _WFlshMem = 0xc0; // Write immediate data to blink memory const uint8_t _OrFlshMem = 0xa0;// OR blink memory with immmediate data const uint8_t _AndFlshMem = 0x80;// AND blink memory with immmediate data const uint8_t _ClearFlsh = 0x00;// Clears all blink memory bits const bool fast = true; const bool slow = false; const uint8_t busyDelay = 2; class METP0000 /*: public Print*/ { public: METP0000(uint8_t NSCK, uint8_t SI, uint8_t BUSY, uint8_t CS); METP0000(uint8_t NSCK, uint8_t SI, uint8_t CS); void init(uint8_t NSCK, uint8_t SI, uint8_t BUSY, uint8_t CS); void begin(uint8_t cols = 6, uint8_t rows = 1, uint8_t charsize = 0); //parameters just to maintain compatibility void clear(uint8_t start = 0, uint8_t stop = 5); void home(); void noDisplay(); void display(); void noBlink(); void blink(); void noCursor(); void cursor(); void scrollDisplayLeft(); void scrollDisplayRight(); void leftToRight(); void rightToLeft(); void autoscroll(); void noAutoscroll(); void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t cursorPos = 0, uint8_t row = 0); // row parameter just to maintain compatibility uint8_t write(uint8_t); void command(uint8_t); // Functions specific to METP0000 void flash(bool speed = slow); void noFlash(); void setFlash(); void unSetFlash(); void setSegment(uint16_t seg); void clearSegment(uint16_t seg); void setBar(uint8_t bar); void unSetBar(uint8_t bar); void print(String); void print(const char*); void print(char); void print(uint32_t, uint8_t base = DEC); void print(int32_t, uint8_t base = DEC); void print(uint16_t, uint8_t base = DEC); void print(int16_t, uint8_t base = DEC); void print(double, uint8_t decimals = 2); // TODO: No yet implimented void customChar(uint16_t); void setWrap(); // set line wrap, for when printing off the end of the display void unSetWrap(); // turn off line wrap private: // Private methods void send(uint8_t); void writeChar(uint16_t); void wait(); void waitClk(); // Functions specific to METP0000 void printNumber(uint32_t, uint8_t base = DEC, bool table = false); void printFloat(double, uint8_t = 2); // Private variables uint8_t _cursorPos = 0; // Digital pin numbers uint8_t _SCK = 0; uint8_t _SI = 0; uint8_t _BUSY = 255; uint8_t _CS = 0; uint8_t _bufferPtr =0; //buffer ptr for scrolling uint16_t _textString[80]; //text buffer bool _bar[5]; //keep track of which under-bars are turned on // TODO: for the future bool _wrapBuf = false; //wrap printing back to start bool _displayCursor = false; //for cursor display function bool _blinkCursor = false; //for cursor blink function }; #endif