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.
MobileLCD.cpp
00001 /* mbed Library - MobileLCD 00002 * Copyright (c) 2007, sford 00003 */ 00004 00005 #include "MobileLCD.h" 00006 00007 #include "mbed.h" 00008 00009 #include "Terminal.h" 00010 00011 Terminal term(USBTX, USBRX); // tx, rx 00012 00013 using namespace mbed; 00014 00015 const unsigned char FONT6x8[97][8] = { 00016 0x06,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char 00017 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 00018 0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00, // ! 00019 0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00, // " 00020 0x50,0x50,0xF8,0x50,0xF8,0x50,0x50,0x00, // # 00021 0x20,0x78,0xA0,0x70,0x28,0xF0,0x20,0x00, // $ 00022 0xC0,0xC8,0x10,0x20,0x40,0x98,0x18,0x00, // % 00023 0x40,0xA0,0xA0,0x40,0xA8,0x90,0x68,0x00, // & 00024 0x30,0x30,0x20,0x40,0x00,0x00,0x00,0x00, // ' 00025 0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x00, // ( 00026 0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00, // ) 00027 0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00, // * 00028 0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00, // + 00029 0x00,0x00,0x00,0x00,0x30,0x30,0x20,0x40, // , 00030 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, // - 00031 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00, // . 00032 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, // / (forward slash) 00033 0x70,0x88,0x88,0xA8,0x88,0x88,0x70,0x00, // 0 0x30 00034 0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00, // 1 00035 0x70,0x88,0x08,0x70,0x80,0x80,0xF8,0x00, // 2 00036 0xF8,0x08,0x10,0x30,0x08,0x88,0x70,0x00, // 3 00037 0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00, // 4 00038 0xF8,0x80,0xF0,0x08,0x08,0x88,0x70,0x00, // 5 00039 0x38,0x40,0x80,0xF0,0x88,0x88,0x70,0x00, // 6 00040 0xF8,0x08,0x08,0x10,0x20,0x40,0x80,0x00, // 7 00041 0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00, // 8 00042 0x70,0x88,0x88,0x78,0x08,0x10,0xE0,0x00, // 9 00043 0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x00, // : 00044 0x00,0x00,0x20,0x00,0x20,0x20,0x40,0x00, // ; 00045 0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00, // < 00046 0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00, // = 00047 0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00, // > 00048 0x70,0x88,0x08,0x30,0x20,0x00,0x20,0x00, // ? 00049 0x70,0x88,0xA8,0xB8,0xB0,0x80,0x78,0x00, // @ 0x40 00050 0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00, // A 00051 0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00, // B 00052 0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00, // C 00053 0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00, // D 00054 0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00, // E 00055 0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00, // F 00056 0x78,0x88,0x80,0x80,0x98,0x88,0x78,0x00, // G 00057 0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00, // H 00058 0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00, // I 00059 0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00, // J 00060 0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00, // K 00061 0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00, // L 00062 0x88,0xD8,0xA8,0xA8,0xA8,0x88,0x88,0x00, // M 00063 0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00, // N 00064 0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00, // O 00065 0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00, // P 0x50 00066 0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00, // Q 00067 0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00, // R 00068 0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00, // S 00069 0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x00, // T 00070 0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00, // U 00071 0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00, // V 00072 0x88,0x88,0x88,0xA8,0xA8,0xA8,0x50,0x00, // W 00073 0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00, // X 00074 0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00, // Y 00075 0xF8,0x08,0x10,0x70,0x40,0x80,0xF8,0x00, // Z 00076 0x78,0x40,0x40,0x40,0x40,0x40,0x78,0x00, // [ 00077 0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00, // \ (back slash) 00078 0x78,0x08,0x08,0x08,0x08,0x08,0x78,0x00, // ] 00079 0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00, // ^ 00080 0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00, // _ 00081 0x60,0x60,0x20,0x10,0x00,0x00,0x00,0x00, // ` 0x60 00082 0x00,0x00,0x60,0x10,0x70,0x90,0x78,0x00, // a 00083 0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00, // b 00084 0x00,0x00,0x70,0x88,0x80,0x88,0x70,0x00, // c 00085 0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00, // d 00086 0x00,0x00,0x70,0x88,0xF8,0x80,0x70,0x00, // e 00087 0x10,0x28,0x20,0x70,0x20,0x20,0x20,0x00, // f 00088 0x00,0x00,0x70,0x98,0x98,0x68,0x08,0x70, // g 00089 0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00, // h 00090 0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00, // i 00091 0x10,0x00,0x10,0x10,0x10,0x90,0x60,0x00, // j 00092 0x80,0x80,0x90,0xA0,0xC0,0xA0,0x90,0x00, // k 00093 0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00, // l 00094 0x00,0x00,0xD0,0xA8,0xA8,0xA8,0xA8,0x00, // m 00095 0x00,0x00,0xB0,0xC8,0x88,0x88,0x88,0x00, // n 00096 0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00, // o 00097 0x00,0x00,0xB0,0xC8,0xC8,0xB0,0x80,0x80, // p 0x70 00098 0x00,0x00,0x68,0x98,0x98,0x68,0x08,0x08, // q 00099 0x00,0x00,0xB0,0xC8,0x80,0x80,0x80,0x00, // r 00100 0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00, // s 00101 0x20,0x20,0xF8,0x20,0x20,0x28,0x10,0x00, // t 00102 0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00, // u 00103 0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00, // v 00104 0x00,0x00,0x88,0x88,0xA8,0xA8,0x50,0x00, // w 00105 0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00, // x 00106 0x00,0x00,0x88,0x88,0x78,0x08,0x88,0x70, // y 00107 0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00, // z 00108 0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00, // { 00109 0x20,0x20,0x20,0x00,0x20,0x20,0x20,0x00, // | 00110 0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00, // } 00111 0x40,0xA8,0x10,0x00,0x00,0x00,0x00,0x00, // ~ 00112 0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00 00113 }; // DEL 00114 00115 const unsigned char FONT8x8[97][8] = { 00116 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char 00117 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 00118 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! 00119 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " 00120 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # 00121 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ 00122 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % 00123 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & 00124 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' 00125 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( 00126 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) 00127 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * 00128 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + 00129 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , 00130 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - 00131 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . 00132 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) 00133 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 00134 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 00135 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 00136 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 00137 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 00138 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 00139 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 00140 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 00141 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 00142 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 00143 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : 00144 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; 00145 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < 00146 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = 00147 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > 00148 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? 00149 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 00150 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A 00151 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B 00152 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C 00153 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D 00154 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E 00155 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F 00156 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G 00157 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H 00158 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I 00159 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J 00160 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K 00161 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L 00162 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M 00163 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N 00164 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O 00165 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 00166 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q 00167 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R 00168 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S 00169 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T 00170 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U 00171 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V 00172 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W 00173 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X 00174 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y 00175 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z 00176 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ 00177 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) 00178 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] 00179 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ 00180 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ 00181 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 00182 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a 00183 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b 00184 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c 00185 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d 00186 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e 00187 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f 00188 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g 00189 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h 00190 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i 00191 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j 00192 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k 00193 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l 00194 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m 00195 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n 00196 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o 00197 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p 00198 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q 00199 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r 00200 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s 00201 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t 00202 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u 00203 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v 00204 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w 00205 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x 00206 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y 00207 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z 00208 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { 00209 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | 00210 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } 00211 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 00212 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00 00213 }; // DEL 00214 00215 const unsigned char FONT8x16[97][16] = { 00216 0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char 00217 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 00218 0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00, // ! 00219 0x00,0x63,0x63,0x63,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // " 00220 0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00, // # 00221 0x0C,0x0C,0x3E,0x63,0x61,0x60,0x3E,0x03,0x03,0x43,0x63,0x3E,0x0C,0x0C,0x00,0x00, // $ 00222 0x00,0x00,0x00,0x00,0x00,0x61,0x63,0x06,0x0C,0x18,0x33,0x63,0x00,0x00,0x00,0x00, // % 00223 0x00,0x00,0x00,0x1C,0x36,0x36,0x1C,0x3B,0x6E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00, // & 00224 0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 00225 0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00,0x00,0x00, // ( 00226 0x00,0x00,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00, // ) 00227 0x00,0x00,0x00,0x00,0x42,0x66,0x3C,0xFF,0x3C,0x66,0x42,0x00,0x00,0x00,0x00,0x00, // * 00228 0x00,0x00,0x00,0x00,0x18,0x18,0x18,0xFF,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00, // + 00229 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00, // , 00230 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // - 00231 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00, // . 00232 0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00, // / (forward slash) 00233 0x00,0x00,0x3E,0x63,0x63,0x63,0x6B,0x6B,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // 0 0x30 00234 0x00,0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,0x00,0x00, // 1 00235 0x00,0x00,0x3E,0x63,0x03,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00, // 2 00236 0x00,0x00,0x3E,0x63,0x03,0x03,0x1E,0x03,0x03,0x03,0x63,0x3E,0x00,0x00,0x00,0x00, // 3 00237 0x00,0x00,0x06,0x0E,0x1E,0x36,0x66,0x66,0x7F,0x06,0x06,0x0F,0x00,0x00,0x00,0x00, // 4 00238 0x00,0x00,0x7F,0x60,0x60,0x60,0x7E,0x03,0x03,0x63,0x73,0x3E,0x00,0x00,0x00,0x00, // 5 00239 0x00,0x00,0x1C,0x30,0x60,0x60,0x7E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // 6 00240 0x00,0x00,0x7F,0x63,0x03,0x06,0x06,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00,0x00,0x00, // 7 00241 0x00,0x00,0x3E,0x63,0x63,0x63,0x3E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // 8 00242 0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x3F,0x03,0x03,0x06,0x3C,0x00,0x00,0x00,0x00, // 9 00243 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00, // : 00244 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00, // ; 00245 0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00, // < 00246 0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00, // = 00247 0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00, // > 00248 0x00,0x00,0x3E,0x63,0x63,0x06,0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00, // ? 00249 0x00,0x00,0x3E,0x63,0x63,0x6F,0x6B,0x6B,0x6E,0x60,0x60,0x3E,0x00,0x00,0x00,0x00, // @ 0x40 00250 0x00,0x00,0x08,0x1C,0x36,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x00,0x00,0x00,0x00, // A 00251 0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x33,0x33,0x33,0x33,0x7E,0x00,0x00,0x00,0x00, // B 00252 0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x60,0x60,0x61,0x33,0x1E,0x00,0x00,0x00,0x00, // C 00253 0x00,0x00,0x7C,0x36,0x33,0x33,0x33,0x33,0x33,0x33,0x36,0x7C,0x00,0x00,0x00,0x00, // D 00254 0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00, // E 00255 0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00, // F 00256 0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x6F,0x63,0x63,0x37,0x1D,0x00,0x00,0x00,0x00, // G 00257 0x00,0x00,0x63,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00, // H 00258 0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00, // I 00259 0x00,0x00,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00, // J 00260 0x00,0x00,0x73,0x33,0x36,0x36,0x3C,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00, // K 00261 0x00,0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00, // L 00262 0x00,0x00,0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00, // M 00263 0x00,0x00,0x63,0x63,0x73,0x7B,0x7F,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00, // N 00264 0x00,0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,0x00,0x00, // O 00265 0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00, // P 0x50 00266 0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x63,0x6B,0x6F,0x3E,0x06,0x07,0x00,0x00, // Q 00267 0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00, // R 00268 0x00,0x00,0x3E,0x63,0x63,0x30,0x1C,0x06,0x03,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // S 00269 0x00,0x00,0xFF,0xDB,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00, // T 00270 0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // U 00271 0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x08,0x00,0x00,0x00,0x00, // V 00272 0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x36,0x00,0x00,0x00,0x00, // W 00273 0x00,0x00,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x00,0x00,0x00,0x00, // X 00274 0x00,0x00,0xC3,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00, // Y 00275 0x00,0x00,0x7F,0x63,0x43,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00, // Z 00276 0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00, // [ 00277 0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00, // \ (back slash) 00278 0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00, // ] 00279 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ^ 00280 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, // _ 00281 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ` 0x60 00282 0x00,0x00,0x00,0x00,0x00,0x3C,0x46,0x06,0x3E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00, // a 00283 0x00,0x00,0x70,0x30,0x30,0x3C,0x36,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,0x00,0x00, // b 00284 0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x60,0x60,0x60,0x63,0x3E,0x00,0x00,0x00,0x00, // c 00285 0x00,0x00,0x0E,0x06,0x06,0x1E,0x36,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00, // d 00286 0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x7E,0x60,0x63,0x3E,0x00,0x00,0x00,0x00, // e 00287 0x00,0x00,0x1C,0x36,0x32,0x30,0x7C,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00, // f 00288 0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x66,0x3C,0x00,0x00, // g 00289 0x00,0x00,0x70,0x30,0x30,0x36,0x3B,0x33,0x33,0x33,0x33,0x73,0x00,0x00,0x00,0x00, // h 00290 0x00,0x00,0x0C,0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00, // i 00291 0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00, // j 00292 0x00,0x00,0x70,0x30,0x30,0x33,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,0x00,0x00,0x00, // k 00293 0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00, // l 00294 0x00,0x00,0x00,0x00,0x00,0x6E,0x7F,0x6B,0x6B,0x6B,0x6B,0x6B,0x00,0x00,0x00,0x00, // m 00295 0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x00, // n 00296 0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00, // o 00297 0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,0x00, // p 0x70 00298 0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00,0x00, // q 00299 0x00,0x00,0x00,0x00,0x00,0x6E,0x3B,0x33,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00, // r 00300 0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x38,0x0E,0x03,0x63,0x3E,0x00,0x00,0x00,0x00, // s 00301 0x00,0x00,0x08,0x18,0x18,0x7E,0x18,0x18,0x18,0x18,0x1B,0x0E,0x00,0x00,0x00,0x00, // t 00302 0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00, // u 00303 0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x36,0x36,0x1C,0x1C,0x08,0x00,0x00,0x00,0x00, // v 00304 0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x00,0x00,0x00,0x00, // w 00305 0x00,0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // x 00306 0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x3F,0x03,0x06,0x3C,0x00,0x00, // y 00307 0x00,0x00,0x00,0x00,0x00,0x7F,0x66,0x0C,0x18,0x30,0x63,0x7F,0x00,0x00,0x00,0x00, // z 00308 0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00, // { 00309 0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00, // | 00310 0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00, // } 00311 0x00,0x00,0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 00312 0x00,0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // DELL 00313 }; 00314 00315 void MobileLCD::command(int value) { 00316 _spi.write(value & 0xFF); 00317 } 00318 00319 void MobileLCD::data(int value) { 00320 _spi.write(value | 0x100); 00321 } 00322 00323 void MobileLCD::_select() { 00324 _cs = 0; 00325 } 00326 00327 void MobileLCD::_deselect() { 00328 _cs = 1; 00329 } 00330 00331 int MobileLCD::width() { 00332 return _width; 00333 } 00334 00335 int MobileLCD::height() { 00336 return _height; 00337 } 00338 00339 void MobileLCD::foreground(int v) { 00340 _foreground = v; 00341 } 00342 00343 void MobileLCD::background(int v) { 00344 _background = v; 00345 } 00346 00347 00348 /*************************************************************************/ 00349 00350 MobileLCD::MobileLCD(PinName mosi, PinName miso, PinName clk, PinName cs, PinName rst) 00351 : _spi(mosi, miso, clk) 00352 , _rst(rst) 00353 , _cs(cs) { 00354 00355 _width = 130; 00356 _height = 130; 00357 foreground(0xFFFFFF); 00358 background(0x000000); 00359 reset(); 00360 } 00361 00362 void MobileLCD::reset() { 00363 00364 _cs = 1; 00365 _rst = 0; 00366 _spi.format(9); 00367 _spi.frequency(5000000); 00368 00369 wait_ms(1); 00370 00371 _rst = 1; 00372 00373 wait_ms(1); 00374 00375 _select(); 00376 00377 command(DISCTL); // display control 00378 data(0x0); 00379 data(31); 00380 data(0x0); 00381 00382 command(COMSCN); // scan 00383 data(0x1); 00384 00385 command(OSCON); // oscillator on 00386 command(SLPOUT); // sleep out 00387 command(PWRCTR); // power control 00388 data(0x0F); 00389 00390 command(DISINV); // invert display 00391 00392 command(VOLCTR); // Voltage control 00393 data(39); // contrast setting: 0..63 00394 data(3); // resistance ratio 00395 00396 wait_ms(1); 00397 00398 command(DATCTL); // data control 00399 data(0x0); // scan dirs 00400 data(0x0); // RGB 00401 data(0x2); // grayscale 00402 00403 command(DISON); // turn on the display 00404 00405 _deselect(); 00406 00407 cls(); 00408 } 00409 00410 void MobileLCD::cls() 00411 { 00412 fill(0, 0, 130, 130, _background); 00413 } 00414 00415 void MobileLCD::_window(int x, int y, int width, int height) 00416 { 00417 int x1, x2, y1, y2; 00418 x1 = x + 0; 00419 y1 = y + 2; 00420 x2 = x1 + width - 1; 00421 y2 = y1 + height - 1; 00422 00423 command(CASET); // column 00424 data(x1); 00425 data(x2); 00426 00427 command(PASET); // page 00428 data(y1); 00429 data(y2); 00430 00431 command(RAMWR); // start write to ram 00432 } 00433 00434 void MobileLCD::fill(int x, int y, int width, int height, int colour) 00435 { 00436 int i = 0; 00437 00438 _select(); 00439 _window(x, y, width, height); 00440 00441 int r4 = (colour >> (16 + 4)) & 0xF; 00442 int g4 = (colour >> (8 + 4)) & 0xF; 00443 int b4 = (colour >> (0 + 4)) & 0xF; 00444 00445 int d1 = (r4 << 4) | g4; 00446 int d2 = (b4 << 4) | r4; 00447 int d3 = (g4 << 4) | b4; 00448 00449 for(i=0; i<(width*height+1)/2; i++) 00450 { 00451 data(d1); 00452 data(d2); 00453 data(d3); 00454 } 00455 00456 _deselect(); 00457 } 00458 00459 void MobileLCD::pixel(int x, int y, int colour) { 00460 fill(x, y, 1, 1, colour); 00461 } 00462 00463 void MobileLCD::setpixel(int x, int y, int colour) { 00464 00465 _select(); 00466 00467 int r4 = (colour >> (16 + 4)) & 0xF; 00468 int g4 = (colour >> (8 + 4)) & 0xF; 00469 int b4 = (colour >> (0 + 4)) & 0xF; 00470 00471 int d1 = (r4 << 4) | g4; 00472 int d2 = (b4 << 4) | r4; 00473 int d3 = (g4 << 4) | b4; 00474 00475 command(CASET); // column 00476 data(x); 00477 data(x); 00478 00479 command(PASET); // page 00480 data(y); 00481 data(y); 00482 00483 command(RAMWR); // start write to ram 00484 00485 data(d1); 00486 data(d2); 00487 data(d3); 00488 00489 _deselect(); 00490 } 00491 00492 void MobileLCD::setline(int x0, int y0, int x1, int y1, int color) { 00493 int dy = y1 - y0; 00494 int dx = x1 - x0; 00495 int stepx, stepy; 00496 00497 if(dy < 0) 00498 { 00499 dy = -dy; 00500 stepy = -1; 00501 } 00502 else 00503 stepy = 1; 00504 00505 if(dx < 0) 00506 { 00507 dx = -dx; 00508 stepx = -1; 00509 } 00510 else 00511 stepx = 1; 00512 00513 dy <<= 1; // dy is now 2*dy 00514 dx <<= 1; // dx is now 2*dx 00515 00516 setpixel(x0, y0, color); 00517 if (dx > dy) 00518 { 00519 int fraction = dy - (dx >> 1); // same as 2*dy - dx 00520 while (x0 != x1) 00521 { 00522 if (fraction >= 0) 00523 { 00524 y0 += stepy; 00525 fraction -= dx; // same as fraction -= 2*dx 00526 } 00527 x0 += stepx; 00528 fraction += dy; // same as fraction -= 2*dy 00529 setpixel(x0, y0, color); 00530 } 00531 } 00532 else 00533 { 00534 int fraction = dx - (dy >> 1); 00535 while (y0 != y1) 00536 { 00537 if (fraction >= 0) 00538 { 00539 x0 += stepx; 00540 fraction -= dy; 00541 } 00542 y0 += stepy; 00543 fraction += dx; 00544 setpixel(x0, y0, color); 00545 } 00546 } 00547 } 00548 00549 void MobileLCD::setrect(int x0, int y0, int x1, int y1, unsigned char tmpNum, int color) { 00550 00551 int xmin, xmax, ymin, ymax; 00552 00553 // check if the rectangle is to be filled 00554 if (tmpNum == FILL) 00555 { 00556 // best way to create a filled rectangle is to define a drawing box 00557 // and loop two pixels at a time 00558 // calculate the min and max for x and y directions 00559 xmin = (x0 <= x1) ? x0 : x1; 00560 xmax = (x0 > x1) ? x0 : x1; 00561 ymin = (y0 <= y1) ? y0 : y1; 00562 ymax = (y0 > y1) ? y0 : y1; 00563 00564 fill(xmin, ymin, (xmax - xmin), (ymax - ymin), color); 00565 } 00566 else 00567 { 00568 // best way to draw un unfilled rectangle is to draw four lines 00569 setline(x0, y0, x1, y0, color); 00570 setline(x0, y1, x1, y1, color); 00571 setline(x0, y0, x0, y1, color); 00572 setline(x1, y0, x1, y1, color); 00573 } 00574 } 00575 00576 void MobileLCD::setcircle(int x0, int y0, int radius, int color) { 00577 00578 int f = 1 - radius; 00579 int ddF_x = 0; 00580 int ddF_y = -2 * radius; 00581 int x = 0; 00582 int y = radius; 00583 00584 setpixel(x0, y0 + radius, color); 00585 setpixel(x0, y0 - radius, color); 00586 setpixel(x0 + radius, y0, color); 00587 setpixel(x0 - radius, y0, color); 00588 00589 while(x < y) 00590 { 00591 if(f >= 0) 00592 { 00593 y--; 00594 ddF_y += 2; 00595 f += ddF_y; 00596 } 00597 x++; 00598 ddF_x += 2; 00599 f += ddF_x + 1; 00600 00601 setpixel(x0 + x, y0 + y, color); 00602 setpixel(x0 - x, y0 + y, color); 00603 setpixel(x0 + x, y0 - y, color); 00604 setpixel(x0 - x, y0 - y, color); 00605 setpixel(x0 + y, y0 + x, color); 00606 setpixel(x0 - y, y0 + x, color); 00607 setpixel(x0 + y, y0 - x, color); 00608 setpixel(x0 - y, y0 - x, color); 00609 } 00610 } 00611 00612 void MobileLCD::bitblit(int x, int y, int width, int height, const char* bitstream, int fColor, int bColor) { 00613 _select(); 00614 _window(x, y, width, height); 00615 for(int i=0; i<height*width/2; i++) { 00616 int byte1 = (i*2) / 8; 00617 int bit1 = (i*2) % 8; 00618 int colour1 = ((bitstream[byte1] << bit1) & 0x80) ? fColor : bColor; 00619 int byte2 = (i*2+1) / 8; 00620 int bit2 = (i*2+1) % 8; 00621 int colour2 = ((bitstream[byte2] << bit2) & 0x80) ? fColor : bColor; 00622 00623 int r41 = (colour1 >> (16 + 4)) & 0xF; 00624 int g41 = (colour1 >> (8 + 4)) & 0xF; 00625 int b41 = (colour1 >> (0 + 4)) & 0xF; 00626 00627 int r42 = (colour2 >> (16 + 4)) & 0xF; 00628 int g42 = (colour2 >> (8 + 4)) & 0xF; 00629 int b42 = (colour2 >> (0 + 4)) & 0xF; 00630 int d1 = (r41 << 4) | g41; 00631 int d2 = (b41 << 4) | r42; 00632 int d3 = (g42 << 4) | b42; 00633 data(d1); 00634 data(d2); 00635 data(d3); 00636 } 00637 _deselect(); 00638 } 00639 00640 void MobileLCD::putchar(int x, int y, int size, int value, int fColor, int bColor) { 00641 00642 switch(size) 00643 { 00644 case SMALL : bitblit(x, y, 8, 8, (char*)&(FONT6x8[value - 0x1F][0]), fColor, bColor); 00645 break; 00646 case MEDIUM : bitblit(x, y, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]), fColor, bColor); 00647 break; 00648 case LARGE : bitblit(x, y, 8, 16, (char*)&(FONT8x16[value - 0x1F][0]), fColor, bColor); 00649 break; 00650 } 00651 00652 }
Generated on Sun Jul 24 2022 09:45:58 by
1.7.2