Class library for a Topway LM6029ACW graphics LCD.

Committer:
grantphillips
Date:
Mon Feb 08 14:53:03 2016 +0000
Revision:
0:79ef6ebe51ae
v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grantphillips 0:79ef6ebe51ae 1 /* LM6029ACW Library v1.0
grantphillips 0:79ef6ebe51ae 2 * Copyright (c) 2016 Grant Phillips
grantphillips 0:79ef6ebe51ae 3 * grant.phillips@nmmu.ac.za
grantphillips 0:79ef6ebe51ae 4 *
grantphillips 0:79ef6ebe51ae 5 *
grantphillips 0:79ef6ebe51ae 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
grantphillips 0:79ef6ebe51ae 7 * of this software and associated documentation files (the "Software"), to deal
grantphillips 0:79ef6ebe51ae 8 * in the Software without restriction, including without limitation the rights
grantphillips 0:79ef6ebe51ae 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
grantphillips 0:79ef6ebe51ae 10 * copies of the Software, and to permit persons to whom the Software is
grantphillips 0:79ef6ebe51ae 11 * furnished to do so, subject to the following conditions:
grantphillips 0:79ef6ebe51ae 12 *
grantphillips 0:79ef6ebe51ae 13 * The above copyright notice and this permission notice shall be included in
grantphillips 0:79ef6ebe51ae 14 * all copies or substantial portions of the Software.
grantphillips 0:79ef6ebe51ae 15 *
grantphillips 0:79ef6ebe51ae 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
grantphillips 0:79ef6ebe51ae 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
grantphillips 0:79ef6ebe51ae 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
grantphillips 0:79ef6ebe51ae 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
grantphillips 0:79ef6ebe51ae 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
grantphillips 0:79ef6ebe51ae 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
grantphillips 0:79ef6ebe51ae 22 * THE SOFTWARE.
grantphillips 0:79ef6ebe51ae 23 */
grantphillips 0:79ef6ebe51ae 24
grantphillips 0:79ef6ebe51ae 25 #ifndef LM6029ACW_H
grantphillips 0:79ef6ebe51ae 26 #define LM6029ACW_H
grantphillips 0:79ef6ebe51ae 27
grantphillips 0:79ef6ebe51ae 28 #include "mbed.h"
grantphillips 0:79ef6ebe51ae 29
grantphillips 0:79ef6ebe51ae 30 #define lcd_delayx 0.000001 //delay for writing and reading from lcd - 1us
grantphillips 0:79ef6ebe51ae 31 #define lcd_init_delay 0.001 //delay when initializing the lcd - 1ms
grantphillips 0:79ef6ebe51ae 32
grantphillips 0:79ef6ebe51ae 33 /** Class library for a Topway LM6029ACW graphics LCD.
grantphillips 0:79ef6ebe51ae 34 *
grantphillips 0:79ef6ebe51ae 35 * Example:
grantphillips 0:79ef6ebe51ae 36 * @code
grantphillips 0:79ef6ebe51ae 37 * #include "mbed.h"
grantphillips 0:79ef6ebe51ae 38 * #include "LM6029ACW.h"
grantphillips 0:79ef6ebe51ae 39 *
grantphillips 0:79ef6ebe51ae 40 * LM6029ACW lcd(PD_7, PE_2, PD_6, PD_3, PD_2, PC_15, PC_14, PC_13, PC_11, PC_9, PC_8, PC_6, PC_2);
grantphillips 0:79ef6ebe51ae 41 * // CS1 RES RS WR RD DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
grantphillips 0:79ef6ebe51ae 42 *
grantphillips 0:79ef6ebe51ae 43 * DigitalOut backlight(PB_7);
grantphillips 0:79ef6ebe51ae 44 *
grantphillips 0:79ef6ebe51ae 45 * int main() {
grantphillips 0:79ef6ebe51ae 46 * backlight = 0; //turn on the lcd's backlight
grantphillips 0:79ef6ebe51ae 47 * while(1) {
grantphillips 0:79ef6ebe51ae 48 * lcd.GotoXY(4, 3); //move cursor to row, col
grantphillips 0:79ef6ebe51ae 49 * lcd.ClrScr(0); //clear all the pixels on the display
grantphillips 0:79ef6ebe51ae 50 * lcd.PutStr("Hello World!", 1); //print text in black pixels
grantphillips 0:79ef6ebe51ae 51 * wait(2.0);
grantphillips 0:79ef6ebe51ae 52 *
grantphillips 0:79ef6ebe51ae 53 * lcd.GotoXY(4, 3); //move cursor to row, col
grantphillips 0:79ef6ebe51ae 54 * lcd.ClrScr(1); //fill all the pixels on the display
grantphillips 0:79ef6ebe51ae 55 * lcd.PutStr("Hello World!", 0); //print text in clear pixels
grantphillips 0:79ef6ebe51ae 56 * wait(2.0);
grantphillips 0:79ef6ebe51ae 57 * }
grantphillips 0:79ef6ebe51ae 58 * }
grantphillips 0:79ef6ebe51ae 59 * @endcode
grantphillips 0:79ef6ebe51ae 60 */
grantphillips 0:79ef6ebe51ae 61
grantphillips 0:79ef6ebe51ae 62 class LM6029ACW {
grantphillips 0:79ef6ebe51ae 63 public:
grantphillips 0:79ef6ebe51ae 64 /** Create a LM6029ACW object for a graphics LCD connected to the specified pins.
grantphillips 0:79ef6ebe51ae 65 * @param CS1 Chip Select pin used to connect to LM6029ACW's CS1 pin
grantphillips 0:79ef6ebe51ae 66 * @param RES Reset pin used to connect to LM6029ACW's RES pin
grantphillips 0:79ef6ebe51ae 67 * @param RS Register Select pin used to connect to LM6029ACW's RS pin
grantphillips 0:79ef6ebe51ae 68 * @param WR Write pin used to connect to LM6029ACW's WR pin
grantphillips 0:79ef6ebe51ae 69 * @param RD Read pin used to connect to LM6029ACW's RD pin
grantphillips 0:79ef6ebe51ae 70 * @param DB7-DB0 Data Bus pin useds to connect to LM6029ACW's DB7 - DB0 pins
grantphillips 0:79ef6ebe51ae 71 */
grantphillips 0:79ef6ebe51ae 72 LM6029ACW(PinName CS1, PinName RES, PinName RS, PinName WR, PinName RD, PinName DB7, PinName DB6, PinName DB5, PinName DB4, PinName DB3, PinName DB2, PinName DB1, PinName DB0);
grantphillips 0:79ef6ebe51ae 73
grantphillips 0:79ef6ebe51ae 74 /** Clears the lcd by clearing or filling all the pixels.
grantphillips 0:79ef6ebe51ae 75 * @param color Bit value; clear pixels(0) or fill pixels(1)
grantphillips 0:79ef6ebe51ae 76 */
grantphillips 0:79ef6ebe51ae 77 void ClrScr(unsigned char color);
grantphillips 0:79ef6ebe51ae 78
grantphillips 0:79ef6ebe51ae 79 /** Puts the lcd in power save mode - display off.
grantphillips 0:79ef6ebe51ae 80 */
grantphillips 0:79ef6ebe51ae 81 void PowerSave(void);
grantphillips 0:79ef6ebe51ae 82
grantphillips 0:79ef6ebe51ae 83 /** Puts the lcd in normal power mode - display on.
grantphillips 0:79ef6ebe51ae 84 */
grantphillips 0:79ef6ebe51ae 85 void PowerActive(void);
grantphillips 0:79ef6ebe51ae 86
grantphillips 0:79ef6ebe51ae 87 /** Draws a pixel on the lcd at the specified xy position.
grantphillips 0:79ef6ebe51ae 88 * @param x x position (0 - 127)
grantphillips 0:79ef6ebe51ae 89 * @param y y position (0 - 63)
grantphillips 0:79ef6ebe51ae 90 * @param color mode of the pixel; cleared(0), filled(1), or toggle(2)
grantphillips 0:79ef6ebe51ae 91 */
grantphillips 0:79ef6ebe51ae 92 void DrawPixel(unsigned char x, unsigned char y, unsigned char color);
grantphillips 0:79ef6ebe51ae 93
grantphillips 0:79ef6ebe51ae 94 /** Draws a line on the lcd from x1,y1 to x2,y2.
grantphillips 0:79ef6ebe51ae 95 * @param x1 x1 position (0 - 127)
grantphillips 0:79ef6ebe51ae 96 * @param y1 y1 position (0 - 63)
grantphillips 0:79ef6ebe51ae 97 * @param x2 x2 position (0 - 127)
grantphillips 0:79ef6ebe51ae 98 * @param y2 y2 position (0 - 63)
grantphillips 0:79ef6ebe51ae 99 * @param color mode of the pixel; cleared(0), filled(1), or toggle(2)
grantphillips 0:79ef6ebe51ae 100 */
grantphillips 0:79ef6ebe51ae 101 void DrawLine(int x1, int y1, int x2, int y2, unsigned int color);
grantphillips 0:79ef6ebe51ae 102
grantphillips 0:79ef6ebe51ae 103 /** Draws a circle on the lcd at x,y with the option to fill it.
grantphillips 0:79ef6ebe51ae 104 * @param x x position (0 - 127)
grantphillips 0:79ef6ebe51ae 105 * @param y y position (0 - 63)
grantphillips 0:79ef6ebe51ae 106 * @param radius radius of the circle (0 - 127)
grantphillips 0:79ef6ebe51ae 107 * @param fill circle must be filled (=1) or not filled (=0)
grantphillips 0:79ef6ebe51ae 108 * @param color mode of the pixel; cleared(0), filled(1)
grantphillips 0:79ef6ebe51ae 109 */
grantphillips 0:79ef6ebe51ae 110 void DrawCircle(unsigned char x, unsigned char y, unsigned char radius, unsigned char fill, unsigned char color);
grantphillips 0:79ef6ebe51ae 111
grantphillips 0:79ef6ebe51ae 112 /** Changes the position on the lcd of the current character cursor from where the next characters will be printed.
grantphillips 0:79ef6ebe51ae 113 * @param x column position (0 - 20)
grantphillips 0:79ef6ebe51ae 114 * @param y row position (0 - 7)
grantphillips 0:79ef6ebe51ae 115 */
grantphillips 0:79ef6ebe51ae 116 void GotoXY(unsigned char x, unsigned char y);
grantphillips 0:79ef6ebe51ae 117
grantphillips 0:79ef6ebe51ae 118 /** Prints a string on the lcd at the current character cursor position.
grantphillips 0:79ef6ebe51ae 119 * @param str string (char array) to print
grantphillips 0:79ef6ebe51ae 120 * @param color mode of the characters in the string; normal(1), inverted(0)
grantphillips 0:79ef6ebe51ae 121 */
grantphillips 0:79ef6ebe51ae 122 void PutStr(char *str, unsigned char color);
grantphillips 0:79ef6ebe51ae 123
grantphillips 0:79ef6ebe51ae 124 /** Prints a character on the lcd at the current character cursor position.
grantphillips 0:79ef6ebe51ae 125 * @param c character to print
grantphillips 0:79ef6ebe51ae 126 * @param color mode of the character; normal(1), inverted(0)
grantphillips 0:79ef6ebe51ae 127 */
grantphillips 0:79ef6ebe51ae 128 void PutChar(unsigned char c, unsigned char color);
grantphillips 0:79ef6ebe51ae 129
grantphillips 0:79ef6ebe51ae 130
grantphillips 0:79ef6ebe51ae 131 private:
grantphillips 0:79ef6ebe51ae 132 DigitalOut CS1pin, RESpin, RSpin, WRpin, RDpin;
grantphillips 0:79ef6ebe51ae 133 BusOut DATApins;
grantphillips 0:79ef6ebe51ae 134 unsigned char DisplayRAM[128][8];
grantphillips 0:79ef6ebe51ae 135 unsigned char character_x, character_y;
grantphillips 0:79ef6ebe51ae 136
grantphillips 0:79ef6ebe51ae 137
grantphillips 0:79ef6ebe51ae 138 /* Creates a delay which is simply a code loop which is independent from any hardware timers.
grantphillips 0:79ef6ebe51ae 139 * @param del 16-bit value to represent the delay cycles
grantphillips 0:79ef6ebe51ae 140 */
grantphillips 0:79ef6ebe51ae 141 void Delay(unsigned int del);
grantphillips 0:79ef6ebe51ae 142
grantphillips 0:79ef6ebe51ae 143 /* Writes a COMMAND to the LM6029ACW lcd module.
grantphillips 0:79ef6ebe51ae 144 * @param cmd The byte of command to write to the lcd
grantphillips 0:79ef6ebe51ae 145 */
grantphillips 0:79ef6ebe51ae 146 void WriteCommand(unsigned char cmd);
grantphillips 0:79ef6ebe51ae 147
grantphillips 0:79ef6ebe51ae 148 /* Writes DATA to the LM6029ACW lcd module.
grantphillips 0:79ef6ebe51ae 149 * @param dat The byte of data to write to the lcd
grantphillips 0:79ef6ebe51ae 150 */
grantphillips 0:79ef6ebe51ae 151 void WriteData(unsigned char dat);
grantphillips 0:79ef6ebe51ae 152
grantphillips 0:79ef6ebe51ae 153 /* Set the display RAM page address.
grantphillips 0:79ef6ebe51ae 154 * @param Page 4-bit value representing the page address (0 - 7)
grantphillips 0:79ef6ebe51ae 155 */
grantphillips 0:79ef6ebe51ae 156 void SetPage(unsigned char Page);
grantphillips 0:79ef6ebe51ae 157
grantphillips 0:79ef6ebe51ae 158 /* Set the column address counter.
grantphillips 0:79ef6ebe51ae 159 * @param Page Byte value representing the column (0 - 127)
grantphillips 0:79ef6ebe51ae 160 */
grantphillips 0:79ef6ebe51ae 161 void SetColumn(unsigned char Col);
grantphillips 0:79ef6ebe51ae 162
grantphillips 0:79ef6ebe51ae 163 /** Initializes the LM6029ACW lcd module.
grantphillips 0:79ef6ebe51ae 164 */
grantphillips 0:79ef6ebe51ae 165 void Init(void);
grantphillips 0:79ef6ebe51ae 166
grantphillips 0:79ef6ebe51ae 167 /* Used by LM6029ACW_DrawChar only updates the column and page numbers..
grantphillips 0:79ef6ebe51ae 168 */
grantphillips 0:79ef6ebe51ae 169 void WriteCharCol(unsigned char v, unsigned char x, unsigned char page, unsigned char color);
grantphillips 0:79ef6ebe51ae 170
grantphillips 0:79ef6ebe51ae 171 /* Used by LM6029ACW_PutChar() only and draws the specified character at byte level using a set font.
grantphillips 0:79ef6ebe51ae 172 */
grantphillips 0:79ef6ebe51ae 173 void DrawChar(unsigned char c, unsigned char x, unsigned char page, unsigned char color);
grantphillips 0:79ef6ebe51ae 174 };
grantphillips 0:79ef6ebe51ae 175
grantphillips 0:79ef6ebe51ae 176 #endif