【开源】迪文串口屏与小凌派rk2206通信控制
屏幕型号T5L DMG85480F050_01WTCZ021、迪文GUI设计,包含一个变量图标控制和2个text显示控件。注意中英文字库问题,字库可用DWIN DGUS软件的DGUS配置工具中的DGUS字库工具,生成0号字库,主要英文、数字和符号,中文字库用GBK编码制作字库。
2、迪文C51设计,串口2自定义处理小凌派rk2206的串口数据,并对显示控件进行控制。用keil开发C51单片机程序,主要main代码如下:
#include "sys.h"
#include "uart2.h"
#include "string.h"
#define FIRST_TXT "手势结果:\0\0" //必须以两个字节的0x00或者两个字节的0xFF为文本结束标记
void main(void)
{
u16 len;
s16 ges;
u8text_buf={0};
u16 ic_sta;//存储ICON值
sys_init();//系统初始化
sys_write_vp(0x2000,FIRST_TXT,sizeof(FIRST_TXT)/2+1);//给第一个文本显示控件设置文本内容
uart2_init(115200);//初始化串口2
while(1)
{
if(uart2_rx_sta&UART2_PACKET_OK)//接受到了串口数据包
{
len = uart2_rx_sta&UART2_PACKET_LEN;//得到串口数据包的长度,不包含"\r\n"或者'\n'结束符的长度
ges = uart2_buf+uart2_buf*256;
switch(ges)
{
case 1:
ic_sta = 0;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_UP:0x%x",ges);
break;
case 2:
ic_sta = 1;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_DOWN:0x%x",ges);
break;
case 4:
ic_sta = 2;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_LEFT:0x%x",ges);
break;
case 8:
ic_sta = 3;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_RIGHT:0x%x",ges);
break;
case 16:
ic_sta = 4;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_FORWARD:0x%x",ges);
break;
case 32:
ic_sta = 5;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_BACKWARD:0x%x",ges);
break;
case 64:
ic_sta = 6;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_CLOCKWISE:0x%x",ges);
break;
case 128:
ic_sta = 7;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_COUNT_CLOCKWISE:0x%x",ges);
break;
case 256:
ic_sta = 8;
sys_write_vp(0x1000,(u8*)&ic_sta,1);
sprintf(text_buf,"GES_WAVE:0x%x",ges);
break;
default:
break;
}
len = strlen(text_buf);
text_buf = 0;
text_buf = 0;
sys_write_vp(0x2064,text_buf,len/2+1);//同时把数据包显示到界面上
uart2_rx_sta = 0;//清0代表处理掉了此串口包
}
}
}
完整代码附件上传。KEIL工程我加入了直接生成T5L51.bin文件功能,大家可以打开工程查看。目标文件修改需要修改bat文件。
3、小凌派rk2206手势控制传感器结果,由串口发送给迪文串口屏的串口2.小凌派跑的是鸿蒙系统,没有的可以使用其他对接开发板即可,也可用另一51单片机串口发送控制,用按键即可,都可以。手里正好有这个板子。
/*
* Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "los_task.h"
#include "ohos_init.h"
#include "lz_hardware.h"
#include "e53_gesture_sensor.h"
/* E53模块中
* UART0_RX_M0 -> GPIO0_B6
* UART0_TX_M0 -> GPIO0_B7
*/
#define UART_ID 0
unsigned short getCRC16(unsigned char *ptr,unsigned char len)
{
unsigned char i;
unsigned short crc = 0xFFFF;
if(ptr==0)
{
return 0;
}
if(len==0)
{
len = 1;
}
//if(len<=255)
{
while(len--)
{
crc ^= *ptr;
for(i=0; i<8; i++)
{
if(crc&1)
{
crc >>= 1;
crc ^= 0xA001;
}
else
crc >>= 1;
}
ptr++;
}
}
return(crc);
}
void uart0_init(void)
{
unsigned int ret;
UartAttribute attr;
LzUartDeinit(UART_ID);
attr.baudRate = 115200;
attr.dataBits = UART_DATA_BIT_8;
attr.pad = FLOW_CTRL_NONE;
attr.parity = UART_PARITY_NONE;
attr.rxBlock = UART_BLOCK_STATE_NONE_BLOCK;
attr.stopBits = UART_STOP_BIT_1;
attr.txBlock = UART_BLOCK_STATE_NONE_BLOCK;
PinctrlSet(GPIO0_PB6, MUX_FUNC2, PULL_KEEP, DRIVE_LEVEL2);
PinctrlSet(GPIO0_PB7, MUX_FUNC2, PULL_KEEP, DRIVE_LEVEL2);
ret = LzUartInit(UART_ID, &attr);
if (ret != LZ_HARDWARE_SUCCESS)
{
printf("%s, %d: LzUartInit(%d) failed!\n", __FILE__, __LINE__, ret);
return;
}
return;
}
void e53_gs_process(void *arg)
{
unsigned int ret = 0;
unsigned int i=0;
unsigned short flag = 0;
unsigned short rc = 0;
unsigned char tubiao = {0};
unsigned char tubiao_str = {0};
e53_gs_init();
uart0_init();
ret = LzUartWrite(UART_ID, tubiao, 4);
if (ret != LZ_HARDWARE_SUCCESS)
{
printf("%s, %d: LzUartInit(%d) failed!\n", __FILE__, __LINE__, ret);
return;
}
while (1)
{
ret = e53_gs_get_gesture_state(&flag);
if (ret != 0)
{
printf("Get Gesture Statu: 0x%x\n", flag);
if (flag & GES_UP)
{
printf("\tUp\n");
}
if (flag & GES_DOWM)
{
printf("\tDown\n");
}
if (flag & GES_LEFT)
{
printf("\tLeft\n");
}
if (flag & GES_RIGHT)
{
printf("\tRight\n");
}
if (flag & GES_FORWARD)
{
printf("\tForward\n");
}
if (flag & GES_BACKWARD)
{
printf("\tBackward\n");
}
if (flag & GES_CLOCKWISE)
{
printf("\tClockwise\n");
}
if (flag & GES_COUNT_CLOCKWISE)
{
printf("\tCount Clockwise\n");
}
if (flag & GES_WAVE)
{
printf("\tWave\n");
}
e53_gs_led_up_set((flag & GES_UP) ? (1) : (0));
e53_gs_led_down_set((flag & GES_DOWM) ? (1) : (0));
e53_gs_led_left_set((flag & GES_LEFT) ? (1) : (0));
e53_gs_led_right_set((flag & GES_RIGHT) ? (1) : (0));
e53_gs_led_forward_set((flag & GES_FORWARD) ? (1) : (0));
e53_gs_led_backward_set((flag & GES_BACKWARD) ? (1) : (0));
e53_gs_led_cw_set((flag & GES_CLOCKWISE) ? (1) : (0));
e53_gs_led_ccw_set((flag & GES_COUNT_CLOCKWISE) ? (1) : (0));
e53_gs_led_wave_set((flag & GES_WAVE) ? (1) : (0));
tubiao = flag;
tubiao = (flag&0xff00)>>8;
tubiao = '\r';
tubiao = '\n';
printf("tubiao:\n");
for(i=0;i<4;i++) {
sprintf(tubiao_str+i*3, "%02X ", tubiao & 0xFF);
}
printf("DOWN HEX: %s", tubiao_str);
printf("\n");
ret = LzUartWrite(UART_ID, tubiao, 4);
if (ret != LZ_HARDWARE_SUCCESS)
{
printf("%s, %d: LzUartInit(%d) failed!\n", __FILE__, __LINE__, ret);
return;
}
}
else
{
/* 如果没有数据,则多等待 */
LOS_Msleep(100);
}
}
}
void e53_gs_example()
{
unsigned int thread_id;
TSK_INIT_PARAM_S task = {0};
unsigned int ret = LOS_OK;
task.pfnTaskEntry = (TSK_ENTRY_FUNC)e53_gs_process;
task.uwStackSize = 2048;
task.pcName = "e53 getsture sensor process";
task.usTaskPrio = 24;
ret = LOS_TaskCreate(&thread_id, &task);
if (ret != LOS_OK)
{
printf("Falied to create Task_One ret:0x%x\n", ret);
return;
}
}
APP_FEATURE_INIT(e53_gs_example);
代码附件可见
页:
[1]