sujingliang 发表于 2023-11-25 09:50:18

89C52驱动16bit并口彩屏


下面是屏幕的一些资料




屏幕主控是ILI9225,分辨率:176*220,16bit并口,262k彩屏
为什么用89c52驱动,因为并口16位,加上CS、RS、WR、RD、RST控制引脚一共需要21个IO口,看了看手头的开发板也就89C52胜任了。
其中:
sbit TFT_RST = P3^3; //复位
sbit TFT_CS = P2^7; //片选
sbit TFT_RS = P2^6; //数据命令选择端
sbit TFT_WR = P2^5; //读写控制
sbit TFT_RD = P3^2; //读写控制

16位并口用P0、P1




main.c
#include "REG51.H"
#include "lcd_driver.h"

/****************************************************************************
*函数名:main
*输入:无
*输出:无
*功能:主函数
****************************************************************************/

void main (void)
{
        TFT_Init();                   //初始化TFT

        while(1)
        {
                TFT_ClearScreen(BLACK);          //刷黑色
                TFT_ClearScreen(BLUE);
                TFT_ClearScreen(RED);
                TFT_ClearScreen(MAGENTA);
                TFT_ClearScreen(GREEN);
                TFT_ClearScreen(CYAN);
                TFT_ClearScreen(YELLOW);
                TFT_ClearScreen(WHITE);               
        }
}

        lcd_driver.h

#ifndef __LCD_DRIVER_H
#define __LCD_DRIVER_H


#include <reg51.h>

//---重定义关键词---//
#ifndef uchar
#define uchar unsigned char
#endif

#ifndef uint
#define uintunsigned int
#endif

//---定义使用的IO口---//
sbit          TFT_RST = P3^3;   //复位
sbit          TFT_CS= P2^7;          //片选
sbit          TFT_RS= P2^6;          //数据命令选择端
sbit          TFT_WR= P2^5;          //读写控制
sbit      TFT_RD= P3^2;   //读写控制

#define   TFT_DATAPORTHP1//放置高8位数据
#define   TFT_DATAPORTLP0
//---定义屏的大小---//
#define TFT_XMAX ((uchar)175)//                //设置TFT屏的大小
#define TFT_YMAX ((uchar)219)//

//---定义颜色的宏---//
#define WHITE          0xFFFF
#define BLACK          0x0000
#define BLUE         0x001F
#define RED            0xF800
#define MAGENTA      0xF81F
#define GREEN          0x07E0
#define CYAN         0x7FFF
#define YELLOW         0xFFE0               //定义颜色的宏

//-- 声明全局函数 --//
void TFT_WriteCmd(uint cmd);
void TFT_WriteData(uint dat);
void TFT_Init(void);
void TFT_SetWindow(uchar xStart, uchar yStart, uchar xEnd, uchar yEnd);
void TFT_ClearScreen(uint color);
#endif
lcd_driver.c



#include "lcd_driver.h"

/****************************************************************************
*函数名:TFT_WriteCmd
*输入:cmd
*输出:
*功能:写命令。
****************************************************************************/          

void TFT_WriteCmd(uint cmd)
{
        uchar cmdH, cmdL;
        cmdH = cmd >> 8;
        cmdL = cmd & 0x00FF;

        TFT_WR = 1;                         //初始化WR
        TFT_CS = 0;                          //打开片选
       
        TFT_RD = 1;         //选择写
        TFT_RS = 0;                          //选择命令
               
        TFT_DATAPORTH = cmdH; //放置命令数据
        TFT_DATAPORTL = cmdL; //放置命令数据

        TFT_WR = 0;                          //写入时序
        TFT_WR = 1;
       
        TFT_CS = 1;                          //关闭片选
}

/****************************************************************************
*函数名:TFT_WriteCmdData
*输入:cmd, dat
*输出:
*功能:写命令, 写数据。
****************************************************************************/          

void TFT_WriteData(uint dat)
{
    uchar datH, datL;
        datH = dat >> 8;
        datL = dat & 0x00FF;

        TFT_WR = 1;                         //初始化WR
        TFT_CS = 0;                          //打开片选
       
        TFT_RD = 1;         //选择写
        TFT_RS = 1;                          //选择发送数据
               
        TFT_DATAPORTH = datH;//放置命令数据
        TFT_DATAPORTL = datL;//放置命令数据

        TFT_WR = 0;                          //写入时序
        TFT_WR = 1;
       
        TFT_CS = 1;                          //关闭片选
}

