410 lines
10 KiB
C
410 lines
10 KiB
C
#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位)数据到LCD模块
|
||
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
|
||
;
|
||
}
|
||
|
||
//uint8_t cmd_test1 = 0x00;
|
||
uint8_t cmd_test2 = 0xA0;
|
||
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(cmd_test2);
|
||
|
||
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)以及窗口大小(x_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);
|
||
}
|
||
}
|
||
|
||
#if 0
|
||
//显示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;
|
||
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);
|
||
}
|
||
|
||
#endif
|
||
|
||
|
||
|