Paul Evans
/
Newhaven_LCD
Newhaven 320x240 LCD
newhaven.h@4:aa6dc362b462, 2011-02-28 (annotated)
- Committer:
- pbevans89
- Date:
- Mon Feb 28 17:48:12 2011 +0000
- Revision:
- 4:aa6dc362b462
- Parent:
- 2:2058e2f79157
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pbevans89 | 1:fa44aeffcfd6 | 1 | /* mbed Newhaven LCD Library, for the NHD-320240WG model |
pbevans89 | 1:fa44aeffcfd6 | 2 | * Copyright (c) 2011, Paul Evans |
pbevans89 | 1:fa44aeffcfd6 | 3 | * |
pbevans89 | 1:fa44aeffcfd6 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
pbevans89 | 1:fa44aeffcfd6 | 5 | * of this software and associated documentation files (the "Software"), to deal |
pbevans89 | 1:fa44aeffcfd6 | 6 | * in the Software without restriction, including without limitation the rights |
pbevans89 | 1:fa44aeffcfd6 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pbevans89 | 1:fa44aeffcfd6 | 8 | * copies of the Software, and to permit persons to whom the Software is |
pbevans89 | 1:fa44aeffcfd6 | 9 | * furnished to do so, subject to the following conditions: |
pbevans89 | 1:fa44aeffcfd6 | 10 | * |
pbevans89 | 1:fa44aeffcfd6 | 11 | * The above copyright notice and this permission notice shall be included in |
pbevans89 | 1:fa44aeffcfd6 | 12 | * all copies or substantial portions of the Software. |
pbevans89 | 1:fa44aeffcfd6 | 13 | * |
pbevans89 | 1:fa44aeffcfd6 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pbevans89 | 1:fa44aeffcfd6 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pbevans89 | 1:fa44aeffcfd6 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pbevans89 | 1:fa44aeffcfd6 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pbevans89 | 1:fa44aeffcfd6 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pbevans89 | 1:fa44aeffcfd6 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pbevans89 | 1:fa44aeffcfd6 | 20 | * THE SOFTWARE. |
pbevans89 | 1:fa44aeffcfd6 | 21 | */ |
pbevans89 | 1:fa44aeffcfd6 | 22 | |
pbevans89 | 1:fa44aeffcfd6 | 23 | #include "mbed.h" |
pbevans89 | 0:c8893901ef8a | 24 | |
pbevans89 | 0:c8893901ef8a | 25 | class NHLCD { |
pbevans89 | 0:c8893901ef8a | 26 | public: |
pbevans89 | 1:fa44aeffcfd6 | 27 | /* Creates a Newhaven LCD interface using several DigitalOut pins and a 8-bit BusInOut |
pbevans89 | 1:fa44aeffcfd6 | 28 | * |
pbevans89 | 1:fa44aeffcfd6 | 29 | * @param PIN_E Operation enable signal |
pbevans89 | 1:fa44aeffcfd6 | 30 | * @param PIN_RW Read/Write select signal (1 = read, 0 = write) |
pbevans89 | 1:fa44aeffcfd6 | 31 | * @param PIN_A0 Register select signal (1 = data, 0 = command) |
pbevans89 | 1:fa44aeffcfd6 | 32 | * @param PIN_CS Active LOW chip select |
pbevans89 | 1:fa44aeffcfd6 | 33 | * @param PIN_RST Active LOW reset signal |
pbevans89 | 1:fa44aeffcfd6 | 34 | * @param BUSLCD Bi-directional 8-bit data bus |
pbevans89 | 1:fa44aeffcfd6 | 35 | */ |
pbevans89 | 0:c8893901ef8a | 36 | NHLCD(PinName PIN_E,PinName PIN_RW,PinName PIN_A0,PinName PIN_CS,PinName PIN_RST, BusInOut *BUSLCD); |
pbevans89 | 2:2058e2f79157 | 37 | |
pbevans89 | 2:2058e2f79157 | 38 | /* Initializes the LCD |
pbevans89 | 2:2058e2f79157 | 39 | */ |
pbevans89 | 0:c8893901ef8a | 40 | void Init(); |
pbevans89 | 2:2058e2f79157 | 41 | |
pbevans89 | 2:2058e2f79157 | 42 | /* Outputs a command across the 8-bit bus to the LCD |
pbevans89 | 2:2058e2f79157 | 43 | * |
pbevans89 | 2:2058e2f79157 | 44 | * @param j hex-code of command |
pbevans89 | 2:2058e2f79157 | 45 | */ |
pbevans89 | 0:c8893901ef8a | 46 | void comm_out(unsigned char j); |
pbevans89 | 2:2058e2f79157 | 47 | |
pbevans89 | 2:2058e2f79157 | 48 | /* Outputs data across the 8-bit bus to the LCD |
pbevans89 | 2:2058e2f79157 | 49 | * |
pbevans89 | 2:2058e2f79157 | 50 | * @param j data to send |
pbevans89 | 2:2058e2f79157 | 51 | */ |
pbevans89 | 0:c8893901ef8a | 52 | void data_out(unsigned char j); |
pbevans89 | 2:2058e2f79157 | 53 | |
pbevans89 | 2:2058e2f79157 | 54 | /* Clears the entire screen of set pixels |
pbevans89 | 2:2058e2f79157 | 55 | */ |
pbevans89 | 0:c8893901ef8a | 56 | void clearScreen(); |
pbevans89 | 2:2058e2f79157 | 57 | |
pbevans89 | 2:2058e2f79157 | 58 | /* Writes text to the LCD (with a resolution of 40x30 characters) |
pbevans89 | 2:2058e2f79157 | 59 | * |
pbevans89 | 2:2058e2f79157 | 60 | * @param text a string of text to write on the screen |
pbevans89 | 2:2058e2f79157 | 61 | * @param row the row of the first character |
pbevans89 | 2:2058e2f79157 | 62 | * @param col the column of the first character |
pbevans89 | 2:2058e2f79157 | 63 | */ |
pbevans89 | 0:c8893901ef8a | 64 | void text(char* text, char row, char col); |
pbevans89 | 2:2058e2f79157 | 65 | |
pbevans89 | 2:2058e2f79157 | 66 | /* Sets an individual pixel on the LCD (with a resolution of 320x240 pixels) |
pbevans89 | 2:2058e2f79157 | 67 | * |
pbevans89 | 2:2058e2f79157 | 68 | * @param row the row of the pixel |
pbevans89 | 2:2058e2f79157 | 69 | * @param col the column of the pixel |
pbevans89 | 4:aa6dc362b462 | 70 | * @param color 1 = on, 0 = off |
pbevans89 | 2:2058e2f79157 | 71 | */ |
pbevans89 | 4:aa6dc362b462 | 72 | void setPixel(int row, int col, int color); |
pbevans89 | 4:aa6dc362b462 | 73 | |
pbevans89 | 4:aa6dc362b462 | 74 | /* draws a line on the LCD |
pbevans89 | 4:aa6dc362b462 | 75 | * |
pbevans89 | 4:aa6dc362b462 | 76 | * @param r1 the row of the first endpoint |
pbevans89 | 4:aa6dc362b462 | 77 | * @param c1 the column of the first endpoint |
pbevans89 | 4:aa6dc362b462 | 78 | * @param r2 the row of the second endpoint |
pbevans89 | 4:aa6dc362b462 | 79 | * @param c2 the column of the second endpoint |
pbevans89 | 4:aa6dc362b462 | 80 | * @param color 1 = on, 0 = off |
pbevans89 | 4:aa6dc362b462 | 81 | */ |
pbevans89 | 4:aa6dc362b462 | 82 | void drawLine(int r1, int c1, int r2, int c2, int color); |
pbevans89 | 4:aa6dc362b462 | 83 | |
pbevans89 | 4:aa6dc362b462 | 84 | /* draws and fills a rectangle on the LCD |
pbevans89 | 4:aa6dc362b462 | 85 | * |
pbevans89 | 4:aa6dc362b462 | 86 | * @param row the row of the top-left pixel |
pbevans89 | 4:aa6dc362b462 | 87 | * @param col the column of the top-left pixel |
pbevans89 | 4:aa6dc362b462 | 88 | * @param width the width of the rectangle |
pbevans89 | 4:aa6dc362b462 | 89 | * @param height the height of the rectangle |
pbevans89 | 4:aa6dc362b462 | 90 | * @param color 1 = on, 0 = off |
pbevans89 | 4:aa6dc362b462 | 91 | */ |
pbevans89 | 4:aa6dc362b462 | 92 | void fillRect(int row, int col, int width, int height, int color); |
pbevans89 | 0:c8893901ef8a | 93 | |
pbevans89 | 0:c8893901ef8a | 94 | private: |
pbevans89 | 0:c8893901ef8a | 95 | DigitalOut E,RW,A0,CS,RST; |
pbevans89 | 4:aa6dc362b462 | 96 | BusInOut *LCD_PORT; |
pbevans89 | 4:aa6dc362b462 | 97 | unsigned char screenBuffer[240*40]; |
pbevans89 | 0:c8893901ef8a | 98 | |
pbevans89 | 0:c8893901ef8a | 99 | }; |
pbevans89 | 0:c8893901ef8a | 100 | |
pbevans89 | 0:c8893901ef8a | 101 | void delay(unsigned int n); |
pbevans89 | 0:c8893901ef8a | 102 | void delay1(unsigned int n); |
pbevans89 | 4:aa6dc362b462 | 103 | void swap(int* a, int* b); |