<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > TFT顯示圖片的驅(qū)動(dòng)函數(shù)

          TFT顯示圖片的驅(qū)動(dòng)函數(shù)

          作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          以下是TFT驅(qū)動(dòng)函數(shù)用來顯示圖片,之前要將圖片進(jìn)行取模并保存在一下數(shù)組中:

          const unsignedchar code Image_pic[7128] = { };

          本文引用地址:http://www.ex-cimer.com/article/201611/321644.htm

          然后只需修改程序中的紅色字體的文字!

          一定記?。菏褂肨FT顯示圖片只需修改紅黑色字體的文字,知道如何用即可,沒有太大的必要親自去寫驅(qū)動(dòng)函數(shù)?。?!除非你有足夠的精力逐句去理解,這對(duì)你也有好處.

          #include
          #include

          #include "LCD.h"

          #defineNOP()_nop_()

          #defineTYPE_LCD_DATA1
          #defineTYPE_LCD_COMMAND0

          char code reserve[3]_at_ 0x3b; //保留0x3b開始的3個(gè)字節(jié)

          #defineDATAP0//定義數(shù)據(jù)輸入端口并行

          sbit LCD_RST= P2^7;
          sbit LCD_RD= P3^2;
          sbit LCD_WR= P3^3;
          sbit LCD_RS= P2^5;
          sbit LCD_CS= P2^6;

          //以上紅色字體是必須要針對(duì)實(shí)際的TFT接口連接情況進(jìn)行修改的,此為應(yīng)用的關(guān)鍵之處

          uint colors[]=
          {
          0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff
          };


          void delay_ms(uint ms)
          {
          unsigned char k;

          while (ms--)
          {
          for (k = 0; k < 228; k++)
          ;
          }
          }


          void LCD_Write(uchar type, uint value)
          {
          LCD_CS = 0;
          LCD_RS = type;// 0: command1: data

          LCD_WR= 0;
          DATA = (uchar)value;
          LCD_WR = 1;
          LCD_CS = 1;
          }


          void LCD_Write_Data8(uchar value)// color data
          {
          LCD_CS = 0;
          LCD_RS = 1;
          LCD_WR= 0;
          DATA = value;
          LCD_WR= 1;
          LCD_CS = 1;
          }


          void LCD_Wirte_Data16(uint value)// color data
          {
          LCD_CS = 0;
          LCD_RS = 1;
          LCD_WR= 0;
          DATA = (uchar)value;
          LCD_WR= 1;
          LCD_WR= 0;
          DATA = (uchar)(value>>8);
          LCD_WR = 1;
          LCD_CS = 1;
          }



          void Reg_Write(uint reg,uint value)
          {
          LCD_Write(TYPE_LCD_COMMAND,reg);
          LCD_Write(TYPE_LCD_DATA,value);
          }



          void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
          {
          uint VerPos,HorPos,StartAddr;

          HorPos= (uint)(xStart | (xEnd<<8));
          VerPos= (uint)(yStart | (yEnd<<8));
          StartAddr = (uint)(xStart | (yStart<<8));

          Reg_Write(0x09, xStart);
          Reg_Write(0x10,yStart);
          Reg_Write(0x11,xEnd);
          Reg_Write(0x12,yEnd);

          Reg_Write(0x18, xStart);
          Reg_Write(0x19, yStart);

          LCD_Write(TYPE_LCD_COMMAND,0x22);// 0x22
          }



          void LCD_init(void)
          {uint num;

          Reg_Write(0x0001,0x0002); //MODE_SEL1
          Reg_Write(0x0002,0x0012);//MODE_SEL2
          Reg_Write(0x0003,0x0000);//MODE_SEL3
          Reg_Write(0x0004,0x0010);//MODE_SEL3
          LCD_SetRamAddr(0,127, 0,159);
          for(num=20480;num>0;num--)
          LCD_Wirte_Data16(0xffff);

          Reg_Write(0x0005,0x0008);//VCO_MODE
          Reg_Write(0x0007,0x007f);//VCOMHT_CTRL
          Reg_Write(0x0008,0x0017);//VCOMLT_CTRL
          Reg_Write(0x0009,0x0000);//write SRAM window start X point
          Reg_Write(0x0010,0x0000);//write SRAM window start y point
          Reg_Write(0x0011,0x0083);//write SRAM window end x point
          Reg_Write(0x0012,0x009f);//write SRAM window end y point
          Reg_Write(0x0017,0x0000);//SRAM contrl
          Reg_Write(0x0018,0x0000);//SRAM x position
          Reg_Write(0x0019,0x0000);//SRAM y position
          Reg_Write(0x0006,0x00c5);//DAC_OP_CTRL2
          delay_ms(10); //延時(shí)

          }


          voidpic_play(uint Start_X, uint End_X,uint Start_Y,uint End_Y)
          {
          uint num,m;
          uint dx,dy;

          dx = (End_X+1)-Start_X;//計(jì)算寫入數(shù)據(jù)的總數(shù)
          dy = (End_Y+1)-Start_Y;
          num = dx*dy<<1;

          LCD_CS = 0;
          LCD_SetRamAddr(Start_X,End_X-1,Start_Y,End_Y-1) ;
          LCD_RS = 1;


          for(m=0; m<7128; m++)
          {
          LCD_Write_Data8(Image_pic[m]);

          }
          LCD_CS = 1;

          }



          voidLCD_clear(uchar n)
          {
          uint num;

          LCD_SetRamAddr(0,127, 0,159);//清屏函數(shù)

          for(num=20480;num>0;num--)//160*128=20480
          {
          LCD_Wirte_Data16(colors[n]);//其實(shí)質(zhì)是對(duì)每一個(gè)點(diǎn)進(jìn)行設(shè)置!
          }
          }

          void main(void)
          {
          P2 = 0xff;
          P0 = 0xff;//端口的初始化

          LCD_init();//屏幕初始化
          LCD_clear(6);//清屏

          pic_play(7,61,8,74);
          pic_play(68,122,8,74);
          pic_play(7,61,82,148);
          pic_play(68,122,82,148);

          //設(shè)置顯示圖片的位置
          while(1);
          }



          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();