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

📄 44blcd.c

📁 Colorlcdtest 是 320*240 的 256色液晶测试源程序。
💻 C
字号:
#include <string.h>
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\lcd.h"
#include "..\inc\lcdlib.h"
#include "..\inc\44blcd.h"
#include "..\inc\PLMM1.h"
#include "..\inc\PLMM2.h"
#include "..\inc\PLMM3.h"
#include "..\inc\PLMM4.h"

#define BPP 8
#define HEIGHT 240
#define WIDTH 320
//#define val (((i*j)/4)-1)

void displaylcd(char num);
void clrscreen(void);
void Lcd_MonoInit(void);
void Lcd_kb_MonoInit(void);
void init_timer0(void);
void Lcd_kb_MonoInit(void);
void displaylcd32(char x, char y, char num);
void touch_lcd(void);
int read_lcd(void);
void closetimer0(void);
void __irq timer0_int(void);
void __irq Adc_TsSep(void);
int mt0cnt=0,picturenum=0;

void __irq Adc_TsSep(void)
{
    int i;
    U32 Pt[6];
     rI_ISPC=BIT_EINT3;	//clear pending_bit
	
	//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
        //  0		1	    0          1
	rPDATE=0XA8;
	// <X-Position Read>
	rADCCON=0x1<<2;			// AIN1
	for(i=0;i<1000;i++);		//delay to set up the next channel
	for(i=0;i<5;i++)
	{
    	    rADCCON|=0x1;		// Start X-position conversion
	    while(rADCCON & 0x1);	// Check if Enable_start is low
    	    while(!(rADCCON & 0x40));	// Check ECFLG
	    Pt[i]=(0x3ff&rADCDAT);
	}
	Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
	Uart_Printf("X-Posion[AIN1] is %04d\n", Pt[5]);

    	// <Y-Position Read>
    	//TSPX(GPE4) TSPY(GPE5) TSMY(GPE6) TSMX(GPE7)
        //  1		0	      1          0
	rPDATE=0X58;
	rADCCON=0x0<<2;			// AIN0
	for(i=0;i<1000;i++);		//delay to set up the next channel
	for(i=0;i<5;i++)
	{
    	    rADCCON|=0x1;		// Start X-position conversion
	    while(rADCCON & 0x1);	// Check if Enable_start is low
    	    while(!(rADCCON & 0x40));	// Check ECFLG
	    Pt[i]=(0x3ff&rADCDAT);
	}
	Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
	Uart_Printf("Y-Posion[AIN0] is %04d\n", Pt[5]);
    	for(i=0;i<1000;i++);		//delay to set up the next channel
    	rPDATE=0X68;	//should be enabled	
    	for(i=0;i<1000;i++);		//delay to set up the next channel
}


void __irq timer0_int(void)
{
    rI_ISPC=BIT_TIMER0;
   // Uart_Printf("let's begin \n");
    mt0cnt++;
    if (mt0cnt>100)
    	{
       Uart_Printf("in 1 second the picture displayed is : %d \n", picturenum);
       mt0cnt=0;
	picturenum=0;
	}
   else ;
   return ;
}


/*volatile char which_int=0;*/
void LcdInit(void)
{
  unsigned int i=0,count=0;
  U32  Xall=0,Yall=0;
  int j=0, oldy=0,oldx=0;
  int  xmax=0,xmin=0xffff, ymax=0,ymin=0xffff;
  rPCONC = (rPCONC & (~(3<<16))) |1<<16 ; // pcon8 out
  rPDATC = rPDATC |1<<8 ;    // pdatc8 ==1  display on
 // Lcd_Init(256);
  Lcd_MonoInit();    //Lcd_kb_MonoInit();
  //touch_lcd();
  //Uart_Printf("LCD DISPLAY\n");
  //Uart_Printf("Type any key to exit!!!\n");
 // displaylcd(0);
  Uart_Printf(" NOW TEST LCD DISPLAY  \n");
  clrscreen();
  while(!(Uart_GetKey()))
  { 
    displaylcd(1);
    Delay(30000);
    displaylcd(2);
    Delay(17000);
    displaylcd(3);
    Delay(17000);
    displaylcd(4);
    Delay(17000);
  }
 //closetimer0();
  }


