试用迪文串口屏

最近用了个迪文的串口屏,7寸电阻触摸,T5UIC2平台。

这个屏很便宜,95元。假如自己买裸屏开发,屏本身也要60元,电阻触摸15元,加上带RGB接口的ARM9至少也要15,还有其他部件如电源稳压,FLASH等等,价格也没差多少甚至更贵。

测试过程只要参考《T5UIC2 开发指南》与《HMI指令集》两个PDF文档。

1.测试屏幕是否正常

拿到屏幕,首先接通电源,使用PC串口助手发送一些命令到串口屏,测试屏是否可以正常使用。

通常可以使用握手指令来测试屏是否正常通电使用(AA 00 CC 33 33 CC)。

2.测试图片显示

首先把符合规格的BMP图片(24位,大小为屏幕分辨率,无压缩BMP)放在SD卡规定位置(文件夹DWIN_SET里),以数字开头命名。插入串口屏,上电后,自动下载进对应的位置。以后就可以使用图片显示命令了。测试发现,如果图片不存在,屏幕会显示全屏暗灰色。其中0号图片为图片上电后默认显示的。

3.代码规划

如果只是简单界面,没有太多元素与层次,则只需要串口直接发送命令,立即绘制UI。但是,一旦界面复杂,简单的串口发送命令,很容易出错。

建议这样做:1.只在一处做界面处理更新。2.把需要发送UI命令,保存在一个FIFO缓冲区里,定时全部一起刷新。

迪文屏的串口缓存为24帧,也就是可以一次性发送24个命令。此屏的断帧方式为检测帧头帧尾巴,而非空闲时间。

4.具体命令代码

IDE为KEIL MDK5

u8 g_fcbc_useless=0;//前景色背景色变量是否为无效
u16 g_fcolor=WHITE,g_bcolor=BLUE; //默认


//设置前景色与背景色
void ui_SetFCBC( u16 fc,u16 bc)
{
    g_fcbc_useless=0;
    g_fcolor = fc;
    g_bcolor = bc;
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x40);
    //FC
    myUSART3_Sendbyte( fc>>8);
    myUSART3_Sendbyte( fc);
    //BC
    myUSART3_Sendbyte( bc>>8);
    myUSART3_Sendbyte( bc);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//取某点颜色到前景色
void ui_GetPointToFC(u16 x,u16 y)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x43);
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
    g_fcbc_useless=1;
}
//取某点颜色到背景色
void ui_GetPointToBC(u16 x,u16 y)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x42);
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
    g_fcbc_useless=1;
}

//设置字符间距和行间距
void ui_SetInterval( u8  dx,u8 dy )
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x41);
    //dx
    myUSART3_Sendbyte( dx);
    //dy
    myUSART3_Sendbyte( dy);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//设置显示光标
//T5UIC2不支持本命令!!!
void ui_SetShowCursor(u16 x,u16 y,u8 dx,u8 dy,u8 en)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x44);
    myUSART3_Sendbyte(en);
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //dx dy
    myUSART3_Sendbyte(dx);
    myUSART3_Sendbyte(dy);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//使用背景色清屏
