/////////////////////////////////////////////////////////////////////////////
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);
}
/////////////////////////////////////////////////////////////////////////////