void init_timer0(void)
{
    rINTMSK=~(BIT_GLOBAL|BIT_TIMER0|BIT_EINT3);
    pISR_TIMER0=(U32) timer0_int; 
    rTCFG0=0x00000064;    //timer0 prescaler=200
    rTCFG1=0x00000004;     //timer0 divider value=1/32; (all interrupt)
    rTCNTB0=(unsigned int)(MCLK/(rTCFG0&0x000000ff)/32/100 );   //40*1000000/200/32/100==63   (10ms)
    rTCON=0x00a;
    rTCON=0x009;
   // rINTCON=0x5;
}

void closetimer0(void)
{    
  rINTMSK=~(BIT_TIMER0)|rINTMSK;
}


void Lcd_MonoInit(void)
{
         #define MVAL_USED 0
     if((U32)frameBuffer256==0)
	{
	    frameBuffer256=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR); 
	}

	rLCDCON1=(0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x3<<27) | ( ((U32)frameBuffer256>>22)<<21 ) | M5D((U32)frameBuffer256>>1);
	    // 256-color, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D(((U32)frameBuffer256+(SCR_XSIZE*(LINEVAL+1)))>>1) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );

	//The following value has to be changed for better display.

	rREDLUT  =0xfdb97531;
	rGREENLUT=0xfdb97531;
	rBLUELUT =0xfb73;

	rDITHMODE=0x0;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	rLCDCON1=(1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
// enable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	    
/*if((U32)frameBuffer1==0)
	{
	    if (( frameBuffer1=(unsigned int (*)[SCR_XSIZE/32])malloc(ARRAY_SIZE_COLOR))==NULL)
	    {
	      Uart_Printf("ERROR !!!!!! NO MEMERY !!!!!!!!! \n");
	    }
   	  else
	       {
	         Uart_Printf("ARRAY_SIZE_color= %d \n", ARRAY_SIZE_COLOR);
		  Uart_Printf("frameBuffer1 = %x \n", frameBuffer1);
	        }
	}

	rLCDCON1=(0)|(0<<1)|(0<<2)|(0<<3)|(2<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x3<<27) | ( ((U32)frameBuffer1>>22)<<21 ) | M5D((U32)frameBuffer1>>1);
	Uart_Printf("rLCDSADDR1 = %x \n", rLCDSADDR1);
	    // color, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D( (((rLCDSADDR1&0x1fffff)+(SCR_XSIZE*LCD_YSIZE/2))>>1) ) | (MVAL<<21);
       Uart_Printf("rLCDSADDR2 = %x \n", rLCDSADDR2);
	//rLCDSADDR2= M5D( (((U32)frameBuffer1+(SCR_XSIZE*LCD_YSIZE/2))>>1) ) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE*8/16) | ( ((SCR_XSIZE-LCD_XSIZE)*8/16)<<9 );
       Uart_Printf("rLCDSADDR3 = %x \n", rLCDSADDR3);
	///////////////////////////////
  	rLCDCON1=(1)|(1<<1)|(0<<2)|(0<<3)|(0<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // enable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
  */
      //640*480   1bit/1pixel lcd          //160x240 4bit/1pixel LCD
    /*#define MVAL_USED 1
     if((U32)frameBuffer16==0)
	{
	  if (( frameBuffer16=(unsigned int (*)[SCR_XSIZE/8])malloc(ARRAY_SIZE_G16))==NULL)
	     {
	        Uart_Printf("ERROR !!!!!!!! NO MEMERY !!!!!!! \n");
	      }
	  else
	       {
	         Uart_Printf("ARRAY_SIZE_g16= %d \n", ARRAY_SIZE_G16);
	        }
         }
      	rLCDCON1=(0)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_MONO<<12); //CLKVAL_MONO
	    // disable,4B_DUAL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);  //HOZVAL
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x2<<27) | ( ((U32)frameBuffer16>>22)<<21 ) | M5D((U32)frameBuffer16>>1);
	    // 16-lever gray  mode , LCDBANK, LCDBASEU
	rLCDSADDR2= M5D( (((U32)frameBuffer16+(SCR_XSIZE*(LINEVAL+1))/2)>>1) ) | (MVAL<<21) |(0<<29);//MVAL
          // 4*SCR_XSIZE*LCD_YSIZE/8
	rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );

       rLCDCON3 = 0;
	   // refresh is enable ;
	rLCDCON1=(1)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_MONO<<12);
	    // enable,(fan xiang), 4B_daul_SCAN,WDLY=8clk,WLH=8clk,MVAL_USED
      // rDP1_2=0;
       rDITHMODE = 0x12210;  */

} 
//

void touch_lcd(void)
{
  rPCONE=(rPCONE&0x300ff)|0x5500 ; //pe4-7 output 
  rPCONG=rPCONG|0x00c0;
  rPUPG=0x0;
   rPDATE=0xc0;
   rPUPE=0x0;	
  //rPDATE=0X68;	//should be enabled	
   rEXTINT=0x22222222;
   rINTCON=0x5;
   pISR_EINT3=(int)Adc_TsSep;

    rCLKCON=0x7ff8;
    rADCPSR=0x4;
   // rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
}


int read_lcd(void)
{
    int i=0, j=0;
    rPDATE=0x90;       //0x90  // pe7=1; pe6=0;pe5=0;pe4=1   x
    rADCCON=0x0<<2;
    for (j=0;j<500; j++) ;
    rADCCON|=0x1;		// Start X-position conversion
    while(rADCCON & 0x1);	// Check if Enable_start is low
    while(rADCCON&0x40 ==0) 
     {
       picturenum++;
     }
    i=rADCDAT&0x3ff;
   picturenum=0;   
  // i=0x141;     
   rPDATE=0x60;       // 0x60                 //pe7=0; pe6=1;pe5=0;pe4=1  y
   rADCCON=0x1<<2;
    for (j=0;j<500; j++) ;
    rADCCON|=0x1;		// Start X-position conversion
    while(rADCCON & 0x1);	// Check if Enable_start is low
    while(rADCCON&0x40 ==0) 
    {
     picturenum++;
    }
   picturenum=0; 
   rPDATE=0x60;                 // 
   i=((i&0x3ff)<<10)|(rADCDAT&0x3ff);     
   return(i);
}

 /*void displaylcd(char num)
{
   unsigned int *pbuffer,temp_data;
   int i,j=0;
   pbuffer =(U32*) frameBuffer256;
    for(i=0,j=0;i<19200;i++,j=j+4)
   {
      pbuffer[i]=(plmmBitmap[j]<<24)+(plmmBitmap[j+1]<<16)+(plmmBitmap[j+2]<<8)+plmmBitmap[j+3];	  
   }

 }   */

void displaylcd(char num)
{
    unsigned int *pbuffer,temp_data;
     int i,j=0;
    pbuffer =(U32*) frameBuffer256;
    if (num == 1)
      {
          for(i=0,j=0;i<19200;i++,j=j+4)
              {
                pbuffer[i]=(plmmBitmap1[j]<<24)+(plmmBitmap1[j+1]<<16)+(plmmBitmap1[j+2]<<8)+plmmBitmap1[j+3];	  
              }
    	}
   else if (num == 2)
      {
          for(i=0,j=0;i<19200;i++,j=j+4)
              {
                pbuffer[i]=(plmmBitmap2[j]<<24)+(plmmBitmap2[j+1]<<16)+(plmmBitmap2[j+2]<<8)+plmmBitmap2[j+3];	  
              }
    	}
  else if (num == 3)
      {
          for(i=0,j=0;i<19200;i++,j=j+4)
              {
                pbuffer[i]=(plmmBitmap3[j]<<24)+(plmmBitmap3[j+1]<<16)+(plmmBitmap3[j+2]<<8)+plmmBitmap3[j+3];	  
              }
    	} 
  else if (num == 4)
      {
          for(i=0,j=0;i<19200;i++,j=j+4)
              {
                pbuffer[i]=(plmmBitmap4[j]<<24)+(plmmBitmap4[j+1]<<16)+(plmmBitmap4[j+2]<<8)+plmmBitmap4[j+3];	  
              }
    	} 
  
}

void clrscreen(void)
{
  int i,j;

 for (i=0;i<20;i++)
     for (j=0;j<320;j++)
   {
     frameBuffer256[j][i]=0;//(0x0FFFFFFFF);  
   }
}



⌨️ 快捷键说明

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