Driver for a 128x64 pixels graphic LCD panel based on a KS0723 driver from Samsung.
Embed:
(wiki syntax)
Show/hide line numbers
LcdKs0723.cpp
00001 /* mbed Samsung LCD Library, for a samsung KS0723 based 128x64 black/white lcd panel. 00002 * Copyright (c) 2011, Jeroen Hilgers 00003 * 00004 * I based the interface on the LCD libraries by Simon Ford, to obtain compatibility 00005 * between different displays. I used TextLCD as an example to implement the 00006 * : public Steam part of this library. 00007 * 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining a copy 00010 * of this software and associated documentation files (the "Software"), to deal 00011 * in the Software without restriction, including without limitation the rights 00012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 * copies of the Software, and to permit persons to whom the Software is 00014 * furnished to do so, subject to the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be included in 00017 * all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 * THE SOFTWARE. 00026 */ 00027 00028 #include "LcdKs0723.h" 00029 00030 LcdKs0723::LcdKs0723(PinName reset, PinName rs, PinName write, PinName read, PinName d0, PinName d1, 00031 PinName d2, PinName d3, PinName d4, PinName d5, PinName d6, PinName d7) : 00032 mReset(reset), mRs(rs), mWrite(write), mRead(read), 00033 mData(d0, d1, d2, d3, d4, d5, d6, d7) 00034 { 00035 mRow = 0; 00036 mCol = 0; 00037 00038 // Init IO 00039 mWrite = 1; 00040 mRead = 1; 00041 mRs = 0; 00042 mData.input(); 00043 00044 // Reset 00045 mReset = 0; 00046 wait(0.001); 00047 mReset = 1; 00048 wait(0.1); 00049 00050 // Select LCD BIAS 00051 WriteControl(0xA3); 00052 00053 // ADCSelect 00054 WriteControl(0xA1); 00055 00056 // PowerControl 00057 WriteControl(0x2C); 00058 wait(0.002); 00059 WriteControl(0x2E); 00060 wait(0.002); 00061 WriteControl(0x2F); 00062 wait(0.002); 00063 00064 // Regulator resistor 00065 WriteControl(0x24); 00066 00067 // Reference Voltage 00068 WriteControl(0x81); 00069 WriteControl(0x20); 00070 wait(0.1); 00071 00072 cls(); 00073 00074 // Display on. 00075 WriteControl(0xAF); 00076 } 00077 00078 int LcdKs0723::_putc(int value) 00079 { 00080 if(value == '\n') 00081 { 00082 mCol = 0; 00083 mRow = (mRow+1) & 7; 00084 return value; 00085 } 00086 00087 const uint8_t *ptr = mFont5x7 + value*5; 00088 uint8_t x; 00089 00090 WriteControl( 0xB0 | mRow); // Page address. 00091 WriteControl( 0x10 | (((mCol+3)>>4)&0x0F) ); // Column address. Display starts at pixel 3. 00092 WriteControl( 0x00 | ((mCol+3)&0x0F) ); // Column address 2nd nibble. 00093 00094 mRs = 1; 00095 mData.output(); 00096 00097 for(x=0; x<5; x++) 00098 { 00099 mData = *ptr++; 00100 mWrite = 0; 00101 mWrite = 1; 00102 } 00103 mData = 0; 00104 mWrite = 0; 00105 mWrite = 1; 00106 00107 mData.input(); 00108 mData = 0; 00109 mCol += 6; 00110 00111 if(mCol > 122) 00112 { 00113 mCol = 0; 00114 mRow = (mRow+1)&7; 00115 } 00116 00117 return value; 00118 } 00119 00120 void LcdKs0723::locate(int column, int row) 00121 { 00122 mRow = row & 7; // Limit to 0-7. 00123 if(column < 21) 00124 mCol = column*6; 00125 else 00126 mCol = 0; 00127 } 00128 00129 void LcdKs0723::cls() 00130 { 00131 uint16_t page; 00132 uint8_t x; 00133 for(page = 0; page<8; page++) 00134 { 00135 WriteControl(0xB0 | page); // Page address. 00136 WriteControl(0x10); // Column address. Start at column 0. 00137 WriteControl(0); // Column address 2nd nibble. 00138 00139 // Setup to write data 0x00 to display. 00140 mRs = 1; 00141 mData.output(); 00142 mData = 0; 00143 00144 // First three columns are attached to '>' symbols next to the pixel area. 00145 // This library has no use for them, but we don't want them uninitialized. 00146 for(x=0; x<3; x++) 00147 { 00148 mWrite = 0; 00149 mWrite = 1; 00150 } 00151 00152 // Columns 3-131 display pixel data. Clear them. 00153 for(x=0; x<128; x++) 00154 { 00155 mWrite = 0; 00156 mWrite = 1; 00157 } 00158 00159 // Last five three columns are attached to '<' symbols next to the pixel area. 00160 // This library has no use for them, but we don't want them uninitialized. 00161 for(x=0; x<5; x++) 00162 { 00163 mWrite = 0; 00164 mWrite = 1; 00165 } 00166 mData.input(); 00167 mData = 0; 00168 } 00169 00170 mRow =0; 00171 mCol = 0; 00172 } 00173 00174 uint8_t LcdKs0723::ReadData (void) 00175 { 00176 uint8_t result; 00177 mData.input(); 00178 mRs = 1; 00179 mRead = 0; 00180 result = mData; 00181 mRead = 1; 00182 return result; 00183 } 00184 00185 void LcdKs0723::WriteData (uint8_t value) 00186 { 00187 mRs = 1; 00188 mData.output(); 00189 mData = value; 00190 mWrite = 0; 00191 mWrite = 1; 00192 mData.input(); 00193 mData = 0; 00194 } 00195 00196 uint8_t LcdKs0723::ReadStatus(void) 00197 { 00198 uint8_t result; 00199 mData.input(); 00200 mRs = 0; 00201 mRead = 0; 00202 result = mData; 00203 mRead = 1; 00204 return result; 00205 } 00206 00207 void LcdKs0723::WriteControl(uint8_t value) 00208 { 00209 mRs = 0; 00210 mData.output(); 00211 mData = value; 00212 mWrite = 0; 00213 mWrite = 1; 00214 mData.input(); 00215 mData = 0; 00216 } 00217 00218 const uint8_t LcdKs0723::mFont5x7[] = 00219 { 00220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00233 0x00, 0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 1A = deg symbol. 00234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x00, 0x00, 00237 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 00238 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62, 00239 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x05, 0x03, 0x00, 0x00, 00240 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 00241 0x14, 0x08, 0x3E, 0x08, 0x14, 0x08, 0x08, 0x3E, 0x08, 0x08, 00242 0x00, 0x50, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 00243 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 00244 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x42, 0x7F, 0x40, 0x00, 00245 0x42, 0x61, 0x51, 0x49, 0x46, 0x21, 0x41, 0x45, 0x4B, 0x31, 00246 0x18, 0x14, 0x12, 0x7F, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 00247 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x01, 0x71, 0x09, 0x05, 0x03, 00248 0x36, 0x49, 0x49, 0x49, 0x36, 0x06, 0x49, 0x49, 0x29, 0x1E, 00249 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x56, 0x36, 0x00, 0x00, 00250 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 00251 0x00, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x51, 0x09, 0x06, 00252 0x32, 0x49, 0x79, 0x41, 0x3E, 0x7E, 0x11, 0x11, 0x11, 0x7E, 00253 0x7F, 0x49, 0x49, 0x49, 0x36, 0x3E, 0x41, 0x41, 0x41, 0x22, 00254 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x7F, 0x49, 0x49, 0x49, 0x41, 00255 0x7F, 0x09, 0x09, 0x09, 0x01, 0x3E, 0x41, 0x49, 0x49, 0x7A, 00256 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 00257 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 00258 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 00259 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 00260 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 00261 0x7F, 0x09, 0x19, 0x29, 0x46, 0x46, 0x49, 0x49, 0x49, 0x31, 00262 0x01, 0x01, 0x7F, 0x01, 0x01, 0x3F, 0x40, 0x40, 0x40, 0x3F, 00263 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 00264 0x63, 0x14, 0x08, 0x14, 0x63, 0x07, 0x08, 0x70, 0x08, 0x07, 00265 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x00, 00266 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x7F, 0x00, 00267 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 00268 0x00, 0x01, 0x02, 0x04, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 00269 0x7F, 0x48, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x20, 00270 0x38, 0x44, 0x44, 0x48, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 00271 0x08, 0x7E, 0x09, 0x01, 0x02, 0x0C, 0x52, 0x52, 0x52, 0x3E, 00272 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 00273 0x20, 0x40, 0x44, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 00274 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 00275 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 00276 0x7C, 0x14, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, 0x18, 0x7C, 00277 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x20, 00278 0x04, 0x3F, 0x44, 0x40, 0x20, 0x3C, 0x40, 0x40, 0x20, 0x7C, 00279 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C, 00280 0x44, 0x28, 0x10, 0x28, 0x44, 0x0C, 0x50, 0x50, 0x50, 0x3C, 00281 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 00282 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 00283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 00284 }; 00285 00286 00287
Generated on Fri Jul 15 2022 19:10:22 by
1.7.2