1.為什么要升級彩屏?
隨著科技的日新月異,品質(zhì)升級已也成為延長產(chǎn)品生命周期的重要因素之一,彩屏替換傳統(tǒng)的顯示方案也早已是大勢所趨。傳統(tǒng)顯示方案主要包括單色(120*120、128*64、192*64、240*128)、斷碼液晶屏(VA、TN、HTN、STN)以及數(shù)碼管,都可以升級為T5UIC1彩屏。
本文主要介紹如何從傳統(tǒng)單色顯示方案快速升級為T5UIC1平臺彩屏。
2.T5UIC1平臺彩屏特點是什么?
何為T5UIC1彩屏呢?T5UIC1平臺是基于迪文科技T5CPU,針對不需要、UI功能簡單、成本要求苛刻的應(yīng)用,例如小家電、美容養(yǎng)生、電梯、自動化儀表等。
主要特點包括:
T5CPU驅(qū)動方案,顯示效果好,成本極低;
匹配基本的UI需求,開發(fā)簡單;
功能齊全:涵蓋圖標指示、JPEG解壓、動態(tài)二維碼、ASCII(6*12-64*64)、漢字庫(12*12-64*64GB2312)、繪圖。
3.如何升級T5UIC1平臺彩屏?
對于硬件方面,需要在控制部分預(yù)留一個串口,并保障電源電壓匹配。對于軟件部分,T5UIC1平臺產(chǎn)品為指令集開發(fā)模式(具體開發(fā)指南可以參照T5UIC1應(yīng)用指南——可在迪文官網(wǎng)“資料下載”欄目的“應(yīng)用設(shè)計參考”子欄目下載壓縮文件包《T5CPU開發(fā)指南》,即可從中找到文件“T5UIC1應(yīng)用指南_V20”)。
本文將MCU指令(以STM32為例)和T5UIC1指令做成了庫函數(shù)的形式(MAIN.C),開發(fā)者可直接復(fù)制使用。
本文庫函數(shù)主要涵蓋字符串顯示、二維碼顯示、繪圖、圖標顯示、動態(tài)圖標等功能。文件主要包括頭文件DWIN.H和庫函數(shù)MAIN.C。
3.1頭文件(DWIN.H)
頭文件作為一種包含功能函數(shù)、數(shù)據(jù)接口聲明的載體文件,主要用于保存程序的聲明。
相關(guān)內(nèi)容:
#ifndef__DWIN_H
#define__DWIN_H
#include
#include"stm32f10x_conf.h"
voidLCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char*format, ...);//顯示字符串或者變量
voiderweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...);//生成二維碼
voidclr(u16 Color);//清屏
voidLinear_interpolation(u8 num,u16 Color,...);//繪制直線
voidPlace_point(u8 num,u16 Color,u16 nx,u16 ny,...);//繪制點
voidDIM_Set(u8 Set);//調(diào)節(jié)背光
voidBode_Set(u16 Set);//調(diào)節(jié)擴展串口波特率
voiddisd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8Delay_time);//設(shè)置動態(tài)圖標
voiddis_ico(u16 x,u16 y,u8 mode,u8 ids);//顯示ico圖標
voidpic(u8 id);//寫數(shù)據(jù)存儲器
#endif
3.2庫函數(shù)(MAIN.C)
內(nèi)容如下:
#include
#include"stm32f10x_conf.h"
#include"dwin.h"
/****************顯示字符串函數(shù)*****************/
/*參數(shù):mode:D7********************************/
voidLCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char*format, ...)
{
chartmp[200];
va_listarg;
va_start(arg,format);
vsprintf(tmp,format,arg);
va_end(arg);
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x11);
Usart_SendByte(USART1,mode);//模式
Usart_SendByte(USART1,Color/256);
Usart_SendByte(USART1,Color%256);//前景顏色
Usart_SendByte(USART1,Bcolor/256);
Usart_SendByte(USART1,Bcolor%256);//背景顏色
Usart_SendByte(USART1,x/256);
Usart_SendByte(USART1,x%256);//橫坐標
Usart_SendByte(USART1,y/256);
Usart_SendByte(USART1,y%256);//Y坐標
Usart_SendString(USART1,tmp);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************顯示二維碼函數(shù)*****************/
/*參數(shù):mode:D7********************************/
voiderweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...)
{
chartmp[200];
va_listarg;
va_start(arg,format);
vsprintf(tmp,format,arg);
va_end(arg);
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x21);
Usart_SendByte(USART1,x/256);
Usart_SendByte(USART1,x%256);//橫坐標
Usart_SendByte(USART1,y/256);
Usart_SendByte(USART1,y%256);//Y坐標
Usart_SendByte(USART1,QR_Pixel);//二維碼每個點的大小
Usart_SendString(USART1,tmp);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************讀存儲器***********************/
/*參數(shù):mode:D7********************************/
voidread_sram_flsh(u16 Length,u8 Type,u16 Address)//寫數(shù)據(jù)存儲器
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x32);
Usart_SendByte(USART1,Type);
Usart_SendByte(USART1,Address/256);
Usart_SendByte(USART1,Address%256);
Usart_SendByte(USART1,Length);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************繪圖清屏函數(shù)*****************/
/*參數(shù):mode:D7********************************/
voidclr(u16 Color)
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x01);
Usart_SendByte(USART1,Color/256);
Usart_SendByte(USART1,Color%256);//顏色
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************繪圖直線插入函數(shù)*****************/
/*參數(shù):mode:D7********************************/
voidLinear_interpolation(u8 num,u16 Color,...)
{
va_listarg_ptr;
inttempValue;
num*=2;
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x03);
Usart_SendByte(USART1,Color/256);
Usart_SendByte(USART1,Color%256);
va_start(arg_ptr,Color);
while(num--)
{
tempValue=va_arg(arg_ptr,int);
Usart_SendByte(USART1,tempValue/256);
Usart_SendByte(USART1,tempValue%256);
}
va_end(arg_ptr);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************繪圖打點插入函數(shù)*****************/
/*參數(shù):mode:D7********************************/
voidPlace_point(u8 num,u16 Color,u16 nx,u16 ny,...)
{
va_listarg_ptr;
inttempValue;
num*=2;
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x02);
Usart_SendByte(USART1,Color/256);
Usart_SendByte(USART1,Color%256);
Usart_SendByte(USART1,nx%256);
Usart_SendByte(USART1,ny%256);
va_start(arg_ptr,ny);
while(num--)
{
tempValue=va_arg(arg_ptr,int);
Usart_SendByte(USART1,tempValue/256);
Usart_SendByte(USART1,tempValue%256);
}
va_end(arg_ptr);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************屏幕背光亮度設(shè)置*****************/
/*參數(shù):mode:D7********************************/
voidDIM_Set(u8 Set)
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x30);
Usart_SendByte(USART1,Set);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************設(shè)置擴展串口波特率**************/
/*參數(shù):mode:D7********************************/
voidBode_Set(u16 Set)//調(diào)節(jié)擴展串口波特率
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x38);
Usart_SendByte(USART1,15667200/Set/256);
Usart_SendByte(USART1,15667200/Set%256);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************從擴展串口發(fā)送字符串**************/
/*參數(shù):mode:D7********************************/
voidUART_TX(const char *format, ...)//串口發(fā)送字符串
{
chartmp[200];
va_listarg;
va_start(arg,format);
vsprintf(tmp,format,arg);
va_end(arg);
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x39);
Usart_SendString(USART1,tmp);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************顯示ICO圖標**************/
/*參數(shù):mode:D7********************************/
voiddis_ico(u16 x,u16 y,u8 mode,u8 ids)//顯示ico圖標
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x23);
Usart_SendByte(USART1,x/256);
Usart_SendByte(USART1,x%256);
Usart_SendByte(USART1,y/256);
Usart_SendByte(USART1,y%256);
Usart_SendByte(USART1,mode);
Usart_SendByte(USART1,ids);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************設(shè)置動態(tài)圖標*******************/
/*參數(shù):mode:D7********************************/
voiddisd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8Delay_time)//顯示ico圖標
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x28);
Usart_SendByte(USART1,x/256);
Usart_SendByte(USART1,x%256);
Usart_SendByte(USART1,y/256);
Usart_SendByte(USART1,y%256);
Usart_SendByte(USART1,mode);
Usart_SendByte(USART1,Icon_lib);
Usart_SendByte(USART1,Icon_IDs);
Usart_SendByte(USART1,Icon_0IDe);
Usart_SendByte(USART1,Delay_time);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************控制動態(tài)圖標*******************/
/*參數(shù):mode:D7********************************/
voiddisc_ico(u16 set)//控制ico動態(tài)圖標
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x29);
Usart_SendByte(USART1,set/256);
Usart_SendByte(USART1,set%256);
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************寫存儲器***********************/
/*參數(shù):mode:D7********************************/
voidwrit_sram_flsh(u16 Length,u8 Type,u16 Address)//寫數(shù)據(jù)存儲器
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x31);
Usart_SendByte(USART1,Type);
Usart_SendByte(USART1,Address/256);
Usart_SendByte(USART1,Address%256);
while(Length--)
{
Usart_SendByte(USART1,Address++);
}
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
/****************讀存儲器***********************/
/*參數(shù):mode:D7********************************/
voidpic(u8 id)
{
Usart_SendByte(USART1,0xaa);
Usart_SendByte(USART1,0x22);
Usart_SendByte(USART1,0x00);
Usart_SendByte(USART1,id);
\
Usart_SendByte(USART1,0xcc);
Usart_SendByte(USART1,0x33);
Usart_SendByte(USART1,0xc3);
Usart_SendByte(USART1,0x3c);
}
4.常用功能例程
4.1顯示文本和數(shù)據(jù)
voidLCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char*format, ...);//顯示字符串或者變量
參數(shù)mode:
.7字符寬度調(diào)整設(shè)置1=調(diào)整0=不調(diào)整。
.6背景色顯示設(shè)置1=顯示0=不顯示。
.5-.4寫0。.3-.0:字號大小,0x00-0x09,對應(yīng)字體大小于下:0x00=6*120x01=8*16 0x02=10*20 0x03=12*24 0x04=14*28 0x05=16*32 0x06=20*400x07=24*48 0x08=28*56 0x09=32*64
Color:字符顯示顏色。
Bcolor:字符背景顯示顏色。
(x,y):字符串顯示的左上角坐標。
例程:LCD_printf(0x42,0xffff,0xf00f,10,10,"迪文科技:%04d",x++);
如示例的調(diào)用形式將顯示“迪文科技:x的值的十進制展現(xiàn)形式”
4.2繪圖類
voidclr(u16 Color);//清屏
color:顏色
voidLinear_interpolation(u8 num,u16 Color,...);// 端點連線
num:點的個數(shù)
color:連線的顏色
…:各點坐標
例程:Linear_interpolation(3,0xff00,0x0000,0x0000,0x0100,0x0100,0x0100,0x0000);
voidPlace_point(u8 num,u16 Color,u16 nx,u16 ny,...);//繪制點
4.3二維碼顯示
voiderweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...);//生成二維碼
x,y為二維碼左上角坐標。QR_Pixel表示二維碼每個點占用的像素點。
…:URL此函數(shù)的分鐘同樣類似printf
例程:erweima(148,50,0x04,"http://zeishuo.com");
4.4調(diào)節(jié)背光亮度
voidDIM_Set(u8 Set);//調(diào)節(jié)背光
set:0x00-0xff
例程:DIM_Set(0xff);//調(diào)節(jié)背光到最亮
4.5調(diào)節(jié)串口波特率
voidBode_Set(u16 Set);//調(diào)節(jié)擴展串口波特率
set:波特率
例程:Bode_Set(9600);//設(shè)置波特率為9600
5. 文件下載說明
庫函數(shù)&頭文件及升級說明見壓縮文件《單色屏升級:如何快速升級T5UIC1彩屏》,文件獲取方式如下:
在迪文官網(wǎng)“資料下載”欄目的“應(yīng)用設(shè)計參考”子欄目下載壓縮文件包《單色屏升級:如何快速升級T5UIC1彩屏》,即可從中找到有關(guān)文件。
(作者/祖曉晨 編輯/孫惠英)
關(guān)注迪文及時了解更多產(chǎn)品資訊