找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3219|回复: 0
收起左侧

TFT144液晶屏单片机源程序(驱动程序)

[复制链接]
ID:553399 发表于 2020-4-29 22:13 | 显示全部楼层 |阅读模式
TFT144液晶屏源程序(驱动程序)

单片机源程序如下:
  1. //********************************************************************************
  2. #include "STC15.H"
  3. #include <intrins.h>


  4. #define uchar unsigned char
  5. #define uint unsigned int

  6. #include "delay.h"

  7. #include "tft128128spi.h"



  8. //---------------------------液晶屏接线说明-------------------------------------//
  9. //接线前请参考液晶屏说明书第10页引脚定义
  10. sbit scl       =P2^7;//接模块CLK引脚,接裸屏Pin9_SCL
  11. sbit sda       =P2^6;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA
  12. sbit reset     =P2^5;//接模块dcT引脚,接裸屏Pin6_RES
  13. sbit dc        =P2^4;//接模块D/C引脚,接裸屏Pin7_A0
  14. sbit cs        =P2^3;//接模块CE引脚,接裸屏Pin12_CS
  15. sbit bl        =P2^2;//接模块BL引脚,背光可以采用IO控制或者PWM控制,也可以直接接到高电平常亮
  16. //---------------------------End of液晶屏接线---------------------------------//



  17. bit USE_LANDSCAPE;//程序横竖屏切换


  18. //向液晶屏写一个8位指令
  19. void  LCD_WrCmd(uchar cmd)
  20. {
  21. uchar i;
  22. cs=0;dc=0;
  23. for(i=0;i<8;i++)
  24. {
  25.   scl=0;
  26.   if(cmd&0x80)sda=1;else sda=0;
  27.   scl=1;
  28.   cmd<<=1;
  29. }       
  30. cs=1;
  31. }

  32. //向液晶屏写一个8位数据
  33. void  LCD_WrDat(uchar dat)
  34. {
  35. uchar i;
  36. cs=0;dc=1;
  37. for(i=0;i<8;i++)
  38. {
  39.   scl=0;
  40.   if(dat&0x80)sda=1;else sda=0;
  41.   scl=1;
  42.   dat<<=1;
  43. }       
  44. cs=1;
  45. }
  46. //向液晶屏写一个16位数据
  47. void  LCD_WrDat_16Bit(uint dat)
  48. {
  49. LCD_WrDat(dat>>8);                         //写入高8位数据
  50. LCD_WrDat(dat);                         //写入低8位数据

  51. }

  52. void Reset()
  53. {
  54.     reset=0;
  55.     delayms(100);
  56.     reset=1;
  57.     delayms(100);
  58. }
  59. //////////////////////////////////////////////////////////////////////////////////////////////
  60. //液晶屏初始化 for S6D02A1
  61. void lcd_initial()
  62. {        Reset();//Reset before LCD Init.
  63.                
  64.         //LCD Init For 1.44Inch LCD Panel with ST7735R.
  65.         LCD_WrCmd(0x11);//Sleep exit
  66.         delayms (120);
  67.                
  68.         //ST7735R Frame Rate
  69.         LCD_WrCmd(0xB1);
  70.         LCD_WrDat(0x01);
  71.         LCD_WrDat(0x2C);
  72.         LCD_WrDat(0x2D);

  73.         LCD_WrCmd(0xB2);
  74.         LCD_WrDat(0x01);
  75.         LCD_WrDat(0x2C);
  76.         LCD_WrDat(0x2D);

  77.         LCD_WrCmd(0xB3);
  78.         LCD_WrDat(0x01);
  79.         LCD_WrDat(0x2C);
  80.         LCD_WrDat(0x2D);
  81.         LCD_WrDat(0x01);
  82.         LCD_WrDat(0x2C);
  83.         LCD_WrDat(0x2D);
  84.        
  85.         LCD_WrCmd(0xB4); //Column invedcion
  86.         LCD_WrDat(0x07);
  87.        
  88.         //ST7735R Power Sequence
  89.         LCD_WrCmd(0xC0);
  90.         LCD_WrDat(0xA2);
  91.         LCD_WrDat(0x02);
  92.         LCD_WrDat(0x84);
  93.         LCD_WrCmd(0xC1);
  94.         LCD_WrDat(0xC5);

  95.         LCD_WrCmd(0xC2);
  96.         LCD_WrDat(0x0A);
  97.         LCD_WrDat(0x00);

  98.         LCD_WrCmd(0xC3);
  99.         LCD_WrDat(0x8A);
  100.         LCD_WrDat(0x2A);
  101.         LCD_WrCmd(0xC4);
  102.         LCD_WrDat(0x8A);
  103.         LCD_WrDat(0xEE);
  104.        
  105.         LCD_WrCmd(0xC5); //VCOM
  106.         LCD_WrDat(0x0E);
  107.        
  108.         LCD_WrCmd(0x36); //MX, MY, RGB mode
  109. if(USE_LANDSCAPE)
  110.         LCD_WrDat(0xA8); //竖屏C8 横屏08 A8
  111. else
  112.         LCD_WrDat(0xC8); //竖屏C8 横屏08 A8
  113.        
  114.         //ST7735R Gamma Sequence
  115.         LCD_WrCmd(0xe0);
  116.         LCD_WrDat(0x0f);
  117.         LCD_WrDat(0x1a);
  118.         LCD_WrDat(0x0f);
  119.         LCD_WrDat(0x18);
  120.         LCD_WrDat(0x2f);
  121.         LCD_WrDat(0x28);
  122.         LCD_WrDat(0x20);
  123.         LCD_WrDat(0x22);
  124.         LCD_WrDat(0x1f);
  125.         LCD_WrDat(0x1b);
  126.         LCD_WrDat(0x23);
  127.         LCD_WrDat(0x37);
  128.         LCD_WrDat(0x00);        
  129.         LCD_WrDat(0x07);
  130.         LCD_WrDat(0x02);
  131.         LCD_WrDat(0x10);

  132.         LCD_WrCmd(0xe1);
  133.         LCD_WrDat(0x0f);
  134.         LCD_WrDat(0x1b);
  135.         LCD_WrDat(0x0f);
  136.         LCD_WrDat(0x17);
  137.         LCD_WrDat(0x33);
  138.         LCD_WrDat(0x2c);
  139.         LCD_WrDat(0x29);
  140.         LCD_WrDat(0x2e);
  141.         LCD_WrDat(0x30);
  142.         LCD_WrDat(0x30);
  143.         LCD_WrDat(0x39);
  144.         LCD_WrDat(0x3f);
  145.         LCD_WrDat(0x00);
  146.         LCD_WrDat(0x07);
  147.         LCD_WrDat(0x03);
  148.         LCD_WrDat(0x10);  
  149.        
  150.         LCD_WrCmd(0x2a);
  151.         LCD_WrDat(0x00);
  152.         LCD_WrDat(0x00+2);
  153.         LCD_WrDat(0x00);
  154.         LCD_WrDat(0x80+2);

  155.         LCD_WrCmd(0x2b);
  156.         LCD_WrDat(0x00);
  157.         LCD_WrDat(0x00+3);
  158.         LCD_WrDat(0x00);
  159.         LCD_WrDat(0x80+3);
  160.        
  161.         LCD_WrCmd(0xF0); //Enable test command  
  162.         LCD_WrDat(0x01);
  163.         LCD_WrCmd(0xF6); //Disable ram power save mode
  164.         LCD_WrDat(0x00);
  165.        
  166.         LCD_WrCmd(0x3A); //65k mode
  167.         LCD_WrDat(0x05);
  168.        
  169.        
  170.         LCD_WrCmd(0x29);//Display on


  171.         bl=1;                         //背光

  172. }



  173. /*************************************************
  174. 函数名:LCD_Set_Region
  175. 功能:设置lcd显示区域,在此区域写点数据自动换行
  176. 入口参数:xy起点和终点
  177. 返回值:无
  178. *************************************************/
  179. void Lcd_SetRegion(uint x_start,uint y_start,uint x_end,uint y_end)reentrant
  180. {       
  181. if(USE_LANDSCAPE)//使用横屏模式
  182.    {
  183.     LCD_WrCmd(0x2a);
  184.         LCD_WrDat(0x00);
  185.         LCD_WrDat(x_start+3);
  186.         LCD_WrDat(0x00);
  187.         LCD_WrDat(x_end+3);

  188.         LCD_WrCmd(0x2b);
  189.         LCD_WrDat(0x00);
  190.         LCD_WrDat(y_start+2);
  191.         LCD_WrDat(0x00);
  192.         LCD_WrDat(y_end+2);
  193.    }
  194. else//竖屏模式       
  195.   {
  196.         LCD_WrCmd(0x2a);
  197.         LCD_WrDat(0x00);
  198.         LCD_WrDat(x_start+2);
  199.         LCD_WrDat(0x00);
  200.         LCD_WrDat(x_end+2);

  201.         LCD_WrCmd(0x2b);
  202.         LCD_WrDat(0x00);
  203.         LCD_WrDat(y_start+3);
  204.         LCD_WrDat(0x00);
  205.         LCD_WrDat(y_end+3);       
  206.   }
  207.         LCD_WrCmd(0x2c);
  208. }




  209. void LCD_Clear(int color)
  210. {
  211.         uchar i,j;
  212.         Lcd_SetRegion(0,0,128-1,128-1);
  213.         for (i=0;i<128;i++)
  214.             for (j=0;j<128;j++)
  215.                 LCD_WrDat_16Bit(color);
  216. }



  217. void LCD_A_Char8X16(uint x, uint y, uint fc, uint bc, uchar *s)reentrant
  218. {
  219. uchar i,j,temp;
  220. Lcd_SetRegion(x,y,x+8-1,y+16-1);
  221. for(i=0;i<16;i++)
  222.         {
  223.          temp=s[i];
  224.          for(j=0;j<8;j++)
  225.            {
  226.             if(temp&0x80)LCD_WrDat_16Bit(fc);
  227.                 else if        (fc!=bc) LCD_WrDat_16Bit(bc);
  228.             temp<<=1;
  229.            }  
  230.         }

  231. }

  232. void LCD_Char8X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)reentrant
  233. {
  234. uchar i;
  235. for(i=0;i<c;i++) LCD_A_Char8X16(x+i*8,y,fc,bc,s+i*16);
  236. }



  237. void LCD_CHN16X16(uint x, uint y, uint fc, uint bc, uchar *s)reentrant //显示一个汉字
  238. {
  239. uchar i,j,temp;
  240. Lcd_SetRegion(x,y,x+16-1,y+16-1);
  241. for(i=0;i<32;i++)
  242.         {
  243.          temp=s[i];
  244.          for(j=0;j<8;j++)
  245.            {
  246.             if(temp&0x80)LCD_WrDat_16Bit(fc);
  247.                 else if        (fc!=bc) LCD_WrDat_16Bit(bc);
  248.             temp<<=1;
  249.            }  
  250.         }
  251. }

  252. void LCD_CHN16X16_String(uint x,uint y,uint fc,uint bc,uchar *s,uchar c)
  253. {
  254. uchar i;
  255. for(i=0;i<c;i++)LCD_CHN16X16(x+i*16,y,fc,bc,s+i*32);
  256. }

  257. //void LCD_A_Char16X32(uint x, uint y, uint fc, uint bc, uchar *s)
  258. //{
  259. // uchar i,j,temp;
  260. // Lcd_SetRegion(x,y,x+16-1,y+32-1);
  261. // for(i=0;i<64;i++)                                                  //16*32西文字符点阵64个8位字节
  262. //        {
  263. //         temp=s[i];
  264. //         for(j=0;j<8;j++)
  265. //           {
  266. //            if(temp&0x80)LCD_WrDat_16Bit(fc);
  267. //                else if        (fc!=bc) LCD_WrDat_16Bit(bc);
  268. //            temp<<=1;
  269. //           }  
  270. //        }
  271. //
  272. //}


  273. /*
  274. void LCD_A_Char24X48(uint x, uint y, uint fc, uint bc, uchar *s)
  275. {
  276. uchar i,j,temp;
  277. Lcd_SetRegion(x,y,x+24-1,y+48-1);
  278. for(i=0;i<144;i++)                                                  //24*48西文字符点阵144个8位字节
  279. ……………………

  280. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
tft144.png
所有资料51hei提供下载:
TFT144液晶屏.zip (2.56 KB, 下载次数: 26)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表