21ic问答首页 - MCU驱动TFT彩屏 刷屏数据40ms左右传完 但刷屏用了300ms
MCU驱动TFT彩屏 刷屏数据40ms左右传完 但刷屏用了300ms
Eltrion2022-02-09
MCU使用SPI驱动TFT彩屏 系统时钟33.1776MHz SPI频率FOSC/2 刷屏数据40ms左右传完了 但屏幕实际刷新时间用了300ms以上 40ms是在刷屏程序里拉低引脚再拉高引脚然后用逻辑分析仪测出来的,刷屏时间的300ms是录屏后数帧数数出来的
请问下这个是哪里的问题,是TFT的初始化有问题吗
以下代码
请问下这个是哪里的问题,是TFT的初始化有问题吗
以下代码
- #include<STC8A8K64D4.H>
- #include "TFT.h"
- #include "weather.h"
- sbit BLK = P5^3; //背光控制
- sbit RS = P0^5; //数据命令切换线
- sbit RST = P0^6; //复位线
- sbit CS = P0^7; //片选
- sbit SCLK = P1^5; //SPI时钟线
- sbit MOSI = P1^3; //SPI数据线
- sbit LED = P5^0;
- unsigned int time_i = 0;
- void Timer0Init(void);
- void UartInit(void);
- bit Lcd_Clean = 0;
- bit Lcd_color = 1;
- void main()
- {
- Timer0Init();
- UartInit();
- LED = 1;
- ET0 = 1;
- EA = 1;
- Lcd_Init();
- while(1)
- {
- if(Lcd_Clean)
- {
- Lcd_Clean = 0;
- if(Lcd_color)
- {
- Lcd_clear(0x8080);
- Lcd_color = 0;
- }
- else
- {
- Lcd_clear(0xFFFF);
- Lcd_color = 1;
- }
- }
- }
- }
- void TM0_Isr() interrupt 1
- {
- time_i++;
- if(time_i == 1000)
- {
- time_i = 0;
- Lcd_Clean = 1;
- }
- }
- void Timer0Init(void) //1毫秒@33.1776MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0x66; //设置定时初始值
- TH0 = 0x7E; //设置定时初始值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void UartInit(void) //115200bps@33.1776MHz
- {
- SCON = 0x50; //8位数据,可变波特率
- AUXR |= 0x40; //定时器时钟1T模式
- AUXR &= 0xFE; //串口1选择定时器1为波特率发生器
- TMOD &= 0x0F; //设置定时器模式
- TL1 = 0xB8; //设置定时初始值
- TH1 = 0xFF; //设置定时初始值
- ET1 = 0; //禁止定时器%d中断
- TR1 = 1; //定时器1开始计时
- }
- void Delay500ms() //@12.000MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 23;
- j = 205;
- k = 120;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void SPI_Init() //初始化SPI SPI频率为FOSC/2
- {
- SPDAT = 0;
- SPSTAT = 0xC0;
- SPCTL = 0xDF;
- }
- void Lcd_Write_cmd(unsigned char cmd) //向TFT写入一个命令
- {
- CS = 0;
- RS = 0;
- SPDAT = cmd;
- while(!(SPSTAT & 0x80));
- SPSTAT = 0xC0;
- CS = 1;
- }
- void Lcd_Write_data(unsigned char dat) //向TFT写入一个8位数据
- {
- CS = 0;
- RS = 1;
- SPDAT = dat;
- while(!(SPSTAT & 0x80));
- SPSTAT = 0xC0;
- CS = 1;
- }
- void Lcd_Write_data_16bit(unsigned int dat) //向TFT写入一个16位数据
- {
- Lcd_Write_data(dat >> 8);
- Lcd_Write_data(dat);
- }
- void Lcd_SetRegion(unsigned char x_start, unsigned char y_start, unsigned char x_end, unsigned char y_end) //选中一个区域
- {
- Lcd_Write_cmd(0x2A); //列地址设置
- Lcd_Write_data(0);
- Lcd_Write_data(x_start+2);
- Lcd_Write_data(0);
- Lcd_Write_data(x_end+2);
- Lcd_Write_cmd(0x2B); //行地址设置
- Lcd_Write_data(0);
- Lcd_Write_data(y_start+3);
- Lcd_Write_data(0);
- Lcd_Write_data(y_end+3);
- Lcd_Write_cmd(0x2C);
- }
- void Lcd_clear(unsigned int color) //清屏
- {
- unsigned int i;
- LED = 0;
- Lcd_SetRegion(0,0,127,127);
- for(i=0;i<16384;i++)
- {
- Lcd_Write_data_16bit(color);
- }
- LED = 1;
- }
- void Lcd_Init() //初始化LCD
- {
- BLK = 0;
- RST = 0;
- Delay500ms();
- RST = 1;
- Delay500ms();
- SPI_Init();
- Delay500ms();
- Lcd_Write_cmd(0x11); //退出休眠
- Delay500ms();
- Lcd_Write_cmd(0xB1); //设置正常刷新率
- Lcd_Write_data(0x01);
- Lcd_Write_data(0x2C);
- Lcd_Write_data(0x2D);
- Lcd_Write_cmd(0xB2); //设置空闲模式刷新率
- Lcd_Write_data(0x01);
- Lcd_Write_data(0x2C);
- Lcd_Write_data(0x2D);
- Lcd_Write_cmd(0xB3); //设置部分/全色的刷新率
- Lcd_Write_data(0x01);
- Lcd_Write_data(0x2C);
- Lcd_Write_data(0x2D);
- Lcd_Write_data(0x01);
- Lcd_Write_data(0x2C);
- Lcd_Write_data(0x2D);
- Lcd_Write_cmd(0xB4); //显示反转模式控制
- Lcd_Write_data(0x07);
- Lcd_Write_cmd(0xC0); //电源控制1
- Lcd_Write_data(0xA2);
- Lcd_Write_data(0x02);
- Lcd_Write_data(0x84);
- Lcd_Write_cmd(0xC1); //电源控制2
- Lcd_Write_data(0xC5);
- Lcd_Write_cmd(0xC2); //电源控制3
- Lcd_Write_data(0x0A);
- Lcd_Write_data(0x00);
- Lcd_Write_cmd(0xC3); //电源控制4
- Lcd_Write_data(0x8A);
- Lcd_Write_data(0x2A);
- Lcd_Write_cmd(0xC4); //电源控制5
- Lcd_Write_data(0x8A);
- Lcd_Write_data(0xEE);
- Lcd_Write_cmd(0xC5); //VCOM控制1
- Lcd_Write_data(0x0E);
- Lcd_Write_cmd(0x36); //内存数据访问控制
- Lcd_Write_data(0xC8);
- //Lcd_Write_cmd(0x21);
- Lcd_Write_cmd(0xE0);
- Lcd_Write_data(0x0F);
- Lcd_Write_data(0x1A);
- Lcd_Write_data(0x0F);
- Lcd_Write_data(0x18);
- Lcd_Write_data(0x2F);
- Lcd_Write_data(0x28);
- Lcd_Write_data(0x20);
- Lcd_Write_data(0x22);
- Lcd_Write_data(0x1F);
- Lcd_Write_data(0x1B);
- Lcd_Write_data(0x23);
- Lcd_Write_data(0x37);
- Lcd_Write_data(0x00);
- Lcd_Write_data(0x07);
- Lcd_Write_data(0x02);
- Lcd_Write_data(0x10);
- Lcd_Write_cmd(0xE1);
- Lcd_Write_data(0x0F);
- Lcd_Write_data(0x1B);
- Lcd_Write_data(0x0F);
- Lcd_Write_data(0x17);
- Lcd_Write_data(0x33);
- Lcd_Write_data(0x2C);
- Lcd_Write_data(0x29);
- Lcd_Write_data(0x2E);
- Lcd_Write_data(0x30);
- Lcd_Write_data(0x30);
- Lcd_Write_data(0x39);
- Lcd_Write_data(0x3F);
- Lcd_Write_data(0x00);
- Lcd_Write_data(0x07);
- Lcd_Write_data(0x03);
- Lcd_Write_data(0x10);
- Lcd_Write_cmd(0xF0); //启动测试命令
- Lcd_Write_data(0x01);
- Lcd_Write_cmd(0xF6); //禁用ram省电模式
- Lcd_Write_data(0x00);
- Lcd_Write_cmd(0x3A); //65k mode
- Lcd_Write_data(0x05);
- Lcd_Write_cmd(0x29); //开启显示
- // Lcd_SetRegion(0,0,127,127); //选中整个屏幕
- Lcd_clear(0x0000); //清屏(青色)
- BLK = 1;
- }
赞0
SWM320 内嵌ARM®CortexTM-M4 控制器,片上包含精度为1%以内的20MHz/40MHz时钟,可通过PLL 倍频到120MHz 时钟,提供多种串行、并行接口,支持扩展NOR Flash、SRAM、SDRAM、TFT彩色液晶屏、SD卡等,具有高性能、低功耗、代码密度大等突出特点,适用于工业控制、白色家电、电机驱动等诸多应用领域。
产品特色
----------------------------------------------------------------------------------------------------------------
① 最高工作频率:120MHz;
② 超大内部存储器:512K Flash、128K RAM;
③ 丰富串行接口:最多4路UART、2路I2C、2路SPI、1路CAN;
④ 丰富并行总线:支持SRAM、SDRAM、NOR Flash;
⑤ LCD接口:支持RGB、MPU,最高分辨率1024*768;
⑥ SDIO接口:支持SDIO接口协议;
⑦ DMA控制器:支持存储器、外设间的数据搬运。
联系方式:18824454153(微信同号)
评论
2022-02-11
赞0
看屏的数据手册的话,初始化的帧数是80fps左右,达到这个帧数的话无论怎样都不会达到300ms的刷屏时间吧?
评论
2022-02-10
赞0
程序里已经规定好了1秒给屏换一次色
评论
2022-02-10
赞0
评论
2022-02-10
赞0
评论
2022-02-10
赞0
评论
2022-02-09
请问数据在40ms左右传完了,为什么屏幕没有及时刷新呢,如果采用并口的话是否也会这样?
赞0
评论
2022-02-09
您需要登录后才可以回复 登录 | 注册