⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdtest.c.bak

📁 以一种4级灰度的液晶为例
💻 BAK
字号:
/*******************************************************************/
/* NAME:       lcdtest.C                                           */
/* DEDCRIPTION:This program can transfer true color BMP(24bit) to  */
/*             TFT-LCD(16bit) HEX file                             */
/* AUTHOR:     linfei                                              */
/* DATE:       2005.6.1                                           */
/*******************************************************************/

#include "stdio.h"

int main(void)
{
	FILE *fp,*fout;
	int i,j;
	unsigned short width,height,widthbyte;
	unsigned short temp0,temp1,temp2;
	unsigned char ch1,ch2;
  unsigned char image[116160];                /*the sizes of 220*176 Bytes*/
  unsigned short buffer[220][172];            /*the lcd data*/
  
  
  if((fp=fopen("tiger.bmp","rb"))==NULL)      /*Is it exist?*/
  {
    printf("\n Can't open BMP file!");
    return 0;
  }

  ch1=fgetc(fp);
	ch2=fgetc(fp);
	if((ch1!='B')||(ch2!='M'))                  /*Is it BMP file?*/
	{
		printf("It's Not BMP file!\n");
		return 0;
	}

	fseek(fp,0x1c,0);
	ch1=fgetc(fp);
	if(ch1!=0x18)                              /*Is it 24bit true color BMP?*/
	{
		printf("It's Not 24bit true color BMP file!\n");
		return 0;
	}
  

	fseek(fp,0x12,0);                          /*get the width on 0x12*/
	width=fgetc(fp);
	fseek(fp,0x16,0);                          /*get the height on 0x16*/
	height=fgetc(fp);

	if((width>0xB0)||(height>0xDC))            /*Is it conform to the LCD(<=220*176)?*/
	{
		printf("The size of BMP is too big!\n");
    return 0;
	}

	if((width*3%4)==0)                         /*every scan-line has N*4Bytes*/
		widthbyte=width*3;
	else
		//widthbyte=width*3+(4-(width*3%4));
		widthbyte=(width*3/4)*4+4;   
  
	fseek(fp,0x0a,0);                          /*get the offset of the imagedata */
	ch1=fgetc(fp);
	fseek(fp,ch1,0);

  fread(image,1,116160,fp);                  /*read the imagedata to Array*/
  
  for(i=0;i<220;i++)                         /*buffer initialization*/
  {
  	for(j=0;j<176;j++)
  	   buffer[i][j]=0;
  }         
  for(i=0;i<height;i++)                      /*write image data to buffer*/
	{
		for(j=0;j<widthbyte;j+=3)
		{
			temp0=image[i*widthbyte+j]>>3;
			temp1=image[i*widthbyte+j+1]>>2;
			temp2=image[i*widthbyte+j+2]>>3;

			buffer[i][j/3]=temp2;
			buffer[i][j/3]+=temp1<<5;
			buffer[i][j/3]+=temp0<<11;
		}
	}
	
	fprintf(fout,"/*The info of BMPDATA:width=%d  height=%d*/\n",width,height);
	fprintf(fout,"const unsigned short lcdbuffer[%d][%d]={ \n",width,height);
	
	for(i=0;i<height;i++)                     /*putout the hex data to array*/
	{
		fprintf(fout,"{");
		for(j=0;j<width;j++)
		{
				fprintf(fout,"0x%x,",buffer[i][j]);
		    if((j+1)%8==0) 
		      fprintf(fout,"\n");
	  }
	  fprintf(fout,"}\n");
	}
	fprintf(fout,"};\n");
	
 	fclose(fp);
 	fclose(fout); 
 	return 1;
}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -