An interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic LCD Serial Backpack, LCD-09352. Derived class from Serial so that you can conveniently send text to the display with printf(), putc(), etc.

Dependents:   DataBus2018

Committer:
shimniok
Date:
Thu Mar 29 18:33:42 2012 +0000
Revision:
2:84b78506add6
Parent:
1:2f436b8aebf4
Child:
3:dff460658aed
Bugfix for rect() due to mistake in datasheet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 2:84b78506add6 1 #include "SerialGraphicLCD.h"
shimniok 2:84b78506add6 2
shimniok 2:84b78506add6 3 #define XSIZE 6
shimniok 2:84b78506add6 4 #define YSIZE 9
shimniok 2:84b78506add6 5
shimniok 2:84b78506add6 6 SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx):
shimniok 2:84b78506add6 7 Serial(tx, rx)
shimniok 2:84b78506add6 8 {
shimniok 2:84b78506add6 9 baud(115200); // default baud rate
shimniok 2:84b78506add6 10 resolution(LCD_128x64); // default resolution
shimniok 2:84b78506add6 11 }
shimniok 2:84b78506add6 12
shimniok 2:84b78506add6 13 void SerialGraphicLCD::clear() {
shimniok 2:84b78506add6 14 putc(0x7c);
shimniok 2:84b78506add6 15 putc(0x00);
shimniok 2:84b78506add6 16 }
shimniok 2:84b78506add6 17
shimniok 2:84b78506add6 18 void SerialGraphicLCD::pos(int col, int row) {
shimniok 2:84b78506add6 19 posXY(XSIZE*col, _yMax-(YSIZE*row)-1);
shimniok 2:84b78506add6 20 }
shimniok 2:84b78506add6 21
shimniok 2:84b78506add6 22 void SerialGraphicLCD::posXY(int x, int y) {
shimniok 2:84b78506add6 23 putc(0x7c);
shimniok 2:84b78506add6 24 putc(0x18);
shimniok 2:84b78506add6 25 putc(x);
shimniok 2:84b78506add6 26 putc(0x7c);
shimniok 2:84b78506add6 27 putc(0x19);
shimniok 2:84b78506add6 28 putc(y);
shimniok 2:84b78506add6 29 }
shimniok 2:84b78506add6 30
shimniok 2:84b78506add6 31 void SerialGraphicLCD::pixel(int x, int y, bool set) {
shimniok 2:84b78506add6 32 putc(0x7c);
shimniok 2:84b78506add6 33 putc(0x10);
shimniok 2:84b78506add6 34 putc(x);
shimniok 2:84b78506add6 35 putc(y);
shimniok 2:84b78506add6 36 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 37 }
shimniok 2:84b78506add6 38
shimniok 2:84b78506add6 39 void SerialGraphicLCD::line(int x1, int y1, int x2, int y2, bool set) {
shimniok 2:84b78506add6 40 putc(0x7c);
shimniok 2:84b78506add6 41 putc(0x0c);
shimniok 2:84b78506add6 42 putc(x1);
shimniok 2:84b78506add6 43 putc(y1);
shimniok 2:84b78506add6 44 putc(x2);
shimniok 2:84b78506add6 45 putc(y2);
shimniok 2:84b78506add6 46 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 47 }
shimniok 2:84b78506add6 48
shimniok 2:84b78506add6 49 void SerialGraphicLCD::circle(int x, int y, int r, bool set) {
shimniok 2:84b78506add6 50 putc(0x7c);
shimniok 2:84b78506add6 51 putc(0x03);
shimniok 2:84b78506add6 52 putc(x);
shimniok 2:84b78506add6 53 putc(y);
shimniok 2:84b78506add6 54 putc(r);
shimniok 2:84b78506add6 55 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 56 }
shimniok 2:84b78506add6 57
shimniok 2:84b78506add6 58 // Unfortunately, the datasheet is incorrect; the box command
shimniok 2:84b78506add6 59 // does not take a 5th parameter for draw/erase like the others
shimniok 2:84b78506add6 60 void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2) {
shimniok 2:84b78506add6 61 putc(0x7c);
shimniok 2:84b78506add6 62 putc(0x0f);
shimniok 2:84b78506add6 63 putc(x1);
shimniok 2:84b78506add6 64 putc(y1);
shimniok 2:84b78506add6 65 putc(x2);
shimniok 2:84b78506add6 66 putc(y2);
shimniok 2:84b78506add6 67 }
shimniok 2:84b78506add6 68
shimniok 2:84b78506add6 69 void SerialGraphicLCD::erase(int x1, int y1, int x2, int y2) {
shimniok 2:84b78506add6 70 putc(0x7c);
shimniok 2:84b78506add6 71 putc(0x05);
shimniok 2:84b78506add6 72 putc(x1);
shimniok 2:84b78506add6 73 putc(y1);
shimniok 2:84b78506add6 74 putc(x2);
shimniok 2:84b78506add6 75 putc(y2);
shimniok 2:84b78506add6 76 }
shimniok 2:84b78506add6 77
shimniok 2:84b78506add6 78 void SerialGraphicLCD::backlight(int i) {
shimniok 2:84b78506add6 79 if (i >= 0 && i <= 100) {
shimniok 2:84b78506add6 80 putc(0x7c);
shimniok 2:84b78506add6 81 putc(0x02);
shimniok 2:84b78506add6 82 putc(i);
shimniok 2:84b78506add6 83 }
shimniok 2:84b78506add6 84 }
shimniok 2:84b78506add6 85
shimniok 2:84b78506add6 86 void SerialGraphicLCD::reverseMode() {
shimniok 2:84b78506add6 87 putc(0x7c);
shimniok 2:84b78506add6 88 putc(0x12);
shimniok 2:84b78506add6 89 }
shimniok 2:84b78506add6 90
shimniok 2:84b78506add6 91 void SerialGraphicLCD::resolution(int type) {
shimniok 2:84b78506add6 92 switch (type) {
shimniok 2:84b78506add6 93 case LCD_128x64 :
shimniok 2:84b78506add6 94 resolution(128, 64);
shimniok 2:84b78506add6 95 break;
shimniok 2:84b78506add6 96 case LCD_160x128 :
shimniok 2:84b78506add6 97 resolution(160, 128);
shimniok 2:84b78506add6 98 break;
shimniok 2:84b78506add6 99 }
shimniok 2:84b78506add6 100 }
shimniok 2:84b78506add6 101
shimniok 2:84b78506add6 102 void SerialGraphicLCD::resolution(int x, int y) {
shimniok 2:84b78506add6 103 _xMax = x;
shimniok 2:84b78506add6 104 _yMax = y;
shimniok 2:84b78506add6 105 }
shimniok 2:84b78506add6 106
shimniok 2:84b78506add6 107
shimniok 2:84b78506add6 108 void SerialGraphicLCD::lcdbaud(int b) {
shimniok 2:84b78506add6 109 if (b > 0 && b < 7) {
shimniok 2:84b78506add6 110 putc(0x7c);
shimniok 2:84b78506add6 111 putc(0x07);
shimniok 2:84b78506add6 112 putc(b+'0');
shimniok 2:84b78506add6 113 }
shimniok 2:84b78506add6 114 }