klcd.c
上传用户:wealth48
上传日期:2022-06-24
资源大小:1701k
文件大小:7k
- #include <stdarg.h>
- #include <stdio.h>
- #include "inc/drv/klcd.h"
- #include "inc/macro.h"
- #include "inc/drv/reg2410.h"
- #define LCDCON1_CLKVAL (1<<8)
- #define LCDCON1_MMODE (0<<7)
- #define LCDCON1_PNRMODE (0x3<<5) //TFT LCD
- #define LCDCON1_BPPMODE (0xc<<1)//16位TFT模式
- #define LCDCON1_ENVID (1)
- #define LCDCON2_VBPD 32//32
- #define LCDCON2_LINEVAL 479
- #define LCDCON2_VFPD 9//9
- #define LCDCON2_VSPW 1//
- #define LCDCON3_HBPD 47//49
- #define LCDCON3_HOZVAL 639
- #define LCDCON3_HFPD 15//14
- #define LCDCON4_HSPW 95//95
- #define LCDCON5_FRM565 1//
- #define LCDCON5_INVVCLK 0
- #define LCDCON5_INVVLINE 1
- #define LCDCON5_INVVFRAME 1
- #define LCDCON5_INVVD 0
- #define LCDCON5_INVVDEN 0
- #define LCDCON5_INVPWREN 0
- #define LCDCON5_INVLEND 0
- #define LCDCON5_PWREN 1
- #define LCDCON5_ENLEND 0
- #define LCDCON5_BSWP 0
- #define LCDCON5_HWSWP 1
- #define BPP24BL 0
- #define TPALEN 1
- #define LPC_EN 1
- #define FIWSEL 0
- #define INT_FrSyn 1
- #define INT_FiCnt 1
- #define MVAL 13
- U16* pLCDBuffer16I1=(U16*)0x32000000;
- U16* pLCDBuffer16I2=(U16*)0x32096000;
- U16 LCDBufferII2[kLCDHEIGHT][kLCDWIDTH];
- U16* pbuf=LCDBufferII2[0];
- U16 LCDBufferII1[307200];
- U8 *LoadBMPBuf;
- /*LCD显示初始化设置函数*/
- void kLCD_Init()
- {
- U32 i;
- U32 LCDBASEU,LCDBASEL,LCDBANK;
- /*以下四条语句设置GPGC,GPGD端口为LCD控制端口*/
- 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]
- // TFT: VCLK = HCLK / [(CLKVAL+1) * 2] ( CLKVAL>=0 )
- rLCDCON1=0|LCDCON1_BPPMODE|LCDCON1_PNRMODE|LCDCON1_MMODE|LCDCON1_CLKVAL;// LCD控制寄存器设置,参见参数宏定义和手册P397-P400
- // disable LINEVAL=hight-1=480-1=479
- rLCDCON2=(LCDCON2_VBPD<<24)|(LCDCON2_LINEVAL<<14)|(LCDCON2_VFPD<<6)|LCDCON2_VSPW;
- //320x240LCD LINEBLANK=15 (without any calculation)
- rLCDCON3=(LCDCON3_HBPD<<19)|(LCDCON3_HOZVAL<<8)|LCDCON3_HFPD;//HOZVAL=width-1=640-1=639
- //MVAL对TFT无效
- rLCDCON4=LCDCON4_HSPW|(MVAL<<8);
- //设定24bpp显示模式时,视频资料在显示缓冲区中的排列顺序(即低位有效还是高位有效)。对于16bpp的64K色显示模式,该设置位无意义。
- //CPU的LCD控制器输出的时序默认是正脉冲,而LCD需要VSYNC(VFRAME)、VLINE(HSYNC)均为负脉冲,因此 INVLINE 和 INVFRAME 必须设为"1",即选择反相输出。
- //PWREN 为LCD电源使能控制。ENLEND 对普通的TFT屏无效,可以不考虑。
- rLCDCON5=(BPP24BL<<12)|(LCDCON5_FRM565<<11)|(LCDCON5_INVVCLK<<10)|(LCDCON5_INVVLINE<<9)|(LCDCON5_INVVFRAME<<8)|(LCDCON5_INVVD<<7)|
- (LCDCON5_INVVDEN<<6)|(LCDCON5_INVPWREN<<5)|(LCDCON5_INVLEND<<4)|(LCDCON5_PWREN<<3)|(LCDCON5_ENLEND<<2)|(LCDCON5_BSWP<<1)|LCDCON5_HWSWP;
-
- LCDBANK=0x32000000>>22;//显示缓冲区地址
- LCDBASEU=0x0;
- LCDBASEL=LCDBASEU+(480)*640;
- //rLCDADDR1=0x33000000>>1;
- //These bits of LCDBANK indicate A[30:22] of the bank location for the video buffer in the system memory.
- rLCDADDR1= (LCDBANK<<21)|LCDBASEU; //设置LCDADDR1寄存器,参见手册P403
- //LCDBASEL = ((the fame end address) >>1) + 1= LCDBASEU +(PAGEWIDTH+OFFSIZE)x(LINEVAL+1)
- rLCDADDR2=LCDBASEL; //设置LCDBASEL,参见手册有关说明
- rLCDADDR3= (640)|(0<<11); //设置显示的宽度和偏移量,参见手册有关说明
- rLCDINTMSK=(INT_FrSyn<<1)|INT_FiCnt;//|(FIWSEL<<2);设置中断屏蔽
- rLCDLPCSEL=0; //LPC3600,显示伴侣设置,未使用
- rTPAL=(0<<24); //调色板设置,参见手册P407
- for(i=0;i<640*480;i++)
- //*(pLCDBuffer161+i)=0xffff;
- *(pLCDBuffer16I1+i)=0x0; //清屏
- //hudelay(5000);
- rLCDCON1+=LCDCON1_ENVID; //打开LCD
-
-
-
- }
- /*屏幕刷新函数*/
- void kLCD_Refresh()
- {
- int i;
- //U16 pixcolor; //一个像素点的颜色
-
- U32 LCDBASEU,LCDBASEL,LCDBANK;
- for(i=0;i<kLCDWIDTH*kLCDHEIGHT;i++){
- //pixcolor=((pbuf[0]&0xf8)<<11)|((pbuf[1]&0xfc)<<6)|(pbuf[2]&0xf8); //变换RGB
- //pbuf+=4; //下一象素
- //LCDBufferII1[i]=pixcolor;
- *(pLCDBuffer16I2+i)=pbuf[i]; //数据送至显示缓冲区
- }
-
- //for(i=0;i<LCDWIDTH*LCDHEIGHT;i++)
- //*(pLCDBuffer16I2+i)=LCDBufferII1[i];
-
- LCDBANK=0x32096000>>22; //重新设置显示缓冲区地址,下面各值定义与上类似
- LCDBASEU=(0x32096000<<9)>>10;
- LCDBASEL=LCDBASEU+(480)*640;
- //rLCDADDR1=0x33000000>>1;
- rLCDADDR1= (LCDBANK<<21)|LCDBASEU;
- rLCDADDR2=LCDBASEL;
- rLCDADDR3= (640)|(0<<11);
-
-
- }
- //---------------部分刷新--------------------
- void kLCD_Part_Refresh(int Wnd_x1,int Wnd_y1,int Wnd_x2,int Wnd_y2)
- {
- int i,j;
- //U16 pixcolor; //一个像素点的颜色
-
- U32 LCDBASEU,LCDBASEL,LCDBANK;
- for(i=Wnd_y1;i < Wnd_y2;i++)
- for(j = Wnd_x1;j < Wnd_x2;j++)
- *(pLCDBuffer16I2+kLCDWIDTH*i+j)=pbuf[kLCDWIDTH*i+j]; //数据送至显示缓冲区
-
- LCDBANK=0x32096000>>22; //重新设置显示缓冲区地址,下面各值定义与上类似
- LCDBASEU=(0x32096000<<9)>>10;
- LCDBASEL=LCDBASEU+(480)*640;
- //rLCDADDR1=0x33000000>>1;
- rLCDADDR1= (LCDBANK<<21)|LCDBASEU;
- rLCDADDR2=LCDBASEL;
- rLCDADDR3= (640)|(0<<11);
-
-
- }
- //-------------------------------------------加载BMP----------------------------------------------
- void LoadBMP(U16* pBMP,char* filename,int bmpWidth,int bmpHeight)
- {
- FILE* pfile;
- // U8 r,b,g;
- int i,j;
- pfile=fopen(filename,"rb");//打开文件
- if(pfile==NULL){//文件打开失败
- // LCD_printf("Can't Open file!n");
- // for(;;)
- // OSTimeDly(1000);
-
- }
-
- fread(pBMP,54,1,pfile);
- fread(LoadBMPBuf,bmpWidth * bmpHeight * 3,1,pfile);
- for(i = 0;i < bmpHeight;i++)
- for(j = 0;j < bmpWidth;j++)
- {
-
- // r=fgetc(pfile);g=fgetc(pfile);b=fgetc(pfile);
- // *(pBMP + (bmpHeight-i-1)*bmpWidth+j)=((b&0xf8)<<8)|((g&0xfc)<<3)|((r&0xf8)>>3);
- *(pBMP + (bmpHeight-i-1)*bmpWidth+j)=((LoadBMPBuf[3*(i*bmpWidth+j)+2]&0xf8)<<8)|((LoadBMPBuf[3*(i*bmpWidth+j)+1]&0xfc)<<3)|((LoadBMPBuf[3*(i*bmpWidth+j)+0]&0xf8)>>3);
- }
- fclose(pfile);
- }
- //-----------------------------------------显示BMP-------------------------------------------------------
- void PaintBMP(U16* screen,U16* pBMP,int bmpX,int bmpY,int bmpWidth,int bmpHeight){
- int i,j;
-
- for(i = bmpY;i < bmpY+bmpHeight;i++)
- for(j = bmpX;j < bmpX+bmpWidth;j++)
- screen[i*kLCDWIDTH+j]=pBMP[(i-bmpY)*bmpWidth+(j-bmpX)];
-
- // kLCD_Part_Refresh(bmpX,bmpY,bmpX+bmpWidth,bmpY+bmpHeight) ;
- }
- //---------------------------------------清屏-----------------------------------------------------------
- void ClreaLCD(){
- int i;
- for(i = 0;i < kLCDWIDTH*kLCDHEIGHT;i++)
- *(pbuf+i)=0x00;
- }
- U32 getrLCDADDR1(){
- return rLCDADDR1;
- }