S3C2440驅(qū)動4.3寸TFT屏程序
- /**************************************************************
- Theinitialandcontrolfor16BppTFTLCD
- **************************************************************/
- #include"def.h"
- #include"option.h"
- #include"2440addr.h"
- #include"2440lib.h"
- #include"2440slib.h"
- #defineMVAL_USED(0)//0=eachframe1=ratebyMVAL
- #defineINVVDEN(1)//0=normal1=inverted
- #defineBSWP(0)//Byteswapcontrol
- #defineHWSWP(1)//Halfwordswapcontrol
- #definePNRMODE(3)//設(shè)置為TFT屏
- #defineBPPMODE(12)//設(shè)置為16bpp模式
- //TFT_SIZE
- #defineLCD_XSIZE_TFT(480)
- #defineLCD_YSIZE_TFT(272)
- #defineSCR_XSIZE_TFT(480)
- #defineSCR_YSIZE_TFT(272)
- #defineHOZVAL_TFT(LCD_XSIZE_TFT-1)
- #defineLINEVAL_TFT(LCD_YSIZE_TFT-1)
- //Timingparameterfor4.3LCD
- #defineVBPD(2)//垂直同步信號的后肩
- #defineVFPD(4)//垂直同步信號的前肩
- #defineVSPW(8)//垂直同步信號的脈寬
- #defineHBPD(10)//水平同步信號的后肩
- #defineHFPD(19)//水平同步信號的前肩
- #defineHSPW(30)//水平同步信號的脈寬
- #defineCLKVAL_TFT(4)//時鐘分頻因子,VCLK=HCLK/((CLKVAL_TFT+1)*2)
- #defineM5D(n)((n)&0x1fffff)//用于設(shè)置顯示緩存區(qū)時,取低21位地址
- volatileunsignedshortLCD_BUFFER[SCR_YSIZE_TFT][SCR_XSIZE_TFT];//定義顯示緩存區(qū)
- /**************************************************************
- TFTLCD功能模塊初始化
- **************************************************************/
- voidLcd_Init(void)
- {
- rGPCUP=0x00000000;
- rGPCCON=0xaaaa02a9;
- rGPDUP=0x00000000;
- rGPDCON=0xaaaaaaaa;//InitializeVD[15:8]
- rLCDCON1=(CLKVAL_TFT<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;//TFTLCDpanel,16bppTFT,ENVID=off
- rLCDCON2=(VBPD<<24)|(LINEVAL_TFT<<14)|(VFPD<<6)|(VSPW);
- rLCDCON3=(HBPD<<19)|(HOZVAL_TFT<<8)|(HFPD);
- rLCDCON4=HSPW;
- rLCDCON5=(1<<11)|(0<<10)|(1<<9)|(1<<8)|(0<<7)|(0<<6)|(1<<3)|(BSWP<<1)|(HWSWP);
- //16位輸出格式565,VCLK下降沿取數(shù)據(jù)等(看數(shù)據(jù)手冊)
- rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);//單掃描
- rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE_TFT*LCD_YSIZE_TFT*2))>>1);
- //LCD_WIDTH×16/16;由于是選擇的16位模式,
- //如果是24位模式,每個像素4字節(jié)則為LCD_WIDTH×32/16
- //(LCD_WIDTH在此為LCD_XSIZE_TFT)
- rLCDSADDR3=(((SCR_XSIZE_TFT-LCD_XSIZE_TFT)/1)<<11)|(LCD_XSIZE_TFT/1);
- rLCDINTMSK|=(3);//MASKLCDSubInterrupt
- rTCONSEL&=(~7);//DisableLPC3600
- rTPAL=0;//禁止臨時調(diào)色板寄存器
- }
- /**************************************************************
- *LCD視頻和控制信號輸出或者停止,1開啟視頻輸出
- **************************************************************/
- voidLcd_EnvidOnOff(intonoff)
- {
- if(onoff==1)
- rLCDCON1|=1;//ENVID=ON
- else
- rLCDCON1=rLCDCON1&0x3fffe;//ENVIDOff
- }
- /**************************************************************
- *TFTLCD電源控制引腳使能
- *pwren=1時,允許PWREN信號
- *pwren=0時,禁止PWREN信號
- *invpwre=1,PWREN信號極性反轉(zhuǎn)
- *invpwre=0,PWREN信號極性正常
- **************************************************************/
- voidLcd_PowerEnable(intinvpwren,intpwren)
- {
- //GPG4issettedasLCD_PWREN
- rGPGUP=rGPGUP&(~(1<<4))|(1<<4);//GPG4上拉電阻無效
- rGPGCON=rGPGCON&(~(3<<8))|(3<<8);//GPG4=LCD_PWREN
- rGPGDAT=rGPGDAT|(1<<4);//GPG4置1
- //invpwren=pwren;
- //EnableLCDPOWERENABLEFunction
- rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3);//PWREN
- rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5);//INVPWREN
- }
- /**************************************************************
- TFTLCD單個象素的顯示數(shù)據(jù)輸出
- **************************************************************/
- voidPutPixel(U32x,U32y,U32c)
- {
- if((x
- LCD_BUFFER[(y)][(x)]=c;
- }
- /**************************************************************
- TFTLCD全屏填充特定顏色單元或清屏
- **************************************************************/
- voidLcd_ClearScr(U32c)
- {
- unsignedintx,y;
- for(y=0;y
- {
- for(x=0;x
- {
- LCD_BUFFER[y][x]=c;
- }
- }
- }
- /**************************************************************
- //實現(xiàn)功能:在屏幕中畫直線
- //參數(shù):
- //x1-起始點的x坐標(biāo)
- //y1-起始點的y坐標(biāo)
- //x2-結(jié)束點的x坐標(biāo)
- //y2-結(jié)束點的y坐標(biāo)
- //color-直線顏色
- //返回值:無
- **************************************************************/
- voidGlib_Line(intx1,inty1,intx2,inty2,intcolor)
- {
- intdx,dy,e;
- dx=x2-x1;
- dy=y2-y1;
- if(dx>=0)
- {
- if(dy>=0)//dy>=0
- {
- if(dx>=dy)//1/8octant
- {
- e=dy-dx/2;
- while(x1<=x2)
- {
- PutPixel(x1,y1,color);
- if(e>0){y1+=1;e-=dx;}
- x1+=1;
- e+=dy;
- }
- }
- else//2/8octant
- {
- e=dx-dy/2;
- while(y1<=y2)
- {
- PutPixel(x1,y1,color);
- if(e>0){x1+=1;e-=dy;}
- y1+=1;
- e+=dx;
- }
- }
- }
- else//dy<0
- {
- dy=-dy;//dy=abs(dy)
- if(dx>=dy)//8/8octant
- {
- e=dy-dx/2;
- while(x1<=x2)
- {
- PutPixel(x1,y1,color);
- if(e>0){y1-=1;e-=dx;}
- x1+=1;
- e+=dy;
- }
- }
- else//7/8octant
- {
- e=dx-dy/2;
- while(y1>=y2)
- {
- PutPixel(x1,y1,color);
- if(e>0){x1+=1;e-=dy;}
- y1-=1;
- e+=dx;
- }
- }
- }
- }
- else//dx<0
- {
- dx=-dx;//dx=abs(dx)
- if(dy>=0)//dy>=0
- {
- if(dx>=dy)//4/8octant
- {
- e=dy-dx/2;
- while(x1>=x2)
- {
- PutPixel(x1,y1,color);
- if(e>0){y1+=1;e-=dx;}
- x1-=1;
- e+=dy;
- }
- }
- else//3/8octant
- {
- e=dx-dy/2;
- while(y1<=y2)
- {
- PutPixel(x1,y1,color);
- if(e>0){x1-=1;e-=dy;}
- y1+=1;
- e+=dx;
- }
- }
- }
- else//dy<0
- {
- dy=-dy;//dy=abs(dy)
- if(dx>=dy)//5/8octant
- {
- e=dy-dx/2;
- while(x1>=x2)
- {
- PutPixel(x1,y1,color);
- if(e>0){y1-=1;e-=dx;}
- x1-=1;
- e+=dy;
- }
- }
- else//6/8octant
- {
- e=dx-dy/2;
- while(y1>=y2)
- {
- PutPixel(x1,y1,color);
- if(e>0){x1-=1;e-=dy;}
- y1-=1;
- e+=dx;
- }
- }
- }
- }
- }
- /**************************************************************
- 在LCD屏幕上畫一個矩形
- **************************************************************/
- voidGlib_Rectangle(intx1,inty1,intx2,inty2,intcolor)
- {
- Glib_Line(x1,y1,x2,y1,color);
- Glib_Line(x2,y1,x2,y2,color);
- Glib_Line(x1,y2,x2,y2,color);
- Glib_Line(x1,y1,x1,y2,color);
- }
- /**************************************************************
- 在LCD屏幕上用顏色填充一個矩形
- **************************************************************/
- voidGlib_FilledRectangle(intx1,inty1,intx2,inty2,intcolor)
- {
- inti;
- for(i=y1;i<=y2;i++)
- Glib_Line(x1,i,x2,i,color);
- }
- /**************************************************************
- 在LCD屏幕上指定坐標(biāo)點畫一個指定大小的圖片
- **************************************************************/
- voidPaint_Bmp(intx0,inty0,inth,intl,unsignedcharbmp[])
- {
- intx,y;
- U32c;
- intp=0;
- for(y=y0;y
- {
- for(x=x0;x
- {
- c=bmp[p+1]|(bmp[p]<<8);
- if(((x0+x)
- LCD_BUFFER[y0+y][x0+x]=c;
- p=p+2;
- }
- }
- }
- //=============================================================
- //語法格式:voidTFT_Circle(intx,inty,intr,intcolor,unsignedcharMode);
- //實現(xiàn)功能:在屏幕中畫圓
- //參數(shù):
- //x-圓心的x坐標(biāo)
- //y-圓心的y坐標(biāo)
- //r-圓的半徑
- //color-圓的顏色
- //Mode-0空心圓
- //1實心圓
- //返回值:無
- //=============================================================
- voidTFT_Circle(intx,inty,intr,intcolor,unsignedcharMode)
- {
- intdx,dy,ref;
- intTemp;
- if(r==0)
- return;
- dx=r;
- dy=1;
- ref=707*r/1000;//參考值為0.707r
- if(Mode==1)//實心圓
- {
- while(dy<=dx)
- {
- if(dx>ref)
- Glib_Line(x+ref+1,y+dy,x+dx,y+dy,color);
- if(x>=ref+1&&dx>ref)
- {
- if(x
- Temp=0;
- else
- Temp=x-dx;
- Glib_Line(Temp,y+dy,x-ref-1,y+dy,color);
- }
- if(y>=dy&&dx>ref)
- Glib_Line(x+ref+1,y-dy,x+dx,y-dy,color);
- if(x>=ref+1&&y>=dy&&dx>ref)
- {
- if(x
- Temp=0;
- else
- Temp=x-dx;
- Glib_Line(Temp,y-dy,x-ref-1,y-dy,color);
- }
- if(dy!=dx||dx==ref)
- {
- if(y
- Temp=0;
- else
- Temp=y-dx;
- Glib_Line(x+dy,Temp,x+dy,y+dx,color);
- }
- if(x>=dy&&(dy!=dx||dy==ref))
- {
- if(y
- Temp=0;
- else
- Temp=y-dx;
- Glib_Line(x-dy,Temp,x-dy,y+dx,color);
- }
- dy++;
- if((r*r-dy*dy)<=(dx-1)*dx)
- dx--;
- }
- Glib_Line(x+ref+1,y,x+r,y,color);
- if(x>=ref+1)
- {
- if(x
- Temp=0;
- else
- Temp=x-r;
- Glib_Line(Temp,y,x-ref-1,y,color);
- }
- if(y
- Temp=0;
- else
- Temp=y-r;
- Glib_Line(x,Temp,x,y+r,color);
- }
- else//空心圓
- {
- while(dy<=dx)
- {
- PutPixel(x+dx,y+dy,color);
- PutPixel(x-dx,y+dy,color);
- PutPixel(x+dx,y-dy,color);
- PutPixel(x-dx,y-dy,color);
- if(dx!=dy)
- {
- PutPixel(x+dy,y+dx,color);
- PutPixel(x+dy,y-dx,color);
- PutPixel(x-dy,y+dx,color);
- PutPixel(x-dy,y-dx,color);
- }
- dy++;
- if((r*r-dy*dy)<=(dx-1)*dx)
- dx--;
- }
- PutPixel(x+r,y,color);
- PutPixel(x-r,y,color);
- PutPixel(x,y+r,color);
- PutPixel(x,y-r,color);
- }
- }
- /**************************************************************
- *
- *LCD屏初始化
- *
- **************************************************************/
- voidLcd_TFT_Init(void)
- {
- Lcd_Init();
- Lcd_PowerEnable(0,1);
- Lcd_EnvidOnOff(1);//turnonvedio
- Lcd_ClearScr((0x00<<11)|(0x00<<5)|(0x00));//565格式純黑色
- }
- voidMain(void)
- {
- SelectFclk(2);//設(shè)置系統(tǒng)時鐘400M
- ChangeClockDivider(2,1);//設(shè)置分頻1:4:8
- CalcBusClk();//計算總線頻率
- Lcd_TFT_Init();
- Lcd_ClearScr((0x00<<11)|(0x00<<5)|(0x0e));//背景整屏藍(lán)屏
- Glib_Rectangle(10,10,150,150,(0x1f<<11)|(0x00<<5)|(0x00));//空心正方形邊為純紅
- Glib_FilledRectangle(20,20,100,100,(0x1f<<11)|(0x00<<5)|(0x1f));//品紅正方形
- Glib_Line(155,5,280,160,(0x00<<11)|(0x00<<5)|(0x00));//黑色直線
- Glib_FilledRectangle(5,180,150,240,(0x1f<<11)|(0x3f<<5)|(0x00));//黃色矩形
- TFT_Circle(360,180,80,(0x1f<<11)|(0x3f<<5)|(0x1f),0);//空心圓
- TFT_Circle(360,170,60,(0x1f<<11)|(0x00<<5)|(0x00),1);//純紅實心圓
- //Lcd_ClearScr((0x00<<11)|(0x00<<5)|(0x1f));//clearscreen
- //Delay(1000);
- }
評論