Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
sed1335text.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 "sed1335text.h" 00025 00026 #include "BusOut.h" 00027 #include "DigitalOut.h" 00028 #include "wait_api.h" 00029 00030 #define FIRSTBANK_MEM 0 00031 #define SECONDBANK_MEM 0x1000 00032 #define THIRDBANK_MEM 0x800 00033 00034 #define HIGH(x) ((x&0xff00)>>8) 00035 #define LOW(x) (x&0xff) 00036 00037 void SED1335TextLCD::writeText(const unsigned int column, const unsigned int row, const char text[]) { 00038 int i=0; 00039 00040 int pos=row*getColumns ()+column; 00041 00042 if (!_guard->take()) 00043 return; 00044 00045 sendCmd(0x46); // set cursor addr 00046 sendData(LOW(pos)); 00047 sendData(HIGH(pos)); 00048 00049 sendCmd(0x42); 00050 while (text[i]!=0) { 00051 sendData(text[i]); 00052 i++; 00053 } 00054 _guard->release(); 00055 } 00056 00057 void SED1335TextLCD::clearBank(int start, int size, int data) { 00058 sendCmd(0x46); // set cursor addr 00059 sendData(LOW(start)); // start of RAM 00060 sendData(HIGH(start)); 00061 wait_ms(1); 00062 00063 sendCmd(0x42); // write to memory 00064 for (int i=0;i<size;i++) 00065 sendData(data); // send space 00066 wait_ms(1); 00067 } 00068 00069 void SED1335TextLCD::clear() { 00070 _guard->take(); 00071 00072 clearBank(FIRSTBANK_MEM,getColumns ()*getRows (),0x20); 00073 clearBank(SECONDBANK_MEM,getColumns ()*getRows ()*8,0); 00074 clearBank(THIRDBANK_MEM,getColumns ()*getRows (),0); 00075 00076 _guard->release(); 00077 } 00078 00079 00080 void SED1335TextLCD::character(int column, int row, int c){ 00081 _guard->take(); 00082 _guard->release(); 00083 } 00084 00085 SED1335TextLCD::SED1335TextLCD 00086 (const unsigned int columns, const unsigned int rows, BusOut *data, const PinName read, const PinName write, const PinName cs, const PinName a0, const PinName reset) 00087 :TextLCDBase(columns, rows) { 00088 _data=data; 00089 _rd=new DigitalOut(read); 00090 _wr=new DigitalOut(write); 00091 _a0=new DigitalOut(a0); 00092 _cs=new DigitalOut(cs); 00093 _reset=new DigitalOut(reset); 00094 wait_ms(100); 00095 } 00096 00097 void SED1335TextLCD::init() { 00098 initInternal(); 00099 initInternal(); 00100 } 00101 00102 void SED1335TextLCD::initInternal() { 00103 _reset->write(0); 00104 wait_ms(2); 00105 _reset->write(1); 00106 wait_ms(10); 00107 00108 sendCmd(0x40); // SYSTEM SET 00109 sendData(0x30); // p1 set cg rom 00110 sendData(0x87); // p2 00111 sendData(0x7); // p3 00112 sendData(getColumns ()-1); // p4 00113 sendData(getColumns ()+3); // p5 00114 sendData(0xef); // p6 00115 sendData(getColumns ()); // p7 00116 sendData(0x0); // p8 00117 wait_ms(1); 00118 00119 sendCmd(0x44); // SCROLL 00120 sendData(LOW(FIRSTBANK_MEM)); // first block 00121 sendData(HIGH(FIRSTBANK_MEM)); 00122 sendData(getRows ()*8); // lines 00123 sendData(LOW(SECONDBANK_MEM)); // second block 00124 sendData(HIGH(SECONDBANK_MEM)); 00125 sendData(getRows ()*8); // lines 00126 sendData(LOW(THIRDBANK_MEM)); // third block at 0x800 00127 sendData(HIGH(THIRDBANK_MEM)); 00128 wait_ms(1); 00129 00130 sendCmd(0x5a); // HDOT SCR 00131 sendData(0x0); 00132 00133 00134 sendCmd(0x5b); // OVLAY 00135 sendData(0x01); // 2 layers, text, x-or 00136 wait_ms(1); 00137 00138 sendCmd(0x59); // DISP on 00139 sendData(0x54); // all layers on, cursor off 00140 // sendData(0x56); // all layers on, cursor flashing 00141 wait_ms(1); 00142 00143 clear(); 00144 00145 sendCmd(0x5d); // CSR FORM 00146 sendData(0x04); // 8 pixels wide 00147 sendData(0x86); // 2 pixel high, block cursor 00148 wait_ms(1); 00149 00150 sendCmd(0x4c); // CSR DIR right 00151 wait_ms(1); 00152 00153 } 00154 00155 void SED1335TextLCD::sendCmd(const unsigned char cmd) { 00156 _rd->write(1); 00157 _wr->write(1); 00158 _a0->write(1); 00159 _cs->write(0); 00160 // address setup time is 0 00161 sendByte(cmd); 00162 wait_us(10); 00163 } 00164 00165 void SED1335TextLCD::sendData(const unsigned char cmd) { 00166 _rd->write(1); 00167 _wr->write(1); 00168 _a0->write(0); 00169 _cs->write(0); 00170 // address setup time is 0 00171 sendByte(cmd); 00172 wait_us(10); 00173 } 00174 00175 void SED1335TextLCD::sendByte(const unsigned char byte) { 00176 // display reads with rising flank of /wr 00177 // first, set data, then set /wr low (no timing needed) 00178 _data->write(byte); 00179 _wr->write(0); 00180 // wait for setup 00181 wait_us(1); 00182 // set /wr back to high 00183 _wr->write(1); 00184 // address / data hold time is 10 / 5 ns, so its handled by executing normal code :) 00185 }
Generated on Tue Jul 12 2022 20:32:52 by
1.7.2
