fix: Horizontal and vertical screen switching;

feat: DrawLine in LCD
This commit is contained in:
liuyihui 2023-04-27 13:44:11 +08:00
parent 99b6474f3e
commit 74aa441111
2 changed files with 43 additions and 7 deletions

View File

@ -32,7 +32,7 @@
typedef unsigned char uchar;
// LCD function 1 enable
#define USE_HORIZONTAL 0 // 横屏
#define USE_HORIZONTAL 1 // 横屏
#define LCD_FAST_IO 1 // 快速IO
// LCD size
@ -105,12 +105,13 @@ typedef unsigned char uchar;
void LCD_RESET();
void LCD_Init();
void LCD_Clear();
void LCD_SetColor(uint16_t color);
void LCD_SetBackColor(uint16_t color);
void LCD_SetXY(uint16_t x, uint16_t y);
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_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
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,11 @@ void LCD_Init() {
LCD_WR_DATA(0XC1);
LCD_WR_REG(LCD_RAM_AC);
LCD_WR_DATA(0x08); // 0x88: MY = MX = MV = 0 从左到右 从上到下, BGR = 1s
#if USE_HORIZONTAL == 1
LCD_WR_DATA(0x88); // 0x08: MY = 1, MX = MV = 0 从左到右 从下到下, BGR = 1s
#else
LCD_WR_DATA(0x08); // 0x08: MY = MX = MV = 0 从左到右 从上到下, BGR = 1s
#endif
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x55);
@ -205,7 +209,7 @@ void LCD_Init() {
LCD_WR_REG(0x29); // Display on
LCD_BL_CLR; // Back Light On
LCD_Clear(BACK_COLOR);
LCD_Clear();
}
void LCD_SetColor(uint16_t color) { PEN_COLOR = color; }
@ -248,14 +252,45 @@ void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color) {
LCD_WR_REG_DATA_16BIT(LCD_RAM_WR, color);
}
void LCD_Clear(uint16_t color) {
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
uint16_t x, y, d, dx, dy, xe, ye, Dx, Dy;
xe = ye = 0;
x = x1, y = y1;
Dx = x2 - x1, Dy = y2 - y1;
if (Dx > 0) dx = 1;
else if (Dx == 0) dx = 0;
else {
dx = -1;
Dx = -Dx;
}
if (Dy > 0) dy = 1;
else if (Dy == 0) dy = 0;
else {
dy = -1;
Dy = -Dy;
}
if (Dx > Dy) d = Dx;
else d = Dy;
for (uint16_t i = 0; i <= d + 1; i++) // 画线输出
{
LCD_DrawPoint(x, y, PEN_COLOR); // 画点
xe += Dx, ye += Dy;
if (xe > d) xe -= d, x += dx;
if (ye > d) ye -= d, y += dy;
}
}
void LCD_Clear() {
LCD_SetRec(0, LCD_W - 1, 0, LCD_H - 1);
LCD_WR_REG(LCD_RAM_WR);
for (uint32_t i = 0; i < LCD_W * LCD_H; i++) LCD_WR_DATA_16BIT(color);
for (uint32_t i = 0; i < LCD_W * LCD_H; i++) LCD_WR_DATA_16BIT(BACK_COLOR);
// for (uint16_t i = 0; i < LCD_W; i++)
// for (uint16_t j = 0; j < LCD_H; j++) {
// LCD_SetXY(i, j);
// LCD_WR_REG_DATA_16BIT(LCD_RAM_WR, color);
// LCD_WR_REG_DATA_16BIT(LCD_RAM_WR, BACK_COLOR);
// }
}