📄 nokia lcd library.txt
字号:
/*--------------------------------------------------------------------------------------------------
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 ( LcdFontSize 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 = 92;
}
if ( size == FONT_1X )
{
for ( i = 0; i < 5; i++ )
{
LcdCache[LcdCacheIdx++] = FontLookup[ch - 32][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 ( LcdFontSize size, byte *dataPtr )
{
while ( *dataPtr )
{
LcdChr( size, *dataPtr++ );
}
}
/*--------------------------------------------------------------------------------------------------
Name : LcdPixel
Description : Displays a pixel at given absolute (x, y) location.
Argument(s) : x, y -> Absolute pixel coordinates
mode -> Off, On or Xor. See enum.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdPixel ( byte x, byte y, LcdPixelMode mode )
{
word index;
byte offset;
byte data;
if ( x > LCD_X_RES ) return;
if ( y > LCD_Y_RES ) return;
index = ((y / 8) * 84) + x;
offset = y - ((y / 8) * 8);
data = LcdCache[index];
if ( mode == PIXEL_OFF )
{
data &= (~(0x01 << offset));
}
else if ( mode == PIXEL_ON )
{
data |= (0x01 << offset);
}
else if ( mode == PIXEL_XOR )
{
data ^= (0x01 << offset);
}
LcdCache[index] = data;
if ( index < LoWaterMark )
{
// Update low marker.
LoWaterMark = index;
}
if ( index > HiWaterMark )
{
// Update high marker.
HiWaterMark = index;
}
}
/*--------------------------------------------------------------------------------------------------
Name : LcdLine
Description : Draws a line between two points on the display.
Argument(s) : x1, y1 -> Absolute pixel coordinates for line origin.
x2, y2 -> Absolute pixel coordinates for line end.
mode -> Off, On or Xor. See enum.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdLine ( byte x1, byte y1, byte x2, byte y2, LcdPixelMode mode )
{
int dx, dy, stepx, stepy, fraction;
dy = y2 - y1;
dx = x2 - x1;
if ( dy < 0 )
{
dy = -dy;
stepy = -1;
}
else
{
stepy = 1;
}
if ( dx < 0 )
{
dx = -dx;
stepx = -1;
}
else
{
stepx = 1;
}
dx <<= 1;
dy <<= 1;
LcdPixel( x1, y1, mode );
if ( dx > dy )
{
fraction = dy - (dx >> 1);
while ( x1 != x2 )
{
if ( fraction >= 0 )
{
y1 += stepy;
fraction -= dx;
}
x1 += stepx;
fraction += dy;
LcdPixel( x1, y1, mode );
}
}
else
{
fraction = dx - (dy >> 1);
while ( y1 != y2 )
{
if ( fraction >= 0 )
{
x1 += stepx;
fraction -= dy;
}
y1 += stepy;
fraction += dx;
LcdPixel( x1, y1, mode );
}
}
UpdateLcd = TRUE;
}
/*--------------------------------------------------------------------------------------------------
Name : LcdUpdate
Description : Copies the LCD cache into the device RAM.
Argument(s) : None.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdUpdate ( void )
{
int i;
if ( LoWaterMark < 0 )
LoWaterMark = 0;
else if ( LoWaterMark >= LCD_CACHE_SIZE )
LoWaterMark = LCD_CACHE_SIZE - 1;
if ( HiWaterMark < 0 )
HiWaterMark = 0;
else if ( HiWaterMark >= LCD_CACHE_SIZE )
HiWaterMark = LCD_CACHE_SIZE - 1;
// Set base address according to LoWaterMark.
LcdSend( 0x80 | (LoWaterMark % LCD_X_RES), LCD_CMD );
LcdSend( 0x40 | (LoWaterMark / LCD_X_RES), LCD_CMD );
// Serialize the video buffer.
for ( i = LoWaterMark; i <= HiWaterMark; i++ )
{
LcdSend( LcdCache[i], LCD_DATA );
}
// Reset watermark pointers.
LoWaterMark = LCD_CACHE_SIZE - 1;
HiWaterMark = 0;
UpdateLcd = FALSE;
}
/*--------------------------------------------------------------------------------------------------
Name : LcdSend
Description : Sends data to display controller.
Argument(s) : data -> Data to be sent
cd -> Command or data (see/use enum)
Return value : None.
--------------------------------------------------------------------------------------------------*/
static void LcdSend ( byte data, LcdCmdData cd )
{
// Enable display controller (active low).
PORTB &= ~LCD_CE_PIN;
if ( cd == LCD_DATA )
{
PORTB |= LCD_DC_PIN;
}
else
{
PORTB &= ~LCD_DC_PIN;
}
// Send data to display controller.
SPDR = data;
// Wait until Tx register empty.
while ( (SPSR & 0x80) != 0x80 );
// Disable display controller.
PORTB |= LCD_CE_PIN;
}
/*--------------------------------------------------------------------------------------------------
Name : Delay
Description : Uncalibrated delay for LCD init routine.
Argument(s) : None.
Return value : None.
--------------------------------------------------------------------------------------------------*/
static void Delay ( void )
{
int i;
for ( i = -32000; i < 32000; i++ );
}
/*--------------------------------------------------------------------------------------------------
End of file.
--------------------------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -