access GT20L16J1Y through UART. Please use Shift-JIS code on serial terminal.
GT20L16J1Yにアクセスするサンプルです。パソコンのシリアルターミナルからShift-JISで文字を入力すると、フォントを表示します。
main.cpp@0:371d6cc5d4fb, 2015-10-23 (annotated)
- Committer:
- ytsuboi
- Date:
- Fri Oct 23 07:15:15 2015 +0000
- Revision:
- 0:371d6cc5d4fb
first version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ytsuboi | 0:371d6cc5d4fb | 1 | #include "mbed.h" |
ytsuboi | 0:371d6cc5d4fb | 2 | |
ytsuboi | 0:371d6cc5d4fb | 3 | Serial pc(USBTX, USBRX); // tx, rx |
ytsuboi | 0:371d6cc5d4fb | 4 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
ytsuboi | 0:371d6cc5d4fb | 5 | DigitalOut cs(p10); |
ytsuboi | 0:371d6cc5d4fb | 6 | |
ytsuboi | 0:371d6cc5d4fb | 7 | unsigned char matrixdata32[32]; //16×16用表示データ |
ytsuboi | 0:371d6cc5d4fb | 8 | unsigned char matrixdata16[16]; //16×8用表示データ |
ytsuboi | 0:371d6cc5d4fb | 9 | |
ytsuboi | 0:371d6cc5d4fb | 10 | /*漢字ROMとやりとり*/ |
ytsuboi | 0:371d6cc5d4fb | 11 | //readFontJIS(JIS上位8bit,JIS下位8bit); |
ytsuboi | 0:371d6cc5d4fb | 12 | void readFontJIS(uint8_t c1, uint8_t c2) |
ytsuboi | 0:371d6cc5d4fb | 13 | { |
ytsuboi | 0:371d6cc5d4fb | 14 | /*jisx変換後の表示*/ |
ytsuboi | 0:371d6cc5d4fb | 15 | pc.printf("JIS X up8 = 0x%x downn8 = 0x%x\r\n", c1, c2); |
ytsuboi | 0:371d6cc5d4fb | 16 | |
ytsuboi | 0:371d6cc5d4fb | 17 | /*jisxの区点を求める*/ |
ytsuboi | 0:371d6cc5d4fb | 18 | uint32_t MSB = c1 - 0x20;//区 |
ytsuboi | 0:371d6cc5d4fb | 19 | uint32_t LSB = c2 - 0x20;//点 |
ytsuboi | 0:371d6cc5d4fb | 20 | /*JISの句点番号で分類*/ |
ytsuboi | 0:371d6cc5d4fb | 21 | uint32_t Address = 0; |
ytsuboi | 0:371d6cc5d4fb | 22 | |
ytsuboi | 0:371d6cc5d4fb | 23 | pc.printf("MSB = d%d LSB = d%d\r\n", MSB, LSB); |
ytsuboi | 0:371d6cc5d4fb | 24 | /*各種記号・英数字・かな(一部機種依存につき注意,㍍などWindowsと互換性なし)*/ |
ytsuboi | 0:371d6cc5d4fb | 25 | if (MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) |
ytsuboi | 0:371d6cc5d4fb | 26 | Address = ( (MSB - 1) * 94 + (LSB - 1)) * 32; |
ytsuboi | 0:371d6cc5d4fb | 27 | /*第一水準*/ |
ytsuboi | 0:371d6cc5d4fb | 28 | if (MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) |
ytsuboi | 0:371d6cc5d4fb | 29 | Address = ( (MSB - 16) * 94 + (LSB - 1)) * 32 + 43584; |
ytsuboi | 0:371d6cc5d4fb | 30 | /*第二水準*/ |
ytsuboi | 0:371d6cc5d4fb | 31 | if (MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) |
ytsuboi | 0:371d6cc5d4fb | 32 | Address = ((MSB - 48) * 94 + (LSB - 1)) * 32 + 138464; |
ytsuboi | 0:371d6cc5d4fb | 33 | |
ytsuboi | 0:371d6cc5d4fb | 34 | /*GT20L16J1Y内部では1区と同等の内容が収録されている*/ |
ytsuboi | 0:371d6cc5d4fb | 35 | if (MSB == 85 && LSB >= 0x01 && LSB <= 94) |
ytsuboi | 0:371d6cc5d4fb | 36 | Address = ((MSB - 85) * 94 + (LSB - 1)) * 32 + 246944; |
ytsuboi | 0:371d6cc5d4fb | 37 | |
ytsuboi | 0:371d6cc5d4fb | 38 | /*GT20L16J1Y内部では2区、3区と同等の内容が収録されている*/ |
ytsuboi | 0:371d6cc5d4fb | 39 | if (MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) |
ytsuboi | 0:371d6cc5d4fb | 40 | Address = ((MSB - 88) * 94 + (LSB - 1)) * 32 + 249952; |
ytsuboi | 0:371d6cc5d4fb | 41 | |
ytsuboi | 0:371d6cc5d4fb | 42 | /*漢字ROMにデータを送信*/ |
ytsuboi | 0:371d6cc5d4fb | 43 | // Deselect the device |
ytsuboi | 0:371d6cc5d4fb | 44 | cs = 1; |
ytsuboi | 0:371d6cc5d4fb | 45 | pc.printf("Address = %u \r\n", Address); |
ytsuboi | 0:371d6cc5d4fb | 46 | |
ytsuboi | 0:371d6cc5d4fb | 47 | // Setup the spi for 8 bit data, high steady state clock |
ytsuboi | 0:371d6cc5d4fb | 48 | spi.format(8,3); |
ytsuboi | 0:371d6cc5d4fb | 49 | spi.frequency(1000000); |
ytsuboi | 0:371d6cc5d4fb | 50 | |
ytsuboi | 0:371d6cc5d4fb | 51 | // Select the device by seting chip select low |
ytsuboi | 0:371d6cc5d4fb | 52 | cs = 0; |
ytsuboi | 0:371d6cc5d4fb | 53 | spi.write(0x03); // Read data byte |
ytsuboi | 0:371d6cc5d4fb | 54 | spi.write(Address >> 16 & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 55 | spi.write(Address >> 8 & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 56 | spi.write(Address & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 57 | |
ytsuboi | 0:371d6cc5d4fb | 58 | /*漢字ROMからデータを受信*/ |
ytsuboi | 0:371d6cc5d4fb | 59 | for (int i = 0; i < 32; i++) { |
ytsuboi | 0:371d6cc5d4fb | 60 | matrixdata32[i] = spi.write(0x00); |
ytsuboi | 0:371d6cc5d4fb | 61 | } |
ytsuboi | 0:371d6cc5d4fb | 62 | // Deselect the device |
ytsuboi | 0:371d6cc5d4fb | 63 | cs = 1; |
ytsuboi | 0:371d6cc5d4fb | 64 | }//spireadfont |
ytsuboi | 0:371d6cc5d4fb | 65 | |
ytsuboi | 0:371d6cc5d4fb | 66 | |
ytsuboi | 0:371d6cc5d4fb | 67 | /*漢字ROMとやりとり*/ |
ytsuboi | 0:371d6cc5d4fb | 68 | //readFontASCII(ASCIIコード); |
ytsuboi | 0:371d6cc5d4fb | 69 | void readFontASCII(uint8_t ASCIICODE) |
ytsuboi | 0:371d6cc5d4fb | 70 | { |
ytsuboi | 0:371d6cc5d4fb | 71 | pc.printf("ASCII,0x"); |
ytsuboi | 0:371d6cc5d4fb | 72 | pc.printf("%x\r\n", ASCIICODE); //10/07 |
ytsuboi | 0:371d6cc5d4fb | 73 | uint32_t Address = 0; |
ytsuboi | 0:371d6cc5d4fb | 74 | /*ASCII文字*/ |
ytsuboi | 0:371d6cc5d4fb | 75 | if (ASCIICODE >= 0x20 && ASCIICODE <= 0x7F) |
ytsuboi | 0:371d6cc5d4fb | 76 | Address = ( ASCIICODE - 0x20) * 16 + 255968; |
ytsuboi | 0:371d6cc5d4fb | 77 | |
ytsuboi | 0:371d6cc5d4fb | 78 | /*漢字ROMにデータを送信*/ |
ytsuboi | 0:371d6cc5d4fb | 79 | // Deselect the device |
ytsuboi | 0:371d6cc5d4fb | 80 | cs = 1; |
ytsuboi | 0:371d6cc5d4fb | 81 | |
ytsuboi | 0:371d6cc5d4fb | 82 | // Setup the spi for 8 bit data, high steady state clock |
ytsuboi | 0:371d6cc5d4fb | 83 | spi.format(8,3); |
ytsuboi | 0:371d6cc5d4fb | 84 | spi.frequency(1000000); |
ytsuboi | 0:371d6cc5d4fb | 85 | |
ytsuboi | 0:371d6cc5d4fb | 86 | // Select the device by seting chip select low |
ytsuboi | 0:371d6cc5d4fb | 87 | cs = 0; |
ytsuboi | 0:371d6cc5d4fb | 88 | spi.write(0x03); |
ytsuboi | 0:371d6cc5d4fb | 89 | spi.write(Address >> 16 & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 90 | spi.write(Address >> 8 & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 91 | spi.write(Address & 0xff); |
ytsuboi | 0:371d6cc5d4fb | 92 | |
ytsuboi | 0:371d6cc5d4fb | 93 | /*漢字ROMからデータを受信*/ |
ytsuboi | 0:371d6cc5d4fb | 94 | for (int i = 0; i < 16; i++) { |
ytsuboi | 0:371d6cc5d4fb | 95 | matrixdata16[i] = spi.write(0x00); |
ytsuboi | 0:371d6cc5d4fb | 96 | } |
ytsuboi | 0:371d6cc5d4fb | 97 | // Deselect the device |
ytsuboi | 0:371d6cc5d4fb | 98 | cs = 1; |
ytsuboi | 0:371d6cc5d4fb | 99 | } |
ytsuboi | 0:371d6cc5d4fb | 100 | |
ytsuboi | 0:371d6cc5d4fb | 101 | /*シリアルモニタへ16*16のデータを表示する*/ |
ytsuboi | 0:371d6cc5d4fb | 102 | void sendDotsToSerial32() |
ytsuboi | 0:371d6cc5d4fb | 103 | { |
ytsuboi | 0:371d6cc5d4fb | 104 | /*上半分*/ |
ytsuboi | 0:371d6cc5d4fb | 105 | for (int i = 0; i < 8; i++) { |
ytsuboi | 0:371d6cc5d4fb | 106 | for (int b = 0; b < 16; b++) { |
ytsuboi | 0:371d6cc5d4fb | 107 | char byteDigit = (1 << i); |
ytsuboi | 0:371d6cc5d4fb | 108 | if (matrixdata32[b] & byteDigit) { |
ytsuboi | 0:371d6cc5d4fb | 109 | pc.printf("XX"); |
ytsuboi | 0:371d6cc5d4fb | 110 | } else { |
ytsuboi | 0:371d6cc5d4fb | 111 | pc.printf("--"); |
ytsuboi | 0:371d6cc5d4fb | 112 | } |
ytsuboi | 0:371d6cc5d4fb | 113 | } |
ytsuboi | 0:371d6cc5d4fb | 114 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 115 | } |
ytsuboi | 0:371d6cc5d4fb | 116 | /*下半分*/ |
ytsuboi | 0:371d6cc5d4fb | 117 | for (int i = 0; i < 8; i++) { |
ytsuboi | 0:371d6cc5d4fb | 118 | for (int b = 16; b < 32 ; b++) { |
ytsuboi | 0:371d6cc5d4fb | 119 | char byteDigit = (1 << i); |
ytsuboi | 0:371d6cc5d4fb | 120 | if (matrixdata32[b] & byteDigit) { |
ytsuboi | 0:371d6cc5d4fb | 121 | pc.printf("XX"); |
ytsuboi | 0:371d6cc5d4fb | 122 | } else { |
ytsuboi | 0:371d6cc5d4fb | 123 | pc.printf("--"); |
ytsuboi | 0:371d6cc5d4fb | 124 | } |
ytsuboi | 0:371d6cc5d4fb | 125 | } |
ytsuboi | 0:371d6cc5d4fb | 126 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 127 | } |
ytsuboi | 0:371d6cc5d4fb | 128 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 129 | } //sendDataToSerial32 |
ytsuboi | 0:371d6cc5d4fb | 130 | |
ytsuboi | 0:371d6cc5d4fb | 131 | |
ytsuboi | 0:371d6cc5d4fb | 132 | /*シリアルモニタへ16*8のデータを表示する*/ |
ytsuboi | 0:371d6cc5d4fb | 133 | void sendDotsToSerial16() |
ytsuboi | 0:371d6cc5d4fb | 134 | { |
ytsuboi | 0:371d6cc5d4fb | 135 | /*上半分*/ |
ytsuboi | 0:371d6cc5d4fb | 136 | for (int i = 0; i < 8; i++) { |
ytsuboi | 0:371d6cc5d4fb | 137 | for (int b = 0; b < 8; b++) { |
ytsuboi | 0:371d6cc5d4fb | 138 | char byteDigit = (1 << i); |
ytsuboi | 0:371d6cc5d4fb | 139 | if (matrixdata16[b] & byteDigit) { |
ytsuboi | 0:371d6cc5d4fb | 140 | pc.printf("XX"); |
ytsuboi | 0:371d6cc5d4fb | 141 | } else { |
ytsuboi | 0:371d6cc5d4fb | 142 | pc.printf("--"); |
ytsuboi | 0:371d6cc5d4fb | 143 | } |
ytsuboi | 0:371d6cc5d4fb | 144 | } |
ytsuboi | 0:371d6cc5d4fb | 145 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 146 | } |
ytsuboi | 0:371d6cc5d4fb | 147 | |
ytsuboi | 0:371d6cc5d4fb | 148 | /*下半分*/ |
ytsuboi | 0:371d6cc5d4fb | 149 | for (int i = 0; i < 8; i++) { |
ytsuboi | 0:371d6cc5d4fb | 150 | for (int b = 8; b < 16; b++) { |
ytsuboi | 0:371d6cc5d4fb | 151 | char byteDigit = (1 << i); |
ytsuboi | 0:371d6cc5d4fb | 152 | if (matrixdata16[b] & byteDigit) { |
ytsuboi | 0:371d6cc5d4fb | 153 | pc.printf("XX"); |
ytsuboi | 0:371d6cc5d4fb | 154 | } else { |
ytsuboi | 0:371d6cc5d4fb | 155 | pc.printf("--"); |
ytsuboi | 0:371d6cc5d4fb | 156 | } |
ytsuboi | 0:371d6cc5d4fb | 157 | } |
ytsuboi | 0:371d6cc5d4fb | 158 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 159 | } |
ytsuboi | 0:371d6cc5d4fb | 160 | pc.printf("\r\n"); |
ytsuboi | 0:371d6cc5d4fb | 161 | } //sendDataToSerial32 |
ytsuboi | 0:371d6cc5d4fb | 162 | |
ytsuboi | 0:371d6cc5d4fb | 163 | |
ytsuboi | 0:371d6cc5d4fb | 164 | /*1byteのSJISを表示する*/ |
ytsuboi | 0:371d6cc5d4fb | 165 | void showSJIS1byte(uint8_t code) |
ytsuboi | 0:371d6cc5d4fb | 166 | { |
ytsuboi | 0:371d6cc5d4fb | 167 | readFontASCII(code); |
ytsuboi | 0:371d6cc5d4fb | 168 | sendDotsToSerial16(); |
ytsuboi | 0:371d6cc5d4fb | 169 | } |
ytsuboi | 0:371d6cc5d4fb | 170 | |
ytsuboi | 0:371d6cc5d4fb | 171 | /*2byteのSJISを表示する*/ |
ytsuboi | 0:371d6cc5d4fb | 172 | //showSJIS2byte(SJIS文字コード) |
ytsuboi | 0:371d6cc5d4fb | 173 | void showSJIS2byte(unsigned short code) |
ytsuboi | 0:371d6cc5d4fb | 174 | { |
ytsuboi | 0:371d6cc5d4fb | 175 | /*Arduinoのシリアルで日本語はSJIS送信なのでSJIS->JIS X 0208変換をする*/ |
ytsuboi | 0:371d6cc5d4fb | 176 | pc.printf("SJIS, 0x%x\r\n", code); |
ytsuboi | 0:371d6cc5d4fb | 177 | uint8_t c1 = ((code & 0xff00) >> 8); |
ytsuboi | 0:371d6cc5d4fb | 178 | uint8_t c2 = (code & 0xFF); |
ytsuboi | 0:371d6cc5d4fb | 179 | if (c1 >= 0xe0) { |
ytsuboi | 0:371d6cc5d4fb | 180 | c1 = c1 - 0x40; |
ytsuboi | 0:371d6cc5d4fb | 181 | } |
ytsuboi | 0:371d6cc5d4fb | 182 | if (c2 >= 0x80) { |
ytsuboi | 0:371d6cc5d4fb | 183 | c2 = c2 - 1; |
ytsuboi | 0:371d6cc5d4fb | 184 | } |
ytsuboi | 0:371d6cc5d4fb | 185 | if (c2 >= 0x9e) { |
ytsuboi | 0:371d6cc5d4fb | 186 | c1 = (c1 - 0x70) * 2; |
ytsuboi | 0:371d6cc5d4fb | 187 | c2 = c2 - 0x7d; |
ytsuboi | 0:371d6cc5d4fb | 188 | } else { |
ytsuboi | 0:371d6cc5d4fb | 189 | c1 = ((c1 - 0x70) * 2) - 1; |
ytsuboi | 0:371d6cc5d4fb | 190 | c2 = c2 - 0x1f; |
ytsuboi | 0:371d6cc5d4fb | 191 | } |
ytsuboi | 0:371d6cc5d4fb | 192 | /*読み出し*/ |
ytsuboi | 0:371d6cc5d4fb | 193 | readFontJIS(c1, c2); |
ytsuboi | 0:371d6cc5d4fb | 194 | /*表示*/ |
ytsuboi | 0:371d6cc5d4fb | 195 | sendDotsToSerial32(); |
ytsuboi | 0:371d6cc5d4fb | 196 | } |
ytsuboi | 0:371d6cc5d4fb | 197 | |
ytsuboi | 0:371d6cc5d4fb | 198 | int main() |
ytsuboi | 0:371d6cc5d4fb | 199 | { |
ytsuboi | 0:371d6cc5d4fb | 200 | while(1) { |
ytsuboi | 0:371d6cc5d4fb | 201 | if (pc.readable() > 0) { |
ytsuboi | 0:371d6cc5d4fb | 202 | /* PCからはSJISで送ること */ |
ytsuboi | 0:371d6cc5d4fb | 203 | wait(0.2);//最低でも2バイト受信したい |
ytsuboi | 0:371d6cc5d4fb | 204 | uint8_t msbdata = pc.getc();//1バイト目 //10/07 |
ytsuboi | 0:371d6cc5d4fb | 205 | /*SJISの1バイトコードか否か*/ |
ytsuboi | 0:371d6cc5d4fb | 206 | if ( (msbdata < 0x80) || ((0xA0 < msbdata) && (msbdata <= 0xdF)) ) { |
ytsuboi | 0:371d6cc5d4fb | 207 | showSJIS1byte(msbdata); |
ytsuboi | 0:371d6cc5d4fb | 208 | } else { |
ytsuboi | 0:371d6cc5d4fb | 209 | uint8_t lsbdata = pc.getc();//2バイト目 //10/07 |
ytsuboi | 0:371d6cc5d4fb | 210 | uint16_t data = ((msbdata << 8) + lsbdata); //2 |
ytsuboi | 0:371d6cc5d4fb | 211 | showSJIS2byte(data); |
ytsuboi | 0:371d6cc5d4fb | 212 | } |
ytsuboi | 0:371d6cc5d4fb | 213 | } |
ytsuboi | 0:371d6cc5d4fb | 214 | } |
ytsuboi | 0:371d6cc5d4fb | 215 | } |