Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
exploringBB::LCDCharacterDisplay Class Reference

A class that provides an interface to an LCD character module. It provices support for multiple rows and columns and provides methods for formatting and printing text. You should use a 4 wire interface and a 74XX595 to communicate with the display module. More...

#include <LCDCharacterDisplay.h>

Public Member Functions

 LCDCharacterDisplay (SPIDevice *device, int width, int height)
 
virtual void write (char c)
 
virtual void print (std::string message)
 
virtual void clear ()
 
virtual void home ()
 
virtual int setCursorPosition (int row, int column)
 
virtual void setDisplayOff (bool displayOff)
 
virtual void setCursorOff (bool cursorOff)
 
virtual void setCursorBlink (bool isBlink)
 
virtual void setCursorMoveOff (bool cursorMoveOff)
 
virtual void setCursorMoveLeft (bool cursorMoveLeft)
 
virtual void setAutoscroll (bool isAutoscroll)
 
virtual void setScrollDisplayLeft (bool scrollLeft)
 
virtual ~LCDCharacterDisplay ()
 

Detailed Description

A class that provides an interface to an LCD character module. It provices support for multiple rows and columns and provides methods for formatting and printing text. You should use a 4 wire interface and a 74XX595 to communicate with the display module.

Constructor & Destructor Documentation

exploringBB::LCDCharacterDisplay::LCDCharacterDisplay ( SPIDevice device,
int  width,
int  height 
)
65  {
66  this->device = device;
67  this->width = width;
68  this->height = height;
69 
70  //Default Cursor, Display and Entry states
71  this->cursorState = LCD_CURSOR_DISPLAY;
73  this->entryState = LCD_ENTRY_MODE_SET | ENTRY_MODE_LEFT;
74 
75  this->setup4bit();
76 }
#define DISPLAY_ENTIRE
Definition: LCDCharacterDisplay.cpp:35
#define DISPLAY_CURSOR_POS
Definition: LCDCharacterDisplay.cpp:37
#define LCD_CURSOR_DISPLAY
Definition: LCDCharacterDisplay.cpp:38
#define LCD_DISPLAY_ON_OFF
Definition: LCDCharacterDisplay.cpp:34
#define LCD_ENTRY_MODE_SET
Definition: LCDCharacterDisplay.cpp:31
#define DISPLAY_CURSOR
Definition: LCDCharacterDisplay.cpp:36
#define ENTRY_MODE_LEFT
Definition: LCDCharacterDisplay.cpp:32
exploringBB::LCDCharacterDisplay::~LCDCharacterDisplay ( )
virtual
334  {
335  this->device->close();
336 }
virtual void close()
Definition: SPIDevice.cpp:245

Member Function Documentation

void exploringBB::LCDCharacterDisplay::clear ( )
virtual
191  {
192  this->command(LCD_CLEAR_DISPLAY);
193  usleep(LCD_LONG_DELAY); //data sheets states that a delay of 1.52ms is required
194 }
#define LCD_LONG_DELAY
Definition: LCDCharacterDisplay.cpp:45
#define LCD_CLEAR_DISPLAY
Definition: LCDCharacterDisplay.cpp:29
void exploringBB::LCDCharacterDisplay::home ( )
virtual
199  {
200  this->command(LCD_RETURN_HOME);
201  usleep(LCD_LONG_DELAY); //data sheets states that a delay of 1.52ms is required
202 }
#define LCD_LONG_DELAY
Definition: LCDCharacterDisplay.cpp:45
#define LCD_RETURN_HOME
Definition: LCDCharacterDisplay.cpp:30
void exploringBB::LCDCharacterDisplay::print ( std::string  message)
virtual
155  {
156  for(unsigned int i=0; i<message.length(); i++){
157  this->write(message[i]);
158  }
159 }
virtual void write(char c)
Definition: LCDCharacterDisplay.cpp:174
void exploringBB::LCDCharacterDisplay::setAutoscroll ( bool  isAutoscroll)
virtual
Parameters
setAutoscroll
304  {
305  if (!isAutoscroll){
306  this->entryState = entryState & (~ENTRY_MODE_S);
307  this->writeEntryState();
308  }
309  else{
310  this->entryState = entryState | ENTRY_MODE_S;
311  this->writeEntryState();
312  }
313 }
#define ENTRY_MODE_S
Definition: LCDCharacterDisplay.cpp:33
void exploringBB::LCDCharacterDisplay::setCursorBlink ( bool  isBlink)
virtual

Turn the blink on or off.

