General purpose character LCD library. I found the TextLCD library had too many constraints and it didn\\\\\\\'t supply acces to all functions in the HD44780 chipset, so i decided to write my own character lcd library.
Revision 2:18f6402fd025, committed 2011-04-07
- Comitter:
- lktromp
- Date:
- Thu Apr 07 11:29:55 2011 +0000
- Parent:
- 1:1349bedd5793
- Commit message:
- Little bit further
Changed in this revision
diff -r 1349bedd5793 -r 18f6402fd025 charLcd.cpp --- a/charLcd.cpp Fri Mar 25 10:01:28 2011 +0000 +++ b/charLcd.cpp Thu Apr 07 11:29:55 2011 +0000 @@ -5,7 +5,15 @@ Serial pc(USBTX, USBRX); #define DEBUG - //constructor for 4-bit lcd control + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ + //constructor for 4-bit lcd control charLcd::charLcd(PinName rs, PinName en, PinName rw, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type) : cl_rs(rs), cl_rw(rw), cl_en(en), cl_charLcdData(d7, d6, d5, d4) { pc.baud(115200); @@ -15,7 +23,15 @@ charLcdResetLCD(); } - //constructor for 8-bit lcd control + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ + //constructor for 8-bit lcd control charLcd::charLcd(PinName rs, PinName en, PinName rw, PinName d0, PinName d1, PinName d2, PinName d3, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type) : cl_rs(rs), cl_rw(rw), cl_en(en), cl_charLcdData(d7, d6, d5, d4, d3, d2, d1, d0) { @@ -29,38 +45,69 @@ } - + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdResetLCD(void) { + cl_charLcdData.output(); + cl_charLcdData = 0x00; cl_en = 1; cl_rs = 0; // command mode cl_rw = 0; - wait_ms(40); // Wait 15ms to ensure powered up - charLcdFunctionSet(0,1,0); - wait_ms(5); // Wait 15ms to ensure powered up - charLcdFunctionSet(0,1,0); - wait_us(100); // Wait 15ms to ensure powered up + wait_ms(10); // Wait 15ms to ensure powered up + //charLcdFunctionSet(0,1,0); + //wait_ms(5); // Wait 15ms to ensure powered up + //charLcdFunctionSet(0,1,0); + //wait_us(100); // Wait 15ms to ensure powered up + //charLcdFunctionSet(0,1,0); + //wait_us(100); // Wait 15ms to ensure powered up + //charLcdFunctionSet(0,1,0); + //charLcdDisplayOn(0); + while (1) { + charLcdClear(); + wait_ms(500); + cl_charLcdData = 0x00; + wait_ms(500); + } + charLcdEntryMode(shift_inc); + wait_ms(20); // Wait 15ms to ensure powered up charLcdFunctionSet(0,1,0); - wait_us(100); // Wait 15ms to ensure powered up - charLcdFunctionSet(0,1,0); - charLcdDisplayOn(0); - charLcdClear(); - charLcdEntryMode(1,0); - //wait_ms(20); // Wait 15ms to ensure powered up - //charLcdFunctionSet(0,1,0); - //wait_ms(20); // Wait 15ms to ensure powered up + wait_ms(20); // Wait 15ms to ensure powered up charLcdDisplayOn(1); wait_ms(20); // Wait 15ms to ensure powered up charLcdCursor(1, 1); wait_ms(20); // Wait 15ms to ensure powered up - charLcdEntryMode(1,0); + charLcdEntryMode(shift_inc); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdClear (void){ #ifdef DEBUG pc.printf("LCD Clear\r\n"); #endif //DEBUG charLcdSendCommand(LCD_CLEAR); } + + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdReturnHome(){ #ifdef DEBUG pc.printf("LCD Home\r\n"); @@ -68,8 +115,25 @@ charLcdSendCommand(LCD_HOME); } -void charLcd::charLcdEntryMode(uint8 increment, uint8 shift){ + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ +//void charLcd::charLcdEntryMode(uint8 increment, uint8 shift){ +void charLcd::charLcdEntryMode(t_charlcd_entry_mode entrymode) { uint8 cmd = LCD_ENTRY_MODE; + + switch(entrymode) { + case shift_inc: {cmd |= (LCD_ENTRY_SHIFT | LCD_ENTRY_INC); break;}; + case shift_dec: {cmd |= (LCD_ENTRY_SHIFT | LCD_ENTRY_DEC );break;}; + case noshift_inc: {cmd |= (LCD_ENTRY_STAT | LCD_ENTRY_INC); break;}; + case noshift_dec: {cmd |= (LCD_ENTRY_STAT | LCD_ENTRY_DEC); break;}; + } + /* if (increment == 0x00){ cmd |= LCD_ENTRY_DEC; #ifdef DEBUG @@ -82,20 +146,30 @@ #endif //DEBUG } if (shift == 0x00){ + cmd |= LCD_ENTRY_STAT; #ifdef DEBUG pc.printf("LCD Entry Mode Static\r\n"); - #endif //DEBUGcmd |= LCD_ENTRY_STAT; + #endif //DEBUG + } else { cmd |=LCD_ENTRY_SHIFT; #ifdef DEBUG pc.printf("LCD Entry Mode Shift\r\n"); #endif //DEBUG - } + } */ charLcdSendCommand(cmd); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdDisplayOn(uint8 on){ uint8 cmd = LCD_DISPLAY_CTR; if (on == 0x00){ @@ -112,6 +186,14 @@ charLcdSendCommand(cmd); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdCursor(uint8 cursor, uint8 blink){ uint8 cmd = LCD_DISPLAY_CTR; if (cursor == 0x00){ @@ -139,6 +221,14 @@ charLcdSendCommand(cmd); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdShift(uint8 left, uint8 cursor){ uint8 cmd = LCD_SHIFT; if (left == 0x00){ @@ -166,6 +256,14 @@ charLcdSendCommand(cmd); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdFunctionSet(uint8 dots, uint8 lines, uint8 bits){ uint8 cmd = LCD_FUNCTION; if (dots == 0x00){ @@ -211,38 +309,97 @@ //#define LCD_FUNC_4BIT 0x00 } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdSetCGRAMaddress(uint8 adr) { charLcdSendCommand(LCD_SET_CGRAM & adr); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdSetDDRAMaddress(uint8 adr) { charLcdSendCommand(LCD_SET_DDRAM & adr); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ uint8 charLcd::charLcdReadBusyFlag() { return 0x00; } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdWriteData(uint8 dat){ cl_rs = 1; + cl_rw = 1; charLcdWriteByte(dat); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ uint8 charLcd::charLcdReadData(){ cl_rs = 0; + cl_rw = 0; return 0x00; } - + + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdSendCommand(uint8 cmd) { cl_rs = 0; + cl_rw = 0; charLcdWriteByte(cmd); } + /** LCD constructor + * + * More details about the function goes here + * and here + * + * @param x a variable used by foo + * @returns something magical done with x + */ void charLcd::charLcdWriteByte(uint8 byte) { cl_charLcdData = byte; pc.printf("Write %#X to LCD\r\n", byte); - wait_us(40); // setup time + wait_us(500); // setup time cl_en = 0; - wait_us(40); //hold time + wait_us(500); //hold time cl_en = 1; }
diff -r 1349bedd5793 -r 18f6402fd025 charLcd.h --- a/charLcd.h Fri Mar 25 10:01:28 2011 +0000 +++ b/charLcd.h Thu Apr 07 11:29:55 2011 +0000 @@ -23,6 +23,14 @@ , LCD20x4 /**< 20x4 LCD panel */ }; + enum t_charlcd_entry_mode { + shift_inc = 4, + noshift_inc = 3, + shift_dec = 2, + noshift_dec = 1, + }; + + //constructor for 4-bit lcd control charLcd(PinName rs, PinName rw, PinName en, PinName d7, PinName d6, PinName d5, PinName d4, LCDType type = LCD16x2); //constructor for 8-bit lcd control @@ -32,7 +40,8 @@ void charLcdResetLCD(void); void charLcdClear (void); void charLcdReturnHome(); - void charLcdEntryMode(uint8 increment, uint8 shift); + //void charLcdEntryMode(uint8 increment, uint8 shift); + void charLcdEntryMode(t_charlcd_entry_mode entrymode); void charLcdDisplayOn(uint8 on); void charLcdCursor(uint8 cursor, uint8 blink); void charLcdShift(uint8 left, uint8 cursor); @@ -70,6 +79,9 @@ //LCD Data bus BusInOut cl_charLcdData; + + + enum t_charlcd_function_set {NO_WIND = 4, NORTH_WIND = 3, SOUTH_WIND = 2, EAST_WIND = 1, WEST_WIND = 0}; };
diff -r 1349bedd5793 -r 18f6402fd025 hd44780.h --- a/hd44780.h Fri Mar 25 10:01:28 2011 +0000 +++ b/hd44780.h Thu Apr 07 11:29:55 2011 +0000 @@ -11,6 +11,7 @@ // HEARTS = 4, // SPADES = 8 // }; + #define LCD_ENTRY_MODE 0x04 #define LCD_ENTRY_INC 0x01 #define LCD_ENTRY_DEC 0x00