Write data to LCD & Flow chart

atferrari

Joined Jan 6, 2004
3,623
Hi, there!

I'm now Drawing the flow chart for LCD 16*2. The file is attached that write data to LCD commands link

Please find flow chart in attachment. Is this a correct idea?
Do you plan to draw a flowchart for every protocol out there? There are hundreds. Can't you be critical enough with your own work?

This particular case has examples in many places, promoted by manufacturers.

Are you going to make your hands dirty implementing this in real hardware or it is just theoretical paperwork?

I created some 4 years ago a nice diagram for the PS/2 protocol (dare to say the best I ever seen in the Web), the respective flow chart but also taught my micro to dutifully read a mouse by writing real code.

Whatever I code for a micro is preceded by a flowchart with detail enough that writing the corresponding code is just clerical work.
 

jpanhalt

Joined Jan 18, 2008
8,437
That datasheet does not show an 8-bit interface. However, the KS0066 controlled it uses is compatible with the HD44780 controller. Unless you plan on using that specific device, I think you will find the documentation for the Hitachi controller more common and easier to follow.
 

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
Do you plan to draw a flowchart for every protocol out there? There are hundreds. Can't you be critical enough with your own work? This particular case has examples in many places, promoted by manufacturers.
Everyone has their own way of learning. We can also learn by looking at the sample code on the Internet. How has someone written code before this. I don't like this way of style. I think simple way is, look the datasheet first and then a flow chart should be made And then write the code

I agree that it takes a lot of time to draw a flow chart. It is not necessary to create a flow chart for every problem. It depends on you which way of learning you like. I'm making a flow chart because I find things more difficult. I will be able to understand things through flow chart.
 
Last edited:

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
That datasheet does not show an 8-bit interface. However, the KS0066 controlled it uses is compatible with the HD44780 controller. Unless you plan on using that specific device, I think you will find the documentation for the Hitachi controller more common and easier to follow.
sorry I attached wrong datasheet. I created a flow chart with references to the links I posted in #1.
 

Attachments

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
Have you seen this datasheet: http://fab.cba.mit.edu/classes/863.06/11.13/44780.pdf

Initialization begins about page 39 and the 8-bit mode flowchart is page 45. There can be slight differences between drivers. The Hitachi is pretty standard, but it would help if you told us which driver you are writing the flowchart for.
@jpanhalt I saw page 39 and page 45.

What is meaning of function set in page 45

Initializing by Instruction
Power on
Wait for 40 ms
Function set
Wait for more than 4.1 ms

But I still do not understand how to Initialization LCD ?
 

Attachments

jpanhalt

Joined Jan 18, 2008
8,437
@jpanhalt I saw page 39 and page 45.

What is meaning of function set in page 45

But I still do not understand how to Initialization LCD ?
That is what you are trying to do, and it is a good flowchart. Basically, copy that chart, understand what each block does, and elaborate on the texts as you feel necessary.

FYI, I think most people use 4-bit mode, as it is almost as fast. That is, 8-bit mode is nowhere nearly twice as fast as 4-bit mode, as there are only two or three additional steps for the 4-bit mode, and the real time waster is waiting for the display to update (about 37 to 40 us or so), which is done only once regardless of the mode.
 

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
FYI, I think most people use 4-bit mode, as it is almost as fast. That is, 8-bit mode is nowhere nearly twice as fast as 4-bit mode, as there are only two or three additional steps for the 4-bit mode, and the real time waster is waiting for the display to update (about 37 to 40 us or so), which is done only once regardless of the mode.
@jpanhalt Then I will also work on 4 bit modes first

Page 42 Table 12

1576670871160.png

Sets to 4-bit operation. command = 000010
Display on/off control command = 000000

command = 0000* *
 

BobaMosfet

Joined Jul 1, 2009
927
@BobaMosfet thanks for your contribution

Please see post #12 I do not understand step 3 table 12

Given function set 0000 * *

Why we need to repeat step 2 and step 3 function set?
Stop overthinking it. Look at the table:

1576853367058.png

Do you see the top TITLE row? : "Step No. RS R/W DB7...."

Those are column titles. Those are flagbits. Of the 6 bits, the left 2 tell the display the mode, and the 4 four are your data nybble. The function set is telling you what you need to set the bits at in order to get the result you want. So, the right 4 bits are 0x02.