Parameters
isBlinkpass true to turn the blink on, false to turn it off
259  {
260  if (!isBlink){
261  this->displayState = displayState & (~DISPLAY_CURSOR_POS); //bit inversion of DISPLAY_ENTIRE
262  this->writeDisplayState();
263  }
264  else{
265  this->displayState = displayState | DISPLAY_CURSOR_POS;
266  this->writeDisplayState();
267  }
268 }
#define DISPLAY_CURSOR_POS
Definition: LCDCharacterDisplay.cpp:37
void exploringBB::LCDCharacterDisplay::setCursorMoveLeft ( bool  cursorMoveLeft)
virtual
Parameters
cursorMoveLeft
289  {
290  if (!cursorMoveLeft){
291  this->cursorState = cursorState & (~CURSOR_DISPLAY_RL);
292  this->writeCursorState();
293  }
294  else{
295  this->cursorState = cursorState | CURSOR_DISPLAY_RL;
296  this->writeCursorState();
297  }
298 }
#define CURSOR_DISPLAY_RL
Definition: LCDCharacterDisplay.cpp:40
void exploringBB::LCDCharacterDisplay::setCursorMoveOff ( bool  cursorMoveOff)
virtual

Turn the cursor moving On or Off

Parameters
cursorOff
274  {
275  if (!cursorMoveOff){
276  this->cursorState = cursorState & (~CURSOR_DISPLAY_SC);
277  this->writeCursorState();
278  }
279  else{
280  this->cursorState = cursorState | CURSOR_DISPLAY_SC;
281  this->writeCursorState();
282  }
283 }
#define CURSOR_DISPLAY_SC
Definition: LCDCharacterDisplay.cpp:39
void exploringBB::LCDCharacterDisplay::setCursorOff ( bool  cursorOff)
virtual

Turn the cursor on or off.

Parameters
cursorOffpass true to turn the cursor off, false to turn it back on
244  {
245  if (cursorOff){
246  this->displayState = displayState & (~DISPLAY_CURSOR);
247  this->writeDisplayState();
248  }
249  else{
250  this->displayState = displayState | DISPLAY_CURSOR;
251  this->writeDisplayState();
252  }
253 }
#define DISPLAY_CURSOR
Definition: LCDCharacterDisplay.cpp:36
int exploringBB::LCDCharacterDisplay::setCursorPosition ( int  row,
int  column 
)
virtual
215  {
216 
217  if ((column>=this->width)||(row>=this->height)) return -1;
218  row = row * LCD_ROW_OFFSET_ADDR;
219  int value = (row + column) | LCD_DDRAM_ADDR;
220  this->command(value);
221  //printf("[%02x]", value);
222  return 0;
223 }
#define LCD_ROW_OFFSET_ADDR
Definition: LCDCharacterDisplay.cpp:47
#define LCD_DDRAM_ADDR
Definition: LCDCharacterDisplay.cpp:43
void exploringBB::LCDCharacterDisplay::setDisplayOff ( bool  displayOff)
virtual

Turn the display on or off.

Parameters
displayOffpass true to turn the display off, false to turn it back on
229  {
230  if (displayOff){
231  this->displayState = displayState & (~DISPLAY_ENTIRE); //bit inversion of DISPLAY_ENTIRE
232  this->writeDisplayState();
233  }
234  else{
235  this->displayState = displayState | DISPLAY_ENTIRE;
236  this->writeDisplayState();
237  }
238 }
#define DISPLAY_ENTIRE
Definition: LCDCharacterDisplay.cpp:35
void exploringBB::LCDCharacterDisplay::setScrollDisplayLeft ( bool  scrollLeft)
virtual
Parameters
scrollDisplayLeft
319  {
320  if (scrollLeft){
321  this->entryState = entryState & (~ENTRY_MODE_LEFT);
322  this->writeEntryState();
323  }
324  else{
325  this->entryState = entryState | ENTRY_MODE_LEFT;
326  this->writeEntryState();
327  }
328 }
#define ENTRY_MODE_LEFT
Definition: LCDCharacterDisplay.cpp:32
void exploringBB::LCDCharacterDisplay::write ( char  c)
virtual
174  {
175  // 4-bit mode. Send lower 4 bits followed by higher 4 bits
176  char upper = (c << 4) & 0b11110000;
177  char lower = c & 0b11110000;
178  // need to write the lower data and toggle the E bit
179  this->device->write(lower | 0b00000011); //lower 4 bits
180  usleep(1); //sleep for at least 300ns
181  this->device->write(lower | 0b00000001); //lower 4 bits
182  // need to write the upper data and toggle the E bit
183  this->device->write(upper | 0b00000011); //lower 4 bits
184  usleep(1); //sleep for at least 300ns
185  this->device->write(upper | 0b00000001); //lower 4 bits
186 }
virtual int write(unsigned char value)
Definition: SPIDevice.cpp:139

The documentation for this class was generated from the following files: