MAPS-KL43套件无论是在结构上还是在外设资源配置上都是非常有特色的,很适合学习与开发者使用,单从显示器件的配备上就可体会到这一点,它不但配有笔端式显示屏来替代耗能的数码管显示,还提供了单色和彩色的液晶屏了,从而不仅能显示字符还可以显示图案、图形,甚至显示彩色的图片。 当然事无巨细,它在一些例程的细节处也是还有需完善的地方,以彩色液晶屏的demo为例,它只提供了一种字符串显示的相关函数,但却没有提供相应的汉字显示函数、图形绘制的相关函数及图片显示函数。为此,我们在这方面做一些介绍以发挥该显示屏的功效。 另外,在外设配置上还提供了mini SD卡座,为SD卡的使用给予了方便。但在demo中却缺少相关的资源支持,为此基于SD卡的文件系统也就更无影无踪了,然而这在多媒体应用方面却是十分重要和关键的,如数码相框功能等都是基于文件系统的支持,因此它也是有待填补的方向。 项目就分别对MDM2802液晶屏在中文显示、图形绘制及图片显示方面的内容加以具体的介绍。 1.图片显示 由于缺少SD卡之类的大容量存储器件的支持,要测试图片显示功能,只好把图片的数组存储在数组中,这样就大大地限制了图片的数量及尺寸规格。以一个40*40像素的QQ企鹅图片的显示为例,它需要使用一个3200字节的一维数组,该数组的存储形式如下所示: uint8_t image[]= { /* 0X00,0X10,0X28,0X00,0X28,0X00,0X01,0X1B,*/ 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XBE,0XF7,0X7D,0XEF, 。。。 } 实现图片再现的函数为showimage(),其显示效果如所示。 图片显示效果
相应的程序代码如下: - void showimage(void)
- {
- int i,j;
- set_cursor(10,30);
- gram_prepare();
- for(j=0;j<40;j++)
- {
- set_cursor(10,30+j);
- gram_prepare();
- for(i=0;i<40;i++)
- {
- write_data(image[(j*40+i)*2+1]);
- write_data(image[(j*40+i)*2]);
- }
- }
- }
复制代码1.图形绘制 图形绘制至少需要直线、圆、矩形等绘制函数所组成,为此提供相应的函数来支持,其中:绘制直线函数为 LCD_DrawLine()、矩形的函数为LCD_DrawRectangle()、圆的函数为Draw_Circle()。 各函数的具体内容如下: - void LCD_DrawLine(int fcolor,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
- {
- uint16_t t;
- int xerr=0,yerr=0,delta_x,delta_y,distance;
- int incx,incy,uRow,uCol;
- delta_x=x2-x1;
- delta_y=y2-y1;
- uRow=x1;
- uCol=y1;
- if(delta_x>0)incx=1;
- else if(delta_x==0)incx=0;
- else {incx=-1;delta_x=-delta_x;}
- if(delta_y>0)incy=1;
- else if(delta_y==0)incy=0;
- else{incy=-1;delta_y=-delta_y;}
- if( delta_x>delta_y)distance=delta_x;
- else distance=delta_y;
- for(t=0;t<=distance+1;t++ )
- {
- ili9341_draw_pixel(fcolor,uRow, uCol);
- xerr+=delta_x ;
- yerr+=delta_y ;
- if(xerr>distance)
- {
- xerr-=distance;
- uRow+=incx;
- }
- if(yerr>distance)
- {
- yerr-=distance;
- uCol+=incy;
- }
- }
- }
- void LCD_DrawRectangle(int fcolor,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
- {
- LCD_DrawLine(fcolor,x1,y1,x2,y1);
- LCD_DrawLine(fcolor,x1,y1,x1,y2);
- LCD_DrawLine(fcolor,x1,y2,x2,y2);
- LCD_DrawLine(fcolor,x2,y1,x2,y2);
- }
- void Draw_Circle(int fcolor,uint16_t x0,uint16_t y0,uint8_t r)
- {
- int a,b;
- int di;
- a=0;b=r;
- di=3-(r<<1);
- while(a<=b)
- {
- ili9341_draw_pixel(fcolor,x0-b, y0-a); //3
- ili9341_draw_pixel(fcolor,x0+b,y0-a); //0
- ili9341_draw_pixel(fcolor,x0-a,y0+b); //1
- ili9341_draw_pixel(fcolor,x0-b,y0-a); //7
- ili9341_draw_pixel(fcolor,x0-a,y0-b); //2
- ili9341_draw_pixel(fcolor,x0+b,y0+a); //4
- ili9341_draw_pixel(fcolor,x0+a,y0-b); //5
- ili9341_draw_pixel(fcolor,x0+a,y0+b); //6
- ili9341_draw_pixel(fcolor,x0-b,y0+a);
- a++;
- if(di<0)di +=4*a+6;
- else
- {
- di+=10+4*(a-b);
- b--;
- }
- ili9341_draw_pixel(fcolor,x0+a, y0+b);
- }
- }
复制代码为了便于管理,应将新增加的函数放在ili9341.c文件中,并在ili9341.h中添加一些语句: extern uint16_t BACK_COLOR, POINT_COLOR; extern void LCD_DrawLine(int fcolor,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); extern void LCD_DrawRectangle(int fcolor,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); extern void Draw_Circle(int fcolor,uint16_t x0,uint16_t y0,uint8_t r); extern void showimage(void); extern void showhanzi(unsigned int x,unsigned int y,unsigned char index);
图形与汉字显示效果
1.中文显示,(中文小字库创建、中文显示) 在不具备硬字库的条件下。可通过字模提取软件来构建小字库,以实现汉字显示。以1个32*32点汉字显示为例,其字模定义如下: uint8_t hanzi[]= { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0xFE,0xFF,0x01, 0x00,0xFE,0xFF,0x01,0x00,0x06,0xC0,0x00,0x00,0x06,0xC0,0x00,0x00,0x06,0xC0,0x00, 0x00,0xFE,0xFF,0x00,0x00,0x06,0xC0,0x00,0x00,0x06,0xC0,0x00,0x00,0x06,0xC0,0x00, 0x00,0xFE,0xFF,0x00,0x00,0x06,0xC0,0x00,0x00,0x06,0xC0,0x00,0x00,0x02,0x00,0x00, 0x30,0x30,0x0C,0x1C,0xF0,0x7F,0xFC,0x3F,0x30,0x30,0x0C,0x1C,0x30,0x30,0x0C,0x1C, 0x30,0x30,0x0C,0x1C,0x30,0x30,0x0C,0x1C,0xF0,0x3F,0xFC,0x1F,0x30,0x30,0x0C,0x1C, 0x30,0x30,0x0C,0x1C,0x30,0x30,0x0C,0x1C,0x30,0x30,0x0C,0x1C,0xF0,0x3F,0xFC,0x1F, 0xF0,0x3F,0xFC,0x1F,0x30,0x30,0x0C,0x1C,0x30,0x10,0x04,0x0C,0x00,0x00,0x00,0x00, 。。。 } 在下面的汉字显示函数配合下,可显示中文的显示。 - void showhanzi(unsigned int x,unsigned int y,unsigned char index)
- {
- unsigned char i,j,k;
- unsigned char *temp=hanzi;
- temp+=index*128;
- for(j=0;j<32;j++)
- {
- for(k=0;k<4;k++)
- {
- for(i=0;i<8;i++)
- {
- if((*temp&(1<<i))!=0)
- {
- ili9341_draw_pixel(POINT_COLOR, x+i+k*8, y+j);
- }
- else
- {
- ili9341_draw_pixel(BACK_COLOR, x+i+k*8, y+j);
- }
- }
- temp++;
- }
- }
- }
复制代码在以上函数的支持下,由main()函数添加以下语句即可体会劳动的快乐。 GUI_printf(0, 0, "HelloWorld!\r\n"); showimage(); xianshi(); showhanzi(0,50,0); showhanzi(32,50,1); LCD_DrawLine(RED,0, 60, 200, 60); LCD_DrawRectangle(BLUE,50, 100, 150, 180); Draw_Circle(GREEN,100,200,60);
|