![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Newhaven 320x240 LCD
newhaven.h@2:2058e2f79157, 2011-02-27 (annotated)
- Committer:
- pbevans89
- Date:
- Sun Feb 27 21:40:59 2011 +0000
- Revision:
- 2:2058e2f79157
- Parent:
- 1:fa44aeffcfd6
- Child:
- 4:aa6dc362b462
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 | 2:2058e2f79157 | 70 | */ |
pbevans89 | 0:c8893901ef8a | 71 | void setPixel(int row, int col); |
pbevans89 | 0:c8893901ef8a | 72 | |
pbevans89 | 0:c8893901ef8a | 73 | private: |
pbevans89 | 0:c8893901ef8a | 74 | DigitalOut E,RW,A0,CS,RST; |
pbevans89 | 0:c8893901ef8a | 75 | BusInOut *LCD_PORT; |
pbevans89 | 0:c8893901ef8a | 76 | |
pbevans89 | 0:c8893901ef8a | 77 | }; |
pbevans89 | 0:c8893901ef8a | 78 | |
pbevans89 | 0:c8893901ef8a | 79 | void delay(unsigned int n); |
pbevans89 | 0:c8893901ef8a | 80 | void delay1(unsigned int n); |