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.
Dependents: Hotboards_SpiLcd-Hello_World Hotboards_SpiLcd-Writing_In_Diferent_Rows Hotboards_SpiLcd_Scrolling_Text Hotboards_SpiLcd_AutoScroll ... more
Hotboards_SpiLcd.cpp
00001 /* 00002 Hotboards_SpiLcd.cpp - Library to control and write an lcd with spi interface and ST7032 controller. 00003 base on Arduino's Liquid Cristal library 00004 Library ported by diego from Hotboards January 16, 2016. 00005 and originally cretaed by 00006 by David A. Mellis 00007 library modified 5 Jul 2009 00008 by Limor Fried (http://www.ladyada.net) 00009 example added 9 Jul 2009 00010 by Tom Igoe 00011 modified 22 Nov 2010 00012 by Tom Igoe 00013 Released into the public domain. 00014 */ 00015 00016 #include "Hotboards_SpiLcd.h" 00017 00018 Hotboards_SpiLcd::Hotboards_SpiLcd( SPI &spi, PinName cs, PinName rs, PinName rst ) 00019 : _spi(spi), _cs_pin(cs), _rs_pin(rs), _rst_pin(rst) 00020 { 00021 _cs_pin = 1; /*chip select deactivated*/ 00022 _rs_pin = 0; 00023 _rst_pin = 1; /*reset not active*/ 00024 } 00025 00026 00027 void Hotboards_SpiLcd::init( void ) 00028 { 00029 _rst_pin = 0; 00030 wait( 0.002 ); 00031 _rst_pin = 1; 00032 wait( 0.02 ); 00033 command( 0x30 );/*wakeup*/ 00034 wait( 0.002 ); 00035 command( 0x30 );/*wakeup*/ 00036 command( 0x30 );/*wakeup*/ 00037 00038 // configure default display functions, two lines, 5x8 charcters 00039 _displayfunction = HT_SPILCD_8BITMODE | HT_SPILCD_2LINE | HT_SPILCD_5x8DOTS | HT_SPILCD_EXTINST; 00040 command( HT_SPILCD_FUNCTIONSET | _displayfunction ); 00041 00042 command( 0x14 );/*internaloscfrequency*/ 00043 command( 0x56 );/*powercontroll*/ 00044 command( 0x6d );/*followercontrol*/ 00045 wait( 0.2 ); 00046 command( 0x70 );/*constrast*/ 00047 00048 // reenable shift functions disbling extended instructions 00049 _displayfunction &= ~HT_SPILCD_EXTINST; 00050 command( HT_SPILCD_FUNCTIONSET | _displayfunction ); 00051 00052 // turn the display on with no cursor or blinking default 00053 _displaycontrol = HT_SPILCD_DISPLAYON | HT_SPILCD_CURSOROFF | HT_SPILCD_BLINKOFF; 00054 display( ); 00055 00056 // Initialize to default text direction (for romance languages) 00057 _displaymode = HT_SPILCD_ENTRYLEFT | HT_SPILCD_ENTRYSHIFTDECREMENT; 00058 // set the entry mode 00059 command( HT_SPILCD_ENTRYMODESET | _displaymode ); 00060 clear( );/*clearscreen*/ 00061 } 00062 00063 00064 void Hotboards_SpiLcd::clear( void ) 00065 { 00066 command( HT_SPILCD_CLEARDISPLAY ); // clear display, set cursor position to zero 00067 wait( 0.002 ); // this command takes a long time! 00068 } 00069 00070 00071 void Hotboards_SpiLcd::home( void ) 00072 { 00073 command( HT_SPILCD_RETURNHOME ); // set cursor position to zero 00074 wait( 0.002 ); // this command takes a long time! 00075 } 00076 00077 00078 void Hotboards_SpiLcd::noDisplay( void ) 00079 { 00080 _displaycontrol &= ~HT_SPILCD_DISPLAYON; 00081 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00082 } 00083 00084 00085 void Hotboards_SpiLcd::display( void ) 00086 { 00087 _displaycontrol |= HT_SPILCD_DISPLAYON; 00088 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00089 } 00090 00091 00092 void Hotboards_SpiLcd::noBlink( void ) 00093 { 00094 _displaycontrol &= ~HT_SPILCD_BLINKON; 00095 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00096 } 00097 00098 00099 void Hotboards_SpiLcd::blink( void ) 00100 { 00101 _displaycontrol |= HT_SPILCD_BLINKON; 00102 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00103 } 00104 00105 00106 00107 void Hotboards_SpiLcd::noCursor( void ) 00108 { 00109 _displaycontrol &= ~HT_SPILCD_CURSORON; 00110 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00111 } 00112 00113 00114 void Hotboards_SpiLcd::cursor( void ) 00115 { 00116 _displaycontrol |= HT_SPILCD_CURSORON; 00117 command( HT_SPILCD_DISPLAYCONTROL | _displaycontrol ); 00118 00119 } 00120 00121 00122 void Hotboards_SpiLcd::scrollDisplayLeft( void ) 00123 { 00124 command( HT_SPILCD_CURSORSHIFT | HT_SPILCD_DISPLAYMOVE | HT_SPILCD_MOVELEFT ); 00125 } 00126 00127 00128 void Hotboards_SpiLcd::scrollDisplayRight( void ) 00129 { 00130 command( HT_SPILCD_CURSORSHIFT | HT_SPILCD_DISPLAYMOVE | HT_SPILCD_MOVERIGHT ); 00131 } 00132 00133 00134 void Hotboards_SpiLcd::leftToRight( void ) 00135 { 00136 _displaymode |= HT_SPILCD_ENTRYLEFT; 00137 command( HT_SPILCD_ENTRYMODESET | _displaymode ); 00138 } 00139 00140 00141 void Hotboards_SpiLcd::rightToLeft( void ) 00142 { 00143 _displaymode &= ~HT_SPILCD_ENTRYLEFT; 00144 command( HT_SPILCD_ENTRYMODESET | _displaymode ); 00145 } 00146 00147 00148 void Hotboards_SpiLcd::autoscroll( void ) 00149 { 00150 _displaymode |= HT_SPILCD_ENTRYSHIFTINCREMENT; 00151 command( HT_SPILCD_ENTRYMODESET | _displaymode ); 00152 } 00153 00154 00155 void Hotboards_SpiLcd::noAutoscroll( void ) 00156 { 00157 _displaymode &= ~HT_SPILCD_ENTRYSHIFTINCREMENT; 00158 command( HT_SPILCD_ENTRYMODESET | _displaymode ); 00159 } 00160 00161 00162 void Hotboards_SpiLcd::setCursor( uint8_t col, uint8_t row ) 00163 { 00164 const uint8_t Buffer[ 2 ]= { 0x00u, 0x40u }; 00165 uint8_t address; 00166 00167 if( row > 1 ) 00168 { 00169 row = 1; 00170 } 00171 address = Buffer[ row ] + col; 00172 command( 0x80 | address ); 00173 } 00174 00175 00176 /*********** mid level commands, for sending data/cmds */ 00177 00178 inline void Hotboards_SpiLcd::command( uint8_t value ) 00179 { 00180 _cs_pin = 0; 00181 send( value, 0 ); 00182 _cs_pin = 1; 00183 wait( 0.00003 ); // commands need > 27us to settle 00184 } 00185 00186 /* 00187 * Write a character to the LCD. 00188 */ 00189 int Hotboards_SpiLcd::_putc(int value) 00190 { 00191 _cs_pin = 0; 00192 send( value, 1 ); 00193 _cs_pin = 1; 00194 wait( 0.00003 ); // commands need > 27us to settle 00195 return 1; 00196 } 00197 00198 int Hotboards_SpiLcd::_getc(void) 00199 { 00200 return -1; 00201 } 00202 00203 /************ low level data pushing commands **********/ 00204 00205 // write either command or data, with automatic 4/8-bit selection 00206 void Hotboards_SpiLcd::send( uint8_t value, uint8_t mode ) 00207 { 00208 _rs_pin = mode; 00209 _spi.write( value ); 00210 }
Generated on Fri Jul 15 2022 20:44:00 by
1.7.2
Hotboards SpiLcd.