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@12:edf31d0a61f0, 2018-11-08 (annotated)
- Committer:
- BenRJG
- Date:
- Thu Nov 08 21:43:49 2018 +0000
- Revision:
- 12:edf31d0a61f0
- Parent:
- 10:4f8b0c09bd2c
- Child:
- 15:f8649829dff9
Created both pages within class; Ability to modify temp,light & pressure; Added S_BYTE type
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 | 10:4f8b0c09bd2c | 13 | wait_us(40); //Wait whilst LCD busy |
| BenRJG | 8:e34e23edfc84 | 14 | _LCD_RS = control; |
| BenRJG | 8:e34e23edfc84 | 15 | LCD_DDRAM = 0; //Clear data line |
| BenRJG | 10:4f8b0c09bd2c | 16 | LCD_DDRAM = (FUNC|bit8)>>4; //Put data on line |
| BenRJG | 8:e34e23edfc84 | 17 | LCD_strobe(); |
| BenRJG | 4:bb7a78619678 | 18 | |
| BenRJG | 10:4f8b0c09bd2c | 19 | /*Step 2*/ cmdLCD(FUNC|lines2); //Function Set 0x20|0x08 = 0x28 |
| BenRJG | 10:4f8b0c09bd2c | 20 | /*Step 3*/ cmdLCD(FUNC|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 | 10:4f8b0c09bd2c | 25 | cmdLCD(RETURN); //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 | 12:edf31d0a61f0 | 35 | if(location != NULL) |
| BenRJG | 12:edf31d0a61f0 | 36 | { |
| BenRJG | 12:edf31d0a61f0 | 37 | cmdLCD(0x80|location); |
| BenRJG | 12:edf31d0a61f0 | 38 | } |
| BenRJG | 9:f8c8f0b11893 | 39 | U_BYTE p = 0; |
| BenRJG | 9:f8c8f0b11893 | 40 | while((str[p]!= NULL)&&(p<16)) |
| BenRJG | 0:f8fe58d43763 | 41 | { |
| BenRJG | 9:f8c8f0b11893 | 42 | putt(str[p]); |
| BenRJG | 9:f8c8f0b11893 | 43 | p++; |
| BenRJG | 0:f8fe58d43763 | 44 | } |
| BenRJG | 0:f8fe58d43763 | 45 | } |
| BenRJG | 0:f8fe58d43763 | 46 | |
| BenRJG | 8:e34e23edfc84 | 47 | void LCD::putt(U_BYTE c) |
| BenRJG | 0:f8fe58d43763 | 48 | { |
| BenRJG | 4:bb7a78619678 | 49 | wait_us(3000); |
| BenRJG | 0:f8fe58d43763 | 50 | _LCD_RS = text; |
| BenRJG | 0:f8fe58d43763 | 51 | set_LCD_data(c); |
| BenRJG | 0:f8fe58d43763 | 52 | } |
| BenRJG | 0:f8fe58d43763 | 53 | |
| Jonathan738 | 6:f3d1ab8a9e99 | 54 | void LCD::cmdLCD(U_BYTE cmd) |
| BenRJG | 0:f8fe58d43763 | 55 | { |
| BenRJG | 4:bb7a78619678 | 56 | wait_us(3000); //Wait whilst LCD busy |
| BenRJG | 0:f8fe58d43763 | 57 | _LCD_RS = control; |
| BenRJG | 0:f8fe58d43763 | 58 | set_LCD_data(cmd); //set data on bus |
| BenRJG | 0:f8fe58d43763 | 59 | } |
| BenRJG | 0:f8fe58d43763 | 60 | |
| BenRJG | 0:f8fe58d43763 | 61 | void LCD::LCD_strobe(void) |
| BenRJG | 0:f8fe58d43763 | 62 | { |
| BenRJG | 0:f8fe58d43763 | 63 | wait_us(10); |
| BenRJG | 0:f8fe58d43763 | 64 | _LCD_E = 1; |
| BenRJG | 0:f8fe58d43763 | 65 | wait_us(10); |
| BenRJG | 0:f8fe58d43763 | 66 | _LCD_E = 0; |
| BenRJG | 0:f8fe58d43763 | 67 | } |
| BenRJG | 0:f8fe58d43763 | 68 | |
| Jonathan738 | 6:f3d1ab8a9e99 | 69 | void LCD::set_LCD_data(U_BYTE d) |
| BenRJG | 0:f8fe58d43763 | 70 | { |
| BenRJG | 0:f8fe58d43763 | 71 | // Send upper 4 bits then lower for bits |
| BenRJG | 0:f8fe58d43763 | 72 | // e.g. 11110000 => 1111 -> 0000 |
| BenRJG | 0:f8fe58d43763 | 73 | |
| BenRJG | 0:f8fe58d43763 | 74 | LCD_DDRAM = 0; //Clear data line |
| BenRJG | 0:f8fe58d43763 | 75 | LCD_DDRAM = d>>4; //Put data on line |
| BenRJG | 0:f8fe58d43763 | 76 | LCD_strobe(); |
| BenRJG | 4:bb7a78619678 | 77 | wait_us(1000); |
| BenRJG | 0:f8fe58d43763 | 78 | LCD_DDRAM = 0; //Clear |
| BenRJG | 0:f8fe58d43763 | 79 | LCD_DDRAM = d; //Put remaining data on line |
| BenRJG | 0:f8fe58d43763 | 80 | LCD_strobe(); |
| BenRJG | 0:f8fe58d43763 | 81 | } |