ILI9341 TFT LCD Vertical scrolling problem. - Page 1
Forum section: electronics / general

author: slow_rider
author_rank: Regular Contributor
timestamp: February 26, 2018, 12:02:26 am
content: I have the following code to write a character to the LCD:Code:void LCDGWriteChar(char c){if (c == '\n') // New line{LCDTextData.cursorY += LCDTextData.textSize * 8;LCDTextData.cursorX = 0;}else if (c != '\r') // Not cartridge return = normal char{LCDGDrawChar(LCDTextData.cursorX, LCDTextData.cursorY, c, LCDTextData.textColor, LCDTextData.textBGColor, LCDTextData.textSize);LCDTextData.cursorX += LCDTextData.textSize * 6;// If end of line, skip to the next lineif (LCDTextData.cursorX >= LCD_W){LCDTextData.cursorY += LCDTextData.textSize * 8;LCDTextData.cursorX = 0;}}// If reached last line, scroll 1 lineif (LCDTextData.cursorY > LCD_H){LCDScrollLine();LCDTextData.cursorY = LCD_H - LCDTextData.textSize * 8;}}After the LCD init I call this:Code:void LCDScrollInit(void){LCDWriteCommand(ILI9341_VSCRDEF);LCDWriteData(0);LCDWriteData(0);LCDWriteData(LCD_H >> 8);LCDWriteData((uint8_t)LCD_H);LCDWriteData(0);LCDWriteData(0);}And from within the draw function, this is being called:Code:void LCDScrollLine(void){uint8_t tempLines = LCDTextData.textSize * 8;LCDWriteCommand(ILI9341_VSCRSADD);LCDWriteData(tempLines >> 8);LCDWriteData((uint8_t)tempLines);}The part with skipping to the next line when the line is filled works as should. I have problems with the vertical scrolling. After running this it seems that the screen will "roll" just once and after that the text is being written 1 line above the edge of the LCD.- Am I using the scroll functionality from the LCD controller as should?- Why LCDTextData.cursorY = LCD_H - LCDTextData.textSize * 8; does not go a single line up, but two (and stays there)?

author: newbrain
author_rank: Super Contributor
timestamp: February 26, 2018, 01:58:29 pm
content: Quote from: slow_rider on February 26, 2018, 12:02:26 amGood., I see nothing wrong with that code, at a first glance.Quote from: slow_rider on February 26, 2018, 12:02:26 amThe scrolling functionality does not actually "scroll" the screen (as in moving memory contents up or down) but just tells the controller to start start displaying at a specific memory address (line), see the pictures in chapter 9.2.2, page 205 of thedatasheet.The display will wrap up ('roll' as you say), but invoking the command more than once with the same parameter will not change the outcome.So your use is correct, but probably not what you're afterThe answer to last question (if I got correctly, but maybe some drawing would have helped) might be easy: the code backs up the cursor one line, but the last line is moved up by the scroll operation, so I expect it to point not to the line at the lower edge of the display, but the one above it.

author: slow_rider
author_rank: Regular Contributor
timestamp: February 28, 2018, 04:59:23 pm
content: OK, I think I get it... I have updated my scrolling function so that the value will increase according to the font size (vertical length).Code:void LCDScrollLine(void){static uint16_t linesShift = 0;linesShift += LCDTextData.textSize * 8;if (linesShift > LCD_H)linesShift %= LCD_H;LCDWriteCommand(ILI9341_VSCRSADD);LCDWriteData(linesShift >> 8);LCDWriteData((uint8_t)linesShift);}The only thing I don't like about the code is that I have to use a variable to hold the value.In addition to this, when I've written till the lower end of the LCD, I don't need to change the address for the next write as I scroll the screen. So it needs to be "stuch" at whatever the vertical length is.Code:void LCDGWriteChar(char c){if (c == '\n') // New line{LCDTextData.cursorY += LCDTextData.textSize * 8;LCDTextData.cursorX = 0;}else if (c != '\r') // Not cartridge return = normal char{LCDGDrawChar(LCDTextData.cursorX, LCDTextData.cursorY, c, LCDTextData.textColor, LCDTextData.textBGColor, LCDTextData.textSize);LCDTextData.cursorX += LCDTextData.textSize * 6;// If end of line, skip to the next lineif (LCDTextData.cursorX >= LCD_W){LCDTextData.cursorY += LCDTextData.textSize * 8;LCDTextData.cursorX = 0;}}// If reached last line, scroll 1 lineif (LCDTextData.cursorY > LCD_H){LCDScrollLine();LCDTextData.cursorY = LCD_H;}}