- #ifndef __DWIN_H
- #define __DWIN_H
- #include<stm32f10x.h>
- #include "stm32f10x_conf.h"
- void LCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char *format, ...);//显示字符串或者变量
- void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...);//生成二维码
- void clr(u16 Color);//清屏
- void Linear_interpolation(u8 num,u16 Color,...);//绘制直线
- void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...);//绘制点
- void DIM_Set(u8 Set);//调节背光
- void Bode_Set(u16 Set);//调节扩展串口波特率
- void disd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8 Delay_time);//设置动态图标
- void dis_ico(u16 x,u16 y,u8 mode,u8 ids);//显示ico图标
- void pic(u8 id);//写数据存储器
- #endif
3.2 库函数(MAIN.C)
- #include<stm32f10x.h>
- #include "stm32f10x_conf.h"
- #include "dwin.h"
- /****************显示字符串函数*****************/
- /*参数:mode:D7********************************/
- void LCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char *format, ...)
- {
- char tmp[200];
- va_list arg;
- 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);
- }
- /****************显示二维码函数*****************/
- /*参数:mode:D7********************************/
- void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...)
- {
- char tmp[200];
- va_list arg;
- 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);
- }
- /****************读存储器***********************/
- /*参数:mode:D7********************************/
- void read_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- 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);
- }
- /****************绘图清屏函数*****************/
- /*参数:mode:D7********************************/
- void clr(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);
- }
- /****************绘图直线插入函数*****************/
- /*参数:mode:D7********************************/
- void Linear_interpolation(u8 num,u16 Color,...)
- {
- va_list arg_ptr;
- int tempValue;
- 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);
- }
- /****************绘图打点插入函数*****************/
- /*参数:mode:D7********************************/
- void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...)
- {
- va_list arg_ptr;
- int tempValue;
- 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);
- }
- /****************屏幕背光亮度设置*****************/
- /*参数:mode:D7********************************/
- void DIM_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);
- }
- /****************设置扩展串口波特率**************/
- /*参数:mode:D7********************************/
- void Bode_Set(u16 Set)//调节扩展串口波特率
- {
- 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);
- }
- /****************从扩展串口发送字符串**************/
- /*参数:mode:D7********************************/
- void UART_TX(const char *format, ...)//串口发送字符串
- {
- char tmp[200];
- va_list arg;
- 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图标**************/
- /*参数:mode:D7********************************/
- void dis_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);
- }
- /****************设置动态图标*******************/
- /*参数:mode:D7********************************/
- void disd_ico(u16 x,u16 y,u8 mode,u8 Icon_lib,u8 Icon_IDs,u8 Icon_0IDe,u8 Delay_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);
- }
- /****************控制动态图标*******************/
- /*参数:mode:D7********************************/
- void disc_ico(u16 set)//控制ico动态图标
- {
- 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);
- }
- /****************写存储器***********************/
- /*参数:mode:D7********************************/
- void writ_sram_flsh(u16 Length,u8 Type,u16 Address)//写数据存储器
- {
- 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);
- }
- /****************读存储器***********************/
- /*参数:mode:D7********************************/
- void pic(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 显示文本和数据
- void LCD_printf(u8 mode,u16 Color,u16 Bcolor,u16 x,u16 y,const char *format, ...);//显示字符串或者变量
- 参数mode:
- .7 字符宽度调整设置 1=调整 0=不调整。
- .6 背景色显示设置 1=显示 0=不显示。
- .5-.4 写 0。 .3-.0:字号大小,0x00-0x09,对应字体大小于下: 0x00=6*12 0x01=8*16 0x02=10*20 0x03=12*24 0x04=14*28 0x05=16*32 0x06=20*40 0x07=24*48 0x08=28*56 0x09=32*64
- Color:字符显示颜色。
- Bcolor:字符背景显示颜色。
- (x,y):字符串显示的左上角坐标。
例程:
- LCD_printf(0x42,0xffff,0xf00f,10,10,"迪文科技:%04d",x++);
如示例的调用形式将显示“迪文科技:x的值的十进制展现形式”
4.2 绘图类
- void clr(u16 Color);//清屏
- color:颜色
- void Linear_interpolation(u8 num,u16 Color,...);// 端点连线
- num:点的个数
- color:连线的颜色
- …:各点坐标
-
- void Place_point(u8 num,u16 Color,u16 nx,u16 ny,...);//绘制点
例程:
- Linear_interpolation(3,0xff00,0x0000,0x0000,0x0100,0x0100,0x0100,0x0000);
4.3 二维码显示
- void erweima(u16 x,u16 y,u8 QR_Pixel,const char *format, ...);//生成二维码
- x,y为二维码左上角坐标。QR_Pixel表示二维码每个点占用的像素点。
- …:URL此函数的分钟同样类似printf
例程:
- erweima(148,50,0x04,"https://www.dwin.com.cn");
4.4 调节背光亮度
- void DIM_Set(u8 Set);//调节背光
- set:0x00-0xff
例程:
4.5 调节串口波特率
- void Bode_Set(u16 Set);//调节扩展串口波特率
- set:波特率
例程:
- Bode_Set(9600);//设置波特率为9600
源码请参照附件