void ui_Clear(void)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x52);//
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//画点
//mod:0 恢复点背景色 ,1 前景色设置点
void ui_DrawPointMulti( u8 mod ,pointType po[],u8 num  )
{
    u16 i;
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x50 + mod );//画点命令:0x51使用前景色,0x52使用背景色
    for(i=0;i>8);
        myUSART3_Sendbyte( po[i].x);
        //y
        myUSART3_Sendbyte( (po[i].y)>>8);
        myUSART3_Sendbyte( po[i].y);
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//连线
//mod:0  背景色 ,1  前景色
void ui_DrawLineMulti( u8 mod ,pointType po[], u8 num )
{
    u16 i;
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x5d - mod*(0x5d-0x56) );//画点命令:0x51使用前景色,0x52使用背景色
    for(i=0;i>8);
        myUSART3_Sendbyte( po[i].x);
        //y
        myUSART3_Sendbyte( (po[i].y)>>8);
        myUSART3_Sendbyte( po[i].y);
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//画频谱
void ui_DrawSpectrogram(u16 x, u16 y , u16 maxH , u8 arr[],u8 num)
{
    u16 i;
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x75);// 画频谱命令
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //最大高度maxH
    if(maxH>0xff)
    {
        myUSART3_Sendbyte(0);
        myUSART3_Sendbyte(maxH>>8);
        myUSART3_Sendbyte(maxH);
        
         for(i=0;i>8);
            myUSART3_Sendbyte( arr[i] );
        }
    }else
    {
        myUSART3_Sendbyte(maxH);
        //高度
         for(i=0;i>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //r
    myUSART3_Sendbyte( r);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//多个同心圆
void ui_DrawCircleConcentric(u16 x,u16 y,u8 r,u8 mod,u8 dr,u8 num)
{
    u8 i;
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x57);// 画圆命令
    for(i=0;i>8);
        myUSART3_Sendbyte( x);
        //y
        myUSART3_Sendbyte( y>>8);
        myUSART3_Sendbyte( y);
        //r
        myUSART3_Sendbyte( r);
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//画圆弧 ,单位0.5度,范围0~720度,竖直方向为0,顺时针方向增加
void ui_DrawArc(u16 x,u16 y,u16 r,u16 as , u16 ae)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x57);// 画圆命令
    myUSART3_Sendbyte(0x04);// 模式为画圆弧
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //r
    myUSART3_Sendbyte( r>>8);
    myUSART3_Sendbyte( r);
    //as
    myUSART3_Sendbyte( as>>8);
    myUSART3_Sendbyte( as);
    //ae
    myUSART3_Sendbyte( ae>>8);
    myUSART3_Sendbyte( ae);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//方框square
void ui_DrawSquare(u16 xs,u16 ys,u16 xe,u16 ye,u8 mod)
{
    switch(mod)
    {
        case 0:mod=0x59;break;//前景色画框
        case 1:mod=0x69;break;//背景色画框
        case 2:mod=0x5B;break;//前景色填充
        case 3:mod=0x5A;break;//背景色填充
        case 4:mod=0x5C;break;//区域取反
        default:return;
    }
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(mod);
    //xs
    myUSART3_Sendbyte( xs>>8);
    myUSART3_Sendbyte( xs);
    //ys
    myUSART3_Sendbyte( ys>>8);
    myUSART3_Sendbyte( ys);
    //xe
    myUSART3_Sendbyte( xe>>8);
    myUSART3_Sendbyte( xe);
    //ye
    myUSART3_Sendbyte( ye>>8);
    myUSART3_Sendbyte( ye);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//方块填充前景色
void ui_FFill(u16 xs,u16 ys,u16 xe,u16 ye )
{
    ui_DrawSquare( xs, ys, xe, ye,2);
}
//方块填充背景色
void ui_BFill(u16 xs,u16 ys,u16 xe,u16 ye )
{
    ui_DrawSquare( xs, ys, xe, ye,3);
}
//多个同心方框square
void ui_DrawSquareConcentric(u16 xs,u16 ys,u16 xe,u16 ye,u8 mod,u16 dx,u16 dy,u8 num)
{
    u8 i;

    switch(mod)
    {
        case 0:mod=0x59;break;//前景色画框
        case 1:mod=0x69;break;//背景色画框
        case 2:mod=0x5B;break;//前景色填充
        case 3:mod=0x5A;break;//背景色填充
        case 4:mod=0x5C;break;//区域取反
    }
    myUSART3_Sendbyte(0xAA);
    for(i=0;i>8);
        myUSART3_Sendbyte( xs);
        //ys
        myUSART3_Sendbyte( ys>>8);
        myUSART3_Sendbyte( ys);
        //xe
        myUSART3_Sendbyte( xe>>8);
        myUSART3_Sendbyte( xe);
        //ye
        myUSART3_Sendbyte( ye>>8);
        myUSART3_Sendbyte( ye);
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//区域填充 凸多边形
//x,y 种子点 
//color 填充色
void ui_RegionFill(u16 x,u16 y,u16 color)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x64);//命令
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //c
    myUSART3_Sendbyte( color>>8);
    myUSART3_Sendbyte( color);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//指定区域横向滚屏
//mod: 0右环移,1左环移,2右移,3左移
void ui_RectHScroll(u16 xs,u16 ys,u16 xe,u16 ye,u8 offset,u8 mod)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(60+mod);//命令
    //xs
    myUSART3_Sendbyte( xs>>8);
    myUSART3_Sendbyte( xs);
    //ys
    myUSART3_Sendbyte( ys>>8);
    myUSART3_Sendbyte( ys);
    //xe
    myUSART3_Sendbyte( xe>>8);
    myUSART3_Sendbyte( xe);
    //ye
    myUSART3_Sendbyte( ye>>8);
    myUSART3_Sendbyte( ye);
    //offset
    myUSART3_Sendbyte( offset);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//不知为何 使用一次ICO后影响文字显示,必须再次使用一次无效ICO号
//ico显示 ICO放在lib_id=0x28=40,文件名为40.ICO 占据4个id宽度 。一个ICO文件内部有多张图片
//mod:0 不显示ICO背景(透明) ,其他 不过滤
//n :ICO内部索引,文件名按照10进制
void _ui_ShowIcon(u16 x,u16 y,u16 n,u8 mod)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x97);
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //lib_ID
    myUSART3_Sendbyte(0x28);
    //模式 
    myUSART3_Sendbyte(mod);
    //n 
    myUSART3_Sendbyte( n>>8);
    myUSART3_Sendbyte( n);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
void ui_ShowIcon(u16 x,u16 y,u16 n,u8 mod)
{
    _ui_ShowIcon( x,  y,  n,  mod);
    _ui_ShowIcon( x,  y,  0x1010,  mod);
}
//显示编号BMP:
//此编号 与SD卡内图片编号一样,是按照10进制。比如10.bmp,是10号图片
void ui_ShowBmp(u8 n)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x70);//命令
    //图片编号
    myUSART3_Sendbyte( n);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//保存图片到HMI ,n对应ui_ShowBmp(u8 n)
