抽空写些东西TFTTFTTFTTFT液晶屏C51C51C51C51控制上次玩了2.8寸的TFT液晶,这几天有点时间了,用51控制了下2.4寸的TFT液晶,驱动是一样的。写了下程序,放网上。/*功能描述:TFT(ILI9325)液晶测试程序*//*作者:AllRee*//*编写时间:2011.8.14*//*功能:TFT液晶显示图片和打印字符*//*STC89C58RD接外部晶振11.0592MHZ*//**************************************************/#includereg52.h#includeILI9325.Hmain(){uchari;LCD_INIT();//TFT初始化LCD_picture_diplay();LCD_write_english_string(20,20,TFTC51TestOK,GREEN,BLACK);LCD_write_english_string(20,40,ClimberWin2010.3.8,GREEN,BLACK);for(i=0;i10;i++){LCD_caitiao_diplay(100,RED);LCD_caitiao_diplay(120,GREEN);LCD_caitiao_diplay(140,BLUE);LCD_caitiao_diplay(160,YELLOW);LCD_caitiao_diplay(180,WHITE);LCD_caitiao_diplay(200,MAGENTA);LCD_caitiao_diplay(220,CYAN);LCD_caitiao_diplay(100,CYAN);LCD_caitiao_diplay(120,RED);LCD_caitiao_diplay(140,GREEN);LCD_caitiao_diplay(160,BLUE);LCD_caitiao_diplay(180,YELLOW);LCD_caitiao_diplay(200,WHITE);LCD_caitiao_diplay(220,MAGENTA);}while(1);}///////////////////////////////////////////////头文件定义//////////////////////////////////////////////////#ifndef_ILI9325_H_#define_ILI9325_H_#includereg52.h#includepicture.h#includeenglish_16x8.h#defineucharunsignedchar#defineuintunsignedint#defineulongunsignedlong#defineBLACK0x0000//黑#defineBLUE0x001F//蓝#defineRED0xF800//红#defineGREEN0x07E0//绿#defineCYAN0x07FF//青#defineMAGENTA0xF81F//洋红#defineYELLOW0xFFE0//黄#defineWHITE0xFFFF//白#defineLCD_DATA_PORTP0//定义数据口D8-D15sbitLCD_RS=P2^0;//数据/命令切换sbitLCD_RST=P2^7;//复位sbitLCD_WR=P2^1;//写控制sbitLCD_RD=P2^2;//读控制sbitLCD_CS=P2^5;voiddelayms(uintcount);voidLCD_Write_REG(uintlcd_reg);//8位数据接口发送16位寄存器地址voidLCD_Write_DATA(uintlcd_data);//8位数据接口发送16位数据voidLCD_Write_REG_DATA(uintlcd_reg,lcd_data);//设置寄存器和数据voidLCD_Add_Set(uintx1,uinty1,uintx2,uinty2);//设置坐标voidLCD_INIT(void);//液晶初始化voidLCD_picture_diplay(void);//显示图片voidLCD_write_english(unsignedchardata1,unsignedintcolor,unsignedintxcolor);//写字符voidLCD_write_english_string(unsignedintx,unsignedinty,unsignedchar*s,unsignedintcolor,unsignedintxcolor);//英文字符串显示voidLcd_SetBox(unsignedintxStart,unsignedintyStart,unsignedintxLong,unsignedintyLong);voidLCD_SetCursor(unsignedintXpos,unsignedintYpos);voidLCD_Clear(unsignedintColor);voidLCD_caitiao_diplay(ucharx,uintcolor);//画彩条20点宽320点长voiddelayms(uintcount){unsignedinti,j;for(i=0;icount;i++)for(j=0;j120;j++);}voidLCD_Write_REG(uintlcd_reg)//8位数据接口发送16位寄存器地址{LCD_RS=0;LCD_CS=0;LCD_DATA_PORT=lcd_reg8;LCD_WR=0;LCD_WR=1;LCD_DATA_PORT=lcd_reg&0XFF;LCD_WR=0;LCD_WR=1;LCD_CS=1;}voidLCD_Write_DATA(uintlcd_data)//8位数据接口发送16位数据{LCD_RS=1;LCD_CS=0;LCD_DATA_PORT=lcd_data8;LCD_WR=0;LCD_WR=1;LCD_DATA_PORT=lcd_data&0XFF;LCD_WR=0;LCD_WR=1;LCD_CS=1;}voidLCD_Write_REG_DATA(uintlcd_reg,lcd_data){LCD_Write_REG(lcd_reg);LCD_Write_DATA(lcd_data);}voidLCD_Add_Set(uintx1,uinty1,uintx2,uinty2){LCD_Write_REG_DATA(0x0020,x1);//设置X坐标位置LCD_Write_REG_DATA(0x0021,y1);//设置Y坐标位置LCD_Write_REG_DATA(0x0050,x1);//开始XLCD_Write_REG_DATA(0x0052,y1);//开始YLCD_Write_REG_DATA(0x0051,x2);//结束XLCD_Write_REG_DATA(0x0053,y2);//结束YLCD_Write_REG(0x0022);}///////////液晶初始化程序////////////////////voidLCD_INIT(void){LCD_RST=1;delayms(5);LCD_RST=0;delayms(10);LCD_RST=1;delayms(20);//*************StartInitialSequence**********//LCD_Write_REG(0x00E5);LCD_Write_DATA(0x78F0);//setSRAMinternaltiming//LCD_Write_REG(0x0001);LCD_Write_DATA(0x0100);//setSSandSMbitLCD_Write_REG(0x0001);LCD_Write_DATA(0x0000);//setSSandSMbit//镜像摄像头应用的时候要用到LCD_Write_REG(0x0002);LCD_Write_DATA(0x0700);//set1lineinversion//LCD_Write_REG(0x0003);LCD_Write_DATA(0x1030);//setGRAMwritedirectionandBGR=1.影响显示模式nnnnnnnLCD_Write_REG(0x0003);LCD_Write_DATA(0x1018);//setGRAMwritedirectionandBGR=1.LCD_Write_REG(0x0004);LCD_Write_DATA(0x0000);//LCD_RSTizeregisterLCD_Write_REG(0x0008);LCD_Write_DATA(0x0207);//setthebackporchandfrontporchLCD_Write_REG(0x0009);LCD_Write_DATA(0x0000);//setnon-displayarearefLCD_RSThcycleISC[3:0]LCD_Write_REG(0x000A);LCD_Write_DATA(0x0000);//FMARKfunctionLCD_Write_REG(0x000C);LCD_Write_DATA(0x0000);//RGBinterfacesettingLCD_Write_REG(0x000D);LCD_Write_DATA(0x0000);//FramemarkerPositionLCD_Write_REG(0x000F);LCD_Write_DATA(0x0000);//RGBinterfacepolarity//*************PowerOnsequence****************////LCD_Write_REG(0x0010);LCD_Write_DATA(0x0000);//SAP,BT[3:0],AP,DSTB,SLP,STBLCD_Write_REG(0x0010);LCD_Write_DATA(0x0080);//SAP,BT[3:0],AP,DSTB,SLP,STBnnnnnnnnnnnLCD_Write_REG(0x0011);LCD_Write_DATA(0x0007);//DC1[2:0],DC0[2:0],VC[2:0]LCD_Write_REG(0x0012);LCD_Write_DATA(0x0000);//VREG1OUTvoltageLCD_Write_REG(0x0013);LCD_Write_DATA(0x0000);//VDV[4:0]forVCOMamplitudeLCD_Write_REG(0x0007);LCD_Write_DATA(0x0001);delayms(200);//Dis-chargecapacitorpowervoltage//LCD_Write_REG(0x0010);LCD_Write_DATA(0x1090);//1490//SAP,BT[3:0],AP,DSTB,SLP,STB//对屏闪有点影响LCD_Write_REG(0x0010);LCD_Write_DATA(0x1590);//1490//SAP,BT[3:0],AP,DSTB,SLP,STBnnnnnnnnnnLCD_Write_REG(0x0011);LCD_Write_DATA(0x0227);//DC1[2:0],DC0[2:0],VC[2:0]delayms(50);//Delay50msLCD_Write_REG(0x0012);LCD_Write_DATA(0x001F);//001C//Internalreferencevoltage=Vci;delayms(50);//Delay50ms//LCD_Write_REG(0x0013);LCD_Write_DATA(0x15