1
\$\begingroup\$

We are using LCD and Keypad in our MCU and I was wondering how do i initialize my LCD so that every time there is a key press the display will automatically shift right and fill up the LCD as more characters are inputted, at first i though of doing this by assigning the individual address for each input i.e on first input it will be placed on 0x80 as it is the address for the first character in the LCD and so on.

but then i was informed that i can do this by simply changing the initialization of the LCD.

but i am not sure as to what part of the initialization do i need to change. i do realize this is basic but im still new to this.

here is my initialization code in C:

instCtrl(0x28); //function set: 4bit; dual-line
    instCtrl(0x08); //display off
    instCtrl(0x01); //display clear
    instCtrl(0x06); //entry mode: increment; shift off
    instCtrl(0x0F); //display on; cursor on; blink off

void instCtrl(unsigned char inst)
{
    int x;

    IO_PDR2.byte = inst>>4; //shift right
    IO_PDR2.bit.P24 = 0;    //set RS to 0 (instruction register)
    IO_PDR5.bit.P53 = 0;    //set RW to 0 (write mode)
    IO_PDR5.bit.P52 = 1;    //set E to 1 (initial state)
    delay(8000);            //delay
    IO_PDR5.bit.P52 = 0;    //set E to 0 (H-L: final state) 
    IO_PDR2.byte = inst;    //transfer lower 4bit
    IO_PDR2.bit.P24 = 0;    //set RS to 0 (instruction register)
    IO_PDR5.bit.P52 = 1;    //set E to 1 (initial state)
    delay(8000);            //delay
    IO_PDR5.bit.P52 = 0;    //set E to 0 (H-L: final state) 

}
\$\endgroup\$
3
  • \$\begingroup\$ Don't depend on the LCD controller's memory for this; it is limited and will run out when you don't need it to. Do it in the MCU. \$\endgroup\$ Jan 14, 2015 at 14:32
  • \$\begingroup\$ @IgnacioVazquez-Abrams how do you suggest doing it in the mcu? thank you \$\endgroup\$ Jan 14, 2015 at 23:59
  • \$\begingroup\$ Double buffer it. Store what the display already says and what it should say, and switch back and forth updating each time. \$\endgroup\$ Jan 15, 2015 at 0:21

1 Answer 1

1
\$\begingroup\$

The normal method of using the HD44780 type lcd is to shift the cursor to the right after every character entered.

Instruction     RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
Entry mode set  0   0   0   0   0   0   0   1   I/D S

Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write.

Bit Settings
I/D 0 = Decrement cursor position   1 = Increment cursor position
S   0 = No display shift            1 = Display shift

Your entry of 0x06 (0b110) sets it to Cursor Shift Right (Increment). If you change it to 0x07 (0b111) it should set it to shift the display right while the cursor stays in the same spot. I believe this is what you want (Characters fill in left to right). So like 0, 10, a10, etc. Shift left (0x05) and it should be 0, 01, 01a, etc.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.