CFAH1604B-TMI-ET Question

Bill Bracken

New member
Please tell me that when you set the address counter and then write data that the address counter increments to the next location. I hope you don't have to write the address and then write the data for every character.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

Bill Bracken

New member
AutoIncrement

Does the auto increment count 00 to 0F for the first line and then increment to 40 for the second line? Or does auto increment really only work on a line?

Also, the Function Set command has a bit N. It's not clear how this should be set. The documentation says

"numbers of display line(N-2-line/1-line)"

This doesn't really explain what value to set N to, and doesn't even address how to set it for 4 lines?

Thanks,

bb
 

Bill Bracken

New member
I'm not sure why you need to provide me code? and what processor I am using? I just need clarification of the N bit when used with a 4 line display. I also need to know where the address counter goes after it counts up to 0F? Does it goto 40?

I will be connecting the LCD to an FPGA.

Thanks,

bb
 

CF Tech

Administrator
Sorry, I was thinking that we might be able to provide code to you, if we knew your platform. No sense re-inventing the wheel too many times.

The 4-line displays look like a 40x2 from the viewpoint of the controller. So you set N to indicate a 2-line display. Plan on resetting the the address at the beginning of every line. It will auto-increment right on a line OK, but (this is the two line thing again) line 1 rolls over to line 3, and line 2 to line 4.

Most of the character controllers are designed to be compatible with the Hitachi HD44780 controller. Here is a copy of the data sheet: Hitachi HD44780 Data Sheet.

Probably the best initialization code I have for the 16x4 is in the CFAH_WinTest.
Code:
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Write_LCD_Control_8(ubyte data,ubyte enable)
  {
  //Make register select 0, Make R/W 0=write
  OnRsL();
  OnRwL();
  //Write the data to the port.
  data_register=data;	
  Update_Buttons_From_Data_Register();
  //Strobe enable
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  }
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Write_LCD_Data_8(ubyte data,ubyte enable)
  {
  //Make register select 1, Make R/W 0=write
  OnRsH();
  OnRwL();
  //Write the data to the port.
  data_register=data;	
  Update_Buttons_From_Data_Register();
  //Strobe enable
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  }
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Write_LCD_Control_4(ubyte data,ubyte enable)
  {
  //Make register select 0, Make R/W 0=write
  OnRsL();
  OnRwL();
  //Apply the high 4 bits of data to the high four bits of the port.
  data_register=data&0xF0;
  Update_Buttons_From_Data_Register();
  //Strobe enable to clock in the high nibble.
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  //Apply the low 4 bits of data to the high four bits of the port.
  data_register=(data<<4)&0xF0;
  Update_Buttons_From_Data_Register();
  //Strobe enable to clock in the low nibble.
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  }
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Write_LCD_Data_4(ubyte data,ubyte enable)
  {
  //Make register select 1, Make R/W 0=write
  OnRsH();
  OnRwL();
  //Apply the high 4 bits of data to the high four bits of the port.
  data_register=data&0xF0;
  Update_Buttons_From_Data_Register();
  //Strobe enable to clock in the high nibble.
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  //Apply the low 4 bits of data to the high four bits of the port.
  data_register=(data<<4)&0xF0;
  Update_Buttons_From_Data_Register();
  //Strobe enable to clock in the low nibble.
  Sleep(1);
  if(enable)
    {
    OnE1H();
    Sleep(1);
    OnE1L();
    }
  else
    {
    OnE0H();
    Sleep(1);
    OnE0L();
    }
  }
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Init_LCD_8(ubyte enable)
  {
  //This sequence is from the initialization on page 45 of the HD44780U
  //data sheet.
  Sleep(40);
  Write_LCD_Control_8(0x38,enable);
  //Yes, the data sheet says write it twice.
  Sleep(5);
  Write_LCD_Control_8(0x38,enable);
  //Yes, the data sheet says write it three times.
  Sleep(125);
  Write_LCD_Control_8(0x38,enable);
  //Yes, the data sheet says write it four times, but at least this one counts.
  //038h is Function set:
  //8 bit,
  //2 line
  //F = (5x8)
  Sleep(1);
  Write_LCD_Control_8(0x38,enable);
  //"Display off"
  Sleep(2);
  Write_LCD_Control_8(0x08,enable);
  //"Display clear"
  Sleep(2);
  Write_LCD_Control_8(0x01,enable);
  //006h is Entry mode set, increment, no shift
	Sleep(2);
  Write_LCD_Control_8(0x06,enable);
  //Display on, cursor on, blinking
	Sleep(2);
  Write_LCD_Control_8(0x0F,enable);
  //Clear the display again. This seems to fix a power-up problem
  //where the display shows "{{{{{" in a couple of places.
	Sleep(2);
  Write_LCD_Control_8(0x01,enable);
  }
/////////////////////////////////////////////////////////////////////////////
void CCFAH_WinTestDlg::Init_LCD_4(ubyte enable)
  {
  //It is not an error that the first writes are "8-bit", see the HD44780
  //data sheet.
  //This sequence is from the initialization on page 46 of the HD44780U
  //data sheet.
  Sleep(40);
  Write_LCD_Control_8(0x30,enable);
  //Yes, the data sheet says write it twice.
  Sleep(5);
  Write_LCD_Control_8(0x30,enable);
  //Yes, the data sheet says write it three times.
  Sleep(125);
  Write_LCD_Control_8(0x30,enable);
  //Yes, the data sheet says write it four times, but at least this one counts.
  //020h is Function set:
  //4 bit,
  //2 line
  //F = (5x8)
  Sleep(1);
  //This is last 8-bit write, which is an instruction to put the LCD into 4-bit mode.
  Write_LCD_Control_8(0x20,enable);
  //Here is the 4-bit instruction to set the font and number of lines.
  Write_LCD_Control_4(0x28,enable);
  //"Display off"
  Sleep(2);
  Write_LCD_Control_4(0x08,enable);
  //"Display clear"
  Sleep(2);
  Write_LCD_Control_4(0x01,enable);
  //006h is Entry mode set, increment, no shift
	Sleep(2);
  Write_LCD_Control_4(0x06,enable);
  //Display on, cursor on, blinking
	Sleep(2);
  Write_LCD_Control_4(0x0F,enable);
  //Clear the display again. This seems to fix a power-up problem
  //where the display shows "{{{{{" in a couple of places.
	Sleep(2);
  Write_LCD_Control_4(0x01,enable);
  }
/////////////////////////////////////////////////////////////////////////////
For the 16x4, the codes that need to be written to the control register to set the address to the start of the lines are:
Code:
line 1 => 0x80
line 2 => 0xC0
line 3 => 0x90
line 4 => 0xD0
you can then "or" in the column if you want an x,y type function.
 
Top