Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
andriym
Date:
Mon May 09 01:08:01 2016 +0000
Revision:
78:43a6b54f0372
Changed radio configs, Player tracking table, Switch team button, Output class (for different displays and Serial), different boards support.

Who changed what in which revision?

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