/****************************************************************************
*函数名:TFT_Init
*输入:
*输出:
*功能:初始化TFT。
****************************************************************************/          

void TFT_Init(void)
{
        uint i;

        TFT_RST = 1;
        for(i=500; i>0; i--);
        TFT_RST = 0;
        for(i=500; i>0; i--);
        TFT_RST = 1;
        for(i=5000; i>0; i--);
       
       TFT_CS = 0;
       

       //LCD Init For 2.0inch LCD Panel with ILI9225.       
        TFT_WriteCmd(0x10);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x11);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x12);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x13);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x14);TFT_WriteData(0x0000);
        for(i=500; i>0; i--);
        TFT_WriteCmd(0x11);TFT_WriteData(0x0018);
        TFT_WriteCmd(0x12);TFT_WriteData(0x200E);
        TFT_WriteCmd(0x13);TFT_WriteData(0x0052);
        TFT_WriteCmd(0x14);TFT_WriteData(0x3961);
        TFT_WriteCmd(0x10);TFT_WriteData(0x0000);
        for(i=500; i>0; i--);
       
        TFT_WriteCmd(0x11);TFT_WriteData(0x1038);
        for(i=500; i>0; i--);
       
        TFT_WriteCmd(0x02);TFT_WriteData(0x0100);
       
        TFT_WriteCmd(0x01);TFT_WriteData(0x011C);
        TFT_WriteCmd(0x03);TFT_WriteData(0x1030);
       
        TFT_WriteCmd(0x07);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x08);TFT_WriteData(0x0808);
        TFT_WriteCmd(0x0B);TFT_WriteData(0x1100);
        TFT_WriteCmd(0x0C);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x0F);TFT_WriteData(0x0501);
        TFT_WriteCmd(0x15);TFT_WriteData(0x0020);
        TFT_WriteCmd(0x20);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x21);TFT_WriteData(0x0000);
       
        TFT_WriteCmd(0x30);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x31);TFT_WriteData(0x00DB);
        TFT_WriteCmd(0x32);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x33);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x34);TFT_WriteData(0x00DB);
        TFT_WriteCmd(0x35);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x36);TFT_WriteData(0x00AF);
        TFT_WriteCmd(0x37);TFT_WriteData(0x0000);
        TFT_WriteCmd(0x38);TFT_WriteData(0x00DB);
        TFT_WriteCmd(0x39);TFT_WriteData(0x0000);
       
        TFT_WriteCmd(0x50);TFT_WriteData(0x0603);
        TFT_WriteCmd(0x51);TFT_WriteData(0x080D);
        TFT_WriteCmd(0x52);TFT_WriteData(0x0D0C);
        TFT_WriteCmd(0x53);TFT_WriteData(0x0205);
        TFT_WriteCmd(0x54);TFT_WriteData(0x040A);
        TFT_WriteCmd(0x55);TFT_WriteData(0x0703);
        TFT_WriteCmd(0x56);TFT_WriteData(0x0300);
        TFT_WriteCmd(0x57);TFT_WriteData(0x0400);
        TFT_WriteCmd(0x58);TFT_WriteData(0x0B00);
        TFT_WriteCmd(0x59);TFT_WriteData(0x0017);
       
        TFT_WriteCmd(0x0F);TFT_WriteData(0x0701);
        TFT_WriteCmd(0x07);TFT_WriteData(0x0012);
        for(i=500; i>0; i--);
        TFT_WriteCmd(0x07);TFT_WriteData(0x1017);

       


}

/****************************************************************************
*函数名:TFT_SetWindow
*输入:xStart, yStart, xEnd, yEnd
*输出:
*功能:设置要操作的窗口。
****************************************************************************/          

