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

📄 44blcd.c

📁 自己编写的
💻 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\plmm.h"

#include "..\inc\character.h"




/*volatile char which_int=0;*/
void LcdInit(void)
{
 
  Lcd_MonoInit();
 // displaylcd();
  Uart_Printf("LCD DISPLAY\n");
  Uart_Printf("Type any key to exit!!!\n");
  
//  Uart_Getch();
}




void Lcd_MonoInit(void)
{
    //160x240 1bit/1pixel LCD
    #define MVAL_USED 0
     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)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);
	    // disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);  
	    //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 );

	rLCDCON1=(1)|(1<<1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);
	    // enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
    
}

void displaylcd(void)
{
   unsigned int *pbuffer,temp_data;
     int i=0;
    pbuffer =(U32*) frameBuffer16;
      
    clrscreen();
    for(i = 0; i< (38400/4) ;i++)
    {
       temp_data = (plmmBitmap[i*4] << 24) + (plmmBitmap[i*4+1] << 16) + (plmmBitmap[i*4+2] << 8) +(plmmBitmap[i*4+3]);
        pbuffer[i] = temp_data;

    }
}

void clrscreen(void)
{
    unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer16;
    for(i = 0; i< (38400/4) ;i++)
    {
        pbuffer[i] = 0;
 }
}

//----------------added by liangweidong 2005-8-17------------------

//---------------------------------------
//initialization 256 color LCD
//---------------------------------------
void	Lcd256_Init(void)
{
    #define MVAL_USED 0

    //initialization the ports

    //PORT C GROUP
    //IISLRCK  IISD0 IISDI IISCLK VD7 VD6 VD5 VD4 nXDACK1 nXDREQ1 GPC10 GPC11 TXD1 RXD1 GPC14 GPC15
    //All input
    //  11      11    11    11    11  11   11  11   11      11     01	01     11   11   01    01
    //rPDATC=0x8400;

    //rPCONC=0x5F5FFFFF;	
    //rPUPC=0x33ff;	//should be enabled	

    rPCONC=0x0f05ff55;	
    rPUPC=0x30f0;	//PULL UP RESISTOR should be enabled to I/O
    rPDATC=0xfeff;	//All I/O Is High   
   
    //PORT D GROUP
    //VFRAME VM VLINE VCLK VD3 VD2 VD1 VD0
    //    10,10,   10,	10, 10,	10, 10,	10  
    rPCOND=0xaaaa;	
    rPUPD=0xff;

	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*LCD_YSIZE))>>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;//0xfdb96420;
	rGREENLUT=0xfdb97531;//0xfdb96420;
	rBLUELUT =0xfb73;//0xfb40;

	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,
}


//--------------------------------------------------------------------
//函数名称: LCD_SetPixel

//功能描述: 在LCD的(x,y)处以颜色color画点;
//输   入:  画点的坐标: (x, y)   
//颜   色: color
//输   出:  无
//--------------------------------------------------------------------
void LCD_SetPixel(unsigned char x, unsigned short int y, unsigned char color)
{
       unsigned int y0, y1;
	unsigned char *pbuffer;
	pbuffer = (U8*)frameBuffer256;
       y0 = y%8;
       y1 = y/8;
       if(y0 < 4)
               y0 = 3 - y0;
       else
               y0 = 7 - y0%4;
       pbuffer[y1*8 + y0 + x*LCD_XSIZE] = color; 
}

//-----------------------------------------
//draw a line along x direction
//start point :start_x, start_y
//the length of the line is linelong
//-----------------------------------------
void ColorXLine(unsigned char start_x, unsigned short int start_y, unsigned  char linelong)
{
	unsigned char i;
	unsigned char x;
	x = LCD_YSIZE - start_x;
	for(i = 0; i < linelong; i++)
		{
			LCD_SetPixel(x-i, start_y, 0xff);
		}
}

//-----------------------------------------
//draw a line along y direction
//start point :start_x, start_y
//the length of the line is linelong
//-----------------------------------------
void ColorYLine(unsigned char start_x, unsigned short int start_y, unsigned  short int linelong)
{
	unsigned short int i;
	unsigned char x;
	x = LCD_YSIZE - start_x;
	for(i = 0; i < linelong; i++)
		{
			LCD_SetPixel(x, start_y+i, 0xff);
		}
}

