久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5311|回復: 5
收起左側

TFT液晶SSD2119的stm32單片機驅動

[復制鏈接]
ID:110517 發表于 2017-9-6 12:25 | 顯示全部樓層 |閱讀模式
SSD2119 ID:9919;基于stm32f1的
0.png

單片機源程序如下:
  1. //-------------------------------------------------------------------------*
  2. //文件名:  LCD.c (LCD操作函數文件)                                         *
  3. //-------------------------------------------------------------------------*
  4. #include "LCD.h"
  5. #include "font.h"
  6. //內部調用的函數聲明
  7. static void WriteRegister(uint16 index,uint16 data);//寫指定地址寄存器的值
  8. static void WriteIndex(uint16 index);//寫 SSD2119 控制器寄存器地址
  9. static void WriteData(uint16 data);//寫 SSD2119 寄存器數據
  10. static uint16 ReadRegister(uint16 index);//讀取指定地址寄存器的值
  11. static uint16 ReadData(void);//讀取控制器數據
  12. static void SetCursor(uint16 x,uint16 y);//設置屏幕坐標
  13. static void Reset();//復位 SSD2119 控制器
  14. static void LCDDrawChar(uint16 x, uint16 y, uint8 *c);//在屏幕上畫一個字符
  15. static void LCDDrawChinese(uint16 x, uint16 y, uint16 *c);//在屏幕上畫一個漢字
  16. //-------------------------------------------------------------------------*
  17. //函數名: LCDInit                                                          *
  18. //功  能: 液晶初始化程序                                                   *
  19. //參  數: 無                                                               *
  20. //返  回: 無                                                               *
  21. //內部調用:WriteRegister                                                   *
  22. //說  明: 初始化液晶的顯示方式                                             *
  23. //-------------------------------------------------------------------------*
  24. void LCDInit(void)
  25. {
  26.         uint8 tmp;
  27.         uint16 i;
  28.     static uint16 DeviceCode;
  29.         PIN_FUNCTION();//配置引腳功能為GPIO
  30.         CONTROL_OUTPUT();//配置控制引腳為輸出  
  31.         //設置GPIO為輸出
  32.         DATA_OUTPUT();
  33.         WriteData(0xffff);
  34.         Set_RST;
  35.         Set_Cs;
  36.         Set_Rs;
  37.         Set_nWr;
  38.         Set_nRd;
  39.         Set_RST;
  40.         Reset();
  41.         Delay(200);                           
  42.         WriteRegister(0x0000,0x0001);
  43.         Delay(200);   
  44.         for(i=50000;i>0;i--);
  45.         for(i=50000;i>0;i--);
  46.         //DeviceCode = ReadRegister(0x0000);
  47.         DeviceCode=0x9919;
  48.         if(DeviceCode == 0x9919)
  49.         {
  50.                 //*********POWER ON &RESET DISPLAY OFF
  51.                 WriteRegister(0x28,0x0006);   
  52.                 WriteRegister(0x00,0x0001);   
  53.                 WriteRegister(0x10,0x0000);   
  54.                 WriteRegister(0x01,0x72ef);   
  55.                 WriteRegister(0x02,0x0600);   
  56.                 WriteRegister(0x03,0x6a38);   
  57.                 //WriteRegister(0x11,0x6874);//70//從左到右(橫屏顯示)
  58.                 WriteRegister(0x11,0x685C);  //70//從上到下(豎屏顯示)  
  59.                 //  RAM WRITE DATA MASK
  60.                 WriteRegister(0x0f,0x0000);
  61.                 //  RAM WRITE DATA MASK
  62.                 WriteRegister(0x0b,0x5308);   
  63.                 WriteRegister(0x0c,0x0003);   
  64.                 WriteRegister(0x0d,0x000a);   
  65.                 WriteRegister(0x0e,0x2e00);  //0030   
  66.                 WriteRegister(0x1e,0x00be);   
  67.                 WriteRegister(0x25,0x8000);   
  68.                 WriteRegister(0x26,0x7800);   
  69.                 WriteRegister(0x27,0x0078);   
  70.                 WriteRegister(0x4e,0x0000);   
  71.                 WriteRegister(0x4f,0x0000);   
  72.                 WriteRegister(0x12,0x08d9);   
  73.                 // -----------------Adjust the Gamma Curve----//
  74.                 WriteRegister(0x30,0x0000);         //0007   
  75.                 WriteRegister(0x31,0x0104);         //0203   
  76.                 WriteRegister(0x32,0x0100);  //0001   
  77.                 WriteRegister(0x33,0x0305);         //0007   
  78.                 WriteRegister(0x34,0x0505);         //0007   
  79.                 WriteRegister(0x35,0x0305);  //0407   
  80.                 WriteRegister(0x36,0x0707);         //0407   
  81.                 WriteRegister(0x37,0x0300);  //0607   
  82.                 WriteRegister(0x3a,0x1200);  //0106   
  83.                 WriteRegister(0x3b,0x0800);               
  84.                 WriteRegister(0x07,0x0033);
  85.         }
  86.         for(i=50000;i>0;i--);
  87.         //LCDClear(0xff00);
  88. }

  89. //-------------------------------------------------------------------------*
  90. //函數名: LCDClear                                                         *
  91. //功  能: 將屏幕填充成指定的顏色,如清屏,則填充 0xffff                    *
  92. //參  數: ClearColor:填充顏色                                              *
  93. //返  回: 無                                                               *
  94. //內部調用:SetCursor,WriteIndex,WriteData                                  *
  95. //說  明: 將屏幕填充成指定的顏色                                           *
  96. //-------------------------------------------------------------------------*
  97. void LCDClear(uint16 ClearColor)
  98. {
  99.         uint32 i;
  100.         SetCursor(0x0000, 0x0000);  
  101.         Clr_Cs;
  102.         WriteIndex(0x0022);
  103.         Set_Rs;   
  104.         for(i=0;i<76800;i++)
  105.         {
  106.                 WriteData(ClearColor);
  107.                 Clr_nWr;
  108.                 Set_nWr;
  109.         }
  110.         Set_Cs;
  111. }
  112. //-------------------------------------------------------------------------*
  113. //函數名: LCDTest                                                          *
  114. //功  能: 測試液晶屏                                                       *
  115. //參  數: 無                                                               *
  116. //返  回: 無                                                               *
  117. //內部調用:WriteIndex,WriteRegister,WriteData                              *
  118. //說  明:                                                                  *
  119. //-------------------------------------------------------------------------*
  120. void LCDTest(void)
  121. {
  122.         uint16 i,j;
  123.         WriteRegister(0x4e, 0);
  124.         WriteRegister(0x4f, 0);
  125.         Clr_Cs;
  126.         WriteIndex(0x22);  
  127.         for(i=0;i<320;i++)
  128.                 for(j=0;j<240;j++)
  129.                 {
  130.                           if(i>279)WriteData(0xffff);
  131.                           else if(i>239)WriteData(0x001f);
  132.                           else if(i>199)WriteData(0x07e0);
  133.                           else if(i>159)WriteData(0x07ff);
  134.                           else if(i>119)WriteData(0xf800);
  135.                           else if(i>79)WriteData(0xf81f);
  136.                           else if(i>39)WriteData(0xffe0);
  137.                           else WriteData(0xffff);
  138.             }
  139.     Set_Cs;
  140. }
  141. //-------------------------------------------------------------------------*
  142. //函數名: LCDSetPixel                                                      *
  143. //功  能: 在指定座標畫點                                                   *
  144. //參  數: x      行座標                                                    *
  145. //        y      列座標                                                    *
  146. //        PixcelColor  像素的顏色                                          *
  147. //返  回: 無                                                               *
  148. //內部調用:SetCursor,WriteIndex,WriteData                                  *
  149. //說  明:                                                                  *
  150. //-------------------------------------------------------------------------*
  151. void LCDSetPixel(uint16 x,uint16 y,uint16 PixcelColor)
  152. {
  153.         if ( (x>320)||(y>240) ) return;
  154.         SetCursor(x,y);
  155.         Clr_Cs;
  156.         WriteIndex(0x0022);
  157.         WriteData(PixcelColor);
  158.         Set_Cs;
  159. }
  160. //-------------------------------------------------------------------------*
  161. //函數名: LCDShowChar                                                      *
  162. //功  能: 顯示一個字符(8*16點陣)                                           *
  163. //參  數: ln:字符要顯示的行                                                *
  164. //       col:字符要顯示的列                                                *
  165. //         c:要顯示的字符                                                  *
  166. //返  回: 無                                                               *
  167. //內部調用:LCDDrawChar                                                     *
  168. //說  明:                                                                  *
  169. //-------------------------------------------------------------------------*
  170. void LCDShowChar(uint16 ln, uint16 col, uint8  c)
  171. {
  172.         c -= 32;
  173.     LCDDrawChar(ln, col, &ASCII_Character[c*16]);
  174. }
  175. //-------------------------------------------------------------------------*
  176. //函數名: LCDShowStringLn                                                  *
  177. //功  能: 在指定的行顯示字符串                                             *
  178. //參  數: ln:要顯示的行                                                    *
  179. //       *s: 指向字符串的指針                                              *
  180. //返  回: 無                                                               *
  181. //內部調用:LCDDrawChar                                                     *
  182. //說  明:                                                                  *
  183. //-------------------------------------------------------------------------*
  184. void LCDShowStringLn(uint16 ln, uint8 *s)
  185. {
  186.         uint16 i = 1;
  187.         uint16 Count=0;
  188.         //uint16  refcolumn = (WIDTH/*-1*/)-16;
  189.         uint16 refcolumn = 240;
  190.         uint8 *p;
  191.         p=s;
  192.         //統計字符個數
  193.         while(*p!= 0)
  194.         {
  195.                 Count++;
  196.                 p++;        
  197.         }
  198.         UartSend1(0,Count);
  199.     while ((*s != 0) && (i <= Count))  //在屏幕上依次寫每個字符
  200.         {
  201.                 LCDShowChar(ln, refcolumn, *s);                        
  202.                    refcolumn -= 8; //列減去一個字符
  203.                 s++;                                             
  204.                 if((i%30)==0)  
  205.                 {
  206.                         refcolumn=240;
  207.                         ln+=16;//換行
  208.                 }            
  209.                 i++;        //統計字符的個數            
  210.         }
  211. }
  212. //-------------------------------------------------------------------------*
  213. //函數名: LCDShowChinese                                                   *
  214. //功  能: 在指定的行、列顯示一個漢字                                       *
  215. //參  數: ln:漢字要顯示的行                                                *
  216. //        col:漢字要顯示的列                                               *
  217. //        start:要顯示的漢字串的開始下標                                   *
  218. //返  回: 無                                                               *
  219. //內部調用:LCDDrawChinese                                                  *
  220. //說  明:                                                                  *
  221. //-------------------------------------------------------------------------*
  222. void LCDShowChinese(uint16 ln, uint16 col, uint8 start)
  223. {
  224.         LCDDrawChinese(ln, col, &ASCII_Chinese[16*start]);
  225. }
  226. //-------------------------------------------------------------------------*
  227. //函數名: LCDShowChineseLine                                               *
  228. //功  能: 在指定的行顯示一串漢字                                           *
  229. //參  數: ln:漢字要顯示的行                                                *
  230. //        start:要顯示的漢字串的開始下標                                   *
  231. //        count:一行中要顯示的漢字個數                                     *
  232. //返  回: 無                                                               *
  233. //內部調用:LCDDrawChinese                                                  *
  234. //說  明:                                                                  *
  235. //-------------------------------------------------------------------------*
  236. void LCDShowChineseLine(uint16 ln, uint8 start,uint8 count)
  237. {
  238.         uint8 i,temp=0;
  239.         uint16 column = 240;
  240.         for(i=start;i<count+start;i++)
  241.         {
  242.                 LCDDrawChinese(ln, column, &ASCII_Chinese[16*i]);
  243.                 column-=16;
  244.                 temp++;
  245.                 if(temp%15==0)
  246.                 {
  247.                         ln+=16;
  248.                         column=240;
  249.                 }
  250.                
  251.         }
  252. }
  253. //-------------------------------------------------------------------------*
  254. //函數名: LCDShowBitmap                                                    *
  255. //功  能: 顯示一幅圖片,x為水平坐標,y為垂直坐標,每個像素用16位二進制表示    *
  256. //        5:6:5格式                                                        *
  257. //參  數: x: 水平起始位置                                                  *
  258. //        y: 垂直起始位置                                                  *
  259. //        w: 圖片的寬度                                                    *
  260. //        h: 圖片的高度                                                    *
  261. //        bitmap: 指向圖片數組的指針                                       *
  262. //返  回: 無                                                               *
  263. //內部調用:                                                                *
  264. //說  明:                                                                  *
  265. //-------------------------------------------------------------------------*
  266. void LCDShowBitmap(uint16 x, uint16 y, uint16 w, uint16 h, uint8 *bitmap)
  267. {
  268.         uint16   i,j;
  269.         uint16  len = w*h;
  270.         uint16 *bitmap_ptr = (uint16 *)bitmap;
  271.         for (j = 0; j< h; j++)
  272.         {
  273.                 SetCursor(x,y);
  274.                 Clr_Cs;
  275.         WriteIndex(0x22);
  276.         Set_Rs;
  277.             for(i = 0; i<w; i++)
  278.             {
  279.                         WriteData(*bitmap_ptr++);
  280.             }
  281.             x++;//換行
  282.             Set_Cs;   
  283.           }
  284. }



  285. //內部調用的函數
  286. //-------------------------------------------------------------------------*
  287. //函數名: WriteRegister                                                    *
  288. //功  能: 寫指定地址寄存器的值                                             *
  289. //參  數: index    寄存器地址                                              *
  290. //        data      寄存器值                                               *
  291. //返  回: 無                                                               *
  292. //內部調用:WriteIndex,WriteData                                            *
  293. //說  明:  內部函數                                                        *
  294. //-------------------------------------------------------------------------*
  295. static void WriteRegister(uint16 index,uint16 data)
  296. {
  297.         /************************************************************************
  298.         **                                                                     **
  299.         ** nCS       ----\__________________________________________/-------   **
  300.         ** RS        ------\____________/-----------------------------------   **
  301.         ** nRD       -------------------------------------------------------   **
  302.         ** nWR       --------\_______/--------\_____/-----------------------   **
  303.         ** DB[0:15]  ---------[index]----------[data]-----------------------   **
  304.         **                                                                     **
  305.         ************************************************************************/
  306.         Clr_Cs;
  307.         WriteIndex(index);
  308.         WriteData(data);
  309.         Set_Cs;
  310. }
  311. //-------------------------------------------------------------------------*
  312. //函數名: WriteIndex                                                       *
  313. //功  能: 寫 SSD2119 控制器寄存器地址                                      *
  314. //參  數: index    寄存器地址                                              *
  315. //返  回: 無                                                               *
  316. //內部調用:                                                                *
  317. //說  明:  調用前需先選中控制器,內部函數                                  *
  318. //-------------------------------------------------------------------------*
  319. static void WriteIndex(uint16 index)
  320. {
  321.         Clr_Rs;
  322.         Set_nRd;
  323.         DATA_LO_PORT = index;
  324.         DATA_HI1_PORT = (index>>8);
  325.         DATA_HI2_PORT = (index>>12);
  326.         Clr_nWr;
  327.         Set_nWr;
  328.         Set_Rs;
  329. }
  330. //-------------------------------------------------------------------------*
  331. //函數名: WriteData                                                        *
  332. //功  能: 寫 SSD2119 寄存器數據                                            *
  333. //參  數: data     寄存器數據                                              *
  334. //返  回: 無                                                               *
  335. //內部調用:                                                                *
  336. //說  明: 向控制器指定地址寫入數據,調用前需先寫寄存器地址,內部函數       *
  337. //-------------------------------------------------------------------------*
  338. static void WriteData(uint16 data)
  339. {
  340.         Set_Rs;
  341.         Set_nRd;
  342.           DATA_LO_PORT = data;
  343.         DATA_HI1_PORT = (data>>8);
  344.         DATA_HI2_PORT = (data>>12);
  345.         Clr_nWr;
  346.         Set_nWr;
  347. }
  348. //-------------------------------------------------------------------------*
  349. //函數名: ReadRegister                                                     *
  350. //功  能: 讀取指定地址寄存器的值                                           *
  351. //參  數: index    寄存器地址                                              *
  352. //返  回: 寄存器值                                                         *
  353. //內部調用: WriteIndex, ReadData                                           *
  354. //說  明: 內部函數                                                         *
  355. //-------------------------------------------------------------------------*
  356. static uint16 ReadRegister(uint16 index)
  357. {
  358.         Clr_Cs;
  359.         WriteIndex(index);
  360.         Clr_nRd;
  361.         index = ReadData();
  362.         Set_nRd;
  363.         Set_Cs;
  364.         return index;
  365. }
  366. //-------------------------------------------------------------------------*
  367. //函數名: ReadData                                                         *
  368. //功  能: 讀取控制器數據                                                   *
  369. //參  數: 無                                                               *
  370. //返  回:返回讀取到的數據                                                  *
  371. //內部調用:                                                                *
  372. //說  明: 內部函數                                                         *
  373. //-------------------------------------------------------------------------*
  374. static uint16 ReadData(void)
  375. {
  376.         //========================================================================
  377.         // **                                                                   **
  378.         // ** nCS       ----\__________________________________________/------- **
  379.         // ** RS        ------\____________/----------------------------------- **
  380.         // ** nRD       -------------------------\_____/---------------------   **
  381.         // ** nWR       --------\_______/-------------------------------------- **
  382.         // ** DB[0:15]  ---------[index]----------[data]----------------------- **
  383.         // **                                                                   **
  384.         //========================================================================
  385.         uint16 tmp;
  386.         DATA_INPUT();
  387.         tmp =DATA_HI2_PORT;
  388.         tmp = (tmp << 4) + DATA_HI1_PORT;       /* 讀入高8位數據*/
  389.         tmp = (tmp << 8) + DATA_LO_PORT;         /* 讀入低8位數據*/
  390.         DATA_OUTPUT();
  391.         return tmp;
  392. }
  393. //-------------------------------------------------------------------------*
  394. //函數名: SetCursor                                                        *
  395. //功  能: 設置屏幕坐標                                                     *
  396. //參  數: x      行坐標                                                    *
  397. //        y      列坐標                                                    *
  398. //返  回:無                                                                *
  399. //內部調用:                                                                *
  400. //說  明: 內部函數                                                         *
  401. //-------------------------------------------------------------------------*
  402. static void SetCursor(uint16 x,uint16 y)
  403. {
  404.     WriteRegister(0x004e,x); // 行
  405.     WriteRegister(0x004f,y); // 列        
  406. }
  407. //-------------------------------------------------------------------------*
  408. //函數名: Reset                                                            *
  409. //功  能: 復位 SSD2119 控制器                                              *
  410. //參  數: 無                                                               *
  411. //返  回: 無                                                               *
  412. //內部調用:                                                                *
  413. //說  明: 復位控制器,內部函數                                             *
  414. //-------------------------------------------------------------------------*
  415. static void Reset()
  416. {
  417.         /***************************************
  418.         **                                    **
  419.         **  -------\______________/-------    **
  420.         **         | <---Tres---> |           **
  421.         **                                    **
  422.         **  Tres: Min.1ms                     **
  423.         ***************************************/  
  424.         Set_RST;  
  425.         Delay(50);
  426.         Cls_RST;
  427.         Delay(50);
  428.         Set_RST;
  429.         Delay(50);
  430. }
  431. //-------------------------------------------------------------------------*
  432. //函數名: LCDDrawChar                                                      *
  433. //功  能: 在給定的行、列畫一個字符(8*16點陣)                               *
  434. //參  數: x :字符所在的行                                                  *
  435. //        y :字符所在的列                                                  *
  436. //        c*:指向字符的指針                                                *
  437. //返  回: 無                                                               *
  438. //內部調用:                                                                *
  439. //說  明: 內部函數                                                         *
  440. //-------------------------------------------------------------------------*
  441. static void LCDDrawChar(uint16 x, uint16 y, uint8 *c)
  442. {
  443.         uint16 index = 0;
  444.         int32  i = 0;
  445.         uint16 Xaddress = 0;   
  446.         Xaddress = x;
  447.         WriteRegister(0x4e, Xaddress);
  448.         WriteRegister(0x4f, y);
  449.         for(index = 0; index < 16; index++)
  450.         {
  451.                 Clr_Cs;
  452.                 WriteIndex(0x22);            
  453.                 for(i = 8; i >= 0; i--)
  454.                 {
  455.                         if((c[index] & (1 << i)) == 0x00)
  456.                         {
  457. ……………………

  458. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
SSD2119驅動.rar (5.03 KB, 下載次數: 60)





回復

使用道具 舉報

ID:110517 發表于 2017-9-6 12:26 | 顯示全部樓層
TFT液晶!!!
回復

使用道具 舉報

ID:351627 發表于 2018-6-14 09:53 | 顯示全部樓層
SSD2119是不是也是屬于8080接口的?
回復

使用道具 舉報

ID:392162 發表于 2018-8-31 22:53 | 顯示全部樓層
本帖最后由 lg2911 于 2018-9-1 11:26 編輯
dengmcu 發表于 2018-6-14 09:53
SSD2119是不是也是屬于8080接口的?

看手冊確認了一下,SSD2119本身是8080和6800兩種接口都支持的,用PS3-PS0來選擇,要看液晶模組是否把這4根線引出來了,要是引出了,那就是可以使用者自己設置的
回復

使用道具 舉報

ID:418685 發表于 2018-11-13 13:52 | 顯示全部樓層
謝謝分享,正在學習這方面知識
回復

使用道具 舉報

ID:513785 發表于 2021-6-15 16:15 | 顯示全部樓層

謝謝分享,正在學習這方面知識
回復

使用道具 舉報

7#
無效樓層,該帖已經被刪除
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品综合 | 亚洲精品乱码久久久久久久久久 | 日韩成人在线网址 | 亚洲一区欧美一区 | 亚洲日本一区二区三区四区 | 欧洲精品一区 | 精品av久久久久电影 | 亚洲欧美日韩在线 | 免费人成在线观看网站 | 欧美激情国产精品 | 91精品国产综合久久福利软件 | 日韩在线一区二区三区 | 户外露出一区二区三区 | 国产精品毛片久久久久久 | 欧美黄色一级毛片 | 99热播精品 | 九九精品在线 | 欧美一区二区三区在线观看 | 欧美一区二区久久 | 在线观看视频91 | 亚洲免费人成在线视频观看 | 免费观看一级视频 | 欧美一区二区三区四区五区无卡码 | 天天操天天操 | 国产在线观看福利 | 精品视频网 | 玖玖视频免费 | 国产精品久久久久久妇女6080 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 欧美日韩黄色一级片 | 亚洲精品一区av在线播放 | 久久久黑人 | 国产精品欧美一区二区三区不卡 | 国产精品视频在线观看 | 国产精品午夜电影 | 久久久久久色 | 国产激情91久久精品导航 | 亚洲精品18 | 精品亚洲一区二区三区四区五区 | 亚洲女人天堂网 | 99热播放 |