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.
LCD.cpp@9:f8c8f0b11893, 2018-11-07 (annotated)
- Committer:
- BenRJG
- Date:
- Wed Nov 07 17:44:59 2018 +0000
- Revision:
- 9:f8c8f0b11893
- Parent:
- 8:e34e23edfc84
- Child:
- 10:4f8b0c09bd2c
Removed unneeded code from LCD class to simplify
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| BenRJG | 0:f8fe58d43763 | 1 | #include "LCD.hpp" |
| Jonathan738 | 6:f3d1ab8a9e99 | 2 | #include "DataTypes.hpp" |
| BenRJG | 0:f8fe58d43763 | 3 | |
| BenRJG | 0:f8fe58d43763 | 4 | void LCD::INIT() |
| BenRJG | 0:f8fe58d43763 | 5 | { |
| BenRJG | 0:f8fe58d43763 | 6 | //All lines default low |
| BenRJG | 0:f8fe58d43763 | 7 | _LCD_RS = 0; |
| BenRJG | 0:f8fe58d43763 | 8 | _LCD_E = 0; |
| BenRJG | 0:f8fe58d43763 | 9 | |
| BenRJG | 0:f8fe58d43763 | 10 | //LCD Initialise |
| BenRJG | 0:f8fe58d43763 | 11 | wait_ms(45); //Wait for LCD startup |
| BenRJG | 8:e34e23edfc84 | 12 | /*Step 1*/ |
| BenRJG | 8:e34e23edfc84 | 13 | wait_us(3000); //Wait whilst LCD busy |
| BenRJG | 8:e34e23edfc84 | 14 | _LCD_RS = control; |
| BenRJG | 8:e34e23edfc84 | 15 | LCD_DDRAM = 0; //Clear data line |
| BenRJG | 8:e34e23edfc84 | 16 | LCD_DDRAM = DDRAM>>4; //Put data on line |
| BenRJG | 8:e34e23edfc84 | 17 | LCD_strobe(); |
| BenRJG | 4:bb7a78619678 | 18 | |
| BenRJG | 0:f8fe58d43763 | 19 | /*Step 2*/ cmdLCD(DDRAM|lines2); //Function Set 0x20|0x08 = 0x28 |
| BenRJG | 0:f8fe58d43763 | 20 | /*Step 3*/ cmdLCD(DDRAM|lines2); //Function Set 0x20|0x08 = 0x28 |
| BenRJG | 0:f8fe58d43763 | 21 | /*Step 4*/ cmdLCD(DISPLAY|on); //Display Control 0x08|0x0x04 = 0x0c |
| BenRJG | 0:f8fe58d43763 | 22 | /*Step 5*/ cmdLCD(CLEAR); //Clear Display 0x01 |
| BenRJG | 0:f8fe58d43763 | 23 | /*Step 6*/ cmdLCD(ENTRYMODE|I); //Set entry mode 0x04|0x02 = 0x06 |
| BenRJG | 0:f8fe58d43763 | 24 | |
| BenRJG | 1:1f9ea120f8a9 | 25 | cmdLCD(0x20); //return home location |
| BenRJG | 0:f8fe58d43763 | 26 | } |
| BenRJG | 0:f8fe58d43763 | 27 | |
| BenRJG | 0:f8fe58d43763 | 28 | void LCD::clear() |
| BenRJG | 0:f8fe58d43763 | 29 | { |
| BenRJG | 0:f8fe58d43763 | 30 | cmdLCD(CLEAR); |
| BenRJG | 0:f8fe58d43763 | 31 | } |
| BenRJG | 0:f8fe58d43763 | 32 | |
| BenRJG | 9:f8c8f0b11893 | 33 | void LCD::display(BYTE* str, UINT_16 location) |
| BenRJG | 0:f8fe58d43763 | 34 | { |
| BenRJG | 9:f8c8f0b11893 | 35 | cmdLCD(0x80|location); |
| BenRJG | 9:f8c8f0b11893 | 36 | U_BYTE p = 0; |
| BenRJG | 9:f8c8f0b11893 | 37 | while((str[p]!= NULL)&&(p<16)) |
| BenRJG | 0:f8fe58d43763 | 38 | { |
| BenRJG | 9:f8c8f0b11893 | 39 | putt(str[p]); |
| BenRJG | 9:f8c8f0b11893 | 40 | p++; |
| BenRJG | 0:f8fe58d43763 | 41 | } |
| BenRJG | 0:f8fe58d43763 | 42 | } |
| BenRJG | 0:f8fe58d43763 | 43 | |
| BenRJG | 8:e34e23edfc84 | 44 | void LCD::putt(U_BYTE c) |
| BenRJG | 0:f8fe58d43763 | 45 | { |
| BenRJG | 4:bb7a78619678 | 46 | wait_us(3000); |
| BenRJG | 0:f8fe58d43763 | 47 | _LCD_RS = text; |
| BenRJG | 0:f8fe58d43763 | 48 | set_LCD_data(c); |
| BenRJG | 0:f8fe58d43763 | 49 | } |
| BenRJG | 0:f8fe58d43763 | 50 | |
| Jonathan738 | 6:f3d1ab8a9e99 | 51 | void LCD::cmdLCD(U_BYTE cmd) |
| BenRJG | 0:f8fe58d43763 | 52 | { |
| BenRJG | 4:bb7a78619678 | 53 | wait_us(3000); //Wait whilst LCD busy |
| BenRJG | 0:f8fe58d43763 | 54 | _LCD_RS = control; |
| BenRJG | 0:f8fe58d43763 | 55 | set_LCD_data(cmd); //set data on bus |
| BenRJG | 0:f8fe58d43763 | 56 | } |
| BenRJG | 0:f8fe58d43763 | 57 | |
| BenRJG | 0:f8fe58d43763 | 58 | void LCD::LCD_strobe(void) |
| BenRJG | 0:f8fe58d43763 | 59 | { |
| BenRJG | 0:f8fe58d43763 | 60 | wait_us(10); |
| BenRJG | 0:f8fe58d43763 | 61 | _LCD_E = 1; |
| BenRJG | 0:f8fe58d43763 | 62 | wait_us(10); |
| BenRJG | 0:f8fe58d43763 | 63 | _LCD_E = 0; |
| BenRJG | 0:f8fe58d43763 | 64 | } |
| BenRJG | 0:f8fe58d43763 | 65 | |
| Jonathan738 | 6:f3d1ab8a9e99 | 66 | void LCD::set_LCD_data(U_BYTE d) |
| BenRJG | 0:f8fe58d43763 | 67 | { |
| BenRJG | 0:f8fe58d43763 | 68 | // Send upper 4 bits then lower for bits |
| BenRJG | 0:f8fe58d43763 | 69 | // e.g. 11110000 => 1111 -> 0000 |
| BenRJG | 0:f8fe58d43763 | 70 | |
| BenRJG | 0:f8fe58d43763 | 71 | LCD_DDRAM = 0; //Clear data line |
| BenRJG | 0:f8fe58d43763 | 72 | LCD_DDRAM = d>>4; //Put data on line |
| BenRJG | 0:f8fe58d43763 | 73 | LCD_strobe(); |
| BenRJG | 4:bb7a78619678 | 74 | wait_us(1000); |
| BenRJG | 0:f8fe58d43763 | 75 | LCD_DDRAM = 0; //Clear |
| BenRJG | 0:f8fe58d43763 | 76 | LCD_DDRAM = d; //Put remaining data on line |
| BenRJG | 0:f8fe58d43763 | 77 | LCD_strobe(); |
| BenRJG | 0:f8fe58d43763 | 78 | } |