查看: 2681|回复: 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
回复

使用道具 举报

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

本版积分规则

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