UniGraphic-Fork for ST7920-LCD-controller and SH1106. Tested with 128x64 LCD with SPI and 128x64-OLED with IIC
Dependents: UniGraphic-St7920-Test AfficheurUTILECO
Fork of UniGraphic by
Fork of the UniGraphic-Library for monochrome LCDs with ST7920 controller and 128x64-IIC-OLED-Display with SH1106-Controller
Had to adapt LCD for following reasons:
- Give access to screenbuffer buffer[] to parent class
- pixel() and pixel_read() as they are hardware-dependent
- added reset-pin to IIC-Interface
GraphicDisplay:: sends buffer to LCD when auto_update is set to true.
Testprogram for ST7920 can be found here:
https://developer.mbed.org/users/charly/code/UniGraphic-St7920-Test/
Inits/UC1608.cpp@3:48f3282c2be8, 2015-02-14 (annotated)
- Committer:
- Geremia
- Date:
- Sat Feb 14 17:42:21 2015 +0000
- Revision:
- 3:48f3282c2be8
- Parent:
- 1:ff019d22b275
- Child:
- 4:12ba0ecc2c1f
small things
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 0:75ec1b3cde17 | 1 | #include "Protocols.h" |
Geremia | 0:75ec1b3cde17 | 2 | #include "UC1608.h" |
Geremia | 0:75ec1b3cde17 | 3 | |
Geremia | 0:75ec1b3cde17 | 4 | ////////////////////////////////////////////////////////////////////////////////// |
Geremia | 0:75ec1b3cde17 | 5 | // display settings /////////////////////////////////////////////////////// |
Geremia | 0:75ec1b3cde17 | 6 | ///////////////////////////////////////////////////////////////////////// |
Geremia | 0:75ec1b3cde17 | 7 | #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 | 8 | #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 | 9 | #define LCDSIZE_X 240 // display X pixels |
Geremia | 0:75ec1b3cde17 | 10 | #define LCDSIZE_Y 120 // display Y pixels, UC1608 is advertised as 240x128 but display size could be smaller |
Geremia | 0:75ec1b3cde17 | 11 | |
Geremia | 0:75ec1b3cde17 | 12 | |
Geremia | 0:75ec1b3cde17 | 13 | |
Geremia | 0:75ec1b3cde17 | 14 | UC1608::UC1608(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name) |
Geremia | 0:75ec1b3cde17 | 15 | : LCD(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name) |
Geremia | 0:75ec1b3cde17 | 16 | { |
Geremia | 0:75ec1b3cde17 | 17 | hw_reset(); |
Geremia | 0:75ec1b3cde17 | 18 | BusEnable(true); |
Geremia | 0:75ec1b3cde17 | 19 | init(); |
Geremia | 0:75ec1b3cde17 | 20 | cls(); |
Geremia | 0:75ec1b3cde17 | 21 | set_orientation(1); |
Geremia | 0:75ec1b3cde17 | 22 | locate(0,0); |
Geremia | 0:75ec1b3cde17 | 23 | } |
Geremia | 1:ff019d22b275 | 24 | 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 | 25 | : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name) |
Geremia | 0:75ec1b3cde17 | 26 | { |
Geremia | 0:75ec1b3cde17 | 27 | hw_reset(); |
Geremia | 0:75ec1b3cde17 | 28 | BusEnable(true); |
Geremia | 0:75ec1b3cde17 | 29 | init(); |
Geremia | 0:75ec1b3cde17 | 30 | cls(); |
Geremia | 0:75ec1b3cde17 | 31 | set_orientation(1); |
Geremia | 0:75ec1b3cde17 | 32 | locate(0,0); |
Geremia | 0:75ec1b3cde17 | 33 | } |
Geremia | 0:75ec1b3cde17 | 34 | // reset and init the lcd controller |
Geremia | 0:75ec1b3cde17 | 35 | void UC1608::init() |
Geremia | 0:75ec1b3cde17 | 36 | { |
Geremia | 0:75ec1b3cde17 | 37 | /* Start Initial Sequence ----------------------------------------------------*/ |
Geremia | 0:75ec1b3cde17 | 38 | |
Geremia | 1:ff019d22b275 | 39 | // wr_cmd8(0xE2); // sw reset |
Geremia | 0:75ec1b3cde17 | 40 | wait_ms(15); |
Geremia | 0:75ec1b3cde17 | 41 | |
Geremia | 1:ff019d22b275 | 42 | wr_cmd8(0x27); // Multiplex rate :128 set temperature consenpation 0% |
Geremia | 1:ff019d22b275 | 43 | wr_cmd8(0xEA); //set bias:1/12bias |
Geremia | 0:75ec1b3cde17 | 44 | |
Geremia | 1:ff019d22b275 | 45 | wr_cmd8(0xC4); // set mirror MX=1,MY=0 (controller->display SEGs wiring inverted) |
Geremia | 1:ff019d22b275 | 46 | // wr_cmd8(0xA0); // ADC select seg0-seg223 |
Geremia | 1:ff019d22b275 | 47 | //wr_cmd8(0xA1); // ADC select seg223-seg0 |
Geremia | 1:ff019d22b275 | 48 | // wr_cmd8(0xC8); // SHL select com63-com0 |
Geremia | 1:ff019d22b275 | 49 | //wr_cmd8(0xC0); // SHL select com0-com63 |
Geremia | 0:75ec1b3cde17 | 50 | |
Geremia | 1:ff019d22b275 | 51 | wr_cmd8(0x2F); // //Power Control:internal, LCD capacitance 60nf-90nf |
Geremia | 0:75ec1b3cde17 | 52 | wait_ms(10); |
Geremia | 0:75ec1b3cde17 | 53 | |
Geremia | 1:ff019d22b275 | 54 | // wr_cmd8(0x81);//Set Gain and Potentiometer |
Geremia | 3:48f3282c2be8 | 55 | // wr_cmd8(0x40|26);//Set Gain and Potentiometer xx xxxxxx |
Geremia | 3:48f3282c2be8 | 56 | set_contrast(26); |
Geremia | 0:75ec1b3cde17 | 57 | |
Geremia | 1:ff019d22b275 | 58 | wr_cmd8(0x88); //disable colum/page address wraparound |
Geremia | 1:ff019d22b275 | 59 | wr_cmd8(0xA4); // LCD display ram (EntireDisplayOn disable) |
Geremia | 1:ff019d22b275 | 60 | wr_cmd8(0x40); // start line = 0 |
Geremia | 1:ff019d22b275 | 61 | wr_cmd8(0xA6); // display normal (1 = illuminated) |
Geremia | 1:ff019d22b275 | 62 | wr_cmd8(0xAF); // display ON |
Geremia | 0:75ec1b3cde17 | 63 | |
Geremia | 0:75ec1b3cde17 | 64 | } |
Geremia | 0:75ec1b3cde17 | 65 | //////////////////////////////////////////////////////////////////// |
Geremia | 0:75ec1b3cde17 | 66 | // functions that overrides the standard ones implemented in LCD.cpp |
Geremia | 0:75ec1b3cde17 | 67 | //////////////////////////////////////////////////////////////////// |
Geremia | 0:75ec1b3cde17 | 68 | void UC1608::mirrorXY(mirror_t mode) |
Geremia | 0:75ec1b3cde17 | 69 | { |
Geremia | 0:75ec1b3cde17 | 70 | switch (mode) |
Geremia | 0:75ec1b3cde17 | 71 | { |
Geremia | 0:75ec1b3cde17 | 72 | case(NONE): |
Geremia | 1:ff019d22b275 | 73 | 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 | 74 | break; |
Geremia | 0:75ec1b3cde17 | 75 | case(X): |
Geremia | 1:ff019d22b275 | 76 | wr_cmd8(0xC0); |
Geremia | 0:75ec1b3cde17 | 77 | break; |
Geremia | 0:75ec1b3cde17 | 78 | case(Y): |
Geremia | 1:ff019d22b275 | 79 | wr_cmd8(0xCC); |
Geremia | 0:75ec1b3cde17 | 80 | break; |
Geremia | 0:75ec1b3cde17 | 81 | case(XY): |
Geremia | 1:ff019d22b275 | 82 | wr_cmd8(0xC8); |
Geremia | 0:75ec1b3cde17 | 83 | break; |
Geremia | 0:75ec1b3cde17 | 84 | } |
Geremia | 0:75ec1b3cde17 | 85 | } |
Geremia | 0:75ec1b3cde17 | 86 | void UC1608::set_contrast(int o) |
Geremia | 0:75ec1b3cde17 | 87 | { |
Geremia | 0:75ec1b3cde17 | 88 | contrast = o; |
Geremia | 1:ff019d22b275 | 89 | // wr_cmd8(0x81); // set volume |
Geremia | 1:ff019d22b275 | 90 | // wr_cmd8(0x40|(o&0x3F)); |
Geremia | 1:ff019d22b275 | 91 | wr_cmd16(0x8140|(o&0x3F)); |
Geremia | 0:75ec1b3cde17 | 92 | } |
Geremia | 0:75ec1b3cde17 | 93 | void UC1608::BusEnable(bool enable) |
Geremia | 0:75ec1b3cde17 | 94 | { |
Geremia | 0:75ec1b3cde17 | 95 | LCD::BusEnable(!enable); // crap IC has CS not inverted (active HIGH) |
Geremia | 0:75ec1b3cde17 | 96 | } |