📄 lcd.c
字号:
LCD_writeSpiCommand (PTLOUT);
// // Scroll area set
// LCD_writeSpiCommand (ASCSET);
// LCD_writeSpiData (0);
// LCD_writeSpiData (0);
// LCD_writeSpiData (40);
// LCD_writeSpiData (3);
// // Vertical scrool address start
// LCD_writeSpiCommand (SCSTART);
// LCD_writeSpiData (0);
// Data control
LCD_writeSpiCommand (DATCTL);
LCD_writeSpiData (0x00); // all inversions off, column direction
LCD_writeSpiData (0x03); // RGB sequence
LCD_writeSpiData (0x02); // Grayscale -> 16
// Page Column set
LCD_writeSpiCommand (CASET);
LCD_writeSpiData (LCD_X_OFFSET);
LCD_writeSpiData (LCD_X_OFFSET + LCD_WIDTH - 1); // 130 pixel viewable
// Page Address set
LCD_writeSpiCommand (PASET);
LCD_writeSpiData (LCD_Y_OFFSET);
LCD_writeSpiData (LCD_Y_OFFSET + LCD_HEIGHT - 1); // 130 pixel viewable
//LCD_writeSpiData (133); // 130 pixel viewable
#endif // GE12
LCD_clear ();
// Finally - Display On
LCD_writeSpiCommand (DISPLAYON);
}
void LCD_write130x130bmpStart ()
{
#ifdef GE12
// Display OFF
LCD_writeSpiCommand (DISPLAYOFF);
#endif
// Page Column set
LCD_writeSpiCommand (CASET);
LCD_writeSpiData (LCD_X_OFFSET);
LCD_writeSpiData (LCD_X_OFFSET + LCD_WIDTH - 1); // 130 pixel viewable
// Page Address set
LCD_writeSpiCommand (PASET);
LCD_writeSpiData (LCD_Y_OFFSET);
LCD_writeSpiData (LCD_Y_OFFSET + LCD_HEIGHT - 1); // 130 pixel viewable
// WRITE MEMORY
LCD_writeSpiCommand (MEMWRITE);
}
void LCD_write130x130bmpData16 (const uint16_t *data)
{
LCD_writeSpiData ((*data) >> 8);
LCD_writeSpiData ((*data) & 0xFF);
}
void LCD_write130x130bmpData8 (const uint8_t *data)
{
LCD_writeSpiData (*data);
}
void LCD_write130x130bmpEnd ()
{
#ifndef GE12
// wait aproximetly 100ms
mdelay (100);
#endif
// Display On
LCD_writeSpiCommand (DISPLAYON);
}
void LCD_write130x130bmp (const unsigned char *bmp)
{
unsigned int j;
LCD_write130x130bmpStart ();
// write to memory
for (j = 0; j < LCD_MEM_SIZE; j++)
{
LCD_writeSpiData (bmp[j]);
}
LCD_write130x130bmpEnd ();
}
void LCD_clear (void)
{
unsigned int j;
#if 0
// Display OFF
LCD_writeSpiCommand (DISPLAYOFF);
#endif
// Page Column set
LCD_writeSpiCommand (CASET);
LCD_writeSpiData (LCD_X_OFFSET);
LCD_writeSpiData (LCD_X_OFFSET + LCD_WIDTH - 1); // 130 pixel viewable
// Page Address set
LCD_writeSpiCommand (PASET);
LCD_writeSpiData (LCD_Y_OFFSET);
LCD_writeSpiData (LCD_Y_OFFSET + LCD_HEIGHT - 1); // 130 pixel viewable
// WRITE MEMORY
LCD_writeSpiCommand (MEMWRITE);
// write to memory
for (j = 0; j < LCD_MEM_SIZE; j++)
{
LCD_writeSpiData (0xFF);
}
#if 0
#ifndef GE12
// wait aproximetly 100ms
Delay (1000);
//Delay (10000);
#endif
// Display On
LCD_writeSpiCommand (DISPLAYON);
#endif
LCD_setXY (0, 0);
LCD_setColor (LCD_DEFAULT_FG_COLOR, LCD_DEFAULT_BG_COLOR);
}
void LCD_clearBall (unsigned char x, unsigned char y)
{
unsigned int j;
// Page address set
LCD_writeSpiCommand (PAGEADDRSET);
LCD_writeSpiData (y);
LCD_writeSpiData (y + 19);
// Column address set
LCD_writeSpiCommand (COLADDRSET);
LCD_writeSpiData (x);
LCD_writeSpiData (x + 19);
// WRITE MEMORY
LCD_writeSpiCommand (MEMWRITE);
for (j = 0; j < 600; j++)
{
LCD_writeSpiData (0xff);
}
#if 0
#ifndef GE12
// wait aproximetly 100ms
Delay (1000);
//Delay (10000);
#endif
// Display On
LCD_writeSpiCommand (DISPLAYON);
#endif
}
void LCD_writeBall (unsigned char x, unsigned char y)
{
unsigned int j;
// Page address set
LCD_writeSpiCommand (PAGEADDRSET);
LCD_writeSpiData (y);
LCD_writeSpiData (y + 19);
// Column address set
LCD_writeSpiCommand (COLADDRSET);
LCD_writeSpiData (x);
LCD_writeSpiData (x + 19);
// WRITE MEMORY
LCD_writeSpiCommand (MEMWRITE);
for (j = 0; j < 600; j++)
{
LCD_writeSpiData (ball[j]);
}
// Display On
//LCD_writeSpiCommand (DISPLAYON);
}
void LCD_writeChar (unsigned char Ascii,
unsigned char x,
unsigned char y,
unsigned short FG_Colour, unsigned short BG_Colour)
{
unsigned int i, j;
unsigned char Byte_1 = 0;
unsigned char Byte_2 = 0;
unsigned char Byte_3 = 0;
unsigned char Pixel = 0;
LCD_writeSpiCommand (COLADDRSET);
LCD_writeSpiData (LCD_X_OFFSET + x);
LCD_writeSpiData (LCD_X_OFFSET + x + FONT_WIDTH - 1);
LCD_writeSpiCommand (PAGEADDRSET);
LCD_writeSpiData (LCD_Y_OFFSET + y);
LCD_writeSpiData (LCD_Y_OFFSET + y + FONT_HEIGHT - 1);
LCD_writeSpiCommand (MEMWRITE);
for (j = 0; j < FONT_HEIGHT; j++)
{
Pixel = font_digits[j + (FONT_HEIGHT * Ascii)];
for (i = 0; i < FONT_WIDTH; i++)
{
if (i % 2)
{
if (Pixel & 0x80) // Pixel ON
{
Byte_2 &= 0xF0;
Byte_2 |= FG_Colour >> 8;
Byte_3 = FG_Colour & 0x00FF;
}
else // Pixel OFF
{
Byte_2 &= 0xF0;
Byte_2 |= BG_Colour >> 8;
Byte_3 = BG_Colour & 0x00FF;
}
LCD_writeSpiData (Byte_1);
LCD_writeSpiData (Byte_2);
LCD_writeSpiData (Byte_3);
}
else
{
if (Pixel & 0x80) // Pixel ON
{
Byte_1 = FG_Colour >> 4;
Byte_2 = FG_Colour << 4;
}
else // Pixel OFF
{
Byte_1 = BG_Colour >> 4;
Byte_2 = 0;
Byte_2 |= BG_Colour << 4;
}
}
Pixel <<= 1;
}
}
}
inline void LCD_setX (uint8_t _x)
{
xBase = x = _x;
}
inline void LCD_setY (uint8_t _y)
{
y = _y;
}
inline void LCD_setXY (uint8_t _x, uint8_t _y)
{
xBase = x = _x;
y = _y;
}
inline uint8_t LCD_getX ()
{
return x;
}
inline uint8_t LCD_getY ()
{
return y;
}
inline void LCD_setFGColor (uint16_t _fgColor)
{
fgColor = _fgColor;
}
inline void LCD_setBGColor (uint16_t _bgColor)
{
bgColor = _bgColor;
}
inline void LCD_setColor (uint16_t _fgColor, uint16_t _bgColor)
{
fgColor = _fgColor;
bgColor = _bgColor;
}
void LCD_printf (const char *fmt, ...)
{
va_list valist;
char buf[LCD_PRINTF_BUF_SIZE];
va_start (valist, fmt);
vsnprintf (buf, sizeof (buf), fmt, valist);
va_end (valist);
LCD_write (buf, strlen (buf));
}
void LCD_write (const char *buf, uint16_t length)
{
uint16_t i;
for (i = 0; i < length; i++) // display str
{
if (buf[i] != '\n')
{
// displays each letter in the str
LCD_writeChar (buf[i], x, y, fgColor, bgColor);
x += FONT_WIDTH;
if (x >= LCD_WIDTH - FONT_WIDTH)
{
x = xBase;
y += FONT_HEIGHT;
}
}
else
{
// new line
x = xBase;
y += FONT_HEIGHT;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -