Electronics > Microcontrollers

ILI9341 TFT LCD Vertical scrolling problem.

(1/1)

slow_rider:
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 line
if (LCDTextData.cursorX >= LCD_W)
{
LCDTextData.cursorY += LCDTextData.textSize * 8;
LCDTextData.cursorX = 0;
}
}

// If reached last line, scroll 1 line
if (LCDTextData.cursorY > LCD_H)
{
LCDScrollLine();
LCDTextData.cursorY = LCD_H - LCDTextData.textSize * 8;
}
}
--- End code ---

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);
}
--- End code ---

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);
}
--- End code ---

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)?

newbrain:

--- Quote from: slow_rider on February 26, 2018, 12:02:26 am ---The part with skipping to the next line when the line is filled works as should.

--- End quote ---
Good. :-+ , I see nothing wrong with that code, at a first glance.


--- Quote from: slow_rider on February 26, 2018, 12:02:26 am ---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)?

--- End quote ---
The 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 the datasheet.

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 after  :-//

The 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.

slow_rider:
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);
}
--- End code ---

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 line
if (LCDTextData.cursorX >= LCD_W)
{
LCDTextData.cursorY += LCDTextData.textSize * 8;
LCDTextData.cursorX = 0;
}
}

// If reached last line, scroll 1 line
if (LCDTextData.cursorY > LCD_H)
{
LCDScrollLine();
LCDTextData.cursorY = LCD_H;
}
}
--- End code ---

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod