找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

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

ST7571 JLX128*128液晶屏的STM32驅(qū)動(dòng)程序 寄存器版和庫(kù)函數(shù)版

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:241423 發(fā)表于 2018-11-24 13:08 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
分享下JLX高性價(jià)比的液晶的驅(qū)動(dòng)程序,這款是模擬IIC驅(qū)動(dòng)的,操作很方便

單片機(jī)源程序如下:
  1. /*         液晶模塊型號(hào):JLX128128G-610-PN-IIC
  2.                 I2C接口
  3.            驅(qū)動(dòng)IC是:ST7571
  4.                 //單片機(jī):STM32F103RBT6
  5. */
  6. #include <stm32f10x_lib.h>
  7. #include <sys.h>
  8. #include <delay.h>
  9. #include <JLX128128G_610_PN_IIC.h>
  10. #include <chinese_code.h>
  11. #include <image.h>

  12. #define uchar unsigned char
  13. #define uint unsigned int
  14. #define ulong unsigned long

  15. //等待按鍵,3個(gè)按鍵,有任何一個(gè)按鍵按下都可以進(jìn)入下一步
  16. void waitkey(void)
  17. {
  18.         repeat:
  19.                 if(key2==1&&key3==1&&key4==1)        goto repeat;
  20.                 else                delay_ms(600);
  21. }

  22. void transfer(int data1)
  23. {
  24.         int i;
  25.         for(i=0;i<8;i++)
  26.    {
  27.                 LCD_SCL=0;
  28.                 if(data1&0x80) LCD_SDA=1;
  29.                 else LCD_SDA=0;
  30.                 LCD_SCL=1;
  31.                  LCD_SCL=0;
  32.                  data1=data1<<1;
  33.    }
  34.                 LCD_SDA=0;
  35.                 LCD_SCL=1;
  36.                 LCD_SCL=0;
  37. }

  38. void start_flag()
  39. {
  40.         LCD_SCL=1;                /*START FLAG*/
  41.         LCD_SDA=1;                /*START FLAG*/
  42.         LCD_SDA=0;                /*START FLAG*/
  43. }


  44. void stop_flag()
  45. {
  46.         LCD_SCL=1;                /*STOP FLAG*/
  47.         LCD_SDA=0;                /*STOP FLAG*/               
  48.         LCD_SDA=1;                /*STOP FLAG*/
  49. }

  50. //寫命令到液晶顯示模塊
  51. void transfer_command(uchar com)   
  52. {
  53.         start_flag();
  54.         transfer(0x78);
  55.         transfer(0x80);
  56.         transfer(com);
  57.         stop_flag();
  58. }

  59. //寫數(shù)據(jù)到液晶顯示模塊
  60. void transfer_data(uchar dat)
  61. {
  62.         start_flag();
  63.         transfer(0x78);
  64.         transfer(0xC0);
  65.         transfer(dat);
  66.         stop_flag();
  67. }

  68. void initial_lcd()
  69. {
  70.   LCD_RST=0;
  71.         delay_ms(1);
  72.         LCD_RST=1;
  73.         delay_ms(10);        
  74.         transfer_command(0x2c);
  75.         delay_ms(200);
  76.         transfer_command(0x2e);
  77.         delay_ms(200);
  78.         transfer_command(0x2f);
  79.         delay_ms(10);
  80.         
  81.         transfer_command(0xae);                //顯示關(guān)
  82.         transfer_command(0x38);                //模式設(shè)置
  83.         transfer_command(0xb8);                //85HZ
  84.         transfer_command(0xc8);                //行掃描順序        
  85.         transfer_command(0xa0);                //列掃描順序
  86.         
  87.         transfer_command(0x44);                //Set initial COM0 register
  88.         transfer_command(0x00);
  89.         transfer_command(0x40);                //Set initial display line register
  90.         transfer_command(0x00);

  91.         transfer_command(0xab);
  92.         transfer_command(0x67);
  93.         transfer_command(0x27);                //粗調(diào)對(duì)比度,可設(shè)置范圍0x20~0x27
  94.         transfer_command(0x81);                //微調(diào)對(duì)比度
  95.         transfer_command(0x28);                //微調(diào)對(duì)比度的值,可設(shè)置范圍0x00~0x3f

  96.         transfer_command(0x56);                //0x56 1/11 bias
  97.         transfer_command(0xf3);
  98.         transfer_command(0x04);
  99.         transfer_command(0x93);
  100.         
  101.         transfer_command(0xaf);                //顯示開(kāi)
  102. }


  103. void lcd_address(uchar page,uchar column)
  104. {
  105.         column=column;
  106.         page=page-1;
  107.         transfer_command(0xb0+page);
  108.         transfer_command(((column>>4)&0x0f)+0x10);
  109.         transfer_command(column&0x0f);
  110. }

  111. void clear_screen()
  112. {        
  113.         uchar i,j;
  114.         for(j=0;j<16;j++)
  115.         {
  116.                 lcd_address(j+1,0);
  117.                 for(i=0;i<128;i++)
  118.                 {
  119.                         transfer_data(0x00);               
  120.                         transfer_data(0x00);
  121.                 }
  122.         }
  123. }


  124. //顯示8x16的點(diǎn)陣的字符串,括號(hào)里的參數(shù)分別為(頁(yè),列,字符串指針)
  125. void display_string_8x16(u8 page,u8 column,u8*text)
  126. {
  127.         u8 i=0,j,k,n;

  128.         while(text[i]>0x00)
  129.         {
  130.                 if((text[i]>=0x20)&&(text[i]<=0x7e))
  131.                 {
  132.                         j=text[i]-0x20;
  133.                         for(n=0;n<2;n++)
  134.                         {
  135.                                 lcd_address(page+n,column);
  136.                                 for(k=0;k<8;k++)
  137.                                 {
  138.                                         transfer_data(ascii_table_8x16[j][k+8*n]);
  139.                                         transfer_data(ascii_table_8x16[j][k+8*n]);
  140.                                 }
  141.                         }
  142.                         i++;
  143.                         column+=8;
  144.                 }
  145.                 else
  146.                 i++;
  147.                
  148.                 if(column>127)
  149.                 {
  150.                         column=0;
  151.                         page+=2;
  152.                  }        
  153.         }        
  154. }

  155. //寫入一組16x16點(diǎn)陣的漢字字符串(字符串表格中需含有此字)
  156. //括號(hào)里的參數(shù):(頁(yè),列,漢字字符串)
  157. void display_string_16x16(u8 page,u8 column,u8 *text)
  158. {
  159.         u8 i,j,k;
  160.         u16 address;
  161.         j = 0;
  162.         while(text[j] != '\0')
  163.         {
  164.                 i=0;
  165.                 address=1;
  166.                 while(Chinese_text_16x16[i]> 0x7e )
  167.                 {
  168.                         if(Chinese_text_16x16[i] == text[j])
  169.                         {
  170.                                 if(Chinese_text_16x16[i+1] == text[j+1])
  171.                                 {
  172.                                         address = i*16;
  173.                                         break;
  174.                                 }
  175.                         }
  176.                         i +=2;
  177.                 }
  178.                 if(column>127)
  179.                 {
  180.                         column =0;
  181.                         page +=2;
  182.                 }
  183.                 if(address !=1)
  184.                 {
  185.                         for(k=0;k<2;k++)
  186.                         {
  187.                                 lcd_address(page+k,column);
  188.                                 for(i=0;i<16;i++)
  189.                                 {
  190.                                         transfer_data(Chinese_code_16x16[address]);
  191.                                         transfer_data(Chinese_code_16x16[address]);
  192.                                         address++;                                
  193.                                 }
  194.                         }
  195.                         j +=2;
  196.                 }
  197.                 else
  198.                 {
  199.                         for(k=0;k<2;k++)
  200.                         {
  201.                                 lcd_address(page+k,column);
  202.                                 for(i=0;i<16;i++)
  203.                                 {
  204.                                         transfer_data(0x00);
  205.                                         transfer_data(0x00);                                
  206.                                 }
  207.                         }
  208.                         j++;
  209.                 }
  210.                 column +=16;
  211.         }
  212. }

  213. //顯示16x16點(diǎn)陣的漢字或者ASCII碼8x16點(diǎn)陣的字符混合字符串
  214. //括號(hào)里的參數(shù):(頁(yè),列,字符串)
  215. void display_string_8x16_16x16(u8 page,u8 column,u8 *text)
  216. {
  217.         u8 temp[3];
  218.         u16 i=0;
  219.         while(text[i] !='\0')
  220.         {
  221.                 if(text[i]>0x7e)
  222.                 {
  223.                         temp[0]=text[i];
  224.                         temp[1]=text[i+1];
  225.                         temp[2]='\0';                                                                                                                //漢字為兩個(gè)字節(jié)
  226.                         display_string_16x16(page,column,temp); //顯示漢字
  227.                         column +=16;
  228.                         i +=2;
  229.                         if(column>127)
  230.                         {
  231.                                 column =0;
  232.                                 page +=2;
  233.                         }
  234.                 }
  235.                 else
  236.                 {
  237.                         temp[0]=text[i];
  238.                         temp[1]='\0';                                                                                                                //字母占一個(gè)字節(jié)
  239.                         display_string_8x16(page,column,temp);  //顯示字母
  240.                         column +=8;
  241.                         i++;
  242.                         if(column>127)
  243.                         {
  244.                                 column =0;
  245.                                 page +=2;
  246.                         }
  247.                 }
  248.         }
  249. }

  250. void display_32x32(u8 page,u8 column,u8 *dp)
  251. {
  252.         u8 i,j;
  253.         for(j=0;j<4;j++)
  254.         {
  255.                 lcd_address(page+j,column);
  256.                 for(i=0;i<32;i++)
  257.                 {
  258.                         transfer_data(*dp);
  259.                         transfer_data(*dp);
  260.                         dp++;
  261.                 }
  262.         }        
  263. }

  264. void display_graphic(u8 *dp)
  265. {
  266.         u8 i,j;
  267.         for(j=0;j<16;j++)
  268.         {
  269.                 lcd_address(j+1,0);
  270.                 for(i=0;i<128;i++)
  271.                 {
  272.                         transfer_data(*dp);
  273.                         transfer_data(*dp);
  274.                         dp++;        
  275.                 }
  276.         }
  277. }

  278. //==========主程序==========================================
  279. int main(void)
  280. {                                                                                                                                                
  281.         Stm32_Clock_Init(9);         //8MHZ*9倍頻=72MHz
  282.         delay_init(72);                           //72MHz
  283.         MCU_Port_initial();
  284.         initial_lcd();
  285.         while(1)
  286.         {
  287.                 clear_screen();
  288.                 display_graphic(bmp2);
  289.                 waitkey();
  290.                 clear_screen();
  291.                 display_32x32(1,16,jing32);
  292.                 display_32x32(1,48,lian32);
  293.                 display_32x32(1,80,xun32);
  294.                 display_string_16x16(5,1,"深圳市晶聯(lián)訊電子有限公司是集研發(fā)、生產(chǎn)、銷售于一體的從事液晶顯示屏及液晶顯示模塊的高科技公司。");
  295.                 waitkey();
  296.                 clear_screen();
  297.                 display_string_8x16(1,1,"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-,-./:;<=>?@[\]^_^{|}~0123456789ABCDFGHIJKLMNOPQRSTUVWXYZ");
  298.                 waitkey();
  299.                 clear_screen();
  300.                 display_string_8x16_16x16(1,1,"深圳市晶聯(lián)訊電子 JLX128128G-610   128x128點(diǎn)陣   視區(qū):59.4x59.4mm帶16x16點(diǎn)陣中文 字庫(kù),或8x16或5x7點(diǎn)陣ASCII碼,四灰度級(jí)顯示功能。");
  301.                 waitkey();               
  302.         }
  303. }
