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.
charLcd.h@2:18f6402fd025, 2011-04-07 (annotated)
- Committer:
- lktromp
- Date:
- Thu Apr 07 11:29:55 2011 +0000
- Revision:
- 2:18f6402fd025
- Parent:
- 1:1349bedd5793
Little bit further
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lktromp | 1:1349bedd5793 | 1 | /*********************************************************************************** |
lktromp | 1:1349bedd5793 | 2 | Filename: CharacterLCD.h |
lktromp | 1:1349bedd5793 | 3 | |
lktromp | 1:1349bedd5793 | 4 | |
lktromp | 1:1349bedd5793 | 5 | ***********************************************************************************/ |
lktromp | 1:1349bedd5793 | 6 | #ifndef CHARLCD_H |
lktromp | 1:1349bedd5793 | 7 | #define CHARLCD_H |
lktromp | 1:1349bedd5793 | 8 | #include "mbed.h" |
lktromp | 1:1349bedd5793 | 9 | |
lktromp | 1:1349bedd5793 | 10 | //move this typedef to project specific datatype header file |
lktromp | 1:1349bedd5793 | 11 | typedef unsigned char uint8; |
lktromp | 1:1349bedd5793 | 12 | |
lktromp | 1:1349bedd5793 | 13 | |
lktromp | 1:1349bedd5793 | 14 | |
lktromp | 1:1349bedd5793 | 15 | class charLcd |
lktromp | 1:1349bedd5793 | 16 | { public: |
lktromp | 1:1349bedd5793 | 17 | |
lktromp | 1:1349bedd5793 | 18 | /** LCD panel format */ |
lktromp | 1:1349bedd5793 | 19 | enum LCDType { |
lktromp | 1:1349bedd5793 | 20 | LCD16x2 /**< 16x2 LCD panel (default) */ |
lktromp | 1:1349bedd5793 | 21 | , LCD16x2B /**< 16x2 LCD panel alternate addressing */ |
lktromp | 1:1349bedd5793 | 22 | , LCD20x2 /**< 20x2 LCD panel */ |
lktromp | 1:1349bedd5793 | 23 | , LCD20x4 /**< 20x4 LCD panel */ |
lktromp | 1:1349bedd5793 | 24 | }; |
lktromp | 1:1349bedd5793 | 25 | |
lktromp | 2:18f6402fd025 | 26 | enum t_charlcd_entry_mode { |
lktromp | 2:18f6402fd025 | 27 | shift_inc = 4, |
lktromp | 2:18f6402fd025 | 28 | noshift_inc = 3, |
lktromp | 2:18f6402fd025 | 29 | shift_dec = 2, |
lktromp | 2:18f6402fd025 | 30 | noshift_dec = 1, |
lktromp | 2:18f6402fd025 | 31 | }; |
lktromp | 2:18f6402fd025 | 32 | |
lktromp | 2:18f6402fd025 | 33 | |
lktromp | 1:1349bedd5793 | 34 | //constructor for 4-bit lcd control |
lktromp | 1:1349bedd5793 | 35 | charLcd(PinName rs, PinName rw, PinName en, PinName d7, PinName d6, PinName d5, PinName d4, LCDType type = LCD16x2); |
lktromp | 1:1349bedd5793 | 36 | //constructor for 8-bit lcd control |
lktromp | 1:1349bedd5793 | 37 | charLcd(PinName rs, PinName rw, PinName en, PinName d7, PinName d6, PinName d5, PinName d4, PinName d3, PinName d2, |
lktromp | 1:1349bedd5793 | 38 | PinName d1, PinName d0, LCDType type = LCD16x2); |
lktromp | 1:1349bedd5793 | 39 | |
lktromp | 1:1349bedd5793 | 40 | void charLcdResetLCD(void); |
lktromp | 1:1349bedd5793 | 41 | void charLcdClear (void); |
lktromp | 1:1349bedd5793 | 42 | void charLcdReturnHome(); |
lktromp | 2:18f6402fd025 | 43 | //void charLcdEntryMode(uint8 increment, uint8 shift); |
lktromp | 2:18f6402fd025 | 44 | void charLcdEntryMode(t_charlcd_entry_mode entrymode); |
lktromp | 1:1349bedd5793 | 45 | void charLcdDisplayOn(uint8 on); |
lktromp | 1:1349bedd5793 | 46 | void charLcdCursor(uint8 cursor, uint8 blink); |
lktromp | 1:1349bedd5793 | 47 | void charLcdShift(uint8 left, uint8 cursor); |
lktromp | 1:1349bedd5793 | 48 | void charLcdFunctionSet(uint8 dots, uint8 lines, uint8 bits); |
lktromp | 1:1349bedd5793 | 49 | |
lktromp | 1:1349bedd5793 | 50 | private: |
lktromp | 1:1349bedd5793 | 51 | void charLcdSetCGRAMaddress(uint8 adr); |
lktromp | 1:1349bedd5793 | 52 | void charLcdSetDDRAMaddress(uint8 address); |
lktromp | 1:1349bedd5793 | 53 | uint8 charLcdReadBusyFlag(); |
lktromp | 1:1349bedd5793 | 54 | void charLcdWriteData(uint8 dat); |
lktromp | 1:1349bedd5793 | 55 | uint8 charLcdReadData(); |
lktromp | 1:1349bedd5793 | 56 | void charLcdSendCommand(uint8 cmd); |
lktromp | 1:1349bedd5793 | 57 | void charLcdWriteByte(uint8 byte); |
lktromp | 1:1349bedd5793 | 58 | |
lktromp | 1:1349bedd5793 | 59 | uint8 LcdStatus; |
lktromp | 1:1349bedd5793 | 60 | uint8 LcdCustomChar[8]; |
lktromp | 1:1349bedd5793 | 61 | |
lktromp | 1:1349bedd5793 | 62 | //LCD Control pins |
lktromp | 1:1349bedd5793 | 63 | DigitalOut cl_rs; |
lktromp | 1:1349bedd5793 | 64 | DigitalOut cl_rw; |
lktromp | 1:1349bedd5793 | 65 | DigitalOut cl_en; |
lktromp | 1:1349bedd5793 | 66 | |
lktromp | 1:1349bedd5793 | 67 | //LCD Data pins |
lktromp | 1:1349bedd5793 | 68 | //DigitalInOut cl_d7; |
lktromp | 1:1349bedd5793 | 69 | //DigitalInOut cl_d6; |
lktromp | 1:1349bedd5793 | 70 | //DigitalInOut cl_d5; |
lktromp | 1:1349bedd5793 | 71 | //DigitalInOut cl_d4; |
lktromp | 1:1349bedd5793 | 72 | //DigitalInOut cl_d3; |
lktromp | 1:1349bedd5793 | 73 | //DigitalInOut cl_d2; |
lktromp | 1:1349bedd5793 | 74 | //DigitalInOut cl_d1; |
lktromp | 1:1349bedd5793 | 75 | //DigitalInOut cl_d0; |
lktromp | 1:1349bedd5793 | 76 | |
lktromp | 1:1349bedd5793 | 77 | //LCD Data port |
lktromp | 1:1349bedd5793 | 78 | //PortInOut charLcdData; |
lktromp | 1:1349bedd5793 | 79 | |
lktromp | 1:1349bedd5793 | 80 | //LCD Data bus |
lktromp | 1:1349bedd5793 | 81 | BusInOut cl_charLcdData; |
lktromp | 2:18f6402fd025 | 82 | |
lktromp | 2:18f6402fd025 | 83 | |
lktromp | 2:18f6402fd025 | 84 | enum t_charlcd_function_set {NO_WIND = 4, NORTH_WIND = 3, SOUTH_WIND = 2, EAST_WIND = 1, WEST_WIND = 0}; |
lktromp | 1:1349bedd5793 | 85 | |
lktromp | 1:1349bedd5793 | 86 | }; |
lktromp | 1:1349bedd5793 | 87 | |
lktromp | 1:1349bedd5793 | 88 | |
lktromp | 1:1349bedd5793 | 89 | |
lktromp | 1:1349bedd5793 | 90 | /**********************************************************************************/ |
lktromp | 1:1349bedd5793 | 91 | #endif //CHARLCD_H |