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.
Fork of 352 by
lcdClass.cpp
00001 #include "lcdClass.h" 00002 #include "mbed.h" 00003 00004 float W = 0.000040; float W1 = 0.00164; 00005 lcdClass::lcdClass(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7) : _rs(rs), _e(e), _d(d4, d5, d6, d7){ 00006 _e = 1; _rs = 0; //E pin high, RS set to 0 for instruction register 00007 wait(0.015); //Wait for VCC to rise 00008 for (int i=0; i<3; i++) {writeByte(0x3);wait(W1);} //Send initialisation value, 0x3. 00009 writeByte(0x2); wait(W); //Set Bus Width (4-bit) 00010 writeCommand(0x28); //4-bit mode, 2-line, 5x7 font 00011 writeCommand(0x0C); //No Cursor or Blink 00012 writeCommand(0x6); //Automatic Increment, No Display Shift 00013 cls(); //Ensure screen is cleared 00014 } 00015 00016 void lcdClass::character(int column, int row, int c) { 00017 int a = 0x80 + (row * 0x40) + column; 00018 writeCommand(a); writeData(c);} 00019 00020 void lcdClass::cls() {writeCommand(0x01); wait(W1); locate(0, 0);} //Send Clear Display Command, Set location back to column 0, row 0 00021 00022 void lcdClass::locate(int column, int row) {_column = column; _row = row;} //Set protected column and row to input column and row 00023 00024 int lcdClass::_putc(int value) { 00025 if (value == '\n') { 00026 _column = 0; _row++; //If input character is \n, set column to 0, increment row. 00027 if (_row >= 2) {_row = 0;} //If row is 2, set row to 0 00028 } 00029 else { 00030 character(_column, _row, value);_column++; //Else write the input value to the 00031 if (_column >= 16) { 00032 _column = 0;_row++; 00033 if (_row >= 2) {_row = 0;} 00034 } 00035 } 00036 return value; 00037 } 00038 int lcdClass::_getc() {return -1;} 00039 void lcdClass::writeByte(int value) { 00040 _d = value >> 4; wait(W); 00041 _e = 0; wait(W); 00042 _e = 1; 00043 _d = value >> 0; wait(W); 00044 _e = 0; wait(W); 00045 _e = 1; 00046 } 00047 00048 void lcdClass::writeCommand(int command) {_rs = 0; writeByte(command);} 00049 void lcdClass::writeData(int data) { _rs = 1; writeByte(data);}
Generated on Tue Jul 12 2022 21:51:19 by
