11 years, 4 months ago.

16x4 PowerTip LCD display?

I've recently read up on LCD displays, memory addressing etc and looked at the cplusplus web site for code help but am a little stuck in trying to understand what is currently happening. I am printing out to a 16 character x 4 line LCD Powertip PC 1604A display Here is my simple code

int main()
{
    while(1) {
        lcd.cls();
        wait(0.50);
        lcd.printf("Start PowerTip\n");
        wait(2.0);
        lcd.printf("Integer %d\n" ,1959);
        wait(2.0);
        lcd.printf("Float %f\n" ,1.732);
        wait(2.0);
        lcd.printf("Characters %c, %c\n" ,'a', 65);
        wait(2.0);
        
    }
}

What happens is on lines 3 and 4 the first characters only start at the 5th line character not the 1st line character. The display looks like this, I've used a code example to paginate the display output on here only.

Line 1:Start PowerTip
Line 2:Integer 1959
Line 3:    Float 1.7320
Line 4:    Characters a,

Any help greatly appreciated as always. Thank you.

2 Answers

11 years, 4 months ago.

I think the thing I'm missing is Wim's answer to my previous Forum questions and that is to 'locate' the printf output to the first character so I suppose really my question is why? Can someone offer an explanation please, and how to use the locate instruction as I can't find a simple reference.

Many thanks again.

11 years, 4 months ago.

You are using \n at the end of each line. The lcd lib will try to re locate the cursor to the correct displayline and column. The fact that it seems to end up 4 positions too far to the right means that you may have configured the lcd as 4x20 rather than 4x16. Check the declaration parameters.

I think I've found the problem here thank you Wim in the TextLCD.cpp file

int TextLCD::_putc(int value) {
    if (value == '\n') {
        _column = 0;
        _row++;
        if (_row >= rows()) {
            _row = 0;
        }
    } else {
        character(_column, _row, value);
        _column++;
        if (_column >= columns()) {
            _column = 0;
            _row++;
            if (_row >= rows()) {
                _row = 0;
            }
        }
    }

case2: and case 3: addresses are probably not correct?

posted by Derek Calland 17 Jan 2013