Programme d'une sonde de température DHT 11 associée à de la sauvegarde de données sur clé USB et à l'affichage de ces données sur afficheur LCD
Dependencies: FatFileSystemCpp mbed
TextLCD.cpp
00001 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780 00002 * Copyright (c) 2007-2010, sford, http://mbed.org 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #include "TextLCD.h" 00024 #include "mbed.h" 00025 00026 TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1, 00027 PinName d2, PinName d3, LCDType type) : _rs(rs), 00028 _e(e), _d(d0, d1, d2, d3), 00029 _type(type) { 00030 00031 _e = 0; 00032 _rs = 0; // command mode 00033 00034 wait(0.050); // Wait 15ms to ensure powered up 00035 00036 // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus) 00037 for (int i=0; i<3; i++) { 00038 writeByte(0x30); 00039 wait(0.002); // this command takes 1.64ms, so wait for it 00040 } 00041 writeByte(0x2); 00042 wait(0.002); 00043 writeCommand(0x29); 00044 wait(0.001f); 00045 writeCommand(0x14); 00046 wait(0.001f); 00047 writeCommand(0x55); 00048 wait(0.001f); 00049 writeCommand(0x6D); 00050 wait(0.001f); 00051 writeCommand(0x78); 00052 wait(0.001f); 00053 writeCommand(0x28); 00054 wait(0.001f); 00055 writeCommand(0x0C); 00056 wait(0.001f); 00057 writeCommand(0x01); 00058 wait_ms(2); 00059 writeCommand(0x06); 00060 wait(0.001f); 00061 } 00062 00063 void TextLCD::character(int column, int row, int c) { 00064 int a = address(column, row); 00065 writeCommand(a); 00066 writeData(c); 00067 } 00068 00069 void TextLCD::cls() { 00070 writeCommand(0x01); // cls, and set cursor to 0 00071 wait(0.00164f); // This command takes 1.64 ms 00072 locate(0, 0); 00073 } 00074 00075 void TextLCD::locate(int column, int row) { 00076 _column = column; 00077 _row = row; 00078 } 00079 00080 int TextLCD::_putc(int value) { 00081 if (value == '\n') { 00082 _column = 0; 00083 _row++; 00084 if (_row >= rows()) { 00085 _row = 0; 00086 } 00087 } else { 00088 character(_column, _row, value); 00089 _column++; 00090 if (_column >= columns()) { 00091 _column = 0; 00092 _row++; 00093 if (_row >= rows()) { 00094 _row = 0; 00095 } 00096 } 00097 } 00098 return value; 00099 } 00100 00101 int TextLCD::_getc() { 00102 return -1; 00103 } 00104 00105 void TextLCD::writeByte(int value) { 00106 _d = value >> 4; 00107 wait(0.000040f); // most instructions take 40us 00108 _e = 0; 00109 wait(0.000040f); 00110 _e = 1; 00111 _d = value >> 0; 00112 wait(0.000040f); 00113 _e = 0; 00114 wait(0.000040f); // most instructions take 40us 00115 _e = 1; 00116 } 00117 00118 void TextLCD::writeCommand(int command) { 00119 _rs = 0; 00120 writeByte(command); 00121 } 00122 00123 void TextLCD::writeData(int data) { 00124 _rs = 1; 00125 writeByte(data); 00126 } 00127 00128 int TextLCD::address(int column, int row) { 00129 switch (_type) { 00130 case LCD20x4: 00131 switch (row) { 00132 case 0: 00133 return 0x80 + column; 00134 case 1: 00135 return 0xc0 + column; 00136 case 2: 00137 return 0x94 + column; 00138 case 3: 00139 return 0xd4 + column; 00140 } 00141 case LCD16x2B: 00142 return 0x80 + (row * 40) + column; 00143 case LCD16x2: 00144 case LCD20x2: 00145 default: 00146 return 0x80 + (row * 0x40) + column; 00147 } 00148 } 00149 00150 int TextLCD::columns() { 00151 switch (_type) { 00152 case LCD20x4: 00153 case LCD20x2: 00154 return 20; 00155 case LCD16x2: 00156 case LCD16x2B: 00157 default: 00158 return 16; 00159 } 00160 } 00161 00162 int TextLCD::rows() { 00163 switch (_type) { 00164 case LCD20x4: 00165 return 4; 00166 case LCD16x2: 00167 case LCD16x2B: 00168 case LCD20x2: 00169 default: 00170 return 2; 00171 } 00172 }
Generated on Wed Jul 20 2022 05:14:59 by 1.7.2