パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。

Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Wed Mar 30 06:05:24 2011 +0000
Revision:
0:d920d64db582
alpha

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lynxeyed_atsu 0:d920d64db582 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
lynxeyed_atsu 0:d920d64db582 2 * Copyright (c) 2007-2010, sford
lynxeyed_atsu 0:d920d64db582 3 *
lynxeyed_atsu 0:d920d64db582 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
lynxeyed_atsu 0:d920d64db582 5 * of this software and associated documentation files (the "Software"), to deal
lynxeyed_atsu 0:d920d64db582 6 * in the Software without restriction, including without limitation the rights
lynxeyed_atsu 0:d920d64db582 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
lynxeyed_atsu 0:d920d64db582 8 * copies of the Software, and to permit persons to whom the Software is
lynxeyed_atsu 0:d920d64db582 9 * furnished to do so, subject to the following conditions:
lynxeyed_atsu 0:d920d64db582 10 *
lynxeyed_atsu 0:d920d64db582 11 * The above copyright notice and this permission notice shall be included in
lynxeyed_atsu 0:d920d64db582 12 * all copies or substantial portions of the Software.
lynxeyed_atsu 0:d920d64db582 13 *
lynxeyed_atsu 0:d920d64db582 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
lynxeyed_atsu 0:d920d64db582 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
lynxeyed_atsu 0:d920d64db582 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
lynxeyed_atsu 0:d920d64db582 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
lynxeyed_atsu 0:d920d64db582 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lynxeyed_atsu 0:d920d64db582 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
lynxeyed_atsu 0:d920d64db582 20 * THE SOFTWARE.
lynxeyed_atsu 0:d920d64db582 21 */
lynxeyed_atsu 0:d920d64db582 22
lynxeyed_atsu 0:d920d64db582 23 #include "TextLCD.h"
lynxeyed_atsu 0:d920d64db582 24 #include "mbed.h"
lynxeyed_atsu 0:d920d64db582 25
lynxeyed_atsu 0:d920d64db582 26 TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1,
lynxeyed_atsu 0:d920d64db582 27 PinName d2, PinName d3, LCDType type) : _rs(rs),
lynxeyed_atsu 0:d920d64db582 28 _e(e), _d(d0, d1, d2, d3),
lynxeyed_atsu 0:d920d64db582 29 _type(type) {
lynxeyed_atsu 0:d920d64db582 30
lynxeyed_atsu 0:d920d64db582 31 _e = 1;
lynxeyed_atsu 0:d920d64db582 32 _rs = 0; // command mode
lynxeyed_atsu 0:d920d64db582 33
lynxeyed_atsu 0:d920d64db582 34 wait(0.015); // Wait 15ms to ensure powered up
lynxeyed_atsu 0:d920d64db582 35
lynxeyed_atsu 0:d920d64db582 36 // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
lynxeyed_atsu 0:d920d64db582 37 for (int i=0; i<3; i++) {
lynxeyed_atsu 0:d920d64db582 38 writeByte(0x3);
lynxeyed_atsu 0:d920d64db582 39 wait(0.00164); // this command takes 1.64ms, so wait for it
lynxeyed_atsu 0:d920d64db582 40 }
lynxeyed_atsu 0:d920d64db582 41 writeByte(0x2); // 4-bit mode
lynxeyed_atsu 0:d920d64db582 42 wait(0.000040f); // most instructions take 40us
lynxeyed_atsu 0:d920d64db582 43
lynxeyed_atsu 0:d920d64db582 44 writeCommand(0x28); // Function set 001 BW N F - -
lynxeyed_atsu 0:d920d64db582 45 writeCommand(0x0C);
lynxeyed_atsu 0:d920d64db582 46 writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
lynxeyed_atsu 0:d920d64db582 47 cls();
lynxeyed_atsu 0:d920d64db582 48 }
lynxeyed_atsu 0:d920d64db582 49
lynxeyed_atsu 0:d920d64db582 50 void TextLCD::character(int column, int row, int c) {
lynxeyed_atsu 0:d920d64db582 51 int a = address(column, row);
lynxeyed_atsu 0:d920d64db582 52 writeCommand(a);
lynxeyed_atsu 0:d920d64db582 53 writeData(c);
lynxeyed_atsu 0:d920d64db582 54 }
lynxeyed_atsu 0:d920d64db582 55
lynxeyed_atsu 0:d920d64db582 56 void TextLCD::cls() {
lynxeyed_atsu 0:d920d64db582 57 writeCommand(0x01); // cls, and set cursor to 0
lynxeyed_atsu 0:d920d64db582 58 wait(0.00164f); // This command takes 1.64 ms
lynxeyed_atsu 0:d920d64db582 59 locate(0, 0);
lynxeyed_atsu 0:d920d64db582 60 }
lynxeyed_atsu 0:d920d64db582 61
lynxeyed_atsu 0:d920d64db582 62 void TextLCD::locate(int column, int row) {
lynxeyed_atsu 0:d920d64db582 63 _column = column;
lynxeyed_atsu 0:d920d64db582 64 _row = row;
lynxeyed_atsu 0:d920d64db582 65 }
lynxeyed_atsu 0:d920d64db582 66
lynxeyed_atsu 0:d920d64db582 67 int TextLCD::_putc(int value) {
lynxeyed_atsu 0:d920d64db582 68 if (value == '\n') {
lynxeyed_atsu 0:d920d64db582 69 _column = 0;
lynxeyed_atsu 0:d920d64db582 70 _row++;
lynxeyed_atsu 0:d920d64db582 71 if (_row >= rows()) {
lynxeyed_atsu 0:d920d64db582 72 _row = 0;
lynxeyed_atsu 0:d920d64db582 73 }
lynxeyed_atsu 0:d920d64db582 74 } else {
lynxeyed_atsu 0:d920d64db582 75 character(_column, _row, value);
lynxeyed_atsu 0:d920d64db582 76 _column++;
lynxeyed_atsu 0:d920d64db582 77 if (_column >= columns()) {
lynxeyed_atsu 0:d920d64db582 78 _column = 0;
lynxeyed_atsu 0:d920d64db582 79 _row++;
lynxeyed_atsu 0:d920d64db582 80 if (_row >= rows()) {
lynxeyed_atsu 0:d920d64db582 81 _row = 0;
lynxeyed_atsu 0:d920d64db582 82 }
lynxeyed_atsu 0:d920d64db582 83 }
lynxeyed_atsu 0:d920d64db582 84 }
lynxeyed_atsu 0:d920d64db582 85 return value;
lynxeyed_atsu 0:d920d64db582 86 }
lynxeyed_atsu 0:d920d64db582 87
lynxeyed_atsu 0:d920d64db582 88 int TextLCD::_getc() {
lynxeyed_atsu 0:d920d64db582 89 return -1;
lynxeyed_atsu 0:d920d64db582 90 }
lynxeyed_atsu 0:d920d64db582 91
lynxeyed_atsu 0:d920d64db582 92 void TextLCD::writeByte(int value) {
lynxeyed_atsu 0:d920d64db582 93 _d = value >> 4;
lynxeyed_atsu 0:d920d64db582 94 wait(0.000040f); // most instructions take 40us
lynxeyed_atsu 0:d920d64db582 95 _e = 0;
lynxeyed_atsu 0:d920d64db582 96 wait(0.000040f);
lynxeyed_atsu 0:d920d64db582 97 _e = 1;
lynxeyed_atsu 0:d920d64db582 98 _d = value >> 0;
lynxeyed_atsu 0:d920d64db582 99 wait(0.000040f);
lynxeyed_atsu 0:d920d64db582 100 _e = 0;
lynxeyed_atsu 0:d920d64db582 101 wait(0.000040f); // most instructions take 40us
lynxeyed_atsu 0:d920d64db582 102 _e = 1;
lynxeyed_atsu 0:d920d64db582 103 }
lynxeyed_atsu 0:d920d64db582 104
lynxeyed_atsu 0:d920d64db582 105 void TextLCD::writeCommand(int command) {
lynxeyed_atsu 0:d920d64db582 106 _rs = 0;
lynxeyed_atsu 0:d920d64db582 107 writeByte(command);
lynxeyed_atsu 0:d920d64db582 108 }
lynxeyed_atsu 0:d920d64db582 109
lynxeyed_atsu 0:d920d64db582 110 void TextLCD::writeData(int data) {
lynxeyed_atsu 0:d920d64db582 111 _rs = 1;
lynxeyed_atsu 0:d920d64db582 112 writeByte(data);
lynxeyed_atsu 0:d920d64db582 113 }
lynxeyed_atsu 0:d920d64db582 114
lynxeyed_atsu 0:d920d64db582 115 int TextLCD::address(int column, int row) {
lynxeyed_atsu 0:d920d64db582 116 switch (_type) {
lynxeyed_atsu 0:d920d64db582 117 case LCD20x4:
lynxeyed_atsu 0:d920d64db582 118 switch (row) {
lynxeyed_atsu 0:d920d64db582 119 case 0:
lynxeyed_atsu 0:d920d64db582 120 return 0x80 + column;
lynxeyed_atsu 0:d920d64db582 121 case 1:
lynxeyed_atsu 0:d920d64db582 122 return 0xc0 + column;
lynxeyed_atsu 0:d920d64db582 123 case 2:
lynxeyed_atsu 0:d920d64db582 124 return 0x94 + column;
lynxeyed_atsu 0:d920d64db582 125 case 3:
lynxeyed_atsu 0:d920d64db582 126 return 0xd4 + column;
lynxeyed_atsu 0:d920d64db582 127 }
lynxeyed_atsu 0:d920d64db582 128 case LCD16x2B:
lynxeyed_atsu 0:d920d64db582 129 return 0x80 + (row * 40) + column;
lynxeyed_atsu 0:d920d64db582 130 case LCD16x2:
lynxeyed_atsu 0:d920d64db582 131 case LCD20x2:
lynxeyed_atsu 0:d920d64db582 132 default:
lynxeyed_atsu 0:d920d64db582 133 return 0x80 + (row * 0x40) + column;
lynxeyed_atsu 0:d920d64db582 134 }
lynxeyed_atsu 0:d920d64db582 135 }
lynxeyed_atsu 0:d920d64db582 136
lynxeyed_atsu 0:d920d64db582 137 int TextLCD::columns() {
lynxeyed_atsu 0:d920d64db582 138 switch (_type) {
lynxeyed_atsu 0:d920d64db582 139 case LCD20x4:
lynxeyed_atsu 0:d920d64db582 140 case LCD20x2:
lynxeyed_atsu 0:d920d64db582 141 return 20;
lynxeyed_atsu 0:d920d64db582 142 case LCD16x2:
lynxeyed_atsu 0:d920d64db582 143 case LCD16x2B:
lynxeyed_atsu 0:d920d64db582 144 default:
lynxeyed_atsu 0:d920d64db582 145 return 16;
lynxeyed_atsu 0:d920d64db582 146 }
lynxeyed_atsu 0:d920d64db582 147 }
lynxeyed_atsu 0:d920d64db582 148
lynxeyed_atsu 0:d920d64db582 149 int TextLCD::rows() {
lynxeyed_atsu 0:d920d64db582 150 switch (_type) {
lynxeyed_atsu 0:d920d64db582 151 case LCD20x4:
lynxeyed_atsu 0:d920d64db582 152 return 4;
lynxeyed_atsu 0:d920d64db582 153 case LCD16x2:
lynxeyed_atsu 0:d920d64db582 154 case LCD16x2B:
lynxeyed_atsu 0:d920d64db582 155 case LCD20x2:
lynxeyed_atsu 0:d920d64db582 156 default:
lynxeyed_atsu 0:d920d64db582 157 return 2;
lynxeyed_atsu 0:d920d64db582 158 }
lynxeyed_atsu 0:d920d64db582 159 }