part 2:
/*--------------------------------------------------------------------------------------------------
Name : LcdContrast
Description : Set display contrast.
Argument(s) : contrast -> Contrast value from 0x00 to 0x7F.
Return value : None.
Notes : No change visible at ambient temperature.
--------------------------------------------------------------------------------------------------*/
void LcdContrast ( byte contrast )
{
// LCD Extended Commands.
LcdSendCmd( 0x21, LCD_CMD );
// Set LCD Vop (Contrast).
LcdSendCmd( 0x80 | contrast, LCD_CMD );
// LCD Standard Commands, horizontal addressing mode.
LcdSendCmd( 0x20, LCD_CMD );
}
/*--------------------------------------------------------------------------------------------------
Name : LcdClear
Description : Clears the display. LcdUpdate must be called next.
Argument(s) : None.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdClear ( void )
{
int i;
for ( i = 0; i < LCD_CACHE_SIZE; i++ )
{
LcdCache[i] = 0x00;
}
// Reset watermark pointers.
LoWaterMark = 0;
HiWaterMark = LCD_CACHE_SIZE - 1;
UpdateLcd = true;
}
/*--------------------------------------------------------------------------------------------------
Name : LcdGotoXY
Description : Sets cursor location to xy location corresponding to basic font size.
Argument(s) : x, y -> Coordinate for new cursor position. Range: 1,1 .. 14,6
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdGotoXY ( byte x, byte y )
{
LcdCacheIdx = (x - 1) * 6 + (y - 1) * 84;
}
/*--------------------------------------------------------------------------------------------------
Name : LcdChr
Description : Displays a character at current cursor location and increment cursor location.
Argument(s) : size -> Font size. See enum.
ch -> Character to write.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdChr ( int size, byte ch )
{
byte i, c;
byte b1, b2;
int tmpIdx;
if ( LcdCacheIdx < LoWaterMark )
{
// Update low marker.
LoWaterMark = LcdCacheIdx;
}
if ( (ch < 0x20) || (ch > 0x7b) )
{
// Convert to a printable character.
ch = 65;
}
if ( size == FONT_1X )
{
for ( i = 0; i < 5; i++ )
{
LcdCache[LcdCacheIdx++] = FontLookup[ch - 65][i] << 1;
}
}
else if ( size == FONT_2X )
{
tmpIdx = LcdCacheIdx - 84;
if ( tmpIdx < LoWaterMark )
{
LoWaterMark = tmpIdx;
}
if ( tmpIdx < 0 ) return;
for ( i = 0; i < 5; i++ )
{
c = FontLookup[ch - 32][i] << 1;
b1 = (c & 0x01) * 3;
b1 |= (c & 0x02) * 6;
b1 |= (c & 0x04) * 12;
b1 |= (c & 0x08) * 24;
c >>= 4;
b2 = (c & 0x01) * 3;
b2 |= (c & 0x02) * 6;
b2 |= (c & 0x04) * 12;
b2 |= (c & 0x08) * 24;
LcdCache[tmpIdx++] = b1;
LcdCache[tmpIdx++] = b1;
LcdCache[tmpIdx + 82] = b2;
LcdCache[tmpIdx + 83] = b2;
}
// Update x cursor position.
LcdCacheIdx += 11;
}
if ( LcdCacheIdx > HiWaterMark )
{
// Update high marker.
HiWaterMark = LcdCacheIdx;
}
// Horizontal gap between characters.
LcdCache[LcdCacheIdx++] = 0x00;
}
/*--------------------------------------------------------------------------------------------------
Name : LcdStr
Description : Displays a character at current cursor location and increment cursor location
according to font size.
Argument(s) : size -> Font size. See enum.
dataPtr -> Pointer to null terminated ASCII string to display.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdStr ( int size, byte *dataPtr )
{
while ( *dataPtr )
{
LcdChr( size, *dataPtr++ );
}
}