feat: LCD_ShowNum and LCD_ShowString;
fix: vertical display
This commit is contained in:
parent
4573e7f17d
commit
0afbab47b7
|
@ -32,7 +32,7 @@
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
|
|
||||||
// LCD function 1 enable
|
// LCD function 1 enable
|
||||||
#define USE_HORIZONTAL 1 // 横屏
|
#define USE_HORIZONTAL 0 // 横屏
|
||||||
#define LCD_FAST_IO 1 // 快速IO
|
#define LCD_FAST_IO 1 // 快速IO
|
||||||
|
|
||||||
// LCD size
|
// 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_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
|
||||||
void LCD_Clear(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_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);
|
||||||
|
|
87
src/tftlcd.c
87
src/tftlcd.c
|
@ -147,7 +147,7 @@ void LCD_Init() {
|
||||||
LCD_WR_DATA(0XC1);
|
LCD_WR_DATA(0XC1);
|
||||||
|
|
||||||
LCD_WR_REG(LCD_RAM_AC);
|
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_REG(0x3A);
|
||||||
LCD_WR_DATA(0x55);
|
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_SetBackColor(uint16_t color) { BACK_COLOR = color; }
|
||||||
|
|
||||||
void LCD_SetXY(uint16_t x, uint16_t y) {
|
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_PAGE_WR, x);
|
||||||
LCD_WR_REG_DATA_16BIT(LCD_COL_WR, y);
|
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
|
// Set a rectangle area
|
||||||
void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
|
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_REG(LCD_PAGE_WR);
|
||||||
LCD_WR_DATA_16BIT(xs);
|
LCD_WR_DATA_16BIT(xs);
|
||||||
LCD_WR_DATA_16BIT(xe);
|
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_REG(LCD_COL_WR);
|
||||||
LCD_WR_DATA_16BIT(ys);
|
LCD_WR_DATA_16BIT(ys);
|
||||||
LCD_WR_DATA_16BIT(ye);
|
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) {
|
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;
|
if (x > LCD_W || y > LCD_H) return;
|
||||||
|
|
||||||
uchar tmp;
|
uchar tmp;
|
||||||
uint16_t x0 = x;
|
|
||||||
const uchar *font;
|
const uchar *font;
|
||||||
if (size == 12) font = &asc2_1206[0][0];
|
if (size == 12) font = &asc2_1206[0][0];
|
||||||
else font = &asc2_1608[0][0];
|
else font = &asc2_1608[0][0];
|
||||||
|
|
||||||
sign = sign - ' ';
|
sign = sign - ' ';
|
||||||
if (!mode) { // non-overlap
|
if (!mode) { // non-overlap
|
||||||
for (uint16_t px = 0; px < size; px++) {
|
for (uint16_t py = 0; py < size; py++) {
|
||||||
tmp = font[sign * size + px];
|
tmp = font[sign * size + py];
|
||||||
for (uint16_t py = 0; py < size / 2; py++) {
|
for (uint16_t px = 0; px < size / 2; px++) {
|
||||||
if (tmp & 0x01) LCD_DrawPoint(x, y, PEN_COLOR);
|
if (tmp & 0x01) LCD_DrawPoint(x + px, y + py, PEN_COLOR);
|
||||||
else LCD_DrawPoint(x, y, BACK_COLOR);
|
else LCD_DrawPoint(x + px, y + py, BACK_COLOR);
|
||||||
tmp >>= 1;
|
tmp >>= 1;
|
||||||
x++;
|
|
||||||
}
|
}
|
||||||
x = x0;
|
|
||||||
y++;
|
|
||||||
}
|
}
|
||||||
} else // overlap
|
} else // overlap
|
||||||
{
|
{
|
||||||
for (uint16_t px = 0; px < size; px++) {
|
for (uint16_t py = 0; py < size; py++) {
|
||||||
tmp = font[sign * size + px];
|
tmp = font[sign * size + py];
|
||||||
for (uint16_t py = 0; py < size / 2; py++) {
|
for (uint16_t px = 0; px < size / 2; px++) {
|
||||||
if (tmp & 0x01) LCD_DrawPoint(x + py, y + px, PEN_COLOR);
|
if (tmp & 0x01) LCD_DrawPoint(x + px, y + py, PEN_COLOR);
|
||||||
tmp >>= 1;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue