#include "uart_lcd.h" #include "usart.h" #include "lwip.h" extern ip4_addr_t ipaddr; uart_lcd_t uart_lcd_state = {0}; uint8_t uart_lcd_data[24] = {0xEE, 0xB1, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0xFF, 0xFC, 0xFF, 0xFF}; static void uart_lcd_current_channel1(void); static void uart_lcd_current_channel2(void); static void uart_lcd_current_channel1(void) { // uint8_t uart_lcd_data[24] = {0xEE, 0xB1, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0xFF, 0xFC, 0xFF, 0xFF}; dma_usart_send(&huart4, uart_lcd_data, ARRAY_LEN(uart_lcd_data)); } uint8_t uart_lcd_data2[24] = {0xEE, 0xB1, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01, 0xFF, 0xFC, 0xFF, 0xFF}; static void uart_lcd_current_channel2(void) { dma_usart_send(&huart4, uart_lcd_data2, ARRAY_LEN(uart_lcd_data2)); } /** * @brief 通过UART向LCD屏幕绘制IP地址 * * 此函数通过UART接口向LCD屏幕发送IP地址,以便在屏幕上显示。 * * @note 此函数假定已经正确初始化了UART接口,并且LCD屏幕已经正确连接到UART接口。 */ void uart_lcd_draw_ipaddr(void) { uint8_t ip_addr[24] = {0}; // 串口发送的固定值为串口屏指令指定的帧头帧尾 ip_addr[0] = 0xEE; // 帧头 ip_addr[1] = 0xB1; ip_addr[2] = 0x10; // 命令码,此处为文本控件文本设置指令 ip_addr[3] = 0x00; // 画面ID高位地址 ip_addr[4] = 0x00; // 画面ID低位地址 ip_addr[5] = 0x00; // 控件ID高位地址 ip_addr[6] = 0x03; // 控件ID低位地址 char *ip_addr_str = ipaddr_ntoa(&ipaddr); MEMCPY(ip_addr + 7, (uint8_t *)ip_addr_str, strlen(ip_addr_str)); ip_addr[7 + strlen(ip_addr_str)] = 0xFF; // 帧尾,下列都为帧尾 ip_addr[8 + strlen(ip_addr_str)] = 0xFC; ip_addr[9 + strlen(ip_addr_str)] = 0xFF; ip_addr[10 + strlen(ip_addr_str)] = 0xFF; dma_usart_send(&huart4, ip_addr, ARRAY_LEN(ip_addr)); } void uart_lcd_init(void) { uart_lcd_state.page_num = 0; uart_lcd_state.key_state[0] = 0; uart_lcd_state.key_state[1] = 1; uart_lcd_state.key_state[2] = 0; uart_lcd_state.current_value[0] = 0; uart_lcd_state.current_value[1] = 0; uart_lcd_channel_switch(uart_lcd_state.key_state[0]); HAL_Delay(10); uart_lcd_current_out(0); HAL_Delay(10); uart_lcd_current_out(1); } uint8_t lcd_channel[15] = {0xEE, 0xB1, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF}; void uart_lcd_current_out(uint8_t channel) { if (channel == 0) { lcd_channel[6] = 0x04; lcd_channel[10] = uart_lcd_state.current_value[0]; dma_usart_send(&huart4, lcd_channel, ARRAY_LEN(lcd_channel)); } else if (channel == 1) { lcd_channel[6] = 0x05; lcd_channel[10] = uart_lcd_state.current_value[1]; dma_usart_send(&huart4, lcd_channel, ARRAY_LEN(lcd_channel)); } } void uart_lcd_channel_switch(uint8_t channel) { switch (channel) { case 0: uart_lcd_current_channel1(); break; case 1: uart_lcd_current_channel2(); break; default: uart_lcd_current_channel1(); break; } }