查看: 2662|回复: 5
打印 上一主题 下一主题

【我是新手我怕谁】【MAPS-K64四色板】之四-优化显示函数

[复制链接] qrcode

29

主题

37

帖子

109

积分

注册会员

Rank: 2

积分
109
楼主
跳转到指定楼层
发表于 2016-5-26 11:18 AM | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 qizc 于 2016-5-26 11:28 编辑

MAPS-K64四色板自带的DEMO内容十分丰富,但是有些函数只是实现了功能,并不完善。
比如LCD的驱动函数,只是能显示字符串,并不能方便的修改字体颜色,背景颜色等。
想画线画图这样的高级功能更是没有实现。
今先优化一下字符串显示函数(解决上次背景色不能设置的问题),使其能方便的更改字体与背景的颜色。
上次没有实现的问题出在函数中颜色定义的为unsigned char,而颜色参数为两个字节,所以不能有效设置。
把所有涉及的颜色的参数改为unsigned short类型后,问题得到解决,再添加字体颜色参数。
先上效果图:

再上代码:
lcdc.c:
  1. void LCDC_DrawPixel(uint16_t x, uint16_t y, unsigned short color)
  2. {
  3.     lcdc_send_cmd(0x2A);
  4.     lcdc_send_data(x>>8);
  5.     lcdc_send_data(x&0xFF);
  6.     lcdc_send_cmd(0x2B);
  7.     lcdc_send_data(y>>8);
  8.     lcdc_send_data(y&0xFF);
  9.     lcdc_send_cmd(0x2c);
  10.                 lcdc_send_data(color);
  11.                
  12. }
