- 本文采用淘晶驰4.3寸IPS串口屏实物验证,HMI串口屏经简单配置即可快速实现,串口通讯效果。串口屏上手简单,有独立的开发套件,容易上手,驱动显示和功能代码独立。本文仅针对串口调试信息显示实现做介绍,不涉及复杂功能实现。
模拟类似于通过电脑上位机串口调试助手,打印调试信息的效果。由于所使用的模块不带RTC,不然可以将接收数据的时间信息也可以添加上去。
http://wiki.tjc1688.com/download/index.html
http://wiki.tjc1688.com/widgets/Text.html
//注意arduino需要注意编码,因为arduino的默认编码是utf-8,串口屏默认编码是gb2312,请保证单片机与串口屏的编码相同,否则串口屏会显示乱码,或者不显示
文本控件-如何换行
如果是上位机软件中直接使用多行编辑,直接按回车可以换行.
在控件的事件中给文本赋值时用\r,例如t0.txt=”123\r456”
单片机通过串口发送给屏幕时用\r\n,例如printf(t0.txt=”123\r\n456”)
文本数据-显示不完全
btlen t10.txt,n1.val//获取当前接收到的数据长度
if(n1.val>1)
{
n1.val=0
if(n2.val==0)
{
t0.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==1)
{
t2.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==2)
{
t3.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==3)
{
t4.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==4)
{
t5.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==5)
{
t6.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==6)
{
t7.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==7)
{
t8.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
if(n2.val==8)
{
t9.txt=t10.txt
//将文本赋值为空
t10.txt=""
}
n2.val+=1
if(n2.val==10)
{
// substr t0.txt,t0.txt,n0.val,sys0-n0.val//清空文本内容
n2.val=1
t0.txt=t10.txt
t10.txt=""
t2.txt=""
t3.txt=""
t4.txt=""
t5.txt=""
t6.txt=""
t7.txt=""
t8.txt=""
t9.txt=""
}
}
printf("t10.txt+=\"STM32F303 SysClk:%u\r\n\"\xff\xff\xff", SysClk);
printf("t10.txt+=\"Hello World%d\r\n\"\xff\xff\xff", cnt);
int main(void)
{
/* USER CODE BEGIN 1 */
uint16_t cnt = 0;
uint32_t TimerUART;
char str[32];
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
uint32_t SysClk = HAL_RCC_GetSysClockFreq();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while(1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if((HAL_GetTick() - TimerUART) > 1000)
{
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
// HAL_Delay(1000);
printf("t10.txt+=\"STM32F303 SysClk:%u\r\n\"\xff\xff\xff", SysClk);
HAL_Delay(500);
cnt++;
printf("t10.txt+=\"Hello World%d\r\n\"\xff\xff\xff", cnt);
// sprintf(str, "t10.txt+=\"Hello World%d\r\n\"\xff\xff\xff", cnt);
// printf("%s", str);
// memset(str, 0, 32);
TimerUART = HAL_GetTick();
}
}
/* USER CODE END 3 */
}
Serial.print("t10.txt+=\"from Arduino UNO\r\n\"\xff\xff\xff");
#include
SoftwareSerial TJC(8,9);//8:RxD,9:TxD
//unsigned long nowtime;
unsigned int cnt;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//初始化串口
TJC.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
//因为串口屏开机会发送88 ff ff ff,所以要清空串口缓冲区
while (TJC.read() >= 0); //清空串口缓冲区
//nowtime = millis(); //获取当前已经运行的时间
}
void loop() {
char str[32];
cnt++;
sprintf(str, "t10.txt+=\"Hello World%d\r\n\"\xff\xff\xff", cnt);
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
delay(1000);
TJC.print(str);
delay(1000);
// Serial.print("t10.txt+=\"from Arduino UNO\r\n\"\xff\xff\xff");
TJC.print("t10.txt+=\"from Arduino UNO\r\n\"\xff\xff\xff");
}