打印
[PIC®/AVR®/dsPIC®产品]

【Curiosity Nano测评报告】+ PIC16F13145的硬件SPI驱动液晶屏与注意事项

[复制链接]
381|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 gaoyang9992006 于 2024-9-11 19:58 编辑

本次实验使用的是液晶屏型号为ST7735S,分辨率为160*80的IPS屏幕,色彩顺序为BGR。
1、创建工程,创建MCC工程,并添加ST7735库文件。
2、配置IO,添加SPI Host模块,添加delay支持。
为方便插拔屏幕模块我们选取这一组接口

配置如下图所示

实物图如下所示,方便直接将排针插在板子上。


3、接下来配置SPI



4、将IO的操作映射到ST7735库函数
void ST7735_SPI_RST_SetLow(void)
{
    RST_SetLow();
}
void ST7735_SPI_RST_SetHigh(void)
{
    RST_SetHigh();
}

void ST7735_SPI_CS_SetLow(void)
{
    CS_SetLow();
}
void ST7735_SPI_CS_SetHigh(void)
{
    CS_SetHigh();
}

void ST7735_SPI_DC_SetLow(void)
{
    DC_SetLow();
}
void ST7735_SPI_DC_SetHigh(void)
{
    DC_SetHigh();
}
5、重要的SPI数据发送函数实现
MCC生成的SPI库函数中有
    while (!PIR5bits.SSP1IF)
    {
        // Wait for flag to get set
    }
    PIR5bits.SSP1IF = 0;
只需要将该函数映射到ST7735的字节发送函数即可。
void ST7735_SPI_SendByte(uint8_t byte)
{
    SPI1_ByteWrite(byte);
}
6、编写测试函数
#include "mcc_generated_files/system/system.h"
#include"ST7735S/st7735.h"
/*
    Main application
*/

int main(void)
{
    SYSTEM_Initialize();
    // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
    // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
    // Use the following macros to:

    // Enable the Global Interrupts
    //INTERRUPT_GlobalInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Enable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptEnable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();
    SPI1_Open(HOST_CONFIG);
    ST7735_Init();
        ST7735_FillScreen(ST7735_BLACK);
        ST7735_DrawRectangle(0,24,160,80,ST7735_YELLOW);
        ST7735_DrawRectangle(20,20+24,120,20,ST7735_BLUE);        
        ST7735_DrawRectangle(40,30+24,80,20,ST7735_RED);        
    while(1)
    {
        LED0_SetLow();
        DELAY_milliseconds(500);
        LED0_SetHigh();
        DELAY_milliseconds(500);
        ST7735_Init();
        ST7735_FillScreen(ST7735_BLACK);
        ST7735_DrawRectangle(0,0+24,10,5,ST7735_YELLOW);
        ST7735_DrawRectangle(15,5+24,10,20,ST7735_BLUE);        
        ST7735_DrawRectangle(30,25+24,10,10,ST7735_RED);
    }   
}


最后看运行效果

使用特权

评论回复
沙发
cc1989summer| | 2024-9-11 20:26 | 只看该作者
厉害

使用特权

评论回复
板凳
gaoyang9992006|  楼主 | 2024-9-11 21:46 | 只看该作者
如果要实现字符,不建议放字库进来,否则空间不够,无法编译通过。经过测试,精简后字库,然后启动最高优化级别,勉强可用。

使用特权

评论回复
地板
heisexingqisi| | 2024-9-12 15:14 | 只看该作者
看起来效果不错。

使用特权

评论回复
5
呐咯密密| | 2024-9-12 16:43 | 只看该作者
ST7735库文件在工具里面可以直接导入吗

使用特权

评论回复
6
gaoyang9992006|  楼主 | 2024-9-12 17:04 | 只看该作者
呐咯密密 发表于 2024-9-12 16:43
ST7735库文件在工具里面可以直接导入吗

复制到这个工程文件夹里就行了。然后手动添加。不太建议这个芯片用这个功能驱动液晶屏,发现,这个芯片内存很小,存不下足够的字库。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:西安公路研究院南京院
简介:主要工作从事监控网络与通信网络设计,以及从事基于嵌入式的通信与控制设备研发。擅长单片机嵌入式系统物联网设备开发,音频功放电路开发。

1938

主题

15839

帖子

204

粉丝