?? lcdlib.c
字號:
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\lcdlib.h"
#include "..\inc\glib.h"
#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_MONO (SCR_XSIZE/8*SCR_YSIZE)
#define ARRAY_SIZE_G4 (SCR_XSIZE/4*SCR_YSIZE)
#define ARRAY_SIZE_G16 (SCR_XSIZE/2*SCR_YSIZE)
#define ARRAY_SIZE_COLOR (SCR_XSIZE/1*SCR_YSIZE*2)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE-1)
#define MVAL (13)
#define CLKVAL_MONO (13) //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_G4 (9) //40Mhz, CLKVAL=9 ->110Hz
#define CLKVAL_G16 (10) //40Mhz, CLKVAL=10 ->101Hz
// 9 ->112Hz
#define CLKVAL_COLOR (6) //60Mhz
unsigned int (*frameBuffer4)[SCR_XSIZE/16];
unsigned int (*frameBuffer16)[SCR_XSIZE/8];
unsigned int (*frameBuffer256)[SCR_XSIZE/4];
unsigned int (*frameBuffer1)[SCR_XSIZE/32];
#define MVAL_USED 0
void Lcd_Init(int depth)
{
//320x240 1bit/1pixel LCD
switch(depth)
{
case 1:
if((U32)frameBuffer1==0)
{
//The total frame memory should be inside 4MB.
//For example, if total memory is 8MB, the frame memory
//should be in 0xc000000~0xc3fffff or c400000~c7fffff.
//But, the following code doesn't meet this condition(4MB)
//if the code size & location is changed..
frameBuffer1=(unsigned int (*)[SCR_XSIZE/32])malloc(ARRAY_SIZE_MONO);
}
rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(8<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x0<<27) | ( ((U32)frameBuffer1>>22)<<21 ) | M5D((U32)frameBuffer1>>1);
// monochrome, LCDBANK, LCDBASEU
rLCDSADDR2= M5D( (((U32)frameBuffer1+(SCR_XSIZE*LCD_YSIZE/8))>>1) ) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/16) | ( ((SCR_XSIZE-LCD_XSIZE)/16)<<9 );
rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
break;
case 4:
if((U32)frameBuffer4==0)
{
//The total frame memory should be inside 4MB.
//For example, if total memory is 8MB, the frame memory
//should be in 0xc000000~0xc3fffff or c400000~c7fffff.
//But, the following code doesn't meet this condition(4MB)
//if the code size & location is changed..
frameBuffer4=(unsigned int (*)[SCR_XSIZE/16])malloc(ARRAY_SIZE_G4);
}
rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);
// disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x1<<27) | ( ((U32)frameBuffer4>>22)<<21 ) | M5D((U32)frameBuffer4>>1);
// 4-gray, LCDBANK, LCDBASEU
rLCDSADDR2= M5D((((U32)frameBuffer4+(SCR_XSIZE*LCD_YSIZE/4))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/8) | ( ((SCR_XSIZE-LCD_XSIZE)/8)<<9 );
//The following value has to be changed for better display.
//Select 4 levels among 16 gray levels.
rBLUELUT=0xfa50;
rDITHMODE=0x0;
rDITHMODE=0x12210;
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)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G4<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
break;
case 16:
if((U32)frameBuffer16==0)
{
//The total frame memory should be inside 4MB.
//For example, if total memory is 8MB, the frame memory
//should be in 0xc000000~0xc3fffff or c400000~c7fffff.
//But, the following code doesn't meet this condition(4MB)
//if the code size & location is changed..
frameBuffer16=(unsigned int (*)[SCR_XSIZE/8])malloc(ARRAY_SIZE_G16);
}
rDITHMODE=0x12210;
//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=(0)|(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-gray, LCDBANK, LCDBASEU
rLCDSADDR2= M5D((((U32)frameBuffer16+(SCR_XSIZE*LCD_YSIZE/2))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );
rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_G16<<12);
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
break;
case 256:
if((U32)frameBuffer256==0)
{
//The total frame memory should be inside 4MB.
//For example, if total memory is 8MB, the frame memory
//should be in 0xc000000~0xc3fffff or c400000~c7fffff.
//But, the following code doesn't meet this condition(4MB)
//if the code size & location is changed..
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 =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =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,
break;
default:
break;
}
}
void Test_LcdColor(void)
{
int i,j;
rPDATE=rPDATE&~(1<<5)|(1<<5); //GPE5=H
rPCONE=rPCONE&~(3<<10)|(1<<10); //GPE5=output
rPCONC=rPCONC&~(0xff<<8)|(0xff<<8); //GPC[4:7] => VD[7:4]
Uart_Printf("[(240x3)x320 COLOR STN LCD TEST]\n");
Uart_Printf(" R:0 ... 7 \n");
Uart_Printf("G:0 B0:1 B0:1 B0:1 \n");
Uart_Printf("G:. 2:3 2:3 2:3 \n");
Uart_Printf("G:. B0:1 B0:1 B0:1 \n");
Uart_Printf("G:. 2:3 2:3 2:3 \n");
Uart_Printf("G:. B0:1 B0:1 B0:1 \n");
Uart_Printf("G:7 2:3 2:3 2:3 \n");
Lcd_Init(MODE_COLOR);
Glib_Init(MODE_COLOR);
Glib_ClearScr(0);
for( j = 0; j < SCR_YSIZE; j += 16 )
for( i = 0; i < SCR_XSIZE; i += 32 )
Glib_FilledRectangle( i, j, i+31, j+31, ((j+i)/32)%256 );
Uart_Printf("虛擬屏測試,按ijkm進行屏幕畫面移動!回車退出?。。n");
MoveViewPort(MODE_COLOR);
Glib_ClearScr(150);
// #0
// 00
Glib_Rectangle(0,0,239,319,100);
Glib_Line(0,0,239,319,100);
Glib_Line(0,319,239,0,100);
// 0#
// 00
Glib_Rectangle(0+240,0,239+240,319,100);
Glib_Line(0+240,0,239+240,320,100);
Glib_Line(0+240,319,239+240,0,100);
// 00
// #0
Glib_Rectangle(0,0+320,239,319+320,100);
Glib_Line(0,0+320,240,319+320,100);
Glib_Line(0,319+320,239,0+320,100);
// 00
// 0#
Glib_Rectangle(0+240,0+320,239+240,319+320,100);
Glib_Line(0+240,0+320,239+240,319+320,100);
Glib_Line(0+240,319+320,239+240,0+320,100);
Glib_Rectangle(50+240,50+320,189+240,269+320,100);
Uart_Printf("Virtual Screen Test(256 color). Press any key[ijkm\\r]!\n");
MoveViewPort(MODE_COLOR);
Lcd_MoveViewPort(0,0,MODE_COLOR);
}
void MoveViewPort(int depth)
{
int vx=0,vy=0,vd;
vd=(depth==1)*16+(depth==4)*8+(depth==16)*4+(depth==256)*2;
while(1)
{
switch(Uart_Getch())
{
case 'i':
if(vy>=vd)vy-=vd;
break;
case 'j':
if(vx>=vd)vx-=vd;
break;
case 'k':
if(vx<=SCR_XSIZE-LCD_XSIZE-vd)vx+=vd;
break;
case 'm':
if(vy<=(SCR_YSIZE-LCD_YSIZE-vd))vy+=vd;
break;
case '\r':
return;
default:
break;
}
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy,depth);
}
}
void Lcd_MoveViewPort(int vx,int vy,int depth)
{
U32 addr;
switch(depth)
{
case 256:
//The processor mode should be superviser mode.
DisableInterrupt();
#if (LCD_XSIZE<64)
while((rLCDCON1>>22)<=1); // if x<64
#else
while((rLCDCON1>>22)==0); // if x>64
#endif
addr=(U32)frameBuffer256+(vx/1)+vy*(SCR_XSIZE/1);
rLCDSADDR1= (0x3<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);
// 256-color, LCDBANK, LCDBASEU
rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
EnableInterrupt();
break;
}
}
void Lcd_DispON(void)
{
Delay(5000);
rPDATG = ( rPDATG & (~(1<<5)) );
Delay(5000);
}
void Lcd_DispOFF(void)
{
Delay(5000);
rPDATG = ( rPDATG | (1<<5 ));
Delay(5000);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -