feat: LCD_ShowNum and LCD_ShowString;

fix: vertical display
This commit is contained in:
liuyihui 2023-04-27 12:09:41 +08:00
parent 4573e7f17d
commit 0afbab47b7
2 changed files with 76 additions and 15 deletions

View File

@ -32,7 +32,7 @@
typedef unsigned char uchar;
// LCD function 1 enable
#define USE_HORIZONTAL 1 // 横屏
#define USE_HORIZONTAL 0 // 横屏
#define LCD_FAST_IO 1 // 快速IO
// LCD size
@ -112,3 +112,5 @@ void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye);
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
void LCD_Clear(uint16_t color);
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode);
void LCD_ShowNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t dir, uint8_t mode);
void LCD_ShowString(uint16_t x, uint16_t y, char *str, uint8_t size, uint8_t dir, uint8_t mode);

View File

@ -147,7 +147,7 @@ void LCD_Init() {
LCD_WR_DATA(0XC1);
LCD_WR_REG(LCD_RAM_AC);
LCD_WR_DATA(0x88); // 0x88: MY = 1, MX = MV = 0 从左到右 从下到上, BGR = 1s
LCD_WR_DATA(0x08); // 0x88: MY = MX = MV = 0 从左到右 从上到下, BGR = 1s
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x55);
@ -213,12 +213,18 @@ void LCD_SetColor(uint16_t color) { PEN_COLOR = color; }
void LCD_SetBackColor(uint16_t color) { BACK_COLOR = color; }
void LCD_SetXY(uint16_t x, uint16_t y) {
#if USE_HORIZONTAL == 1
LCD_WR_REG_DATA_16BIT(LCD_PAGE_WR, x);
LCD_WR_REG_DATA_16BIT(LCD_COL_WR, y);
#else
LCD_WR_REG_DATA_16BIT(LCD_COL_WR, x);
LCD_WR_REG_DATA_16BIT(LCD_PAGE_WR, y);
#endif
}
// Set a rectangle area
void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
#if USE_HORIZONTAL == 1
LCD_WR_REG(LCD_PAGE_WR);
LCD_WR_DATA_16BIT(xs);
LCD_WR_DATA_16BIT(xe);
@ -226,6 +232,15 @@ void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
LCD_WR_REG(LCD_COL_WR);
LCD_WR_DATA_16BIT(ys);
LCD_WR_DATA_16BIT(ye);
#else
LCD_WR_REG(LCD_COL_WR);
LCD_WR_DATA_16BIT(xs);
LCD_WR_DATA_16BIT(xe);
LCD_WR_REG(LCD_PAGE_WR);
LCD_WR_DATA_16BIT(ys);
LCD_WR_DATA_16BIT(ye);
#endif
}
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color) {
@ -256,32 +271,76 @@ void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t sign, uint8_t size, uint8_t mo
if (x > LCD_W || y > LCD_H) return;
uchar tmp;
uint16_t x0 = x;
const uchar *font;
if (size == 12) font = &asc2_1206[0][0];
else font = &asc2_1608[0][0];
sign = sign - ' ';
if (!mode) { // non-overlap
for (uint16_t px = 0; px < size; px++) {
tmp = font[sign * size + px];
for (uint16_t py = 0; py < size / 2; py++) {
if (tmp & 0x01) LCD_DrawPoint(x, y, PEN_COLOR);
else LCD_DrawPoint(x, y, BACK_COLOR);
for (uint16_t py = 0; py < size; py++) {
tmp = font[sign * size + py];
for (uint16_t px = 0; px < size / 2; px++) {
if (tmp & 0x01) LCD_DrawPoint(x + px, y + py, PEN_COLOR);
else LCD_DrawPoint(x + px, y + py, BACK_COLOR);
tmp >>= 1;
x++;
}
x = x0;
y++;
}
} else // overlap
{
for (uint16_t px = 0; px < size; px++) {
tmp = font[sign * size + px];
for (uint16_t py = 0; py < size / 2; py++) {
if (tmp & 0x01) LCD_DrawPoint(x + py, y + px, PEN_COLOR);
for (uint16_t py = 0; py < size; py++) {
tmp = font[sign * size + py];
for (uint16_t px = 0; px < size / 2; px++) {
if (tmp & 0x01) LCD_DrawPoint(x + px, y + py, PEN_COLOR);
tmp >>= 1;
}
}
}
}
/*
@brief Display a number on the position of (x,y)
@param x x of the first charactor
@param y y of the first charactor
@param num the number
@param len length of the number
@param size size of one charactor, 12x06 or 16x08
@param dir the direction to display the number, 0: keep x the same, 1: keep y the same
@param mode 0: non-overlap, 1: overlap
*/
void LCD_ShowNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t dir, uint8_t mode) {
uint8_t tmp;
if (!dir)
for (uint8_t i = 0; i < len; i++) {
tmp = num % 10;
LCD_ShowChar(x + size / 2 * (len - i - 1), y, tmp + '0', size, mode);
num /= 10;
}
else
for (uint8_t i = 0; i < len; i++) {
tmp = num % 10;
LCD_ShowChar(x, y + size * (len - i - 1), tmp + '0', size, mode);
num /= 10;
}
}
/*
@brief Display a string on the position of (x,y)
@param x x of the first charactor
@param y y of the first charactor
@param str the string
@param size size of one charactor, 12x06 or 16x08
@param dir the direction to display the string, 0: keep x the same, 1: keep y the same
@param mode 0: non-overlap, 1: overlap
*/
void LCD_ShowString(uint16_t x, uint16_t y, char *str, uint8_t size, uint8_t dir, uint8_t mode) {
if (!dir)
while (*str) {
LCD_ShowChar(x, y, *str++, size, mode);
x += size / 2;
}
else
while (*str) {
LCD_ShowChar(x, y, *str++, size, mode);
y += size;
}
}