📄 lcdlib.c
字号:
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\lcdlib.h"
//SCR_XSIZE,SCR_YSIZE,LCD_XSIZE,LCD_YSIZE are defined in lcd.h
#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_G16 (SCR_XSIZE/2*SCR_YSIZE)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE-1)
#define MVAL (13)
#define CLKVAL_G16 (10) //40Mhz, CLKVAL=10 ->101Hz
// 9 ->112Hz
#define CLKVAL_COLOR (10) //60Mhz
void Lcd_Init();
unsigned int (*frameBuffer16)[SCR_XSIZE/8];
#define MVAL_USED 0
void Lcd_Init(void)
{
//320x240 1bit/1pixel LCD
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);
}
//The following value has to be changed for better display.
/* rDITHMODE=0x1223a; //philips
rDP1_2 =0x5a5a;
rDP4_7 =0x366cd9b;
rDP3_5 =0xda5a7;
rDP2_3 =0xad7;
rDP5_7 =0xfeda5b7;
rDP3_4 =0xebd7;
rDP4_5 =0xebfd7;
rDP6_7 =0x7efdfbf;*/
//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;*/
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,
}
void Lcd_MoveViewPort(int vx,int vy)
{
U32 addr;
//The processor mode should be superviser mode.
DisableInterrupt();
#if (LCD_XSIZE<128)
while((rLCDCON1>>22)<=1); // if x<128
#else
while((rLCDCON1>>22)==0); // if x>128
#endif
addr=(U32)frameBuffer16+(vx/2)+vy*(SCR_XSIZE/2);
rLCDSADDR1= (0x2<<27) | ( (addr>>22)<<21 ) | M5D(addr>>1);
// 16-gray, LCDBANK, LCDBASEU
rLCDSADDR2= M5D(((addr+(SCR_XSIZE*LCD_YSIZE/2))>>1)) | (MVAL<<21);
EnableInterrupt();
}
void (*PutPixel)(U32,U32,U8);
void Glib_Init(int depth)
{
PutPixel=_PutPixelG16;
}
void _PutPixelG16(U32 x,U32 y,U8 c)
{
if(x<SCR_XSIZE && y<SCR_YSIZE)
frameBuffer16[(y)][(x)/8]=( frameBuffer16[(y)][x/8] & ~(0xf0000000>>((x)%8)*4) )
| ( (c)<<((8-1-((x)%8))*4) );
}
void Glib_ClearScr(U8 c)
{
//Very inefficient function.
int i,j;
for(j=0;j<SCR_YSIZE;j++)
for(i=0;i<SCR_XSIZE;i++)
PutPixel(i,j,c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -