LCD 2x16 problem

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Iam using a lcd 2x16 (HD44780) with atmega32.
I send data from pc to atmega32 through ft232r
and the mcu prints data to lcd.
all works fine but the problem is that the lcd is comport like 2x40.
It start from 0,0 (up, left corner) and after 40 characters continue to 2nd line. also in 2nd line and
after 40 chars it change line again to 1st.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Working as designed. The controller thinks all lcds have 2 lines of 40 chars. You can "position the cursor" to char position 0, write 16chars, then "position the cursor" to char position 40, send the next 16 chars.
The position the cursor routine sets the address to write to in the ram array.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i use the lcd_putc()
and i think this part of code, do this automatically

void lcd_putc(char c)
{
    uint8_t pos;


    pos = lcd_waitbusy();   // read busy-flag and address counter
    if (c=='\n')
    {
        lcd_newline(pos);
    }
    else
    {
#if LCD_WRAP_LINES==1
#if LCD_LINES==1
        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
        }
#elif LCD_LINES==2
        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
        }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ){
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
        }
#elif LCD_LINES==4
        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
        }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE3,0);
        }else if ( pos == LCD_START_LINE3+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE4,0);
        }else if ( pos == LCD_START_LINE4+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
        }
#endif
        lcd_waitbusy();
#endif
        lcd_write(c, 1);
    }

}/* lcd_putc */

else, to do that you say, i will need to have an extra variable where shows the number of chars they having printing in lcd.

and if i print a whole string, it must be exist
an even more method to count the number of chars (of string) and adding this number to "number_of_printing_chars" variable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can imagine that a 4 line display would be easy to read if the text scrolled up line by line. A two line display is very usable just by positioning the cursor to the beginning of either line and sending 16 chars.
But if I had to write a function that copied 4 lines of 20 chars from a text buffer to the lcd and handled cr and lf and scrolled the bottom lines up a line when it gets a lf on line 3, I bet I could do it. How bout you?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

with positioning the cursor to the beginning and
send 16 chars, writing char by char is easy!
but, what about when the cursor is in 0,13 and
i printing a "Hello" with

extern void lcd_puts(const char *s);

???

this fuction calls the

void lcd_putc(char c)

in which there's a control of lcd lines with "if" fuctions (code in my above post)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this isnt the control for changing line every 16 chars?

#elif LCD_LINES==2
if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);
}else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ){
lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have LCD_WRAP_LINES defined to 0 in your lcd.h. Notice the

#if LCD_WRAP_LINES==1 
  .
  .
  .

that in your current configuration disables all handling of "automatic wrapping" in lcd_putc().

Please READ through EVERY line of your lcd.h and INVESTIGATE where and how it is used. Your editor most likely have excellent functionality for locating every occurrence of a specific text in your source files.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
You have LCD_WRAP_LINES defined to 0 in your lcd.h. Notice the

#if LCD_WRAP_LINES==1 
  .
  .
  .

that in your current configuration disables all handling of "automatic wrapping" in lcd_putc().

Please READ through EVERY line of your lcd.h and INVESTIGATE where and how it is used. Your editor most likely have excellent functionality for locating every occurrence of a specific text in your source files.


i'm not noticed that!
thank you!

now, i make a "backspace" action

					if (lcdchar == 8)
					{	
						lcd_command(LCD_MOVE_CURSOR_LEFT);				
						lcd_puts(" ");
						lcd_command(LCD_MOVE_CURSOR_LEFT);
					}

and the previews problem are appears when i typing backspace button.

anyway! thank you very much for help!