Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LcdWindow by
ks0108_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 "ks0108_8bit.h" 00025 00026 #include "BusOut.h" 00027 #include "DigitalOut.h" 00028 #include "wait_api.h" 00029 #include "font.h" 00030 00031 #define ENABLE 1 00032 00033 void KS0108LCD8bit::writeText(const unsigned int column, const unsigned int row, const char text[]) { 00034 int i=0; 00035 while (text[i]!=0) { 00036 character(column+i, row,text[i]); 00037 i++; 00038 } 00039 } 00040 00041 void KS0108LCD8bit::clear() { 00042 if (!_guard->take()) 00043 return; 00044 clearHalf(_left); 00045 if (NULL!=_right) 00046 clearHalf(_right); 00047 _guard->release(); 00048 } 00049 00050 void KS0108LCD8bit::clearHalf(DigitalOut* cs) { 00051 for (int x=0;x<8;x++) 00052 { 00053 sendCmd(0xb8|x,cs); 00054 wait_us(1); 00055 for (int y=0;y<64;y++) 00056 { 00057 sendCmd(0x40|y,cs); 00058 wait_us(1); 00059 sendData(0,cs); 00060 wait_us(1); 00061 } 00062 } 00063 } 00064 00065 void KS0108LCD8bit::character(int column, int row, int c){ 00066 DigitalOut* cs=NULL; 00067 int icolumn=column; 00068 if (icolumn>7) 00069 { 00070 cs=_right; 00071 icolumn-=8; 00072 } 00073 else 00074 { 00075 cs=_left; 00076 } 00077 if (NULL==cs) 00078 return; 00079 00080 if (!_guard->take()) 00081 return; 00082 sendCmd(0xb8|row,cs); // set x page 00083 00084 unsigned int y=icolumn*8; 00085 sendCmd(0x40|y,cs); // set start line 00086 00087 // send character data 00088 for (int i=0;i<8;i++) 00089 { 00090 sendData(font_data[c][i],cs); 00091 } 00092 00093 _guard->release(); 00094 } 00095 00096 KS0108LCD8bit::KS0108LCD8bit 00097 (const unsigned int columns, const unsigned int rows, BusOut *data, const PinName enable, const PinName rs, const PinName leftCS, const PinName rightCS) 00098 :TextLCDBase(columns, rows) { 00099 _data=data; 00100 _rs=new DigitalOut(rs); 00101 _enable=new DigitalOut(enable); 00102 _left=new DigitalOut(leftCS); 00103 _left->write(1-ENABLE); 00104 if (NC!=rightCS) 00105 { 00106 _right=new DigitalOut(rightCS); 00107 _right->write(1-ENABLE); 00108 } 00109 else 00110 _right=NULL; 00111 _enable->write(0); 00112 wait_ms(80); 00113 } 00114 00115 void KS0108LCD8bit::init() { 00116 sendCmd(0x3f, _left); 00117 wait_ms(10); 00118 sendCmd(0xc0, _left); 00119 00120 if (NULL!=_right) 00121 { 00122 sendCmd(0x3f, _right); 00123 wait_ms(10); 00124 sendCmd(0xc0, _right); 00125 } 00126 wait_ms(50); 00127 clear(); 00128 } 00129 00130 void KS0108LCD8bit::sendCmd(const unsigned char cmd, DigitalOut *cs) { 00131 _rs->write(0); 00132 wait_us(1); 00133 sendByte(cmd, cs); 00134 wait_us(10); 00135 } 00136 00137 void KS0108LCD8bit::sendData(const unsigned char cmd, DigitalOut *cs) { 00138 _rs->write(1); 00139 wait_us(1); 00140 sendByte(cmd, cs); 00141 wait_us(10); 00142 } 00143 00144 void KS0108LCD8bit::sendByte(const unsigned char byte, DigitalOut *cs) { 00145 // display reads flags with rising flank of E 00146 _enable->write(0); 00147 cs->write(ENABLE); 00148 _data->write(byte); 00149 00150 wait_us(2); 00151 _enable->write(1); 00152 00153 // display reads data with falling flank of E 00154 wait_us(2); 00155 _enable->write(0); 00156 00157 wait_us(30); 00158 cs->write(1-ENABLE); 00159 }
Generated on Tue Jul 12 2022 20:32:51 by
1.7.2
