问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG - TFT彩屏
  • MCU驱动TFT彩屏 刷屏数据40ms左右传完 但刷屏用了300ms

    [color=#333333][backcolor=rgb(255, 255, 255)][font=微软雅黑][size=16px]MCU使用SPI驱动TFT彩屏 系统时钟33.1776MHz SPI频率FOSC/2 刷屏数据40ms左右传完了 但屏幕实际刷新时间用了300ms以上 40ms是在刷屏程序里拉低引脚再拉高引脚然后用逻辑分析仪测出来的,刷屏时间的300ms是录屏后数帧数数出来的[/size][/font][/backcolor][/color] [color=#333333][backcolor=rgb(255, 255, 255)][font=微软雅黑][size=16px]请问下这个是哪里的问题,是TFT的初始化有问题吗[/size][/font][/backcolor][/color] [img]https://file.**/web2/M00/2F/5A/poYBAGICQ-KAJgOOAAAvKPq8EeU266.png[/img] [img]https://bbs.**/data/attachment/forum/202202/08/182027ptb3fdnnmzz4462o.gif[/img] [color=#333333][backcolor=rgb(255, 255, 255)][font=微软雅黑][size=16px]以下代码[/size][/font][/backcolor][/color][color=#333333][backcolor=rgb(255, 255, 255)][font=微软雅黑][size=16px] [/size][/font][/backcolor][/color] [list=1] [*]#include [*]#include "TFT.h" [*]#include "weather.h" [*] [*]sbit BLK = P5^3; //背光控制 [*]sbit RS = P0^5; //数据[color=rgb(65, 131, 196)]命令[/color]切换线 [*]sbit RST = P0^6; //复位线 [*]sbit CS = P0^7; //片选 [*]sbit SCLK = P1^5; //SPI[color=rgb(65, 131, 196)]时钟[/color]线 [*]sbit MOSI = P1^3; //SPI数据线 [*]sbit [color=rgb(65, 131, 196)]LED[/color] = P5^0; [*]unsigned int [color=rgb(65, 131, 196)]ti[/color]me_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开始[color=rgb(65, 131, 196)]计时[/color] [*]} [*]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[color=rgb(65, 131, 196)]频率[/color]为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); //显示[color=rgb(65, 131, 196)]反转[/color]模式控制 [*] Lcd_Write_data(0x07); [*] [*] Lcd_Write_cmd(0xC0); //[color=rgb(65, 131, 196)]电源[/color]控制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); //启动[color=rgb(65, 131, 196)]测试[/color]命令 [*] 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; [*]} [/list]

    单片机 51单片机 MCU TFT彩屏 spi

    7152浏览量 7回复量 关注量