Since you communicate with the display in parallel, in 4-bits at a time (a nybble), the way you write to it is you set the appropriate control flagbits (RS, R/W, etc), and then you put 0x02 into 4-bits of an output port on the MCU. You then enable the bus (your 4-bit parallel communication highway that you've created to the display), you then disable the bus and wait for 5ms. You have to wait to give the display time to register the signal levels on the incoming 4 pins.

Now... one of the things you need to be doing is learning how we're teaching you to look at stuff and understand it. Don't come back to us asking the same questions in another thread about another device- We expect you _learn_ as you go, or you will never go anywhere with this. Just being honest with you. Having said that, I understand you've put your mind in 'learning mode' so you're a bit 'dear in the headlights' not really thinking anything through, just absorbing. That is fine, except _THIS_ is what other people we're trying to explain to you about learning- Don't do it all in your head. Learn a little, and then go test it. Real, actual, fiddling with things will give you confidence, and teach you faster, than doing things in your head. I kid you not.

Now, to clarify your question about the table:

1576854018841.png

You don't repeat steps 2 & 3. This is a documentation confusion on their part. They are simply showing you 2 commands in step #3, in order that you can see how you issue 2 commands. Normally, this _is_ where you would set 4-bit, and tell it how many lines and character set, just as they are explaining.
 
Last edited:

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
Don't come back to us asking the same questions in another thread about another device- We expect you _learn_ as you go, or you will never go anywhere with this.
I try to give my best If you see my first post, you will see that I did not copy any code, I made a flow chart for how the program will work.

If you look at my old threads, you will see that I have worked till the end

There is a difference between the new boy and the experience. I am new boy I just started learning So may be a reason i'm making more mistakes

@JohnInTX I am very impressed by your nature. I like the way you explain. You always be positive and help till the end.
 

BobaMosfet

Joined Jul 1, 2009
927
I try to give my best If you see my first post, you will see that I did not copy any code, I made a flow chart for how the program will work.

If you look at my old threads, you will see that I have worked till the end

There is a difference between the new boy and the experience. I am new boy I just started learning So may be a reason i'm making more mistakes

@JohnInTX I am very impressed by your nature. I like the way you explain. You always be positive and help till the end.
Wasn't a complaint, was constructive criticism. That's why I gave you so much help on this thread. I know you're learning.
 

Thread Starter

Gajyamadake

Joined Oct 9, 2019
266
Okay I have written code for 8 bit mode but the problem is that display show only cursor it's not showing data on LCD

I'm trying to solve the problem from long time But i haven't got success yet. i am referring table 13 in datasheet

C:
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
#include <xc.h>

#define RS           RB1
#define RW           RB2
#define EN           RB3
#define LCD_Port     PORTD

/* Make all PORTD pins low and Configured PORT pins as Output*/
void  Port_Initialize (void)
{
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;
   PORTE = 0;

   TRISA = 0b00000000;
   TRISB = 0b00000000;
   TRISC = 0b00000000;
   TRISD = 0b00000000;
   TRISE = 0b00000000;
}

/* Function to send command instruction to LCD */
void LCD_Command(unsigned char Command)
{
    LCD_Port = Command;
    RS=0;
    RW=0;
    EN=1;
    __delay_ms(2);
    EN=0;
}
/*LCD Initialize*/
void LCD_Initialize (void)
{
    LCD_Command(0b0111000);
    __delay_ms(20);
    LCD_Command(0b0001110);
    __delay_ms(20);
    LCD_Command(0b0000110);
    __delay_ms(20);
    LCD_Command(0b1001000);
    __delay_ms(20);
}

/*Function to send message to LCD */
void LCD_Data(unsigned char Message)
{
    LCD_Port = Message;
    RS=1;
    RW=0;
    EN=1;
   __delay_ms(2);
    EN=0;
}


void Messagebuffer( unsigned char *pointer)
{
  
    while (*pointer != '\0')
    {
      LCD_Data(*pointer);
      
        pointer++;
    }
}

void main(void)
{
  int i = 0;

  unsigned char Message1 []="Hello World";

  Port_Initialize ();
  LCD_Initialize ();

  Messagebuffer(Message1);
    
    while(1)
    {

    }
    return;
}
1577631902087.png
 

JohnInTX

Joined Jun 26, 2012
3,936
I have tried all sequence but I don't know which command would be use to display on first line ?
You need to use the Set DDRAM Address command that you have highlighted to set the cursor position to 0,0 before you write characters. Set DDRAM Address is described on page 29 of the datasheet you linked above. Note that after writing the last character in the first line, you MUST set the cursor to the beginning of the second line using Set DDRRAM Address - the two displayed lines are not contiguous.

Post your current code with the fixed init values and we can take a look.
 
Last edited:

jpanhalt

Joined Jan 18, 2008
8,437
Two ways to do that:
1) Hitachi datasheet, page 12:
1577643055811.png
NOTE: Even thought the display may only show 16 characters, the controller is designed for 20 (0x14) characters. Then, to tell it to go to a DDRAM, address, you "OR" it (or add to) with 0x80 (i.e., you simply set bit<7>). Thus, for line 0, position 0, you send 0x80. Line 1, position 0 = 0x80 OR'd with 0x14 to give 0x94 and so forth. The lines on a 4x16 didplay begin:

Line 0 = 0x80
Line 1 = 0x94
Line 2 = 0xA8
Line 3 = 0xBC

2) Cheat and use a widely available table such as this:
1577643433181.png

Source: Parallax character display users' manual.

On a 2x16 display,the lines go like this:
Code:
Line 0 = 0x80 to 0x8F, but the controller sees the whole line which ends at 0x93
Line 1 = 0x94 to 0xA3,          "                                   ends at 0xA7
Line 2 = 0xA8 to  ??                                                ends at   ??
Line 3 = 0xBC to  ??                                                ends at   ??
Now, as an exercise, complete the table for a 4x16 display.

EDIT: The above is "simplified" for illustration. In a 4-line display, the actual lines you usually see alternate, so the starting positions are really:
1577645150952.png
Parallax has a backpack and the lines to not alternate on its 4-line display.
 
Last edited:
Top