void ui_StoreBmpTo(u8 n)
{
    if(n>4 && n<128)
    {
        myUSART3_Sendbyte(0xAA);
        myUSART3_Sendbyte(0xE2);//命令
        //图片编号
        myUSART3_Sendbyte( n);
        //END
        myUSART3_Sendbyte(0xCC);
        myUSART3_Sendbyte(0x33);
        myUSART3_Sendbyte(0xC3);
        myUSART3_Sendbyte(0x3C);
    }
}
//显示图片,并获取CRC-16
void ui_ShowBmpGetCRC(u8 n)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x7B);//命令
    //图片编号
    myUSART3_Sendbyte( n);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//剪切编号图片某个区域,到屏幕位置线,(x,y)
//区别在于多次剪切
void ui_CutAndShowBmp(u8 n,u16 xs,u16 ys,u16 xe,u16 ye,u16 x,u16 y,u8 mod)
{
    switch(mod)
    {
        case 0:mod=0x71;break;// 正常剪切
        case 1:mod=0x9C;break;// 透明效果,恢复最初背景(要求被切区域 背景纯色)
        case 2:mod=0x9D;break;// 恢复之前背景(要求被切区域 背景纯色)
        default:return;
    }
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(mod);//命令
    //图片编号
    myUSART3_Sendbyte( n);
    //xs
    myUSART3_Sendbyte( xs>>8);
    myUSART3_Sendbyte( xs);
    //ys
    myUSART3_Sendbyte( ys>>8);
    myUSART3_Sendbyte( ys);
    //xe
    myUSART3_Sendbyte( xe>>8);
    myUSART3_Sendbyte( xe);
    //ye
    myUSART3_Sendbyte( ye>>8);
    myUSART3_Sendbyte( ye);
    //x
    myUSART3_Sendbyte( x>>8);
    myUSART3_Sendbyte( x);
    //y
    myUSART3_Sendbyte( y>>8);
    myUSART3_Sendbyte( y);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//剪切并旋转显示到屏幕位置
//mod:0 透明剪切,1不透明
void ui_CutAndRotateShowBmp(u8 n,u16 xs,u16 ys,u16 xe,u16 ye,u16 xc0,u16 yc0,u16 al,u16 xc1,u16 yc1,u8 mod)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x9E);
    myUSART3_Sendbyte(mod);//模式
    //图片编号
    myUSART3_Sendbyte( 0);
    myUSART3_Sendbyte( n);
    //xs
    myUSART3_Sendbyte( xs>>8);
    myUSART3_Sendbyte( xs);
    //ys
    myUSART3_Sendbyte( ys>>8);
    myUSART3_Sendbyte( ys);
    //xe
    myUSART3_Sendbyte( xe>>8);
    myUSART3_Sendbyte( xe);
    //ye
    myUSART3_Sendbyte( ye>>8);
    myUSART3_Sendbyte( ye);
    //xc0
    myUSART3_Sendbyte( xc0>>8);
    myUSART3_Sendbyte( xc0);
    //yc0
    myUSART3_Sendbyte( yc0>>8);
    myUSART3_Sendbyte( yc0);
    //al
    myUSART3_Sendbyte( al>>8);
    myUSART3_Sendbyte( al);
 
    //xc1
    myUSART3_Sendbyte( xc1>>8);
    myUSART3_Sendbyte( xc1);
    //yc1
    myUSART3_Sendbyte( yc1>>8);
    myUSART3_Sendbyte( yc1);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//设置文本区域限制
