Baseline for testing
Diff: LCD.cpp
- Revision:
- 1:0f1dffc6103a
- Parent:
- 0:c428f1d60316
- Child:
- 2:73721d9e0056
--- a/LCD.cpp Thu Jul 25 00:43:40 2019 +0000 +++ b/LCD.cpp Thu Sep 12 11:27:29 2019 +0000 @@ -1,5 +1,7 @@ #include "mbed.h" #include "LCD.h" +#include <stdio.h> +#include <ctype.h> LCD::LCD(): LCD_E1(p17), @@ -174,60 +176,61 @@ /************************************************************************/ void LCD::init(void) { - - wait_ms(100); - - LCD_E1 = 0; - LCD_E2 = 0; - - for (int i=0;i<3;i++) { - command1(0x3);//Wake up - command2(0x3); - wait_ms(1); // wait 40 us for most commands + wait_ms(100); + + LCD_E1 = 0; + LCD_E2 = 0; + + for (int i=0; i<3; i++) { + command1(0x3);//Wake up + command2(0x3); + wait_ms(1); // wait 40 us for most commands } command1(0x2);// Set 4 bit mode command2(0x2); wait_ms(1); // wait 40 us for most commands - + LCD_RW = 0; LCD_RS = 0; - - writeCommand(0x28,1,1); //Turn on display - - writeCommand(LCD_setDisplayOff,1,1); //Turn on display + + writeCommand(0x2C,1,1); //Turn on display + + writeCommand(LCD_setDisplayOff,1,1); //Turn on display //writeCommand2(LCD_setDisplayOff); - - writeCommand(LCD_clearDisplay,1,1); //Clear display + + writeCommand(LCD_clearDisplay,1,1); //Clear display //writeCommand2(LCD_clearDisplay); - writeCommand(LCD_entryModeSet,1,1); //Entry mode cursor increment + writeCommand(LCD_entryModeSet,1,1); //Entry mode cursor increment //writeCommand2(LCD_entryModeSet); - - writeCommand(LCD_setDisplayOn,1,1); //Turn on display; no cursor + + writeCommand(LCD_setDisplayOn,1,1); //Turn on display; no cursor //writeCommand2(LCD_setDisplayOn); - - - LCD_E1 = 0; - LCD_E2 = 0; - + + + LCD_E1 = 0; + LCD_E2 = 0; + } void LCD::locate(int row, int column) { - _row = row; + + _row = row; _column = column; + } +void LCD::cls(){ +} void LCD::clear(int e1, int e2 ){ - + writeCommand(LCD_clearDisplay,e1,e2); _row = 0; _column = 0; - - // for debugging, write spaces to each cell - memset( displayBuffer, 0x85, sizeof(displayBuffer)); + } @@ -255,7 +258,7 @@ //printf("isBusy1? = 0x%02x 0x%02x \n\r", lo,hi ); - if ((0x8 & input)); // wait until display is ready + if ((0x8 & input)) // wait until display is ready { result = 1; } @@ -286,7 +289,7 @@ //printf("isBusy1? = 0x%02x \n\r", input ); - if ((0x8 & input)); // wait until display is ready + if ((0x8 & input)) // wait until display is ready { result = 1; } @@ -321,7 +324,7 @@ //printf("0x%02x \n\r", input ); - if ((0x8 & input)); // wait until display is ready + if ((0x8 & input)) // wait until display is ready { result = 1; } @@ -341,7 +344,7 @@ __nop(); LCD_E2 = 0; - if ((0x8 & input)); // wait until display is ready + if ((0x8 & input)) // wait until display is ready { result = 1; } @@ -425,11 +428,9 @@ char buffer[128]; va_list argptr; va_start(argptr, message); - - vsprintf( buffer, message, argptr); - write (buffer); - - va_end(argptr); + vsprintf( buffer, message, argptr); + write (buffer); + va_end(argptr); } void LCD::write(const char* text) { @@ -437,11 +438,21 @@ //_column = 0; int characterAmount =0; - for(int i = 0; text[i] != '\0'; i++) + for(int i = 0; text[i] != '\0'; i++) { + if (!isprint(text[i])) { fprintf(stdout,"^%02x ", text[i]);} characterAmount++; + } + + if (characterAmount > 40 - _column ) { + fprintf(stdout,"OVERFLOW+(%d+%d) %d: [%s] \n\r",_row, _column, characterAmount, text); + characterAmount = 40 - _column ; + } for (int i = 0; i < characterAmount && i < rows() * columns(); i++){ - character(_row, _column, text[i]); + if (isprint(text[i])) + character(_row, _column, text[i]); + + wait_us(1); } } @@ -509,12 +520,7 @@ void LCD::character(int row, int column, char c) { uint8_t a = address(row, column); - - // ------------------------------------ - // write to internal buffer - // ------------------------------------ - displayBuffer [row][column] = c; - + if(row<2){ writeCommand(a,1,0); writeChar(c,1,0); @@ -557,19 +563,3 @@ writeCommand(LCD_setDisplayOn,1,1); } } - -void LCD::dump(Serial * pc) { - - fprintf(stdout,"\n\r"); - fprintf(stdout,"----------------------------------------------\n\r"); - for (int i=0;i<rows();i++) - { - fprintf(stdout,"[%d]",i); - for (int j=0;j<columns();j++) - { - fprintf(stdout,"%c",displayBuffer[i][j]); - } - fprintf(stdout,"\n\r"); - } - fprintf(stdout,"\n\r"); -} \ No newline at end of file