MCU使用SPI驱动TFT彩屏 系统时钟33.1776MHz SPI频率FOSC/2 刷屏数据40ms左右传完了 但屏幕实际刷新时间用了300ms以上 40ms是在刷屏程序里拉低引脚再拉高引脚然后用逻辑分析仪测出来的,刷屏时间的300ms是录屏后数帧数数出来的
请问下这个是哪里的问题,是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;
- }
|