硬件准备
ADSP-EDU-BF533:BF533开发板
AD-HP530ICE:ADI DSP仿真器
软件准备
Visual DSP++软件
硬件链接
功能介绍
代码实现了将字库信息显示到液晶屏上。
代码使用说明
增加了液晶屏驱动,将内存数据显示到液晶屏上。
内存数据转换:
RGB888_RGB565(DisplayBuffer,391680,DisplayBuffer_565);
将 DisplayBuffer 数组中的 RGB888 格式数据转为 RGB565 格式,存在 DisplayBuffer_565 中,数据转换大小为 391680 字节。
代码实验步骤
在液晶屏上可以看到内存的数据显示出。
程序源码
cpu.c
#include
void Set_PLL(int pmsel,int pssel)
{
int new_PLL_CTL;
*pPLL_DIV = pssel;
asm(“ssync;”);
new_PLL_CTL = (pmsel & 0x3f) << 9;
*pSIC_IWR |= 0xffffffff;
if (new_PLL_CTL != *pPLL_CTL)
{
*pPLL_CTL = new_PLL_CTL;
asm(“ssync;”);
asm(“idle;”);
}
}
void Init_SDRAM(void)
{
*pEBIU_SDRRC = 0x00000817;
*pEBIU_SDBCTL = 0x00000013;
*pEBIU_SDGCTL = 0x0091998d;
ssync();
}
void Init_EBIU(void)
{
*pEBIU_AMBCTL0 = 0x7bb07bb0;
*pEBIU_AMBCTL1 = 0x7bb07bb0;
*pEBIU_AMGCTL = 0x000f;
}
void Init_Timers0(int dat)
{
*pTIMER0_CONFIG = 0x0019;
*pTIMER0_WIDTH = dat;
*pTIMER0_PERIOD = 2000;
}
void Enable_Timers0(void)
{
*pTIMER_ENABLE|= 0x0001;
asm(“ssync;”);
}
void Disable_Timers0(void)
{
*pTIMER_DISABLE |= 0x0001;
}
ziku.c
#include “ascii16_8.h”
#include “hzk16.h”
extern unsigned char DisplayBuffer[272][1440];
void PutPixel(int x,int y,unsigned int color)
{
if((x<480)&&(y<272))
{
DisplayBuffer[y][3x] = (color>>16)&0xff;
DisplayBuffer[y][3x+1] = (color>>8)&0xff;
DisplayBuffer[y][3*x+2] = (color)&0xff;
}
}
/以特定颜色填充一块区域/
void Rect(int x,int y,int width,int high,unsigned int color)
{
int i,j;
for(i=y;i
for(j=x;j<(x+width);j++)
{
DisplayBuffer[i][3j] = (color>>16)&0xff;
DisplayBuffer[i][3j+1] = (color>>8)&0xff;
DisplayBuffer[i][3*j+2] = (color)&0xff;
}
}
}
//水平方向显示字符串
void Glib_disp_ascii16x8_v(int x,int y,char *s,int colour)
{
int i,j,k;
while(*s)
{
for(i=0;i<91;i++)
{
if(*s==ASCII_16x8[i].Index)
{
for (j=0;j<16;j++)
{
for(k=0;k<8;k++)
{
if( ((ASCII_16x8[i].ASCII_Dot[j]>>(7-k)) & 0x1)!=0 )
{
PutPixel(x+k,y+j,colour); //加4条暗线
}
}
}
}
}
s+=1;
x+=8;
}
}
//显示汉字
void Glib_disp_hzk16_v(int x,int y,char s,int colour)
{
char buffer[32]; / 32字节的字模缓冲区 /
int i,j,k;
unsigned char qh,wh;
unsigned long location;
while(s)
{
qh=s-0xa0; / 计算区码 /
wh=(s+1)-0xa0; / 计算位码 /
location=(94(qh-1)+(wh-1))32L; / 计算字模在文件中的位置 /
memcpy(buffer, &HZK16X16[location], 32); / 获取汉字字模 /
for(i=0;i<16;i++) / 每一行 /
{
for(j=0;j<2;j++) / 一行两个字节 /
{
for(k=0;k<8;k++) / 每个字节按位显示 /
{
if(((buffer[i2+j]>>(7-k)) & 0x1) != 0)
PutPixel(x+8(j)+k,y+4+i,colour); /* 显示一位 /
}
}
}
s+=2; / 下一个汉字 /
x+=16; / 汉字间距 */
}
}
void Mouse(int x,int y,int color)
{
int i,j,k;
for (i=0;i<16;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<8;k++)
{
if( ((mouse[i2+j]>>(7-k)) & 0x1)!=0 )
{
PutPixel(x+8j+k,y+i,color);
}
}
}
}
}
tftlcd.c
#include
section(“sdram0_bank1”) unsigned char DisplayBuffer[272][1440] ;
section(“sdram0_bank1”) unsigned char DisplayBuffer_565[272][1440] ;
section(“sdram0_bank1”) unsigned char TempBuffer_img[272][1440] ;
section(“sdram0_bank1”) unsigned char Inputdata[391734];
void InitDMA(void)
{
int addr;
addr = &DisplayBuffer_565;
addr -= 1920;
*pDMA0_START_ADDR = addr;
*pDMA0_X_COUNT = 480;
*pDMA0_X_MODIFY = 2;
*pDMA0_Y_COUNT = 286;
*pDMA0_Y_MODIFY = 2;
*pDMA0_CONFIG = 0x1034;
}
void InitPPI(void)
{
*pPPI_CONTROL = 0x781e;
*pPPI_DELAY = 0;
*pPPI_COUNT = 479;
*pPPI_FRAME = 286;
}
void InitTimer(void)
{
*pTIMER1_PERIOD = 525;
*pTIMER1_WIDTH = 41;
*pTIMER1_CONFIG = 0x00a9;
*pTIMER2_PERIOD = 150150;
*pTIMER2_WIDTH = 5250;
*pTIMER2_CONFIG = 0x00a9;
}
void PPI_TMR_DMA_Enable(void)
{
*pDMA0_CONFIG |= 0x1;
asm(“ssync;”);
InitTimer();
*pPPI_CONTROL |= 0x1;
asm(“ssync;”);
*pTIMER_ENABLE|= 0x0006;
asm(“ssync;”);
}
void PPI_TMR_DMAR_Disable(void)
{
*pDMA0_CONFIG &= (~0x1);
*pPPI_CONTROL &= (~0x1);
}
void bgrtorgb24(void)
{
int i,j;
int a,b,c;
for(i=0;i<272;i++)
{
for(j=0;j<1440;j++)
{
TempBuffer_img[i][j] = Inputdata[i1440+j+54];
}
}
for(i=0;i<272;i++)
{
for(j=0;j<480;j++)
{
a = TempBuffer_img[i][j3];
b = TempBuffer_img[i][j3+1];
c = TempBuffer_img[i][j3+2];
TempBuffer_img[i][j3] = c;
TempBuffer_img[i][j3+1] = b;
TempBuffer_img[i][j*3+2] = a;
}
}
for(i=0;i<272;i++)
{
for(j=0;j<1440;j++)
{
DisplayBuffer[i][j] = (TempBuffer_img[271-i][j]);
}
}
}
void color_bar(void)
{
int i,j;
for(i=0;i<272;i++)
{
for(j=0;j<40;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0x00;
DisplayBuffer[i][j*3+2] = 0x00;
}
for(j=40;j<80;j++)
{
DisplayBuffer[i][j*3+0] = 0xff;
DisplayBuffer[i][j*3+1] = 0x00; DisplayBuffer[i][j*3+1] = 0x00;
DisplayBuffer[i][j*3+2] = 0x00;//red
}
for(j=80;j<120;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0x00;//green
}
for(j=120;j<160;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0x00;
DisplayBuffer[i][j*3+2] = 0xff;//blue
}
for(j=160;j<200;j++)
{
DisplayBuffer[i][j*3+0] = 0xff;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0x0;//red+green
}
for(j=200;j<240;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0xff;//red+blue
}
for(j=240;j<280;j++)
{
DisplayBuffer[i][j*3+0] = 0xff;
DisplayBuffer[i][j*3+1] = 0x00;
DisplayBuffer[i][j*3+2] = 0xff;//green+blue
}
for(j=280;j<320;j++)
{
DisplayBuffer[i][j*3+0] = 0xff;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0xff;
}
for(j=320;j<360;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0x00;//green
}
for(j=360;j<400;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0x00;
DisplayBuffer[i][j*3+2] = 0xff;//blue
}
for(j=400;j<440;j++)
{
DisplayBuffer[i][j*3+0] = 0xff;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0x0;//red+green
}
for(j=440;j<480;j++)
{
DisplayBuffer[i][j*3+0] = 0x00;
DisplayBuffer[i][j*3+1] = 0xff;
DisplayBuffer[i][j*3+2] = 0xff;//red+blue
}
}
}
void RGB888_RGB565(unsigned char *src, int src_len, unsigned char *dst)
{
int i = 0;
int j = 0;
if (src_len % 3 != 0)
{
return;
}
for (i = 0; i < src_len; i += 3)
{
dst[j+1] = src[i+2] &0xf8; //B
dst[j+1] |= ((src[i+1]>>5) & 0x07); //GH
dst[j] = ((src[i+1]<<3) & 0xe0); //GL
dst[j] |= ((src[i]>>3) &0x1f); //R
j += 2;
}
}
main.c
#include
extern unsigned char DisplayBuffer[272][1440] ;
extern unsigned char DisplayBuffer_565[272][1440] ;
extern unsigned char Inputdata[];
void main(void)
{
Set_PLL(16,4);
Init_EBIU();
Init_SDRAM();
LCDBK_Disable();
memset(DisplayBuffer,'\0',391680);
Glib_disp_ascii16x8_v(130,0,"A",0x0000ff);//显示ASCII字符
Glib_disp_ascii16x8_v(138,0,"bcd",0xffffff);
Glib_disp_ascii16x8_v(162,0,"E",0xffff00);
Glib_disp_ascii16x8_v(170,0,"f",0xff0000);
Glib_disp_ascii16x8_v(178,0,"GH",0xffffff);
Glib_disp_hzk16_v(130,200,"北京",0xffffff);
Rect(100,100,200,100,0xff0000);
Mouse(240,135,0x00ff00);
Glib_disp_hzk16_v(100,130,"液晶屏汉字库测试",0x0000ff);
RGB888_RGB565(DisplayBuffer,391680,DisplayBuffer_565);
InitDMA();
InitPPI();
InitTimer();
PPI_TMR_DMA_Enable();
Init_Timers0(1999);//1~1999 控制背光亮度
Enable_Timers0();
LCD_Enable();
LCDBK_Enable();
while(1);
}