找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6896|回复: 7
打印 上一主题 下一主题
收起左侧

STM32硬件SPI驱动ST7735R TFTLCD Proteus仿真实现

  [复制链接]
跳转到指定楼层
楼主
       最近经理通知要做项目了,让我选型一个LCD开始试着做下。这是我用仿真实现的一个smt32的硬件SPI1来驱动的ST7735R,难度挺小的,因为大部分的代码LCD的厂商已经给我们提供了,我们主要修改成硬件SPI来驱动就好了。
        此次仿真上面有2个问题,不知道是代码的问题还是仿真图上的问题。第一个问题是仿真运行时有时会出通信数据传输问题,导致指令越界报警,这个可能是SPI不稳定导致的;第二个问题是在改用SPI2或者SPI3来驱动没有任何反应,猜测是代码时钟没开对或者仿真图上面还要加上具体晶振。
        代码工程和仿真工程都已压缩打包,可放心下载。。。

先贴上仿真实现图:
   

再贴上部分代码:


/**ST7735驱动**/
#include "ST7735.h"
#include "usart.h"
u16 BACK_COLOR, POINT_COLOR;   //背景色,画笔色  

void WriteCommand_7735(u8 CmdData)  //写指令
{
SPI_LCD_CS_LOW; //片选
SPI_LCD_COMMAND_W;//写指令
SPI_I2S_SendData(LCD_SPIx,CmdData);
while (SPI_I2S_GetFlagStatus(LCD_SPIx, SPI_I2S_FLAG_TXE) == RESET){}
SPI_LCD_CS_HIGH;
}

void WriteDate_7735(u8 Data)  //写8位数据
{
SPI_LCD_CS_LOW; //片选
SPI_LCD_DATA_W;//写数据
SPI_I2S_SendData(LCD_SPIx,Data);
while(SPI_I2S_GetFlagStatus(LCD_SPIx, SPI_I2S_FLAG_TXE) == RESET){}
  SPI_LCD_CS_HIGH;
}

void WriteDate16(int data) //写16位数据
{
WriteDate_7735(data>>8);
WriteDate_7735(data);
}

