klcd.c
上传用户:wealth48
上传日期:2022-06-24
资源大小:1701k
文件大小:7k
源码类别:

uCOS

开发平台:

C/C++

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include "inc/drv/klcd.h"
  4. #include "inc/macro.h"
  5. #include "inc/drv/reg2410.h"
  6. #define LCDCON1_CLKVAL (1<<8)
  7. #define LCDCON1_MMODE (0<<7)
  8. #define LCDCON1_PNRMODE (0x3<<5)    //TFT LCD 
  9. #define LCDCON1_BPPMODE (0xc<<1)//16位TFT模式
  10. #define LCDCON1_ENVID (1)
  11. #define LCDCON2_VBPD 32//32
  12. #define LCDCON2_LINEVAL 479
  13. #define LCDCON2_VFPD 9//9
  14. #define LCDCON2_VSPW 1//
  15. #define LCDCON3_HBPD 47//49
  16. #define LCDCON3_HOZVAL 639
  17. #define LCDCON3_HFPD 15//14
  18. #define LCDCON4_HSPW 95//95
  19. #define LCDCON5_FRM565 1//
  20. #define LCDCON5_INVVCLK 0
  21. #define LCDCON5_INVVLINE 1
  22. #define LCDCON5_INVVFRAME 1
  23. #define LCDCON5_INVVD 0
  24. #define LCDCON5_INVVDEN 0
  25. #define LCDCON5_INVPWREN 0
  26. #define LCDCON5_INVLEND 0
  27. #define LCDCON5_PWREN 1
  28. #define LCDCON5_ENLEND 0
  29. #define LCDCON5_BSWP 0
  30. #define LCDCON5_HWSWP 1
  31. #define BPP24BL 0
  32. #define TPALEN 1
  33. #define LPC_EN 1
  34. #define FIWSEL 0
  35. #define INT_FrSyn 1
  36. #define INT_FiCnt 1
  37. #define MVAL 13
  38. U16* pLCDBuffer16I1=(U16*)0x32000000;
  39. U16* pLCDBuffer16I2=(U16*)0x32096000;
  40. U16 LCDBufferII2[kLCDHEIGHT][kLCDWIDTH];
  41. U16* pbuf=LCDBufferII2[0];
  42. U16 LCDBufferII1[307200];
  43. U8 *LoadBMPBuf;
  44. /*LCD显示初始化设置函数*/
  45. void kLCD_Init()
  46. {
  47. U32 i;
  48. U32 LCDBASEU,LCDBASEL,LCDBANK;
  49. /*以下四条语句设置GPGC,GPGD端口为LCD控制端口*/
  50.     rGPCUP=0xffffffff; // Disable Pull-up register
  51.     rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
  52.     rGPDUP=0xffffffff; // Disable Pull-up register
  53.     rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
  54.     // TFT: VCLK = HCLK / [(CLKVAL+1) * 2] ( CLKVAL>=0 )
  55.     rLCDCON1=0|LCDCON1_BPPMODE|LCDCON1_PNRMODE|LCDCON1_MMODE|LCDCON1_CLKVAL;// LCD控制寄存器设置,参见参数宏定义和手册P397-P400 
  56.     // disable   LINEVAL=hight-1=480-1=479
  57. rLCDCON2=(LCDCON2_VBPD<<24)|(LCDCON2_LINEVAL<<14)|(LCDCON2_VFPD<<6)|LCDCON2_VSPW;
  58.     //320x240LCD  LINEBLANK=15 (without any calculation) 
  59. rLCDCON3=(LCDCON3_HBPD<<19)|(LCDCON3_HOZVAL<<8)|LCDCON3_HFPD;//HOZVAL=width-1=640-1=639
  60.     //MVAL对TFT无效
  61.     rLCDCON4=LCDCON4_HSPW|(MVAL<<8);
  62.     //设定24bpp显示模式时,视频资料在显示缓冲区中的排列顺序(即低位有效还是高位有效)。对于16bpp的64K色显示模式,该设置位无意义。
  63.     //CPU的LCD控制器输出的时序默认是正脉冲,而LCD需要VSYNC(VFRAME)、VLINE(HSYNC)均为负脉冲,因此 INVLINE 和 INVFRAME 必须设为"1",即选择反相输出。
  64.     //PWREN 为LCD电源使能控制。ENLEND 对普通的TFT屏无效,可以不考虑。
  65. rLCDCON5=(BPP24BL<<12)|(LCDCON5_FRM565<<11)|(LCDCON5_INVVCLK<<10)|(LCDCON5_INVVLINE<<9)|(LCDCON5_INVVFRAME<<8)|(LCDCON5_INVVD<<7)|
  66.      (LCDCON5_INVVDEN<<6)|(LCDCON5_INVPWREN<<5)|(LCDCON5_INVLEND<<4)|(LCDCON5_PWREN<<3)|(LCDCON5_ENLEND<<2)|(LCDCON5_BSWP<<1)|LCDCON5_HWSWP;
  67. LCDBANK=0x32000000>>22;//显示缓冲区地址
  68. LCDBASEU=0x0;   
  69. LCDBASEL=LCDBASEU+(480)*640;
  70. //rLCDADDR1=0x33000000>>1;
  71. //These bits of LCDBANK indicate A[30:22] of the bank location for the video buffer in the system memory.
  72. rLCDADDR1= (LCDBANK<<21)|LCDBASEU;    //设置LCDADDR1寄存器,参见手册P403
  73.     //LCDBASEL = ((the fame end address) >>1) + 1= LCDBASEU +(PAGEWIDTH+OFFSIZE)x(LINEVAL+1)
  74. rLCDADDR2=LCDBASEL;                   //设置LCDBASEL,参见手册有关说明
  75. rLCDADDR3= (640)|(0<<11);             //设置显示的宽度和偏移量,参见手册有关说明
  76. rLCDINTMSK=(INT_FrSyn<<1)|INT_FiCnt;//|(FIWSEL<<2);设置中断屏蔽
  77. rLCDLPCSEL=0;                         //LPC3600,显示伴侣设置,未使用
  78. rTPAL=(0<<24);                       //调色板设置,参见手册P407
  79. for(i=0;i<640*480;i++)
  80. //*(pLCDBuffer161+i)=0xffff;       
  81. *(pLCDBuffer16I1+i)=0x0;   //清屏 
  82. //hudelay(5000);
  83.     rLCDCON1+=LCDCON1_ENVID;           //打开LCD
  84.     
  85.    
  86.   
  87. }
  88. /*屏幕刷新函数*/
  89. void kLCD_Refresh()
  90. {
  91. int i;
  92. //U16 pixcolor; //一个像素点的颜色
  93. U32 LCDBASEU,LCDBASEL,LCDBANK;
  94. for(i=0;i<kLCDWIDTH*kLCDHEIGHT;i++){
  95. //pixcolor=((pbuf[0]&0xf8)<<11)|((pbuf[1]&0xfc)<<6)|(pbuf[2]&0xf8); //变换RGB
  96. //pbuf+=4;                                                         //下一象素  
  97.     //LCDBufferII1[i]=pixcolor;
  98.     *(pLCDBuffer16I2+i)=pbuf[i];                                       //数据送至显示缓冲区      
  99. }
  100. //for(i=0;i<LCDWIDTH*LCDHEIGHT;i++)
  101. //*(pLCDBuffer16I2+i)=LCDBufferII1[i];
  102. LCDBANK=0x32096000>>22;                //重新设置显示缓冲区地址,下面各值定义与上类似
  103. LCDBASEU=(0x32096000<<9)>>10;   
  104. LCDBASEL=LCDBASEU+(480)*640;
  105. //rLCDADDR1=0x33000000>>1;
  106. rLCDADDR1= (LCDBANK<<21)|LCDBASEU;    
  107. rLCDADDR2=LCDBASEL;
  108. rLCDADDR3= (640)|(0<<11);
  109. }
  110. //---------------部分刷新--------------------
  111. void kLCD_Part_Refresh(int Wnd_x1,int Wnd_y1,int Wnd_x2,int Wnd_y2)
  112. {
  113. int i,j;
  114. //U16 pixcolor; //一个像素点的颜色
  115. U32 LCDBASEU,LCDBASEL,LCDBANK;
  116. for(i=Wnd_y1;i < Wnd_y2;i++)
  117. for(j = Wnd_x1;j < Wnd_x2;j++)
  118.     *(pLCDBuffer16I2+kLCDWIDTH*i+j)=pbuf[kLCDWIDTH*i+j];                                       //数据送至显示缓冲区      
  119. LCDBANK=0x32096000>>22;                //重新设置显示缓冲区地址,下面各值定义与上类似
  120. LCDBASEU=(0x32096000<<9)>>10;   
  121. LCDBASEL=LCDBASEU+(480)*640;
  122. //rLCDADDR1=0x33000000>>1;
  123. rLCDADDR1= (LCDBANK<<21)|LCDBASEU;    
  124. rLCDADDR2=LCDBASEL;
  125. rLCDADDR3= (640)|(0<<11);
  126. }
  127. //-------------------------------------------加载BMP----------------------------------------------
  128. void LoadBMP(U16* pBMP,char* filename,int bmpWidth,int bmpHeight)
  129. {
  130. FILE* pfile;
  131. // U8 r,b,g;
  132. int i,j;
  133. pfile=fopen(filename,"rb");//打开文件
  134. if(pfile==NULL){//文件打开失败
  135. // LCD_printf("Can't Open file!n");
  136. // for(;;)
  137. // OSTimeDly(1000);
  138. }
  139. fread(pBMP,54,1,pfile);
  140. fread(LoadBMPBuf,bmpWidth * bmpHeight * 3,1,pfile);
  141. for(i = 0;i < bmpHeight;i++)
  142. for(j = 0;j < bmpWidth;j++)
  143. {
  144. // r=fgetc(pfile);g=fgetc(pfile);b=fgetc(pfile);
  145. // *(pBMP + (bmpHeight-i-1)*bmpWidth+j)=((b&0xf8)<<8)|((g&0xfc)<<3)|((r&0xf8)>>3);
  146. *(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);
  147. }
  148. fclose(pfile);
  149. }
  150. //-----------------------------------------显示BMP-------------------------------------------------------
  151. void PaintBMP(U16* screen,U16* pBMP,int bmpX,int bmpY,int bmpWidth,int bmpHeight){
  152. int i,j;
  153. for(i = bmpY;i < bmpY+bmpHeight;i++)
  154. for(j = bmpX;j < bmpX+bmpWidth;j++)
  155. screen[i*kLCDWIDTH+j]=pBMP[(i-bmpY)*bmpWidth+(j-bmpX)];
  156.    // kLCD_Part_Refresh(bmpX,bmpY,bmpX+bmpWidth,bmpY+bmpHeight) ;
  157. }
  158. //---------------------------------------清屏-----------------------------------------------------------
  159. void ClreaLCD(){
  160. int i;
  161. for(i = 0;i < kLCDWIDTH*kLCDHEIGHT;i++)
  162. *(pbuf+i)=0x00;
  163. }
  164. U32 getrLCDADDR1(){
  165. return rLCDADDR1;
  166. }