//-----------------------------------------
//clear all point
//-----------------------------------------
void clrscreen_color(void)
{
    unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE/4) ;i++)
    {
        pbuffer[i] = 0;
 }
}

//test

//------------------------------------------------
//translate text code into color data and auto-display.
//------------------------------------------------
void  translate(unsigned char data_text, unsigned short int x, unsigned short int y)
{
	unsigned char temp =0;
	unsigned int k = 0;
	for(k = 8 ; k > 0 ; k --)
		{
		temp = ((data_text >>(k - 1))& 0x01) * LCD_WHITE;
		LCD_SetPixel(x, y++, temp);
		}
}

//------------------------------------------------
//display 8X16 charactor
//------------------------------------------------
void Display8X16(unsigned char data[], unsigned int x, unsigned int y)
{
	unsigned char  j, k;
	for(j = 0; j < 2; j++)
		{
		for(k = 0 ; k < 8 ; k ++)
			{
			translate(data[k + j*8], x++, y);
			}
		y = y+8;
		x = x-8;
		}
}

//------------------------------------------------
//display 6X8 charactor
//------------------------------------------------
void Display6X8(char data[], unsigned char x, unsigned short int y)
{
	unsigned char k;
	for(k = 0; k < 6; k++)
		{
	//		translate(data[k], x++, y);
			translate(data[k], x--, y);
		}
}

//------------------------------------------------
//display 8X8 charactor
//------------------------------------------------
void Display8X8(char data[], unsigned char x, unsigned short int y)
{
	unsigned char k;
	for(k = 0; k < 8; k++)
		{
			translate(data[k], x--, y);
		}
}

//------------------------------------------------
//display ASCII table charactors
//------------------------------------------------
void Display_ASCIITable(unsigned char x, unsigned short int y,   char *p)
{
	unsigned char k, c;
	k = (LCD_YSIZE -1) -x;
	do
		{
		c = *p++;
		if((c>= 32)&&(c<=122))
			{
			Display6X8(ASCII_table[c-32], k, y);
			k -=6;
			if(k >=240)
				break;
			}
		}while(c != NULL);
}

//------------------------------------------------
//display ASCII table charactors
//------------------------------------------------
//void DisplayNumber( unsigned char x, unsigned short int y,  short int n)
void Display_number( unsigned char x, unsigned short int y,  int n)
{
	unsigned char k, i;
	short int c;
	
	k = (LCD_YSIZE -1) -x;
	c = n;
	do
		{
			i = c % 10;
			c /=10;
			Display6X8(ASCII_table[(48 + i) - 32], k, y);
			k +=6;
			if(k >=240)
			break;
		}while(c != NULL);
}






void blackscreen(void)
{
    U8 *pbuffer;
    unsigned int i;
    pbuffer =(U8*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE); i++)
    {
        pbuffer[i] = 0xff;
    }
}



void drawcolorline(void)
{
unsigned int i, x =0, y = 0;
unsigned char color = 0;
for(i = 0; i < 240; i++)
	{
	LCD_SetPixel(x++, y++, color++);
	Delay(300);
	}
}

void drawcolorpic(void)
{
unsigned int x, y, i;
x = 0;
i = 0xe0;

for(x = 0; x < 80; x++ )
	{
	y = x*x/20;
	LCD_SetPixel(x, y, i);
	Delay(300);
	}
}

void  testcolor_tm320240(void)
{
    unsigned char *pbuffer;
    unsigned int i;
    pbuffer =(U8*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE) ;i++)
    {
       pbuffer[i] =i/300;
	Delay(10);
    }
}


void redscreen(void)
{
    unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE) ;i++)
    {
        pbuffer[i] = 0xe0e0e0e0;	//red
    }
}

void greenscreen(void)
{
    unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE) ;i++)
    {
        pbuffer[i] = 0x1c1c1c1c;	//green
    }
}

void bluescreen(void)
{
    unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (LCD_XSIZE*LCD_YSIZE) ;i++)
    {
        pbuffer[i] = 0x03030303;	//blue
    }
}


//----------------added by liangweidong 2005-8-17------------------

⌨️ 快捷键说明

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