Troubleshooting

Committer:
BenRJG
Date:
Fri Nov 09 14:24:39 2018 +0000
Revision:
17:b7cd66c5f845
Parent:
15:f8649829dff9
export to keil

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BenRJG 0:f8fe58d43763 1 #include "LCD.hpp"
Jonathan738 6:f3d1ab8a9e99 2 #include "DataTypes.hpp"
BenRJG 0:f8fe58d43763 3
BenRJG 15:f8649829dff9 4 //LCD data sheet: https://www.rapidonline.com/pdf/57-2224.pdf
BenRJG 15:f8649829dff9 5
BenRJG 0:f8fe58d43763 6 void LCD::INIT()
BenRJG 0:f8fe58d43763 7 {
BenRJG 0:f8fe58d43763 8 //All lines default low
BenRJG 0:f8fe58d43763 9 _LCD_RS = 0;
BenRJG 0:f8fe58d43763 10 _LCD_E = 0;
BenRJG 0:f8fe58d43763 11
BenRJG 0:f8fe58d43763 12 //LCD Initialise
BenRJG 0:f8fe58d43763 13 wait_ms(45); //Wait for LCD startup
BenRJG 8:e34e23edfc84 14 /*Step 1*/
BenRJG 10:4f8b0c09bd2c 15 wait_us(40); //Wait whilst LCD busy
BenRJG 8:e34e23edfc84 16 _LCD_RS = control;
BenRJG 8:e34e23edfc84 17 LCD_DDRAM = 0; //Clear data line
BenRJG 10:4f8b0c09bd2c 18 LCD_DDRAM = (FUNC|bit8)>>4; //Put data on line
BenRJG 8:e34e23edfc84 19 LCD_strobe();
BenRJG 4:bb7a78619678 20
BenRJG 10:4f8b0c09bd2c 21 /*Step 2*/ cmdLCD(FUNC|lines2); //Function Set 0x20|0x08 = 0x28
BenRJG 10:4f8b0c09bd2c 22 /*Step 3*/ cmdLCD(FUNC|lines2); //Function Set 0x20|0x08 = 0x28
BenRJG 0:f8fe58d43763 23 /*Step 4*/ cmdLCD(DISPLAY|on); //Display Control 0x08|0x0x04 = 0x0c
BenRJG 0:f8fe58d43763 24 /*Step 5*/ cmdLCD(CLEAR); //Clear Display 0x01
BenRJG 0:f8fe58d43763 25 /*Step 6*/ cmdLCD(ENTRYMODE|I); //Set entry mode 0x04|0x02 = 0x06
BenRJG 0:f8fe58d43763 26
BenRJG 10:4f8b0c09bd2c 27 cmdLCD(RETURN); //return home location
BenRJG 0:f8fe58d43763 28 }
BenRJG 0:f8fe58d43763 29
BenRJG 0:f8fe58d43763 30 void LCD::clear()
BenRJG 0:f8fe58d43763 31 {
BenRJG 0:f8fe58d43763 32 cmdLCD(CLEAR);
BenRJG 0:f8fe58d43763 33 }
BenRJG 0:f8fe58d43763 34
BenRJG 9:f8c8f0b11893 35 void LCD::display(BYTE* str, UINT_16 location)
BenRJG 0:f8fe58d43763 36 {
BenRJG 12:edf31d0a61f0 37 if(location != NULL)
BenRJG 12:edf31d0a61f0 38 {
BenRJG 15:f8649829dff9 39 pos(location);
BenRJG 12:edf31d0a61f0 40 }
BenRJG 9:f8c8f0b11893 41 U_BYTE p = 0;
BenRJG 9:f8c8f0b11893 42 while((str[p]!= NULL)&&(p<16))
BenRJG 0:f8fe58d43763 43 {
BenRJG 9:f8c8f0b11893 44 putt(str[p]);
BenRJG 9:f8c8f0b11893 45 p++;
BenRJG 0:f8fe58d43763 46 }
BenRJG 0:f8fe58d43763 47 }
BenRJG 0:f8fe58d43763 48
BenRJG 15:f8649829dff9 49 void LCD::pos(UINT_16 location)
BenRJG 15:f8649829dff9 50 {
BenRJG 15:f8649829dff9 51 cmdLCD(0x80|location);
BenRJG 15:f8649829dff9 52 }
BenRJG 15:f8649829dff9 53
BenRJG 8:e34e23edfc84 54 void LCD::putt(U_BYTE c)
BenRJG 0:f8fe58d43763 55 {
BenRJG 4:bb7a78619678 56 wait_us(3000);
BenRJG 0:f8fe58d43763 57 _LCD_RS = text;
BenRJG 0:f8fe58d43763 58 set_LCD_data(c);
BenRJG 0:f8fe58d43763 59 }
BenRJG 0:f8fe58d43763 60
Jonathan738 6:f3d1ab8a9e99 61 void LCD::cmdLCD(U_BYTE cmd)
BenRJG 0:f8fe58d43763 62 {
BenRJG 4:bb7a78619678 63 wait_us(3000); //Wait whilst LCD busy
BenRJG 0:f8fe58d43763 64 _LCD_RS = control;
BenRJG 0:f8fe58d43763 65 set_LCD_data(cmd); //set data on bus
BenRJG 0:f8fe58d43763 66 }
BenRJG 0:f8fe58d43763 67
BenRJG 0:f8fe58d43763 68 void LCD::LCD_strobe(void)
BenRJG 0:f8fe58d43763 69 {
BenRJG 0:f8fe58d43763 70 wait_us(10);
BenRJG 0:f8fe58d43763 71 _LCD_E = 1;
BenRJG 0:f8fe58d43763 72 wait_us(10);
BenRJG 0:f8fe58d43763 73 _LCD_E = 0;
BenRJG 0:f8fe58d43763 74 }
BenRJG 0:f8fe58d43763 75
Jonathan738 6:f3d1ab8a9e99 76 void LCD::set_LCD_data(U_BYTE d)
BenRJG 0:f8fe58d43763 77 {
BenRJG 0:f8fe58d43763 78 // Send upper 4 bits then lower for bits
BenRJG 0:f8fe58d43763 79 // e.g. 11110000 => 1111 -> 0000
BenRJG 0:f8fe58d43763 80
BenRJG 0:f8fe58d43763 81 LCD_DDRAM = 0; //Clear data line
BenRJG 0:f8fe58d43763 82 LCD_DDRAM = d>>4; //Put data on line
BenRJG 0:f8fe58d43763 83 LCD_strobe();
BenRJG 4:bb7a78619678 84 wait_us(1000);
BenRJG 0:f8fe58d43763 85 LCD_DDRAM = 0; //Clear
BenRJG 0:f8fe58d43763 86 LCD_DDRAM = d; //Put remaining data on line
BenRJG 0:f8fe58d43763 87 LCD_strobe();
BenRJG 15:f8649829dff9 88 }
BenRJG 15:f8649829dff9 89
BenRJG 15:f8649829dff9 90 void LCD::enableCursor()
BenRJG 15:f8649829dff9 91 {
BenRJG 15:f8649829dff9 92 cmdLCD(DISPLAY|on|cursor);
BenRJG 15:f8649829dff9 93 }
BenRJG 15:f8649829dff9 94
BenRJG 15:f8649829dff9 95 void LCD::disableCursor()
BenRJG 15:f8649829dff9 96 {
BenRJG 15:f8649829dff9 97 cmdLCD(DISPLAY|on);
BenRJG 0:f8fe58d43763 98 }