找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3512|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

請大神幫個忙,看看是什么問題,為什么在TFT彩屏上顯示的是線條

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:85337 發(fā)表于 2015-7-20 22:23 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <reg51.h>

#define TFT_DATAPORTH P1               
#define TFT_DATAPORTL P0

typedef unsigned char uchar;
typedef unsigned int uint;

sbit TFT_RW=P2^5;
sbit TFT_RS=P2^6;
sbit TFT_CS=P2^7;                    //片選(低電平有效)
sbit TFT_RST=P3^3;                    //低電平復(fù)位
sbit TFT_RD=P3^0;                //RD=0:讀信號;RD=1:寫數(shù)據(jù)

void TFT_init(void);
void delay(int x);
void TFT_writecmd(uint cmd);                                              //該函數(shù)把命令字寫入到TFT控制器
void TFT_writedata(uint dat);                              //該函數(shù)把數(shù)據(jù)字寫入到TFT控制器
void TFT_write_cmd_data(uint cmd,uint dat);          //該函數(shù)把命令字和數(shù)據(jù)字都寫入到TFT控制器
void TFT_clearscreen(uint color);                                          //清屏函數(shù)
void TFT_setwindow(uchar xStart,uchar yStart,uchar xEnd,uchar yEnd);  //設(shè)置顯示窗口
void GUI_Write32CnChar(uint x, uint y, uchar *cn, uint wordColor, uint backColor);//顯示漢字

typedef struct _Cn32Char                   // 漢字字模數(shù)據(jù)結(jié)構(gòu)
{
        uchar GBK[2];            // 漢字內(nèi)碼索引,一個漢字占兩個字節(jié)        
        uchar hanzi[116];            // 點陣碼數(shù)據(jù)(32*29/8)
}Cn32Char;

Cn32Char code CnChar32x29[]={

/*--  文字:  普  --*/
/*--  宋體22;  此字體下對應(yīng)的點陣為:寬x高=29x29   --*/
/*--  寬度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=32x29  --*/
"普",0x00,0x00,0x00,0x00,0x00,0x07,0x0C,0x00,0x00,0x1E,0x3E,0x00,0x00,0x3C,0x0E,0x00,
0x00,0x3C,0x87,0x03,0xF8,0xFF,0xFF,0x07,0x00,0x1C,0x07,0x00,0x60,0x1C,0xE7,0x00,
0xE0,0x1C,0xE7,0x01,0xC0,0x1D,0x77,0x00,0xC0,0x1F,0x77,0x00,0x80,0x1F,0x3F,0x00,
0x80,0x1D,0x1F,0x07,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x00,0x30,0x00,0x80,0xFF,0x7F,0x00,0x80,0x03,0x38,0x00,0x80,0x03,0x38,0x00,
0x80,0x03,0x38,0x00,0x80,0xFF,0x3F,0x00,0x80,0x03,0x38,0x00,0x80,0x03,0x38,0x00,
0x80,0x03,0x38,0x00,0x80,0xFF,0x3F,0x00,0x80,0x03,0x38,0x00,0x80,0x01,0x18,0x00,
0x00,0x00,0x00,0x00
};


void main(void)
{
        int i=0;
        TFT_init();
        TFT_clearscreen(0xf800);
       
        GUI_Write32CnChar(24,25,"普",0x0000,0x0f800);
       
        while(1);

}


void delay(int x)
{
        int a;
        while(x--)
        {
                 for(a=0;a<200;a++);
        }
}


