烽火社区
标题:
【我是新手我怕谁】【MAPS-K64四色板】之四-优化显示函数
[打印本页]
作者:
漫漫人生路
时间:
2016-5-26 11:18 AM
标题:
【我是新手我怕谁】【MAPS-K64四色板】之四-优化显示函数
本帖最后由 qizc 于 2016-5-26 11:28 编辑
MAPS-K64四色板自带的DEMO内容十分丰富,但是有些函数只是实现了功能,并不完善。
比如LCD的驱动函数,只是能显示字符串,并不能方便的修改字体颜色,背景颜色等。
想画线画图这样的高级功能更是没有实现。
今先优化一下字符串显示函数(解决上次背景色不能设置的问题),使其能方便的更改字体与背景的颜色。
上次没有实现的问题出在函数中颜色定义的为unsigned char,而颜色参数为两个字节,所以不能有效设置。
把所有涉及的颜色的参数改为unsigned short类型后,问题得到解决,再添加字体颜色参数。
先上效果图:
[attach]29009[/attach]
再上代码:
lcdc.c:
void LCDC_DrawPixel(uint16_t x, uint16_t y, unsigned short color)
{
lcdc_send_cmd(0x2A);
lcdc_send_data(x>>8);
lcdc_send_data(x&0xFF);
lcdc_send_cmd(0x2B);
lcdc_send_data(y>>8);
lcdc_send_data(y&0xFF);
lcdc_send_cmd(0x2c);
lcdc_send_data(color);
}
复制代码
void LCDC_DrawChar_6x8(unsigned int x, unsigned int y, unsigned short bc,unsigned short fc, unsigned char c)
{
int k = 0, i, j;
if (0x1F < c && c < 0x90)
{
k = (c - 0x20)*8;
for (i = 0; i < 8; i++)
{
for (j = 0; j < 6; j++)
{
if (Font_6x8_h[k+i] & (0x01<<(7-j)))
{
LCDC_DrawPixel(x+j, y+i, fc);
}
else
{
if (bc)
{
LCDC_DrawPixel(x+j, y+i, bc);
}
}
}
}
}
}
复制代码
void LCDC_DrawChar_8x16(unsigned int x, unsigned int y, unsigned short backcolor,unsigned short fc, unsigned char c)
{
int k = 0, i, j;
if (0x1F<c && c<0x90)
{
k = (c)*16;
for (i=0; i<16; i++)
{
for (j=0; j<8; j++)
{
if (Font_8x16_h[k+i] & 0x01<<(7-j))
{
LCDC_DrawPixel(x+j, y+i, fc);
}
else
{
if (backcolor)
{
LCDC_DrawPixel(x+j, y+i, backcolor);
}
}
}
}
}
}
复制代码
代码上传失败,见下面楼层。
作者:
ElC—YL
时间:
2016-5-26 11:24 AM
本帖最后由 qizc 于 2016-5-26 15:25 编辑
lcdc.c的修改部分
void LCDC_DisplayString(unsigned int x, unsigned int y, unsigned char fontsize, unsigned short backcolor, unsigned short fc,char *string)
{
while (*string)
{
switch(fontsize)
{
case 0:
LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
x += 6;
break;
case 1:
LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
x += 8;
break;
default:
LCDC_DisplayChar(x, y, fontsize, backcolor,fc, *string++);
x += 8;
break;
}
}
}
复制代码
作者:
回复用户5
时间:
2016-5-26 11:39 AM
名字很霸气
作者:
cqulp
时间:
2016-5-26 03:28 PM
lcdc.h的修改部分
#ifndef _LCDC_H
#define _LCDC_H
#include "board.h"
//画笔颜色
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
//GUI颜色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
#define LIGHTGREEN 0X841F //浅绿色
//#define LIGHTGRAY 0XEF5B //浅灰色(PANNEL)
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
extern void LCDC_Init(void);
extern void LCDC_DisplayChar(unsigned int x, unsigned int y, unsigned char font, unsigned short bc,unsigned short fc, char c);
extern void LCDC_DisplayString(unsigned int x, unsigned int y, unsigned char fi, unsigned short bc,unsigned short fc, char *string);
extern void LCDC_Bmp(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned short *bmp);
extern void LCDC_Fill_Color(unsigned short color);
复制代码
作者:
南风hny
时间:
2016-5-26 03:28 PM
测试语句
LCDC_Fill_Color(0X0000);
//LCDC_Bmp(0,0,320,240,(unsigned short *)p1);
LCDC_DisplayString(0, 0, 1, RED,BLACK, "My Freescale testing RED");
LCDC_DisplayString(0, 20, 1, GRAY,WHITE, "My Freescale testing GRAY");
LCDC_DisplayString(0, 40, 1, BLUE,WHITE, "My Freescale testing BLUE");
LCDC_DisplayString(0, 60, 1, BRED,WHITE, "My Freescale testing BRED");
LCDC_DisplayString(0, 80, 1, GRED,GREEN, "My Freescale testing GRED");
LCDC_DisplayString(0, 100, 1, GBLUE,GREEN, "My Freescale testing GBLUE");
LCDC_DisplayString(0, 120, 1, MAGENTA,GREEN, "My Freescale testing MAGENTA");
LCDC_DisplayString(0, 140, 1, GREEN,BLUE, "My Freescale testing GREEN");
LCDC_DisplayString(0, 160, 1, CYAN,BLUE, "My Freescale testing CYAN");
LCDC_DisplayString(0, 180, 1, YELLOW,BLUE, "My Freescale testing YELLOW");
复制代码
作者:
hncb0093
时间:
2016-5-26 03:31 PM
void LCDC_DisplayChar这个函数复制代码报错,相应的修改就行。
欢迎光临 烽火社区 (https://bbs.cnecport.com/)
Powered by Discuz! X3.2