62 typedef enum {
DIM_8x1,
DIM_8x2,
DIM_8x4,
DIM_16x1_1,
DIM_16x1_2,
DIM_16x2,
DIM_16x4,
DIM_20x1,
DIM_20x2,
DIM_20x4,
DIM_24x1,
DIM_24x2,
DIM_40x1,
DIM_40x2,
80 #define HD44780_ERRORS_LIMIT 16 82 #define HD44780_ERRORS_BASE 48 108 uint8_t ddramCharRowBreak;
110 uint8_t ddramLineEnd;
122 static const uint8_t CLEAR = BIT_0;
123 static const uint8_t RET_HOME = BIT_1;
124 static const uint8_t ENTRY_MODE_SET = BIT_2;
125 static const uint8_t DISPLAY_CTRL = BIT_3;
126 static const uint8_t SHIFT = BIT_4;
127 static const uint8_t FUNCTION_SET = BIT_5;
128 static const uint8_t SET_CGRAM_ADDR = BIT_6;
129 static const uint8_t SET_DDRAM_ADDR = BIT_7;
136 static const uint8_t SHIFT_INC = BIT_1;
137 static const uint8_t SHIFT_EN = BIT_0;
144 static const uint8_t DISPLAY_PWR = BIT_2;
145 static const uint8_t CURSOR = BIT_1;
146 static const uint8_t BLINK = BIT_0;
153 static const uint8_t SHIFT_DISPLAY = BIT_3;
154 static const uint8_t SHIFT_RIGHT = BIT_2;
161 static const uint8_t FUNC_8BIT_MODE = BIT_4;
162 static const uint8_t FUNC_2LINE_MODE = BIT_3;
163 static const uint8_t FUNC_5x10_CHAR = BIT_2;
171 this->m_curPos = &(this->m_bogus);
172 this->m_curPos->row = 0;
173 this->m_curPos->col = 0;
195 waitcnt(250 * MILLISECOND + CNT);
209 this->m_dataPort.
set_mask(lsbDataPin, bitmode);
213 this->generate_mem_map(dimensions);
214 this->m_bitmode = bitmode;
223 this->m_dataPort.
write(arg);
225 waitcnt(100 * MILLISECOND + CNT);
228 waitcnt(100 * MILLISECOND + CNT);
231 waitcnt(10 * MILLISECOND + CNT);
234 this->m_dataPort.
write(0x2);
239 arg = PropWare::HD44780::FUNCTION_SET;
241 arg |= PropWare::HD44780::FUNC_8BIT_MODE;
242 arg |= PropWare::HD44780::FUNC_2LINE_MODE;
247 arg = PropWare::HD44780::SHIFT;
251 arg = PropWare::HD44780::DISPLAY_CTRL
252 | PropWare::HD44780::DISPLAY_PWR;
256 arg = PropWare::HD44780::ENTRY_MODE_SET
257 | PropWare::HD44780::SHIFT_INC;
267 this->
cmd(PropWare::HD44780::CLEAR);
268 this->m_curPos->row = 0;
269 this->m_curPos->col = 0;
270 waitcnt(1530 * MICROSECOND + CNT);
279 void move (
const uint8_t row,
const uint8_t col)
const {
280 uint8_t ddramLine, addr = 0;
284 if (this->m_memMap.ddramCharRowBreak > this->m_memMap.ddramLineEnd) {
285 ddramLine = col / this->m_memMap.ddramLineEnd;
288 addr |= col % this->m_memMap.ddramLineEnd;
289 }
else if (4 == this->m_memMap.charRows) {
294 addr += this->m_memMap.ddramCharRowBreak;
295 addr += col % this->m_memMap.ddramCharRowBreak;
303 this->
cmd(addr | PropWare::HD44780::SET_DDRAM_ADDR);
304 this->m_curPos->row = row;
305 this->m_curPos->col = col;
308 void puts (
const char string[]) {
309 const char *s = (
char *)
string;
320 this->m_curPos->row++;
321 if (this->m_curPos->row == this->m_memMap.charRows)
322 this->m_curPos->row = 0;
323 this->m_curPos->col = 0;
324 this->
move(this->m_curPos->row, this->m_curPos->col);
325 }
else if (
'\t' == c) {
329 }
else if (
'\r' == c)
330 this->
move(this->m_curPos->row, 0);
335 this->write((
const uint8_t) c);
338 ++this->m_curPos->col;
339 if (this->m_memMap.charColumns == this->m_curPos->col)
344 if (this->m_memMap.ddramCharRowBreak
345 > this->m_memMap.ddramLineEnd)
346 this->
move(this->m_curPos->row, this->m_curPos->col);
355 void cmd (
const uint8_t command)
const {
358 this->write(command);
362 char str[] =
"HD44780 Error %u: %s\n";
370 "invalid LCD dimension; please choose from the HD44780::Dimensions type");
386 void write (
const uint8_t val)
const {
392 this->m_dataPort.
write(val >> 4);
396 this->m_dataPort.
write(val);
400 this->m_dataPort.
write(val);
409 void clock_pulse (
void)
const {
411 waitcnt(MILLISECOND + CNT);
421 switch (dimensions) {
423 this->m_memMap.charRows = 1;
424 this->m_memMap.charColumns = 8;
425 this->m_memMap.ddramCharRowBreak = 8;
426 this->m_memMap.ddramLineEnd = 8;
429 this->m_memMap.charRows = 2;
430 this->m_memMap.charColumns = 8;
431 this->m_memMap.ddramCharRowBreak = 8;
432 this->m_memMap.ddramLineEnd = 8;
435 this->m_memMap.charRows = 4;
436 this->m_memMap.charColumns = 8;
437 this->m_memMap.ddramCharRowBreak = 8;
438 this->m_memMap.ddramLineEnd = 16;
441 this->m_memMap.charRows = 1;
442 this->m_memMap.charColumns = 16;
443 this->m_memMap.ddramCharRowBreak = 8;
444 this->m_memMap.ddramLineEnd = 8;
447 this->m_memMap.charRows = 1;
448 this->m_memMap.charColumns = 16;
449 this->m_memMap.ddramCharRowBreak = 16;
450 this->m_memMap.ddramLineEnd = 16;
453 this->m_memMap.charRows = 2;
454 this->m_memMap.charColumns = 16;
455 this->m_memMap.ddramCharRowBreak = 16;
456 this->m_memMap.ddramLineEnd = 16;
459 this->m_memMap.charRows = 4;
460 this->m_memMap.charColumns = 16;
461 this->m_memMap.ddramCharRowBreak = 16;
462 this->m_memMap.ddramLineEnd = 32;
465 this->m_memMap.charRows = 1;
466 this->m_memMap.charColumns = 20;
467 this->m_memMap.ddramCharRowBreak = 20;
468 this->m_memMap.ddramLineEnd = 20;
471 this->m_memMap.charRows = 2;
472 this->m_memMap.charColumns = 20;
473 this->m_memMap.ddramCharRowBreak = 20;
474 this->m_memMap.ddramLineEnd = 20;
477 this->m_memMap.charRows = 4;
478 this->m_memMap.charColumns = 20;
479 this->m_memMap.ddramCharRowBreak = 20;
480 this->m_memMap.ddramLineEnd = 40;
483 this->m_memMap.charRows = 1;
484 this->m_memMap.charColumns = 24;
485 this->m_memMap.ddramCharRowBreak = 24;
486 this->m_memMap.ddramLineEnd = 24;
489 this->m_memMap.charRows = 2;
490 this->m_memMap.charColumns = 24;
491 this->m_memMap.ddramCharRowBreak = 24;
492 this->m_memMap.ddramLineEnd = 24;
495 this->m_memMap.charRows = 1;
496 this->m_memMap.charColumns = 40;
497 this->m_memMap.ddramCharRowBreak = 40;
498 this->m_memMap.ddramLineEnd = 40;
501 this->m_memMap.charRows = 2;
502 this->m_memMap.charColumns = 40;
503 this->m_memMap.ddramCharRowBreak = 40;
504 this->m_memMap.ddramLineEnd = 40;
516 HD44780::MemMap m_memMap;
522 Pin m_rs, m_rw, m_en;
Utility class to handle general purpose I/O pins.
void set_dir(const PropWare::Port::Dir direction) const
Set port as either input or output.
The PropWare::SimplePort is the recommended way to use data ports on the Propeller. All pins are consecutive, which allows for some simple shortcuts in reading, writing, and initialization.
void put_char(const char c)
Print a single character.
void clear() const
Clear selected output port (set it to 0)
Generic definitions and functions for the Parallax Propeller.
#define HD44780_ERRORS_BASE
Support for the common "character LCD" modules using the HD44780 controller for the Parallax Propelle...
void move(const uint8_t row, const uint8_t col) const
Move the cursor to a specified column and row.
void printf(const char fmt[], const T first, const Targs...remaining) const
Similar in functionality to the C-standard function printf.
void clear(void)
Clear the LCD display and return cursor to home.
Container class that has formatting methods for human-readable output. This class can be constructed ...
Bitmode
LCD databus width.
Dimensions
Supported LCD dimensions; Used for determining cursor placement.
void write(uint32_t value) const
Allow easy writing to a port w/o destroying data elsewhere in the port; A shift is performed before w...
void puts(const char string[])
Send a null-terminated character array. Though this method could be created using put_char...
void set() const
Set selected output port high (set all pins to 1)
void cmd(const uint8_t command) const
Send a control command to the LCD module.
Interface for all classes capable of printing.
static const uint8_t TAB_WIDTH
void start(const PropWare::Pin::Mask lsbDataPin, const Pin rs, const Pin rw, const Pin en, const HD44780::Bitmode bitmode, const HD44780::Dimensions dimensions)
Initialize an HD44780 LCD display.
void set_mask(const PropWare::Port::Mask firstPin, uint8_t portWidth)
Configure a port's bit-mask.