void TFT_init(void)
{
        TFT_RST=1;
        delay(1);
        TFT_RST=0;
        delay(1);
        TFT_RST=1;
        delay(1);

        TFT_CS=0;
       
        TFT_write_cmd_data(0x0014,0x0030);
        TFT_write_cmd_data(0x000f,0x0008);
        TFT_write_cmd_data(0x0011,0x0231);
        TFT_write_cmd_data(0x0012,0x000a);       
        TFT_write_cmd_data(0x0013,0x145d);
        TFT_write_cmd_data(0x0010,0x5268);
        delay(10);

        TFT_write_cmd_data(0x0012,0x001a);
        delay(10);

          TFT_write_cmd_data(0x0010,0x5260);
           TFT_write_cmd_data(0x0013,0x345d);
        delay(10);
       
        TFT_write_cmd_data(0x0030,0x0000);
        TFT_write_cmd_data(0x0031,0x0705);
        TFT_write_cmd_data(0x0032,0x0706);
        TFT_write_cmd_data(0x0033,0x0102);
        TFT_write_cmd_data(0x0034,0x0204);
        TFT_write_cmd_data(0x0035,0x0000);
        TFT_write_cmd_data(0x0036,0x0104);
        TFT_write_cmd_data(0x0037,0x0007);
        TFT_write_cmd_data(0x0038,0x0000);
        TFT_write_cmd_data(0x0039,0x0000);
        TFT_write_cmd_data(0x0001,0x011b);
        TFT_write_cmd_data(0x0002,0x0700);
        TFT_write_cmd_data(0x0003,0x1030);
        TFT_write_cmd_data(0x000b,0x1010);
        TFT_write_cmd_data(0x000a,0x4420);
        TFT_write_cmd_data(0x000b,0x5030);
        TFT_write_cmd_data(0x0007,0x0005);
        TFT_write_cmd_data(0x0007,0x0025);
        TFT_write_cmd_data(0x0007,0x0027);
        TFT_write_cmd_data(0x0007,0x0037);       
                               
}



void TFT_writecmd(uint cmd)
{
        TFT_RW=1;
        TFT_CS=0;

        TFT_RD=1;
        TFT_RS=0;

        TFT_DATAPORTH=cmd>>8;

        TFT_RW=0;
        TFT_RW=1;

        TFT_DATAPORTL=cmd&0x00ff;

        TFT_RW=0;
        TFT_RW=1;

        TFT_CS=1;

}


void TFT_writedata(uint dat)
{

        TFT_RW=1;
        TFT_CS=0;

        TFT_RD=1;
        TFT_RS=1;

        TFT_DATAPORTH=dat>>8;

        TFT_RW=0;
        TFT_RW=1;

        TFT_DATAPORTL=dat&0x00ff;

        TFT_RW=0;
        TFT_RW=1;

        TFT_CS=1;

}



void TFT_write_cmd_data(uint cmd,uint dat)
{
        TFT_writecmd(cmd);
        TFT_writedata(dat);
}


void TFT_clearscreen(uint color)
{
        int i,j;
       
        TFT_setwindow(0,0,175,219);
         
        for(i=0;i<=175;i++)
        {
                for(j=0;j<=219;j++)
                {
                        TFT_writedata(color);
                }
        }        
}


void TFT_setwindow(uchar xStart,uchar yStart,uchar xEnd,uchar yEnd)
{
        uint x,y,z;

        x=(xEnd<<8)|xStart;
        y=(yEnd<<8)|yStart;
        z=(yStart<<8)|xStart;

        TFT_write_cmd_data(0x44,x);

        TFT_write_cmd_data(0x45,y);

        TFT_write_cmd_data(0x21,z);                                                           

        TFT_write_cmd_data(0x22,0x0000);
}          


void GUI_Write32CnChar(uint x, uint y, uchar *cn, uint wordColor, uint backColor)
{
        uchar i,j,wordNum;
    uint color;
    while(*cn!='\0')
    {
                TFT_setwindow(x,y,x+31,y+28);
        for(wordNum=0;wordNum<20;wordNum++)
        {        //wordNum掃描字庫的字
                        if((CnChar32x29[wordNum].GBK[0]==*cn)&&(CnChar32x29[wordNum].GBK[1]==*(cn+1)))
            {
                    for(i=0; i<116; i++)
                {        //MSK的位數(shù)
                        color=CnChar32x29[wordNum].hanzi[i];
                    for(j=0;j<8;j++)
                    {
                            if((color&0x80)==0x80)
                        {
                                TFT_writedata(wordColor);
                        }                                                
                        else
                        {
                                TFT_writedata(backColor);
                        }
                        color<<=1;
                    }//for(j=0;j<8;j++)結(jié)束
                }   
            }
       } //for (wordNum=0; wordNum<20; wordNum++)結(jié)束         
       cn+=2;
       x+=32;
        }
}                                               
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:85337 發(fā)表于 2015-7-20 22:24 | 只看該作者
請大神看看,為什么在TFT彩屏上顯示的是線條
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表