經過近兩個星期的奮戰!今天我敢說我成功了,因為我在液晶屏上成功的顯示了彩色圖片!真是不容易啊。回顧這些日子,我沒睡一個安穩覺,實驗達一百多次,與現在興奮相比,都是浮云了!再一次次失敗中我也在總結經驗,一直在問位什么?下面:
我開始做TFT液晶實在做完SD卡之后,雖然我沒有弄文件系統,可是SD作為一個超大容量的RAM還是可以的,這一點我在技術上是能實現的!那么怎樣才能把SD卡上的數據準確無誤的顯示在TFT液晶上呢?沒有任何頭緒,雖然做過12864但是你看看TFT的數據手冊,你就明白了什么叫做不是一個級別!做之前,我在網上瘋狂的搜著關于TFT液晶的資料,最后只找到了一份英文的TFT手冊,我不懂英文!但還沒有中文的!在網上的大都是只言片語的簡介!于是開始用金山詞霸翻譯!大約有一個星期左右,關于TFT大概的知識懂了一點g點,當然現在的我也只是知道一點!因為他的功能實在是太強了!知道了控制器是9325的!知道了他的數據操作時分很多種的(16,8,SPI,...)。知道了他內部的寄存器很多!但是那是的我認為,不就是一塊液晶嗎!能難倒哪去?我現在才知道我當時錯了!大概有個了解后,我開始搭接實驗板!單片機驅動液晶調試正式開始,按照8位數據傳輸模式連接接口!數據按照一次傳送8位,傳兩次(因為不論是數據還是指令都是16位的數據結構)高字節在前的順序!開始我只想運行刷屏的程序,可是遲遲不能運行,后來發現是數據跟指令沒搞明白!RS=1表示寫的是數據,RS=0表示寫的是寄存器的地址。然后初始化,這里的初始話我是調用別人的做好的!后來程序開始在液晶上運行了!當然是刷屏程序!接下來市讓屏幕上顯示彩條!就想電視里的那種一條紅一條綠,一樣,這是為了測試液晶的GRAM你能可靠地控制!我實現這一步也要感謝網絡!正式網絡我才一點點的積累經驗,實現了自如的控制GRAM的顯示!(我想在液晶的任意坐標系內顯示任意的顏色或色條。┑竭@里我不禁想起了12864,因為當你控制了這一點時,你基本上離顯示圖片不遠了!因為你控制了這一點很容易的能實現行和場的掃描!有了行場掃描你就可以顯示一幅畫了!當然這是理論上!這是前天晚上的事!昨天一天我都在調一個東西!那就是關鍵的也是最后一步!SD卡和TFT液晶聯合試驗!單片機要完成從SD卡中讀取數據!然后送入到TFT液晶的控制器里,并且提供行掃描光和場掃描!SD卡的程序我以前調好的,直接拿來用!液晶的也拿來用,組合起來用XDATE中的RAM作為聯系兩個期間的數據緩沖單元!當我寫入內存卡一幅圖片!想著顯示出的畫面有多好時!打開電源!掃描開始!然而我失望了!出來的竟然是無數的紅綠白黑的點!俗稱花屏!為什么會這樣那?我開始考慮!是不是取模有問題!然后改變image2lcd的取模方式!復制粘貼!WINHEX中查看數據!這樣反復,還是不能顯示!相反出現了一個有趣的現象!出現了很多網文!這是行場不同步,像素沒有正確的寫入自己的位置造成的!這個問題從昨天下午直到半夜!還是沒解決!心情很郁悶!但是我總感覺我里成功很近了,一步之遙!昨晚上做到很晚,夢里還在想!結果誰大了,7:30才醒!醒了我就在想這個網文!我忽略了一個細節!當時我掃描方式時!我曾采用過行逆程顯示!結果表明有一部分圖像顯現出來!不過在邊緣!,里面都是網文!和亂踢八糟的彩色點!只有在邊緣是細膩的圖像,只有一小塊,而且每隔多少行一塊!突然一個想法在腦子里閃現!是不是我重復數據掃描了!有一想我主程序里是512個掃描周期,分了兩個字節!總共是1024!而我讀一扇區只有512,所以肯定有一半的數據是重復的!,想到這里我想趕緊驗證下!電話響了!安保近的,說工地有事讓我去趟!我也沒顧得實驗!直接去工地,辦完事回來吧程序改了,512改成了256,這樣正是512字節,然后又實驗!這次能顯示圖像的輪廓了,但是很模糊!我有WINHEX開查看!是字節未按高字節在前的順序,排列,調整后,一點也不大差的顯示在屏幕上了!IMAGE取模吧JPG轉換成BMP的彩色圖片寬度240,高度320,16位色,高位在前,水平掃描!生成BIN文件存入存儲卡中OVER!當然在中間還要用串口查看數據是否正確!
}
程序:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define DATE P0
- //bit flage;
- //SD卡的
- sbit p1_7=P1^7;
- sbit CS=P2^0; //片選信號(低電平有效)
- sbit DATEIN =P2^1;//主-從數據輸入
- sbit SCLK=P2^2;//時鐘信號
- sbit DATEOUT=P2^3;//從-主數據輸出
-
- //液晶的
- sbit RS=P3^7;
- sbit RW=P3^6;
- sbit RES=P3^5;
- sbit CStft=P3^4;
-
-
- uint btime;
- uchar c;
-
- unsigned char bdata dat;
- sbit dat_0=dat^0;
- sbit dat_1=dat^1;
- sbit dat_2=dat^2;
- sbit dat_3=dat^3;
- sbit dat_4=dat^4;
- sbit dat_5=dat^5;
- sbit dat_6=dat^6;
- sbit dat_7=dat^7;
-
- bit is_init;//決定是否延時;
- uchar lpp;
- unsigned char fhz;//返回值
- uchar fhz_buff; //讀返回值中間量
- unsigned char xdata tab[512];
-
-
- void delay(uint time)
- { while(time)
- time--;
- }
-
- //**********************************************
- /*讀sd卡子程序,無返回值,有參函數,參數為要寫入DATEIN數據線的字節*/
- void write(unsigned char wr_)// 寫入一個字節SD卡
- {
- dat=wr_;
- DATEIN=dat_7;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_6;
-
- SCLK=0;
- if(!is_init)delay(2);
- if(is_init)delay(200);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_5;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_4;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_3;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_2;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_1;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
-
- DATEIN=dat_0;
-
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=1;
- if(is_init) delay(200);
- if(!is_init)delay(2);
- }
- unsigned char read()// 讀取一個字節SD卡
- {
- DATEOUT=1;
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_7=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_6=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_5=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_4=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_3=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_2=DATEOUT;
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_1=DATEOUT;
-
-
- SCLK=1;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- SCLK=0;
- if(is_init)delay(200);
- if(!is_init)delay(2);
- dat_0=DATEOUT;
-
-
- return (dat);
-
- }
-
- void restsd()//復位SD卡
- { uchar i;
- uchar pcmd[6]={0x40,0x00,0x00,0x00,0x00,0x95};
- is_init=1;
-
- CS=1;
- for(i=0;i<15;i++)
- {
- //120時鐘
- write(0xff);
- }
-
-
-
-
- CS=1;
- write(0xff);//據說是提高兼容性
- CS=0;//片選開
-
- write( pcmd[0]);
- write( pcmd[1]);
- write( pcmd[2]);
- write( pcmd[3]);
- write( pcmd[4]);
- write( pcmd[5]);
-
- fhz=read();
- for(;;)
- {
- fhz=read();
- if(fhz==0x01)break;
-
-
- }
-
-
- CS=1;
- write(0xff);
-
- }
-
-
-
-
- void initsd()//初始化
- {
- //
- uchar pcmd[6]={0x41,0x00,0x00,0x00,0x00,0xff};//
- //
-
- CS=1;
- write(0xff);//據說是提高兼容性
- CS=0;//片選開
-
- write( pcmd[0]);
- write( pcmd[1]);
- write( pcmd[2]);
- write( pcmd[3]);
- write( pcmd[4]);
- write( pcmd[5]);
-
-
- fhz=read();
- for(;;)
- {
- fhz=read();
- if(fhz==0x00)break;
-
-
- }
-
-
- CS=1;
- write(0xff);
-
-
-
-
-
-
-
-
- }
- void readsd(unsigned long addstart)//讀SD卡物理扇區
-
- { unsigned long sdbuff1,sdbuff2,sdbuff3,sdbuff4;
- uint j,n;
- uchar zh1,zh2,zh3,zh4;
- sdbuff1=addstart;
- sdbuff2=addstart;
- sdbuff3=addstart;
- sdbuff4=addstart;
-
- zh1=(sdbuff1>>24)&0x000000ff;
- zh2=(sdbuff2>>16)&0x000000ff;
- zh3=(sdbuff3>>8)&0x000000ff;
- zh4=sdbuff4&0x000000ff;
- // uchar pcmd[6]={0x51,zh1,zh2,zh3,zh4,0xff};//原來這里是高地址字節在前地地址在后啊201012月14日邏輯扇區在253*512=0X0001fa00
-
-
-
- CS=1;
- write(0xff);//據說是提高兼容性
- CS=0;//片選開
-
- write( 0x51);
- write( zh1);
- write( zh2);
- write( zh3);
- write( zh4);
- write( 0xff);
- DATEOUT=1;
-
- for(;;)
- {
- fhz=read();
- if(fhz==0x00)break;
-
-
- }
- DATEOUT=1;
-
- for(;;)
- {
- fhz=read();
- if(fhz==0xfe)break;
-
-
- }
-
- DATEOUT=1;
- n=0;
- for(j=512;j;j--)
- {
- tab[n]=read();
- n++;
-
- }
- fhz=read();
- fhz=read();
- CS=1;
- write(0xff);
-
-
-
-
-
-
-
-
- }
- /*
- //********************************一下是液晶的
- void delay1ms(uint x) //延時程序
- { unsigned char a,b,c;
- uint z;
- for(z=x;z;z--)
- {
- for(c=8;c>0;c--)
- for(b=197;b>0;b--)
- for(a=2;a>0;a--);
- }
- }
-
- void write_date(uchar hight,uchar low) //定義搞八位字節和低八位字節寫然后寫入數據
- {
- CStft=0;
- RS=1;
- DATE=hight;
- RW=0;
- RW=1;
- DATE=low;
- RW=0;
- RW=1;
- CStft=1;
-
- }
- void write_cmd(uchar hight,uchar low )//定義搞八位字節和低八位字節寫然后寫入指令
- {
-
- CStft=0;
- RS=0;
- DATE=hight;
- RW=0;
- RW=1;
- DATE=low;
- RW=0;
- RW=1;
- CStft=1;
-
- }
- void wr_cmd_date(uint cmmd,uint datesh) //寫入指令和相應的數據;
- {
- uchar g,d,g1,d1; /* 2010年12月21日與天津第四項目部終于做完了9325的TFT262萬色彩色液晶,感覺比他媽的12864爽多了,
- 畢竟一個是黑白的一個是彩色的,呵呵,加油啊,下一步是組合SD卡和TFT液晶,讓液晶顯示彩色圖片,加油吧!*/
-
-
- d=datesh;
- d=(d&0x00ff);
- g=(datesh>>8)&0x0ff;
-
-
- d1=cmmd;
- d1=(d1&0x00ff);
- g1=(cmmd>>8)&0x0ff;
-
- write_cmd(g1,d1 );
- write_date(g,d ) ;
-
-
- }
- void initTFT()//注意:這里是用的設置庫,網絡上多的很,感謝網絡啊。
- {
- wr_cmd_date(0x0001,0x0100); //s1-s720
- wr_cmd_date(0x0002,0x0700);
- wr_cmd_date(0x0003,0x1030);
- wr_cmd_date(0x0004,0x0000);
- wr_cmd_date(0x0008,0x0207);
- wr_cmd_date(0x0009,0x0000);
- wr_cmd_date(0x000A,0x0000);
- wr_cmd_date(0x000C,0x0000);
- wr_cmd_date(0x000D,0x0000);
- wr_cmd_date(0x000F,0x0000);
- //power on sequence VGHVGL
- wr_cmd_date(0x0010,0x0000);
- wr_cmd_date(0x0011,0x0007);
- wr_cmd_date(0x0012,0x0000);
- wr_cmd_date(0x0013,0x0000);
- //vgh
- wr_cmd_date(0x0010,0x1290);
- wr_cmd_date(0x0011,0x0227);
- delay1ms(100);
- //vregiout
- wr_cmd_date(0x0012,0x001d); //0x001b
- delay1ms(100);
- //vom amplitude
- wr_cmd_date(0x0013,0x1500);
- delay1ms(100);
- //vom H
- wr_cmd_date(0x0029,0x0018);
- wr_cmd_date(0x002B,0x000D);
-
- //gamma
- wr_cmd_date(0x0030,0x0004);
- wr_cmd_date(0x0031,0x0307);
- wr_cmd_date(0x0032,0x0002);// 0006
- wr_cmd_date(0x0035,0x0206);
- wr_cmd_date(0x0036,0x0408);
- wr_cmd_date(0x0037,0x0507);
- wr_cmd_date(0x0038,0x0204);//0200
- wr_cmd_date(0x0039,0x0707);
- wr_cmd_date(0x003C,0x0405);// 0504
- wr_cmd_date(0x003D,0x0F02);
- //ram
- wr_cmd_date(0x0050,0x0000);
- wr_cmd_date(0x0051,0x00EF);
- wr_cmd_date(0x0052,0x0000);
- wr_cmd_date(0x0053,0x013F);
- wr_cmd_date(0x0060,0xA700);
- wr_cmd_date(0x0061,0x0001);
- wr_cmd_date(0x006A,0x0000);
- //
- wr_cmd_date(0x0080,0x0000);
- wr_cmd_date(0x0081,0x0000);
- wr_cmd_date(0x0082,0x0000);
- wr_cmd_date(0x0083,0x0000);
- wr_cmd_date(0x0084,0x0000);
- wr_cmd_date(0x0085,0x0000);
- //
- wr_cmd_date(0x0090,0x0010);
- wr_cmd_date(0x0093,0x0003);
- wr_cmd_date(0x0095,0x0110);
- wr_cmd_date(0x0097,0x0000);
- wr_cmd_date(0x0098,0x0000);
- wr_cmd_date(0x0007,0x0133);
-
-
- }
- //****************以上是液晶的
- void lcm_coordinate(unsigned int x1,unsigned int y1 )//掃描地
- {
- wr_cmd_date(0x0050,x1);
- wr_cmd_date(0x0051,x1);
- wr_cmd_date(0x0052,y1);
- wr_cmd_date(0x0053,y1);
- wr_cmd_date(0x0020,x1);
- wr_cmd_date(0x0021,y1);
- }
- void main()
-
- { unsigned long numb;
- unsigned int x,y; //掃描地址;
- uint a;
- uint f,buff_sd_tft;
- uint m1,m2;
- delay1ms(30);
- CS=1;
- RES=0;
- delay1ms(150);
- RES=1;
- delay1ms(50);
-
- //******
- initTFT();
- //InitUART(); //串口初始化
- is_init=1;
- restsd();
- initsd();
- is_init=0;//提高始終頻率
- //p1_7=0;
- //********
- while(1)
- {
- /* x=0;y=0;
-
- for(;;)
- {
- lcm_coordinate(x,y );
- wr_cmd_date(0x0022,0x0000);
- x++;
- delay20us();
-
- if(x==240){x=0;y++;}
- if(y==80)break; //檢測是否寫到屏的邊緣 240x320
-
- }
-
- for(;;)
- {
- lcm_coordinate(x,y );
- wr_cmd_date(0x0022,0xf800);
- x++;
- delay20us(); //必須加延時,實時勝于雄辯,如果不加延時的話,極易出現花屏,及掃描過高引起的數據無法寫入,他媽的耽誤了我一下午時間。2010年12月22日
- if(x==240){x=0;y++;}
- if(y==160)break; //檢測是否寫到屏的邊緣 240x320
-
- }
-
- for(;;)
- {
- lcm_coordinate(x,y );
- wr_cmd_date(0x0022,0x0000);
- x++;
- delay20us(); //必須加延時,實時勝于雄辯,如果不加延時的話,極易出現花屏,及掃描過高引起的數據無法寫入,他媽的耽誤了我一下午時間啊!2010年12月22日
- if(x==240){x=0;y++;}
- if(y==240)break; //檢測是否寫到屏的邊緣 240x320
-
- }
- for(;;)
- {
- lcm_coordinate(x,y );
- wr_cmd_date(0x0022,0x001f);
- x++;
- delay20us(); //必須加延時,實時勝于雄辯,如果不加延時的話,極易出現花屏,及掃描過高引起的數據無法寫入,他媽的耽誤了我一下午時間。2010年12月22日
- if(x==240){x=0;y++;}
- if(y==320)break; //檢測是否寫到屏的邊緣 240x320
-
- }
- }*/
-
- // while(1);
- //p1_7=1;
- // btime=65536;
-
-
-
-
-
-
-
-
-
- // SendOneByte(0x88);
- x=0;y=0;
- numb=4327936;
- do
- {
-
-
- readsd(numb);//讀物理扇區
- //SendOneByte(0x88);
- f=0;
- for(a=256;a;a--)
- {
-
- m1=tab[f];
- // SendOneByte(m1);
- m1=(m1<<8)&0xff00;
- f++;
- m2=tab[f];
- // SendOneByte(m2);
- f++;
- buff_sd_tft=m1+m2;
-
-
- lcm_coordinate(x,y );
- wr_cmd_date(0x0022,buff_sd_tft);
- x++;
- delay1ms(1); //必須加延時,實時勝于雄辯,如果不加延時的話,極易出現花屏,及掃描過高引起的數據無法寫入,他媽的耽誤了我一下午時間!2010年12月22日
- if(x==240){x=0;y++;}
- if(y==320)y=0; //檢測是否寫到屏的邊緣 240x320
- }
- //SendOneByte(0xcc);
- numb=(numb+512);
- }
- while(0x0044620!=numb);
- // EA=0;
-
- // ES = 0;
- // TR1 = 0;
-
- while(1);
-
-
-
- }
復制代碼
|