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

📄 lcd.c

📁 在arm realview下的s3c2410开发板测试工程及代码
💻 C
字号:
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "lcdlib.h"
#include "lcd.h"

void Lcd_Port_Init(void);
void Lcd_Port_Return(void);
int LCD_Menu(void);
void Display_Photo(void);
unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON; 
unsigned lcd_count;
extern volatile U32 downloadFileSize;
extern U32 tempDownloadAddress;


void Lcd_Port_Init(void)
{
    save_rGPCCON=rGPCCON;
    save_rGPCDAT=rGPCDAT;
    save_rGPCUP=rGPCUP;
    save_rGPDCON=rGPDCON;
    save_rGPDDAT=rGPDDAT;
    save_rGPDUP=rGPDUP;
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
    Uart_Printf("Initializing GPIO ports..........\n");
}

void Lcd_Port_Return(void)
{
    rGPCCON=save_rGPCCON;
    rGPCDAT=save_rGPCDAT;
    rGPCUP=save_rGPCUP;
    rGPDCON=save_rGPDCON;
    rGPDDAT=save_rGPDDAT;
    rGPDUP=save_rGPDUP;
}



void Test_Lcd_Cstn_8Bit(void)
{
    int i,j;
    int x1,x2,y1,y2;
    U32 Color;
    U32 photoSize;
    char cKey;
    Lcd_Port_Init();
    Lcd_Init();
    Lcd_CstnOnOff(1); // Enable ENVID Bit and GPB5 output
    Uart_Printf("[CSTN LCD(8bit/1pixel) WILL BE TURNED ON EVEN DURING OTHER TEST]\n");
    Uart_Printf("If you'd like to off the CSTN LCD, then excute other LCD test program,\n"); 
    while(1)
    {
		LCD_Menu();
		cKey=0;
		while(cKey==0)
		{
			cKey=Uart_GetKey();//waiting for a key
		}
		switch(cKey)
		{
		case '0':
			Color=0;
			Uart_Printf("\n[0]	Clear the sreen!");   
			Uart_Printf("\nPlease input color RGB[<255]:",Color);
                        Color=Uart_GetIntNum();
                        Glib_ClearScr(Color);
                        break;
		case '1':
			Color=0;
			Uart_Printf("\n[0]	Draw a line!");   
			Uart_Printf("\nPlease input color RGB[0h~%xh]:",Color);
			x1=y1=0;
			x2=320;
			y2=240;
                           Color=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate x1[0h~%x1]:",x1);
                           x1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the right top coordinate x2[0h~%x2]:",x2);
                           x2=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y1[0h~%y1]:",y1);
                           y1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y2[0h~%y2]:",y2);
                           y2=Uart_GetIntNum();
                           Glib_Line(x1,y1,x2,y2,Color);
			break;
                case '2':
			Color=0;
			Uart_Printf("\n[0]	Draw a rectangle!");   
			Uart_Printf("\nPlease input color RGB[0h~%xh]:",Color);
			x1=y1=0;
			x2=320;
			y2=240;
                        Color=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate x1[0h~%x1h]:",x1);
                        x1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the right top coordinate x2[0h~%x2h]:",x2);
                        x2=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y1[0h~%y1h]:",y1);
                        y1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y2[0h~%y2h]:",y2);
                        y2=Uart_GetIntNum();
                        Glib_Rectangle(x1,y1,x2,y2,Color);
                        break;
                case '3':
			Color=0;
			Uart_Printf("\n[0]	Fill a rectangle!");   
			Uart_Printf("\nPlease input color RGB[0h~%xh]:",Color);
			x1=y1=0;
			x2=320;
			y2=240;
                           Color=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate x1[0h~%x1h]:",x1);
                           x1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the right top coordinate x2[0h~%x2h]:",x2);
                           x2=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y1[0h~%y1h]:",y1);
                           y1=Uart_GetIntNum();
			Uart_Printf("\nPlease input the left top coordinate y2[0h~%y2h]:",y2);
                           y2=Uart_GetIntNum();
                           Glib_FilledRectangle(x1,y1,x2,y2,Color);
                        break;
	       case '4':
	       		Display_Photo();
		      
		      break;
                case 'q':
                        break;
		default:
			Uart_Printf("An invalidate key,please input it again!\n");   
			break;  
               }
               if(cKey=='q')
                    break;			
			                        
       }                        						
			
    Uart_Printf("Data have been transfered to LCD,Please Check it!\n");     
    Uart_Printf("LCD Test is Over!\n");    
    Lcd_CstnOnOff(0); // Enable ENVID Bit and GPB5 output
    return; 


}
int LCD_Menu(void)
{
	Uart_Printf("***************************************************************\n");
	Uart_Printf("*                    LCD Test Menu                            *\n");
	//Uart_Printf("***************************************************************\n");
	Uart_Printf("*Please use the item number:                                  *\n");
	Uart_Printf("*  [0]    Clear the sreen!                                    *\n");
	Uart_Printf("*  [1]    Draw a line!                                        *\n");
	Uart_Printf("*  [2]    Draw a rectangle!                                   *\n");
	Uart_Printf("*  [3]    Fill a rectangle!                                   *\n");
	Uart_Printf("*  [4]    Display a photo!                                    *\n");
	Uart_Printf("*  [q]    Quit                                                *\n");	
	Uart_Printf("***************************************************************\n");
	return 1;
}

void Display_Photo(void)
{
	U32 photoWidth,photoHeight,photoSize;
	U32 photoAddr;
        U32 tempAddr;
	U32 i;
        U32 j;
        U8   k;
        U32  color;
        U8  tempColor;
        U8  red,green,blue;
	Uart_Printf("To display a photo, first you should download a 8 bits 'bmp' using menu[1]!\n"); 
	photoSize=downloadFileSize;//DownloadData(0x32000000);
	/*         baseAddr  + fileSize+ bmpfile header+ info header + palette*/
	photoAddr=tempDownloadAddress+0x12;
	Uart_Printf("Photo data address 0x%x,photo size=0x%x!\n",tempDownloadAddress,downloadFileSize); 
	photoWidth=(*((volatile U32 *)(photoAddr)));
	photoHeight=(*((volatile U32 *)(photoAddr+4)));
	if(photoWidth<0 || photoWidth>1000 || photoHeight<0 || photoHeight>1000)
	{
		Uart_Printf("You have not download photo, please quit and select main menu[1]\n");
		return; 
	}
	Uart_Printf("Photo width %d,photo height=%d\n",photoWidth,photoHeight); 
	photoAddr=tempDownloadAddress+14+40;//0x36;//0x436;//4+14+40+256*4;
	photoSize=320*240;
         Glib_ClearScr(0);
         //for(i=0;i<photoSize;i++)
		//(*((volatile U32 *)(0x33800000+i))) =(*((volatile U32 *)(photoAddr+i)));

        for(j=0;j<photoHeight;j++)
        {
	   for(i=0;i<photoWidth;i++)
            {
		tempAddr=photoAddr+j*photoWidth*3+i*3;
		//color=(*((volatile U8 *)(tempAddr)));
		blue=(*((volatile U8 *)(tempAddr)));
		green=(*((volatile U8 *)(tempAddr+1)));
		red=(*((volatile U8 *)(tempAddr+2)));
                  //red=color&(0xff<<8);
                  //green=color&(0xff<<8*2);
                  //blue=color&(0xff<<8*3);
                  red=(red*7)/255;
                  green=(green*7)/255;
                  blue=(blue*3)/255;
                  tempColor=(red<<5) | (green<<2) | blue;
                  //tempColor=224;
                  PutPixel((photoWidth-i),j,(U32)tempColor);
		//(*((volatile U32 *)(0x33800000))) =(*((volatile U32 *)(photoAddr)));
             
             }
        }
        Uart_Printf("\n\n\n/********************************/\n");
        Uart_Printf("*Photo is displaying,please enjoy it!*\n");
        Uart_Printf("/********************************/\n\n\n");
        return;
}	

⌨️ 快捷键说明

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