你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

分享个驱动TFT的程序

[复制链接]
holts1 发布时间:2015-2-3 08:27

程序支持STM,FSL, ST 三家公司的MCU,通用的,只要改下头文件就可以了,方便移值


  1. #include "st7585.h"
  2. #include "asc0508.h"

  3. const unsigned char  hanzi[]=
  4. {
  5. /*--  文字:  S  --*/
  6. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  7. 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8. 0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  9. /*--  文字:  T  --*/
  10. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  11. 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  12. 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  13. /*--  文字:  M  --*/
  14. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  15. 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16. 0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  17. /*--  文字:  8  --*/
  18. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  19. 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  20. 0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  21. /*--  文字:  开  --*/
  22. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  23. 0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,
  24. 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,
  25. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  26. 0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00,
  27. 0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00,
  28. /*--  文字:  板  --*/
  29. /*--  Trebuchet MS12;  此字体下对应的点阵为:宽x高=16x16   --*/
  30. 0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFC,0x24,0xE4,0x24,0x22,0x23,0xE2,0x00,0x00,
  31. 0x04,0x03,0x00,0xFF,0x00,0x83,0x60,0x1F,0x80,0x41,0x26,0x18,0x26,0x41,0x80,0x00,
  32. };


  33. extern volatile unsigned char LCDDly;

  34. //=============================================================
  35. //延时
  36. //=============================================================
  37. void DlyMs(unsigned char nCount)
  38. {
  39.   LCDDly = nCount ;
  40.   while ( LCDDly > 0 );
  41. }

  42. //=============================================================
  43. //传送数据
  44. //=============================================================
  45. void LCD_WriteBus(unsigned char Value)  
  46. {     unsigned char i;      
  47.         LCD_SDA_1;   
  48.         LCD_SCL_0;
  49.     for(i=0;i<8;i++)
  50.     {       LCD_SCL_0;
  51.         if(Value&0x80) LCD_SDA_1; else LCD_SDA_0;
  52.         LCD_SCL_1;           
  53.          Value=Value<<1;            
  54.     }
  55.     LCD_SCL_1;
  56.     LCD_SDA_1;
  57. }

  58. //=============================================================
  59. //写命令
  60. //=============================================================
  61. void LCD_WriteCmd(unsigned char Cmd)     
  62. {   
  63.     LCD_CS_0;
  64.     LCD_RS_0;
  65.     LCD_WriteBus(Cmd);
  66.     LCD_CS_1;
  67. }

  68. //=============================================================
  69. //写数据
  70. //=============================================================
  71. void LCD_WriteDat(unsigned char Dat)     
  72. {
  73.     LCD_CS_0;
  74.     LCD_RS_1;
  75.     LCD_WriteBus(Dat);
  76.     LCD_CS_1;
  77. }

  78. /*******************************************************************************
  79. *函  数: LCD_SetXY(unsigned char x,unsigned char y)                            *
  80. *功  能: 移动显示指针到指定位置                                                *
  81. *参  数: X,Y  座标值                                                           *
  82. *******************************************************************************/
  83. void LCD_SetXY(unsigned char X,unsigned char Y)
  84. {
  85.     LCD_WriteCmd(0x80 | X); // row
  86.     LCD_WriteCmd(0x40 | Y); // column
  87. }

  88. /*******************************************************************************
  89. *函  数: lcd_goto1(unsigned char x)                                            *
  90. *功  能: 移动到第一行的指定位置                                                *
  91. *参  数: 字符在屏上的位置    ( 0 - 16 )                                        *
  92. *******************************************************************************/
  93. void lcd_goto1(unsigned char x){LCD_SetXY(x*6,7);} //第1行x位
  94. void lcd_goto2(unsigned char x){LCD_SetXY(x*6,6);} //第2行x位
  95. void lcd_goto3(unsigned char x){LCD_SetXY(x*6,5);} //第3行x位
  96. void lcd_goto4(unsigned char x){LCD_SetXY(x*6,4);} //第4行x位
  97. void lcd_goto5(unsigned char x){LCD_SetXY(x*6,3);} //第5行x位
  98. void lcd_goto6(unsigned char x){LCD_SetXY(x*6,2);} //第6行x位
  99. void lcd_goto7(unsigned char x){LCD_SetXY(x*6,1);} //第7行x位
  100. void lcd_goto8(unsigned char x){LCD_SetXY(x*6,0);} //第8行x位

  101. /*******************************************************************************
  102. *函  数: lcd_cls(unsigned int Color)                                           *
  103. *功  能: 清屏                                                                  *
  104. *参  数: Color                                                                 *
  105. *******************************************************************************/
  106. void lcd_cls(unsigned int Color)
  107. {
  108.     unsigned char t;
  109.     unsigned char k;
  110.     LCD_SetXY(0,0);
  111.     for(t=0;t<9;t++)
  112.         { for(k=0;k<LCD_W;k++) { LCD_WriteDat(0x00); } }
  113. }

  114. void lcd_putc(unsigned char asc)
  115. {
  116.     unsigned char line;
  117.     for (line=0; line<5; line++)
  118.         LCD_WriteDat(Asc0508[(asc-32)*5+line]);
  119.     LCD_WriteDat(0x00);
  120. }

  121. void lcd_puts(char *s)
  122. { while (*s) { lcd_putc(*s++); } }


  123. void LcdWriteHanzi(unsigned char row,unsigned char page,unsigned char c)
  124. {
  125.     unsigned char i;      

  126.     LCD_SetXY(row*8, page);// 列,页
  127.     for(i=16; i<32;i++) { LCD_WriteDat(hanzi[c*32+i]); }   
  128.     LCD_SetXY(row*8, page+1);// 列,页
  129.     for(i=0; i<16;i++) { LCD_WriteDat(hanzi[c*32+i]);}

  130. }

  131. //=============================================================
  132. //初始化LCD
  133. //=============================================================
  134. void lcd_init(void)
  135. {
  136. //LCD_AdjBacklight(255);
  137. /* Configure the LCD  pins --------------------------------------------*/
  138. //  SET_BUS_OUTPUT();

  139.   gpio_init(LCD_CS, 1, 0);
  140.   gpio_init(LCD_RES, 1, 0);
  141.   gpio_init(LCD_RS, 1, 0);
  142.   gpio_init(LCD_SDA, 1, 0);
  143.   gpio_init(LCD_SCL, 1, 0);

  144.   DlyMs(MS10);
  145.   LCD_CS_0;
  146.   LCD_RES_0;
  147.   DlyMs(MS10);
  148.   LCD_RES_1;
  149.   DlyMs(MS10);
  150.    
  151.   LCD_WriteCmd(0x21);//LCD功能设置:芯片活动,水平寻址,使用扩展指令
  152.   LCD_WriteCmd(0x9C);//设置VOP值,室温下的编程范围为3.00-10.68
  153.   LCD_WriteCmd(0x30);
  154.   DlyMs(MS50);

  155.   LCD_WriteCmd(0x20);//LCD功能设置:芯片活动,水平寻址,使用基本指令
  156.   LCD_WriteCmd(0x0C);//设定显示配置:普通模式
  157. }


  158. void LcdTest(void)
  159. {
  160.     lcd_init();          //初始化LCD模块
  161.     lcd_cls(0x00);         //清屏幕

  162.     LcdWriteHanzi(0,2,0);    //S
  163.     LcdWriteHanzi(1,2,1);    //T
  164.     LcdWriteHanzi(2,2,2);    //M
  165.     LcdWriteHanzi(3,2,3);    //8
  166.     LcdWriteHanzi(4,2,4);    //开
  167.     LcdWriteHanzi(6,2,5);    //发
  168.     LcdWriteHanzi(8,2,6);    //板

  169.     lcd_goto1(0);
  170.     lcd_puts("This is a demo.");

  171.     lcd_goto2(0);
  172.     lcd_puts("1234567890ABCDEFG");

  173.     lcd_goto4(1);
  174.     lcd_puts("1234567890ABCDEFG");
  175. }

复制代码


收藏 评论6 发布时间:2015-2-3 08:27

举报

6个回答
raulgu-332879 回答时间:2015-3-4 11:28:08
屏也不分啊、、这能用吗。应该可以
holts1 回答时间:2015-3-5 13:05:13
屏不是写的很清了
w小菜才 回答时间:2015-3-11 20:02:20
怒赞!!!!
kqh1120 回答时间:2015-3-14 19:23:57
谢谢分享。学习 了 14.gif
wu1169668869 回答时间:2015-3-14 19:59:52
我承认我没有看懂
只知道是串行口= =
叶开-335763 回答时间:2018-5-31 15:52:29
顶一下

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版