void LCD_Init(void)
{
        
        LCD_RES_HIGH;
  delay_ms(5);        
        LCD_RES_LOW;
        delay_ms(5);
        LCD_RES_HIGH;
        SPI_LCD_CS_HIGH;
        delay_ms(5);
        SPI_LCD_CS_LOW;  //打开片选使能

                WriteCommand_7735(0x11); //Sleep out
        delay_ms(120); //Delay 120ms
        //------------------------------------ST7735S Frame Rate-----------------------------------------//
        WriteCommand_7735(0xB1);
        WriteDate_7735(0x05);


WriteCommand_7735(0x11);//Sleep exit
delay_ms (120);
//ST7735R Frame Rate
WriteCommand_7735(0xB1);
WriteDate_7735(0x01);

WriteDate_7735(0x2C); WriteDate_7735(0x2D);
WriteCommand_7735(0xB2);
WriteDate_7735(0x01); WriteDate_7735(0x2C); WriteDate_7735(0x2D);
WriteCommand_7735(0xB3);
WriteDate_7735(0x01); WriteDate_7735(0x2C); WriteDate_7735(0x2D);
WriteDate_7735(0x01); WriteDate_7735(0x2C); WriteDate_7735(0x2D);

WriteCommand_7735(0xB4); //Column inversion
WriteDate_7735(0x07);
//ST7735R Power Sequence
WriteCommand_7735(0xC0);
WriteDate_7735(0xA2); WriteDate_7735(0x02); WriteDate_7735(0x84);
WriteCommand_7735(0xC1); WriteDate_7735(0xC5);
WriteCommand_7735(0xC2);
WriteDate_7735(0x0A); WriteDate_7735(0x00);
WriteCommand_7735(0xC3);
WriteDate_7735(0x8A); WriteDate_7735(0x2A);
WriteCommand_7735(0xC4);
WriteDate_7735(0x8A); WriteDate_7735(0xEE);
WriteCommand_7735(0xC5); //VCOM
WriteDate_7735(0x0E);
WriteCommand_7735(0x36); //MX, MY, RGB mode
WriteDate_7735(0xC8);

//ST7735R Gamma Sequence
WriteCommand_7735(0xe0);
WriteDate_7735(0x0f); WriteDate_7735(0x1a);
WriteDate_7735(0x0f); WriteDate_7735(0x18);
WriteDate_7735(0x2f); WriteDate_7735(0x28);
WriteDate_7735(0x20); WriteDate_7735(0x22);
WriteDate_7735(0x1f); WriteDate_7735(0x1b);
WriteDate_7735(0x23); WriteDate_7735(0x37); WriteDate_7735(0x00);

WriteDate_7735(0x07);
WriteDate_7735(0x02); WriteDate_7735(0x10);
WriteCommand_7735(0xe1);
WriteDate_7735(0x0f); WriteDate_7735(0x1b);
WriteDate_7735(0x0f); WriteDate_7735(0x17);
WriteDate_7735(0x33); WriteDate_7735(0x2c);
WriteDate_7735(0x29); WriteDate_7735(0x2e);
WriteDate_7735(0x30); WriteDate_7735(0x30);
WriteDate_7735(0x39); WriteDate_7735(0x3f);
WriteDate_7735(0x00); WriteDate_7735(0x07);
WriteDate_7735(0x03); WriteDate_7735(0x10);  

WriteCommand_7735(0x2a);
WriteDate_7735(0x00);WriteDate_7735(0x00);
WriteDate_7735(0x00);WriteDate_7735(0x7f);
WriteCommand_7735(0x2b);
WriteDate_7735(0x00);WriteDate_7735(0x00);
WriteDate_7735(0x00);WriteDate_7735(0x7f);

/*下面这2个指令对ST7735R好像不起作用,仿真会报警告,应该是没有这2条指令*/
//WriteCommand_7735(0xF0); //Enable test command  
//WriteDate_7735(0x01);
//WriteCommand_7735(0xF6); //Disable ram power save mode
//WriteDate_7735(0x00);
WriteCommand_7735(0x3A); //65k mode
WriteDate_7735(0x05);
WriteCommand_7735(0x29); //Display on
WriteCommand_7735(0x2C);
}                                    

   代码就贴这么多吧,具体的下载来看吧,网上基于这款LCD的项目挺少的。特别注意点是设置SPI的CS脚,费了我一天时间在那测试,一直没找到错误点,当时都快哭了,终于还是做出来了,希望以后的同学仿真少走弯路吧。CS脚(片选)一定要设定成复用推挽输出,并且不要设置到SPI的NSS脚上,即PA4,接上反正是运行不起来。。。

STM32驱动TFTLCD仿真实验.7z

234.12 KB, 下载次数: 368, 下载积分: 黑币 -5

STM32硬件SPI驱动ST7735

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏7 分享淘帖 顶2 踩
回复

使用道具 举报

沙发
ID:337139 发表于 2020-9-24 15:30 | 只看该作者
这个是液晶片吗?还是模块来的?
回复

使用道具 举报

板凳
ID:576497 发表于 2020-9-27 14:26 | 只看该作者
长风007 发表于 2020-9-24 15:30
这个是液晶片吗?还是模块来的?

没理解你的意思,这个彩色的液晶
回复

使用道具 举报

地板
ID:307544 发表于 2020-9-27 20:35 | 只看该作者
这个驱动ST7735不错,可以用的
回复

使用道具 举报

5#
ID:853963 发表于 2020-12-3 19:27 | 只看该作者
能帮助指导一下吗大佬
回复

使用道具 举报

6#
ID:46087 发表于 2024-3-12 10:23 | 只看该作者
why 爲何沒有51+ST7735R的proteus呀?
回复

使用道具 举报

7#
ID:1116647 发表于 2024-4-15 12:08 | 只看该作者
为什么我无法再现你的结果呀,我直接下你的压缩包了的
回复

使用道具 举报

8#
ID:262 发表于 2024-4-15 20:02 | 只看该作者
lsb_lunch 发表于 2024-4-15 12:08
为什么我无法再现你的结果呀,我直接下你的压缩包了的

我用的Proteus8.13版本可以,,你是不是没有重新选择你的hex文件所在路径?

51hei.png (28.95 KB, 下载次数: 9)

51hei.png
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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