简略的配色原理
- /**************************************************************
- 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)//设置为TFT屏
- #defineBPPMODE(12)//设置为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)//用于设置显现缓存区时,取低21位地址
- volatileunsignedshortLCD_BUFFER[SCR_YSIZE_TFT][SCR_XSIZE_TFT];//界说显现缓存区
- /**************************************************************
- 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下降沿取数据等(看数据手册)
- 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字节则为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;//制止暂时调色板寄存器
- }
- /**************************************************************
- *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信号极性回转
- *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单个象素的显现数据输出
- **************************************************************/
- 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;
- }
- }
- }
- /**************************************************************
- //完成功用:在屏幕中画直线
- //参数:
- //x1-起始点的x坐标
- //y1-起始点的y坐标
- //x2-完毕点的x坐标
- //y2-完毕点的y坐标
- //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屏幕上指定坐标点画一个指定巨细的图片
- **************************************************************/
- 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);
- //完成功用:在屏幕中画圆
- //参数:
- //x-圆心的x坐标
- //y-圆心的y坐标
- //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);//设置体系时钟400M
- ChangeClockDivider(2,1);//设置分频1:4:8
- CalcBusClk();//核算总线频率
- Lcd_TFT_Init();
- Lcd_ClearScr((0x00<<11)|(0x00<<5)|(0x0e));//布景整屏蓝屏
- 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);
- }