復(fù)制代碼

所有資料51hei提供下載:
128128改庫(kù)函數(shù)版本.rar (304.32 KB, 下載次數(shù): 168)
JLX128128G-610-PN-IIC-STM32.7z (148.29 KB, 下載次數(shù): 116)


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏5 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:148204 發(fā)表于 2020-1-12 13:24 | 只看該作者
下載試一下能不能點(diǎn)亮
回復(fù)

使用道具 舉報(bào)

板凳
ID:589512 發(fā)表于 2020-2-20 15:56 | 只看該作者
下來(lái)看看能不能驅(qū)起來(lái)
回復(fù)

使用道具 舉報(bào)

地板
ID:345352 發(fā)表于 2020-3-2 18:45 | 只看該作者
你好,我想問(wèn)一下,顯示內(nèi)容的灰度是怎么設(shè)置的,初始已經(jīng)設(shè)置成Gray-Scale mode了,說(shuō)明書好像只說(shuō)了灰度模式需要2個(gè)字節(jié)每8個(gè)像素,黑白模式只需1個(gè)字節(jié)
回復(fù)

使用道具 舉報(bào)

5#
ID:844879 發(fā)表于 2020-11-17 15:18 | 只看該作者
正需要,下載參考下資源文件
回復(fù)

使用道具 舉報(bào)

6#
ID:71233 發(fā)表于 2024-5-18 08:40 | 只看該作者
顯示屏的對(duì)比度一般,灰度實(shí)在沒(méi)有多大意義。
回復(fù)

使用道具 舉報(bào)

7#
ID:166310 發(fā)表于 2024-7-26 10:51 | 只看該作者
謝謝樓主提供這么好的資料。
回復(fù)

使用道具 舉報(bào)

8#
ID:45026 發(fā)表于 2025-3-19 09:37 | 只看該作者
學(xué)習(xí)了,正是需要的資料,很不錯(cuò),感謝分享,下載了!。。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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