Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
hd44780_8bit.cpp@0:ae5037e3d6e0, 2010-11-15 (annotated)
- Committer:
- hlipka
- Date:
- Mon Nov 15 22:37:30 2010 +0000
- Revision:
- 0:ae5037e3d6e0
- Child:
- 1:65f72ed914fa
add support for KS0108-based graphical displays
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:ae5037e3d6e0 | 1 | /* |
hlipka | 0:ae5037e3d6e0 | 2 | * mbed LCDWindow library |
hlipka | 0:ae5037e3d6e0 | 3 | * Copyright (c) 2010 Hendrik Lipka |
hlipka | 0:ae5037e3d6e0 | 4 | * |
hlipka | 0:ae5037e3d6e0 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
hlipka | 0:ae5037e3d6e0 | 6 | * of this software and associated documentation files (the "Software"), to deal |
hlipka | 0:ae5037e3d6e0 | 7 | * in the Software without restriction, including without limitation the rights |
hlipka | 0:ae5037e3d6e0 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hlipka | 0:ae5037e3d6e0 | 9 | * copies of the Software, and to permit persons to whom the Software is |
hlipka | 0:ae5037e3d6e0 | 10 | * furnished to do so, subject to the following conditions: |
hlipka | 0:ae5037e3d6e0 | 11 | * |
hlipka | 0:ae5037e3d6e0 | 12 | * The above copyright notice and this permission notice shall be included in |
hlipka | 0:ae5037e3d6e0 | 13 | * all copies or substantial portions of the Software. |
hlipka | 0:ae5037e3d6e0 | 14 | * |
hlipka | 0:ae5037e3d6e0 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hlipka | 0:ae5037e3d6e0 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hlipka | 0:ae5037e3d6e0 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hlipka | 0:ae5037e3d6e0 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hlipka | 0:ae5037e3d6e0 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hlipka | 0:ae5037e3d6e0 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hlipka | 0:ae5037e3d6e0 | 21 | * THE SOFTWARE. |
hlipka | 0:ae5037e3d6e0 | 22 | */ |
hlipka | 0:ae5037e3d6e0 | 23 | |
hlipka | 0:ae5037e3d6e0 | 24 | #include "hd44780_8bit.h" |
hlipka | 0:ae5037e3d6e0 | 25 | |
hlipka | 0:ae5037e3d6e0 | 26 | #include "BusOut.h" |
hlipka | 0:ae5037e3d6e0 | 27 | #include "DigitalOut.h" |
hlipka | 0:ae5037e3d6e0 | 28 | #include "wait_api.h" |
hlipka | 0:ae5037e3d6e0 | 29 | |
hlipka | 0:ae5037e3d6e0 | 30 | |
hlipka | 0:ae5037e3d6e0 | 31 | void HD44780LCD8bit::writeText(unsigned int line, unsigned int pos, char text[]) { |
hlipka | 0:ae5037e3d6e0 | 32 | // printf("print to %d,%d {%s}\n",line,pos,text); |
hlipka | 0:ae5037e3d6e0 | 33 | int address=line*0x40+pos; |
hlipka | 0:ae5037e3d6e0 | 34 | sendCmd((unsigned char)address|0x80); |
hlipka | 0:ae5037e3d6e0 | 35 | wait_us(30); |
hlipka | 0:ae5037e3d6e0 | 36 | |
hlipka | 0:ae5037e3d6e0 | 37 | int i=0; |
hlipka | 0:ae5037e3d6e0 | 38 | while (text[i]!=0) { |
hlipka | 0:ae5037e3d6e0 | 39 | sendData(text[i]); |
hlipka | 0:ae5037e3d6e0 | 40 | wait_us(30); |
hlipka | 0:ae5037e3d6e0 | 41 | i++; |
hlipka | 0:ae5037e3d6e0 | 42 | } |
hlipka | 0:ae5037e3d6e0 | 43 | } |
hlipka | 0:ae5037e3d6e0 | 44 | |
hlipka | 0:ae5037e3d6e0 | 45 | void HD44780LCD8bit::clear() { |
hlipka | 0:ae5037e3d6e0 | 46 | sendCmd(1); |
hlipka | 0:ae5037e3d6e0 | 47 | } |
hlipka | 0:ae5037e3d6e0 | 48 | |
hlipka | 0:ae5037e3d6e0 | 49 | void HD44780LCD8bit::sendCmd(unsigned char cmd) { |
hlipka | 0:ae5037e3d6e0 | 50 | _rs->write(0); |
hlipka | 0:ae5037e3d6e0 | 51 | wait_us(1); |
hlipka | 0:ae5037e3d6e0 | 52 | sendByte(cmd); |
hlipka | 0:ae5037e3d6e0 | 53 | } |
hlipka | 0:ae5037e3d6e0 | 54 | |
hlipka | 0:ae5037e3d6e0 | 55 | void HD44780LCD8bit::sendData(unsigned char cmd) { |
hlipka | 0:ae5037e3d6e0 | 56 | _rs->write(1); |
hlipka | 0:ae5037e3d6e0 | 57 | wait_us(1); |
hlipka | 0:ae5037e3d6e0 | 58 | sendByte(cmd); |
hlipka | 0:ae5037e3d6e0 | 59 | } |
hlipka | 0:ae5037e3d6e0 | 60 | |
hlipka | 0:ae5037e3d6e0 | 61 | HD44780LCD8bit::HD44780LCD8bit |
hlipka | 0:ae5037e3d6e0 | 62 | (unsigned int width, unsigned int height, BusOut *data, PinName enable, PinName rs) |
hlipka | 0:ae5037e3d6e0 | 63 | :TextLCDBase(width, height) |
hlipka | 0:ae5037e3d6e0 | 64 | { |
hlipka | 0:ae5037e3d6e0 | 65 | _data=data; |
hlipka | 0:ae5037e3d6e0 | 66 | _rs=new DigitalOut(rs); |
hlipka | 0:ae5037e3d6e0 | 67 | _enable=new DigitalOut(enable); |
hlipka | 0:ae5037e3d6e0 | 68 | _enable->write(0); |
hlipka | 0:ae5037e3d6e0 | 69 | wait_ms(80); |
hlipka | 0:ae5037e3d6e0 | 70 | } |
hlipka | 0:ae5037e3d6e0 | 71 | |
hlipka | 0:ae5037e3d6e0 | 72 | void HD44780LCD8bit::init() { |
hlipka | 0:ae5037e3d6e0 | 73 | unsigned char initCmd[5]={0x38,0x08,0x01,0x06,0x0c}; |
hlipka | 0:ae5037e3d6e0 | 74 | for (int i=0;i<sizeof(initCmd);i++) { |
hlipka | 0:ae5037e3d6e0 | 75 | sendCmd(initCmd[i]); |
hlipka | 0:ae5037e3d6e0 | 76 | wait_ms(50); |
hlipka | 0:ae5037e3d6e0 | 77 | } |
hlipka | 0:ae5037e3d6e0 | 78 | } |
hlipka | 0:ae5037e3d6e0 | 79 | |
hlipka | 0:ae5037e3d6e0 | 80 | void HD44780LCD8bit::sendByte(unsigned char byte) { |
hlipka | 0:ae5037e3d6e0 | 81 | _data->write(byte); |
hlipka | 0:ae5037e3d6e0 | 82 | _enable->write(1); |
hlipka | 0:ae5037e3d6e0 | 83 | wait_us(2); |
hlipka | 0:ae5037e3d6e0 | 84 | _enable->write(0); |
hlipka | 0:ae5037e3d6e0 | 85 | wait_us(30); |
hlipka | 0:ae5037e3d6e0 | 86 | } |
hlipka | 0:ae5037e3d6e0 | 87 |