复制代码
  1. void LCDC_DrawChar_6x8(unsigned int x, unsigned int y, unsigned short bc,unsigned short fc,  unsigned char c)
  2. {
  3.     int k = 0, i, j;
  4.    
  5.     if (0x1F < c && c < 0x90)
  6.     {
  7.         k = (c - 0x20)*8;
  8.         for (i = 0; i < 8; i++)
  9.         {
  10.             for (j = 0; j < 6; j++)
  11.             {
  12.                 if (Font_6x8_h[k+i] & (0x01<<(7-j)))
  13.                 {
  14.                     LCDC_DrawPixel(x+j, y+i, fc);
  15.                 }
  16.                 else
  17.                 {
  18.                     if (bc)
  19.                     {
  20.                         LCDC_DrawPixel(x+j, y+i, bc);
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
复制代码
  1. void LCDC_DrawChar_8x16(unsigned int x, unsigned int y, unsigned short backcolor,unsigned short fc, unsigned char c)
  2. {
  3.     int k = 0, i, j;
  4.    
  5.     if (0x1F<c && c<0x90)
  6.     {
  7.         k = (c)*16;
  8.         for (i=0; i<16; i++)
  9.         {
  10.             for (j=0; j<8; j++)
  11.             {
  12.               if (Font_8x16_h[k+i] & 0x01<<(7-j))
  13.               {
  14.                   LCDC_DrawPixel(x+j, y+i, fc);
  15.               }
  16.               else
  17.               {
  18.                   if (backcolor)
  19.                   {
  20.                       LCDC_DrawPixel(x+j, y+i, backcolor);
  21.                   }
  22.               }
  23.             }
  24.         }
  25.     }
  26. }
复制代码


代码上传失败,见下面楼层。



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

0

主题

79

帖子

6

积分

新手上路

Rank: 1

积分
6
沙发
发表于 2016-5-26 11:24 AM | 只看该作者
本帖最后由 qizc 于 2016-5-26 15:25 编辑

lcdc.c的修改部分
  1. void LCDC_DisplayString(unsigned int x, unsigned int y, unsigned char fontsize, unsigned short backcolor, unsigned short fc,char *string)
  2. {
  3.     while (*string)
  4.     {
  5.         switch(fontsize)
  6.         {
  7.         case 0:
  8.           LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
  9.           x += 6;
  10.           break;
  11.         case 1:
  12.           LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
  13.           x += 8;
  14.           break;
  15.         default:
  16.           LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
  17.           x += 8;
  18.           break;
  19.         }
  20.     }
  21. }
复制代码


回复 支持 反对

使用道具 举报

0

主题

168

帖子

202

积分

中级会员

Rank: 3Rank: 3

积分
202
板凳
发表于 2016-5-26 11:39 AM | 只看该作者
名字很霸气
回复 支持 反对

使用道具 举报

0

主题

100

帖子

44

积分

新手上路

Rank: 1

积分
44
地板
发表于 2016-5-26 03:28 PM | 只看该作者
lcdc.h的修改部分
  1. #ifndef _LCDC_H
  2. #define _LCDC_H

  3. #include "board.h"

  4. //画笔颜色
  5. #define WHITE       0xFFFF
  6. #define BLACK              0x0000          
  7. #define BLUE               0x001F  
  8. #define BRED        0XF81F
  9. #define GRED                                  0XFFE0
  10. #define GBLUE                                 0X07FF
  11. #define RED         0xF800
  12. #define MAGENTA     0xF81F
  13. #define GREEN       0x07E0
  14. #define CYAN        0x7FFF
  15. #define YELLOW      0xFFE0
  16. #define BROWN                         0XBC40 //棕色
  17. #define BRRED                         0XFC07 //棕红色
  18. #define GRAY                          0X8430 //灰色
  19. //GUI颜色

  20. #define DARKBLUE               0X01CF        //深蓝色
  21. #define LIGHTBLUE               0X7D7C        //浅蓝色  
  22. #define GRAYBLUE                0X5458 //灰蓝色


  23. #define LIGHTGREEN             0X841F //浅绿色
  24. //#define LIGHTGRAY     0XEF5B //浅灰色(PANNEL)
  25. #define LGRAY                                          0XC618 //浅灰色(PANNEL),窗体背景色

  26. #define LGRAYBLUE              0XA651 //浅灰蓝色(中间层颜色)
  27. #define LBBLUE          0X2B12 //浅棕蓝色(选择条目的反色)

  28. extern void LCDC_Init(void);
  29. extern void LCDC_DisplayChar(unsigned int x, unsigned int y, unsigned char font, unsigned short bc,unsigned short fc,  char c);
  30. extern void LCDC_DisplayString(unsigned int x, unsigned int y, unsigned char fi, unsigned short bc,unsigned short fc, char *string);
  31. extern void LCDC_Bmp(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned short *bmp);
  32. extern void LCDC_Fill_Color(unsigned short color);
复制代码


回复 支持 反对

使用道具 举报

0

主题

89

帖子

26

积分

新手上路

Rank: 1

积分
26
5#
发表于 2016-5-26 03:28 PM | 只看该作者
测试语句
  1. LCDC_Fill_Color(0X0000);

  2.         //LCDC_Bmp(0,0,320,240,(unsigned short *)p1);
  3.                                 LCDC_DisplayString(0, 0, 1, RED,BLACK, "My Freescale testing RED");
  4.                                 LCDC_DisplayString(0, 20, 1, GRAY,WHITE, "My Freescale testing GRAY");
  5.                                 LCDC_DisplayString(0, 40, 1, BLUE,WHITE, "My Freescale testing BLUE");
  6.                                 LCDC_DisplayString(0, 60, 1, BRED,WHITE, "My Freescale testing BRED");
  7.                                 LCDC_DisplayString(0, 80, 1, GRED,GREEN, "My Freescale testing GRED");
  8.                                 LCDC_DisplayString(0, 100, 1, GBLUE,GREEN, "My Freescale testing GBLUE");
  9.                                 LCDC_DisplayString(0, 120, 1, MAGENTA,GREEN, "My Freescale testing MAGENTA");
  10.                                 LCDC_DisplayString(0, 140, 1, GREEN,BLUE, "My Freescale testing GREEN");
  11.                                 LCDC_DisplayString(0, 160, 1, CYAN,BLUE, "My Freescale testing CYAN");
  12.                                 LCDC_DisplayString(0, 180, 1, YELLOW,BLUE, "My Freescale testing YELLOW");

复制代码


回复 支持 反对

使用道具 举报

0

主题

86

帖子

18

积分

新手上路

Rank: 1

积分
18
6#
发表于 2016-5-26 03:31 PM | 只看该作者
void LCDC_DisplayChar这个函数复制代码报错,相应的修改就行。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表