void TFT_SetWindow(uchar xStart, uchar yStart, uchar xEnd, uchar yEnd)
{
       uint x,y,xy;

       x=(xEnd <<8)|xStart;
       y=(yEnd <<8)|yStart;
       xy = (yStart<<8)|xStart;

       TFT_WriteCmd(0x44);TFT_WriteData(x);
       TFT_WriteCmd(0x45);TFT_WriteData(y);
       TFT_WriteCmd(0x21);TFT_WriteData(xy);


       /*TFT_WriteCmd(0x20);TFT_WriteData(xStart);   //xStart
       TFT_WriteCmd(0x21);TFT_WriteData(yStart);   //yStart
       */
       TFT_WriteCmd(0x22);
}


/****************************************************************************
*函数名:GUI_Clearcreen
*输入:backColor
*输出:
*功能:清屏并涂上颜色。
****************************************************************************/
          
void TFT_ClearScreen(uint color)
{
        uint i, j;

        TFT_SetWindow(0, 0, TFT_XMAX, TFT_YMAX);       //作用区域
        for(i=0; i<=TFT_XMAX; i++)
        {
                for (j=0; j<=TFT_YMAX; j++)
                {
                        TFT_WriteData(color);
                }
        }
}



神农鼎 发表于 2023-11-25 12:33:49

用 STC8H8K64U / STC32G12K128 有 DMA支持

wjy123 发表于 2024-6-18 19:57:15

TFT屏是不是用BLK引脚来调节亮度?

小涵子爸爸 发表于 2024-8-3 09:33:38

wjy123 发表于 2024-6-18 19:57
TFT屏是不是用BLK引脚来调节亮度?

对的,通过BLK引脚可以控制背光亮灭,也可以实现亮度调节

ka1265 发表于 2024-8-6 15:44:38

{:4_165:}

stcsun 发表于 2024-11-5 10:50:15

看代码没看到使用16位并口P0'P1

stb988 发表于 2024-11-9 10:30:37

应该很慢吧,c52驱动彩屏

神农鼎 发表于 2024-11-9 10:44:31

改用管脚兼容的 Ai8051U, 视频级刷屏



https://www.stcaimcu.com/forum.p ... id=10511&pid=103755

Ai8051U,USB 型 1T 8051,支持32位和8位指令集, LQFP48-RMB2.3
===直接 USB下载 / USB仿真,1个芯片搞定
管脚兼容天王级别的:89C52RC,12C5A60S2
要兼容 8位8051指令集,可以用 Keil C51/IAR/SDCC 编译器
===就相当于更强大的 8H8K64U
要兼容 32位8051指令集,可以用 Keil C251 编译器,双核兼容设计
===就相当于更强大的 32G12K128, 32G8K64
34K SRAM(2K edata, 32K xdata), 64K Flash
TFPU@120MHz, 硬件浮点/硬件三角函数 运算器
DMA支持PWM, DMA支持外设直接到外设, P2P
120MHz-PWM支持硬件移相,16位PWM; 真12位ADC
USB, 4组串口,12位ADC, 轨到轨比较器
QSPI, SPI, I2S, I2C,TFT-i8080/M6800 接口
PDIP40,LQFP44,LQFP48

============================================



Ai8051U-LQFP48比普通 M0/M3,如 32F103C8T6 强太多的地方:
1,Ai8051U有TFPU@120MHz, 算力比他强, uS级硬件三角函数/浮点运算器;
2,Ai8051U的抗干扰比他强;
3,Ai8051U的内部复位是专业级的复位电路,彻底省外部复位;
4,Ai8051U的内部时钟完全满足串口通信要求,4组串口;
5,Ai8051U-LQFP48有 QSPI, i8080/M6800-TFT 接口,32F103C8T6没有;
6,Ai8051U的PWM支持硬件移相@120MHz
7,Ai8051U是 34K SRAM
8,Ai8051U是 自带硬件USB, 1个芯片就能直接USB连接电脑仿真/下载,全球唯一

Ai8051U-LQFP48, RMB2.3含税


soma 发表于 2024-11-9 11:24:56

flash有点小,如果图片还要外挂flash吧,刷新率也不是很高吧

wlhet 发表于 2024-11-9 13:02:06

soma 发表于 2024-11-9 11:24
flash有点小,如果图片还要外挂flash吧,刷新率也不是很高吧

89C52跑起来都很慢的
页: [1] 2
查看完整版本: 89C52驱动16bit并口彩屏