sggt/App/LCD/JLX240-00301-BN.c

399 lines
10 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "JLX240-00301-BN.h"
#include "main.h"
#include "stdio.h"
#include "stm32f407xx.h"
#include "mux_signal.h"
#include "tm1650.h"
// LCM resolution:240x320,
// driver IC:ST7789V,
#include <chinese_code.h>
typedef struct
{
GPIO_TypeDef *port;
uint16_t pin;
} st_lcd_data;
st_lcd_data lcd_data[8] = {
{LCD_DB0_GPIO_Port, LCD_DB0_Pin},
{LCD_DB1_GPIO_Port, LCD_DB1_Pin},
{LCD_DB2_GPIO_Port, LCD_DB2_Pin},
{LCD_DB3_GPIO_Port, LCD_DB3_Pin},
{LCD_DB4_GPIO_Port, LCD_DB4_Pin},
{LCD_DB5_GPIO_Port, LCD_DB5_Pin},
{LCD_DB6_GPIO_Port, LCD_DB6_Pin},
{LCD_DB7_GPIO_Port, LCD_DB7_Pin},
};
static void lcd_data2pin(uint8_t *data)
{
if (!data)
return;
uint8_t i;
uint8_t data_temp;
data_temp = *data;
for (i = 0; i < 8; i++)
{
if (data_temp & 0x01)
HAL_GPIO_WritePin(lcd_data[i].port, lcd_data[i].pin, GPIO_PIN_SET);
else
HAL_GPIO_WritePin(lcd_data[i].port, lcd_data[i].pin, GPIO_PIN_RESET);
data_temp >>= 1;
}
}
void transfer_command(uint8_t com1)
{
CS_RESET(); // CS0 = 0;
RS_RESET(); // DC0 = 0;
RD_SET(); // RD0 = 1;
lcd_data2pin(&com1); // P1 = com1;
WR_RESET(); // WR0 = 0;
WR_RESET(); // delay_us(1);
WR_SET(); // WR0 = 1;
CS_SET(); // CS0 = 1;
}
void transfer_data(uint8_t data1)
{
CS_RESET(); // CS0 = 0;
RS_SET(); // DC0 = 1;
RD_SET(); // RD0 = 1;
lcd_data2pin(&data1); // P1 = data1;
WR_RESET(); // WR0 = 0;
WR_RESET(); // WR0 = 0;
WR_SET(); // WR0 = 1;
CS_SET(); // CS0 = 1;
}
// 杩炲啓2锟???瀛楄妭锛堝嵆16浣嶏級鏁版嵁鍒癓CD妯″潡
void transfer_data_16(uint16_t data_16bit)
{
transfer_data(data_16bit >> 8);
transfer_data(data_16bit);
}
void delay(long i)
{
int j, k;
for (j = 0; j < i; j++)
for (k = 0; k < 110; k++)
;
}
void delay_us(long i)
{
int j, k;
for (j = 0; j < i; j++)
;
for (k = 0; k < 1; k++)
;
}
// uint8_t key = 0;
void Switch()
{
repeat:
if (key == 1)
goto repeat;
else
delay(1000);
if (key)
goto repeat;
else
;
}
void lcd_initial()
{
RST_RESET(); // reset = 0;
delay(200);
RST_SET(); // reset = 1;
delay(200);
//------------------------------display and color format setting--------------------------------//
transfer_command(0x36); // 琛屾壂鎻忛『搴忓強RGB锛屽垪锟???鎻忛『搴忥紝锟???锟???/绔栨斁
transfer_data(0x00);
transfer_data(0x48);
transfer_command(0xB6); // 鏄剧ず鍔熻兘璁剧疆锛氬垪/锟??? 鏄剧ず椤哄簭
transfer_data(0x0A);
transfer_data(0x82); // 鏀瑰彉SOURCE绾跨殑鏂瑰悜锟???0xa2锛氬乏鍒板彸锟???0x82锛氬彸鍒板乏
transfer_command(0x3a); // 256K 16bit/pixel
transfer_data(0x05);
//--------------------------------ST7789V Frame rate setting----------------------------------//
transfer_command(0xb2);
transfer_data(0x0c);
transfer_data(0x0c);
transfer_data(0x00);
transfer_data(0x33);
transfer_data(0x33);
transfer_command(0xb7);
transfer_data(0x35);
//---------------------------------ST7789V Power setting--------------------------------------//
transfer_command(0xbb);
transfer_data(0x28);
transfer_command(0xc0);
transfer_data(0x2c);
transfer_command(0xc2);
transfer_data(0x01);
transfer_command(0xc3);
transfer_data(0x10);
transfer_command(0xc4);
transfer_data(0x20);
transfer_command(0xc6);
transfer_data(0x0f);
transfer_command(0xd0);
transfer_data(0xa4);
transfer_data(0xa1);
//--------------------------------ST7789V gamma setting---------------------------------------//
transfer_command(0xe0);
transfer_data(0xd0);
transfer_data(0x00);
transfer_data(0x02);
transfer_data(0x07);
transfer_data(0x0a);
transfer_data(0x28);
transfer_data(0x32);
transfer_data(0x44);
transfer_data(0x42);
transfer_data(0x06);
transfer_data(0x0e);
transfer_data(0x12);
transfer_data(0x14);
transfer_data(0x17);
transfer_command(0xe1);
transfer_data(0xd0);
transfer_data(0x00);
transfer_data(0x02);
transfer_data(0x07);
transfer_data(0x0a);
transfer_data(0x28);
transfer_data(0x31);
transfer_data(0x54);
transfer_data(0x47);
transfer_data(0x0e);
transfer_data(0x1c);
transfer_data(0x17);
transfer_data(0x1b);
transfer_data(0x1e);
transfer_command(0x11); // 閫€鍑虹潯锟???
delay(200);
transfer_command(0x29); // 鎵撳紑鏄剧ず
}
// 瀹氫箟绐楀彛鍧愭爣锛氬紑濮嬪潗鏍囷紙XS,YS)浠ュ強绐楀彛澶у皬锛坸_total,y_total)
void lcd_address(int XS, int YS, int x_total, int y_total)
{
int XE, YE;
XE = XS + x_total - 1;
YE = YS + y_total - 1;
transfer_command(0x2a); // 璁剧疆X寮€濮嬪強缁撴潫鐨勫湴鍧€
transfer_data_16(XS); // X寮€濮嬪湴鍧€(16浣嶏級
transfer_data_16(XE); // X缁撴潫鍦板潃(16浣嶏級
transfer_command(0x2b); // 璁剧疆Y寮€濮嬪強缁撴潫鐨勫湴鍧€
transfer_data_16(YS); // Y寮€濮嬪湴鍧€(16浣嶏級
transfer_data_16(YE); // Y缁撴潫鍦板潃(16浣嶏級
transfer_command(0x2c); // 鍐欐暟锟???寮€锟???
}
void mono_transfer_data_16(int mono_data, int font_color, int back_color)
{
int i;
for (i = 0; i < 8; i++)
{
if (mono_data & 0x80)
{
transfer_data_16(font_color); // 褰撴暟锟???锟???1鏃讹紝鏄剧ず瀛椾綋棰滆壊
}
else
{
transfer_data_16(back_color); // 褰撴暟锟???锟???0鏃讹紝鏄剧ず搴曡壊
}
mono_data <<= 1;
}
}
// 鍏ㄥ睆鏄剧ず涓€绉嶏拷?锟借壊
void display_color(int color_data)
{
int i, j;
lcd_address(0, 0, 240, 320);
for (i = 0; i < 240; i++)
{
for (j = 0; j < 320; j++)
{
transfer_data_16(color_data);
}
}
}
void display_black(void)
{
int i, j, k;
transfer_command(0x2c); // 鍐欐暟锟???寮€锟???
for (i = 0; i < 240; i++)
{
transfer_data_16(0xffff);
}
for (i = 0; i < 318; i++)
{
for (k = 0; k < 1; k++)
{
transfer_data_16(0xffff);
}
for (j = 0; j < 238; j++)
{
transfer_data_16(0x0000);
}
for (k = 0; k < 1; k++)
{
transfer_data_16(0xffff);
}
}
for (i = 0; i < 320; i++)
{
transfer_data_16(0xffff);
}
}
// 鏄剧ず8x16鐐归樀鐨勫瓧绗︿覆
void disp_string_8x16(int x, int y, const char *text, int font_color, int back_color)
{
int i = 0, j, k;
while (text[i] > 0x00)
{
if ((text[i] >= 0x20) && (text[i] <= 0x7e))
{
j = text[i] - 0x20;
lcd_address(x, y, 8, 16);
for (k = 0; k < 16; k++)
{
mono_transfer_data_16(ascii_table_8x16[j * 16 + k], font_color, back_color); //?a??"ascii_table_8x16[]"?a??锚y脳茅?煤"ASCII_TABLE_5X8_8X16_horizontal.h"脿?
}
x += 8;
i++;
}
else
i++;
}
}
void display_string_16x16(int x, int y, const char *text, int font_color, int back_color)
{
uchar i, j, k;
uint address;
j = 0;
while (text[j] != '\0') //'\0' 瀛楋拷?锟戒覆缁撴潫鏍囧織
{
i = 0;
address = 1;
while (Chinese_horizontal_text_16x16[i] > 0x7e) // >0x7f鍗筹拷?锟芥槑涓嶆槸ASCII鐮佸瓧锟???
{
if (Chinese_horizontal_text_16x16[i] == text[j])
{
if (Chinese_horizontal_text_16x16[i + 1] == text[j + 1])
{
address = i * 16;
break;
}
}
i += 2;
}
if (y > 320)
{
y = 0;
x += 16;
}
if (address != 1) // 鏄剧ず姹夊瓧
{
lcd_address(x, y, 16, 16);
for (i = 0; i < 2; i++)
{
for (k = 0; k < 16; k++)
{
mono_transfer_data_16(Chinese_horizontal_code_16x16[address], font_color, back_color);
address++;
}
}
j += 2;
}
else // 鏄剧ず绌虹櫧瀛楋拷??
{
lcd_address(x, y, 16, 16);
for (i = 0; i < 2; i++)
{
for (k = 0; k < 16; k++)
{
mono_transfer_data_16(0x00, font_color, back_color);
}
}
j += 2;
}
x = x + 16;
}
}
// 鏄剧ず32x32鐐归樀鐨勫崟鑹茬殑鍥惧儚
void disp_32x32(int x, int y, const char *dp, int font_color, int back_color)
{
int i, j;
lcd_address(x, y, 32, 32);
for (i = 0; i < 32; i++)
{
for (j = 0; j < 4; j++)
{
mono_transfer_data_16(*dp, font_color, back_color);
dp++;
}
}
}
// 鏄剧ず涓€骞呭僵锟???
void display_image(int x, int y, const uchar *dp)
{
uchar i, j, k = 0;
lcd_address(x, y, 120, 160);
for (i = 0; i < 120; i++)
{
for (j = 0; j < 160; j++)
{
transfer_data(*dp); // 浼犱竴锟???鍍忕礌鐨勫浘鐗囨暟锟???鐨勯珮锟???
dp++;
transfer_data(*dp); // 浼犱竴锟???鍍忕礌鐨勫浘鐗囨暟锟???鐨勪綆锟???
dp++;
}
}
}
void lcd_menu(void)
{
static uint8_t init_flag = 0;
char content[128];
if (init_flag == 0)
{
init_flag = 1;
display_color(blue);
}
sprintf(content, "AI:ch[%02d] vol[%2.4f]V.", mux_signal.channel, mux_signal.data_sv / 1000.0f);
disp_string_8x16(10, 10, content, white, blue);
sprintf(content, "AO:ch[%02d] vol[%2.4f]V.", mux_signal.channel, mux_signal.data_sv / 1000.0f);
disp_string_8x16(10, 30, content, white, blue);
sprintf(content, "AI:ch[%02d] vol[%2.4f]V.", mux_signal.channel, mux_signal.data_sv / 1000.0f);
disp_string_8x16(10, 50, content, white, blue);
sprintf(content, "AO:ch[%02d] vol[%2.4f]V.", mux_signal.channel, mux_signal.data_sv / 1000.0f);
disp_string_8x16(10, 70, content, white, blue);
}