Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
hd44780_8bit.cpp
00001 /* 00002 * mbed LCDWindow library 00003 * Copyright (c) 2010 Hendrik Lipka 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #include "hd44780_8bit.h" 00025 00026 #include "BusOut.h" 00027 #include "DigitalOut.h" 00028 #include "wait_api.h" 00029 00030 void HD44780LCD8bit::character(int column, int row, int c) 00031 { 00032 int address=(row)*0x40+(column); 00033 if (!_guard->take()) 00034 return; 00035 sendCmd((unsigned char)address|0x80); 00036 wait_us(30); 00037 sendData(c); 00038 _guard->release(); 00039 wait_us(30); 00040 } 00041 00042 00043 void HD44780LCD8bit::writeText(const unsigned int column, const unsigned int row, const char text[]) { 00044 // printf("print to %d,%d {%s}\n",line,pos,text); 00045 int address=row*0x40+column; 00046 if (!_guard->take()) 00047 return; 00048 sendCmd((unsigned char)address|0x80); 00049 wait_us(30); 00050 00051 int i=0; 00052 while (text[i]!=0) { 00053 sendData(text[i]); 00054 wait_us(30); 00055 i++; 00056 } 00057 _guard->release(); 00058 } 00059 00060 void HD44780LCD8bit::clear() { 00061 if (!_guard->take()) 00062 return; 00063 sendCmd(1); 00064 _guard->release(); 00065 } 00066 00067 void HD44780LCD8bit::sendCmd(const unsigned char cmd) { 00068 _rs->write(0); 00069 wait_us(1); 00070 sendByte(cmd); 00071 } 00072 00073 void HD44780LCD8bit::sendData(const unsigned char cmd) { 00074 _rs->write(1); 00075 wait_us(1); 00076 sendByte(cmd); 00077 } 00078 00079 HD44780LCD8bit::HD44780LCD8bit 00080 (unsigned int columns, unsigned int rows, BusOut *data, PinName enable, PinName rs) 00081 :TextLCDBase(columns, rows) 00082 { 00083 _data=data; 00084 _rs=new DigitalOut(rs); 00085 _enable=new DigitalOut(enable); 00086 _enable->write(0); 00087 wait_ms(80); 00088 } 00089 00090 void HD44780LCD8bit::init() { 00091 unsigned char initCmd[5]={0x38,0x08,0x01,0x06,0x0c}; 00092 for (int i=0;i<sizeof(initCmd);i++) { 00093 sendCmd(initCmd[i]); 00094 wait_ms(50); 00095 } 00096 } 00097 00098 void HD44780LCD8bit::sendByte(const unsigned char byte) { 00099 _data->write(byte); 00100 _enable->write(1); 00101 wait_us(2); 00102 _enable->write(0); 00103 wait_us(30); 00104 } 00105
Generated on Tue Jul 12 2022 20:32:51 by
1.7.2
