Display

Dependents:   Termocamera_ironblack

Committer:
Geremia
Date:
Sun Feb 15 20:06:07 2015 +0000
Revision:
4:12ba0ecc2c1f
Parent:
3:48f3282c2be8
Child:
9:1749ae993cfe
Added PAR16, separated 16bit writes for cmd parameters and pixeldata

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 4:12ba0ecc2c1f 1 /* mbed UniGraphic library - Device specific class
Geremia 4:12ba0ecc2c1f 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 4:12ba0ecc2c1f 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 4:12ba0ecc2c1f 4 */
Geremia 0:75ec1b3cde17 5 #include "Protocols.h"
Geremia 0:75ec1b3cde17 6 #include "UC1608.h"
Geremia 0:75ec1b3cde17 7
Geremia 0:75ec1b3cde17 8 //////////////////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 9 // display settings ///////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 10 /////////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 11 #define IC_X_SEGS 240 // UC1608 SEG has range 0-239 (239-0 if MX=1), check your datasheet, important for the orientation
Geremia 0:75ec1b3cde17 12 #define IC_Y_COMS 128 // UC1608 COM has range 0-127 (127-0 if MY=1), check your datasheet, important for the orientation
Geremia 0:75ec1b3cde17 13 #define LCDSIZE_X 240 // display X pixels
Geremia 0:75ec1b3cde17 14 #define LCDSIZE_Y 120 // display Y pixels, UC1608 is advertised as 240x128 but display size could be smaller
Geremia 0:75ec1b3cde17 15
Geremia 0:75ec1b3cde17 16
Geremia 0:75ec1b3cde17 17
Geremia 0:75ec1b3cde17 18 UC1608::UC1608(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name)
Geremia 0:75ec1b3cde17 19 : LCD(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
Geremia 0:75ec1b3cde17 20 {
Geremia 0:75ec1b3cde17 21 hw_reset();
Geremia 0:75ec1b3cde17 22 BusEnable(true);
Geremia 0:75ec1b3cde17 23 init();
Geremia 0:75ec1b3cde17 24 cls();
Geremia 0:75ec1b3cde17 25 set_orientation(1);
Geremia 0:75ec1b3cde17 26 locate(0,0);
Geremia 0:75ec1b3cde17 27 }
Geremia 1:ff019d22b275 28 UC1608::UC1608(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name)
Geremia 1:ff019d22b275 29 : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name)
Geremia 0:75ec1b3cde17 30 {
Geremia 0:75ec1b3cde17 31 hw_reset();
Geremia 0:75ec1b3cde17 32 BusEnable(true);
Geremia 0:75ec1b3cde17 33 init();
Geremia 0:75ec1b3cde17 34 cls();
Geremia 0:75ec1b3cde17 35 set_orientation(1);
Geremia 0:75ec1b3cde17 36 locate(0,0);
Geremia 0:75ec1b3cde17 37 }
Geremia 0:75ec1b3cde17 38 // reset and init the lcd controller
Geremia 0:75ec1b3cde17 39 void UC1608::init()
Geremia 0:75ec1b3cde17 40 {
Geremia 0:75ec1b3cde17 41 /* Start Initial Sequence ----------------------------------------------------*/
Geremia 0:75ec1b3cde17 42
Geremia 1:ff019d22b275 43 // wr_cmd8(0xE2); // sw reset
Geremia 0:75ec1b3cde17 44 wait_ms(15);
Geremia 0:75ec1b3cde17 45
Geremia 1:ff019d22b275 46 wr_cmd8(0x27); // Multiplex rate :128 set temperature consenpation 0%
Geremia 1:ff019d22b275 47 wr_cmd8(0xEA); //set bias:1/12bias
Geremia 0:75ec1b3cde17 48
Geremia 1:ff019d22b275 49 wr_cmd8(0xC4); // set mirror MX=1,MY=0 (controller->display SEGs wiring inverted)
Geremia 1:ff019d22b275 50 // wr_cmd8(0xA0); // ADC select seg0-seg223
Geremia 1:ff019d22b275 51 //wr_cmd8(0xA1); // ADC select seg223-seg0
Geremia 1:ff019d22b275 52 // wr_cmd8(0xC8); // SHL select com63-com0
Geremia 1:ff019d22b275 53 //wr_cmd8(0xC0); // SHL select com0-com63
Geremia 0:75ec1b3cde17 54
Geremia 1:ff019d22b275 55 wr_cmd8(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf
Geremia 0:75ec1b3cde17 56 wait_ms(10);
Geremia 0:75ec1b3cde17 57
Geremia 1:ff019d22b275 58 // wr_cmd8(0x81);//Set Gain and Potentiometer
Geremia 3:48f3282c2be8 59 // wr_cmd8(0x40|26);//Set Gain and Potentiometer xx xxxxxx
Geremia 3:48f3282c2be8 60 set_contrast(26);
Geremia 0:75ec1b3cde17 61
Geremia 1:ff019d22b275 62 wr_cmd8(0x88); //disable colum/page address wraparound
Geremia 1:ff019d22b275 63 wr_cmd8(0xA4); // LCD display ram (EntireDisplayOn disable)
Geremia 1:ff019d22b275 64 wr_cmd8(0x40); // start line = 0
Geremia 1:ff019d22b275 65 wr_cmd8(0xA6); // display normal (1 = illuminated)
Geremia 1:ff019d22b275 66 wr_cmd8(0xAF); // display ON
Geremia 0:75ec1b3cde17 67
Geremia 0:75ec1b3cde17 68 }
Geremia 0:75ec1b3cde17 69 ////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 70 // functions that overrides the standard ones implemented in LCD.cpp
Geremia 0:75ec1b3cde17 71 ////////////////////////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 72 void UC1608::mirrorXY(mirror_t mode)
Geremia 0:75ec1b3cde17 73 {
Geremia 0:75ec1b3cde17 74 switch (mode)
Geremia 0:75ec1b3cde17 75 {
Geremia 0:75ec1b3cde17 76 case(NONE):
Geremia 1:ff019d22b275 77 wr_cmd8(0xC4); // this is in real X mirror command, but my display have SEGs wired inverted, so assume this is the default no-x-mirror
Geremia 0:75ec1b3cde17 78 break;
Geremia 0:75ec1b3cde17 79 case(X):
Geremia 1:ff019d22b275 80 wr_cmd8(0xC0);
Geremia 0:75ec1b3cde17 81 break;
Geremia 0:75ec1b3cde17 82 case(Y):
Geremia 1:ff019d22b275 83 wr_cmd8(0xCC);
Geremia 0:75ec1b3cde17 84 break;
Geremia 0:75ec1b3cde17 85 case(XY):
Geremia 1:ff019d22b275 86 wr_cmd8(0xC8);
Geremia 0:75ec1b3cde17 87 break;
Geremia 0:75ec1b3cde17 88 }
Geremia 0:75ec1b3cde17 89 }
Geremia 0:75ec1b3cde17 90 void UC1608::set_contrast(int o)
Geremia 0:75ec1b3cde17 91 {
Geremia 0:75ec1b3cde17 92 contrast = o;
Geremia 1:ff019d22b275 93 // wr_cmd8(0x81); // set volume
Geremia 1:ff019d22b275 94 // wr_cmd8(0x40|(o&0x3F));
Geremia 1:ff019d22b275 95 wr_cmd16(0x8140|(o&0x3F));
Geremia 0:75ec1b3cde17 96 }
Geremia 0:75ec1b3cde17 97 void UC1608::BusEnable(bool enable)
Geremia 0:75ec1b3cde17 98 {
Geremia 0:75ec1b3cde17 99 LCD::BusEnable(!enable); // crap IC has CS not inverted (active HIGH)
Geremia 0:75ec1b3cde17 100 }