void ui_SetTextboxLimit(u16 xs,u16 ys,u16 xe,u16 ye)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x45);
    //xs
    myUSART3_Sendbyte( xs>>8);
    myUSART3_Sendbyte( xs);
    //ys
    myUSART3_Sendbyte( ys>>8);
    myUSART3_Sendbyte( ys);
    //xe
    myUSART3_Sendbyte( xe>>8);
    myUSART3_Sendbyte( xe);
    //ye
    myUSART3_Sendbyte( ye>>8);
    myUSART3_Sendbyte( ye);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//取消文本显示区域
void ui_ResetTextboxLimit(void)
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x45);
    myUSART3_Sendbyte(0x00);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//显示单个ASCII
void ui_StandardShowChar( u16 x,u16 y,u8 size,u8 hex )
{
    char cmd;
    switch(size)
    {
        case  12:cmd=0x6E;break;
        case  16:cmd=0x54;break;
        case  24:cmd=0x6F;break;
        case  32:cmd=0x55;break;
        default:return;
    }
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(cmd);
    //X,Y
    myUSART3_Sendbyte(x>>8 );
    myUSART3_Sendbyte(x );
    myUSART3_Sendbyte(y>>8 );
    myUSART3_Sendbyte(y );
    //STRING
    myUSART3_Sendbyte(hex);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//显示字符串GBK
void ui_StandardShowString(u16 x,u16 y, u8 size,char *s)
{
    char cmd;
    switch(size)
    {
        case  12:cmd=0x6E;break;
        case  16:cmd=0x54;break;
        case  24:cmd=0x6F;break;
        case  32:cmd=0x55;break;
        default:return;
    }
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(cmd);
    //X,Y
    myUSART3_Sendbyte(x>>8 );
    myUSART3_Sendbyte(x );
    myUSART3_Sendbyte(y>>8 );
    myUSART3_Sendbyte(y );
    //STRING
    while(*s != '\0')
    {      
        myUSART3_Sendbyte(  *s) ;
        s++;
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//显示数组方式的字符串 
void ui_StandardShowArr(u16 x,u16 y, u8 size,char *arr,uint8_t len)
{
    char cmd;
    uint8_t i=0;
    switch(size)
    {
        case  12:cmd=0x6E;break;
        case  16:cmd=0x54;break;
        case  24:cmd=0x6F;break;
        case  32:cmd=0x55;break;
        default:return;
    }
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(cmd);
    //X,Y
    myUSART3_Sendbyte(x>>8 );
    myUSART3_Sendbyte(x );
    myUSART3_Sendbyte(y>>8 );
    myUSART3_Sendbyte(y );
    //ARR
   
    while( i <  len )
    {      
        myUSART3_Sendbyte( arr[i]) ;
        i++;    
    }
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}
//显示数字 
//len 占据个数
void ui_StandardShowNum(u16 x,u16 y, u8 size  ,int num)
{
    char *p= mymalloc(12);
    if(p!=NULL){
        sprintf(p,"%d", num);
        ui_StandardShowString( x, y,  size,p);
        myfree(p);
    }
}
//带空格占长度
void ui_StandardShowLenNum(u16 x,u16 y, u8 size,u8 len ,int num)
{
    char *p;
    if(len<=12){
        p= mymalloc(12);
    }else{
        p= mymalloc(len+1);
    }
    if(p!=NULL){
        sprintf(p,"%*d",len, num);
        ui_StandardShowString( x, y,  size,p);
        myfree(p);
    }
}

//调节背光
void ui_SetBkl(u8 pwm )
{
    myUSART3_Sendbyte(0xAA);
    myUSART3_Sendbyte(0x5F);//命令
    //亮度 0-0X3F
    myUSART3_Sendbyte(pwm);
    //END
    myUSART3_Sendbyte(0xCC);
    myUSART3_Sendbyte(0x33);
    myUSART3_Sendbyte(0xC3);
    myUSART3_Sendbyte(0x3C);
}

//模仿printf方式把字符打印到串口屏,换行符\r\n要与ui_SetTextboxLimit()配合使用
void ui_print(u16 x, u16 y, u8 size, char *str, ...)
{
    s16 len;
    char *p;
    va_list pArgs;
    
    va_start(pArgs, str);
    len = vsnprintf(NULL,0,str,pArgs) + 1;//计算内容长度 失败返回负数
    if(len>0)
    {
        p=mymalloc(len);//申请内存
        if(p != NULL) 
        {
            vsnprintf(p,len,str,pArgs); //格式化成字符串 
            ui_StandardShowString(  x,  y,   size, p);
            myfree(p);
        }else   ui_StandardShowString(  x,  y,   size, "lcd print malloc err!");
    }
    va_end(pArgs);
}

最后一个函数ui_printf()可实现类似printf格式化输出功能,直接把字符打印到串口屏上,非常方便。

你可能感兴趣的:(stm32)