单片机驱动彩屏最简方案:单片机_RA8889最小开发板驱动控制TFT彩屏介绍(三)软件设计
本篇介绍软件设计,相关代码请从本人相关文章获取,已上传多种参考代码,大同小异。
一、老样子,先上一张软件代码导图:
代码三步曲:
- 设定通信方式(已写好各种通信方式的参考代码了);
- 初始化RA8889,如上图所示,看似很多,代码都是直接调用API函数;
- 调用API函数进行界面设计,对于工业上所使用的UI,这些API足够用,也十分简洁!
二、代码要点:
1. 一些宏定义请先修改,在userdef.h
(1)显存规划:
#define canvas_image_width 1600
#define main_image_width 1600
#define LCD_Width 800
#define LCD_Height 480
(2)主频配置,一般只修改SCAN_FREQ即可
#define OSC_FREQ 10
#define DRAM_FREQ 133
#define CORE_FREQ 120
#define SCAN_FREQ 30
(3)液晶屏型号定义,最终是在初始化中Set_LCD_Panel();执行,不同液晶屏配置不同,许多RD还不熟悉彩屏,这里先卖个关子,待后续文章另起新篇针对该项专门介绍。
下方为AT070TN92的液晶屏参数配置:
#ifdef L80480R70
Select_LCD_Sync_Mode();
PCLK_Falling();
VSCAN_T_to_B();
PDATA_Set_RGB();
HSYNC_Low_Active();
VSYNC_Low_Active();
DE_High_Active();
LCD_HorizontalWidth_VerticalHeight(800,480);
LCD_Horizontal_Non_Display(64);
LCD_HSYNC_Start_Position(208);
LCD_HSYNC_Pulse_Width(24);
LCD_Vertical_Non_Display(16);
LCD_VSYNC_Start_Position(22);
LCD_VSYNC_Pulse_Width(16);
#endif
下方为AT043TN25的液晶屏参数配置:
#ifdef AT043TN25
Select_LCD_DE_Mode();
PCLK_Falling();
VSCAN_T_to_B();
PDATA_Set_RGB();
HSYNC_Low_Active();
VSYNC_Low_Active();
DE_High_Active();
LCD_HorizontalWidth_VerticalHeight(480, 272);
LCD_Horizontal_Non_Display(38);
LCD_HSYNC_Start_Position(20);
LCD_HSYNC_Pulse_Width(20);
LCD_Vertical_Non_Display(4);
LCD_VSYNC_Start_Position(15);
LCD_VSYNC_Pulse_Width(3);
#endif
参考演示程序已经预设各种分辨率的液晶屏参数配置,可以直接代入测试,再进行微调。使用上非常简单!
(4)MCU通信方式和显示色深定义:
#define MCU_8bit_ColorDepth_24bpp
- 延时函数
使用毫秒即可,请依照自己的MCU主频调整延时长度:
void delay_ms(unsigned int n);
三、进行UI界面设计
底层封装好API函数了,存放在RA8889_API.c(51单片机请改用RA8889_API_51.c),每个函数头均有用法说明,不明白请进函数查阅详细参数说明。并且所有代码透明,感兴趣的话请进入函数查看底层寄存器的设定。
UI界面基础三要素为 绘图、显示文字、显示图片, 这些都是RA8889硬件支持的功能,显示速度很快!如下列举主要的显示函数:
void putPixel(unsigned short x,unsigned short y,unsigned long color);
void MPU8_8bpp_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned char *data_array);
void MPU8_16bpp_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned char *data_array);
void MPU8_24bpp_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned char *data_array);
void MPU16_16bpp_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned short *data_array);
void MPU16_24bpp_Mode1_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned short *data_array);
void MPU16_24bpp_Mode2_Memory_Write (unsigned short x,unsigned short y,unsigned short w ,unsigned short h ,const unsigned short *data_array);
void Draw_Line(unsigned long LineColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2);
void Draw_Triangle(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3);
void Draw_Triangle_Fill(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3);
void Draw_Circle(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short R);
void Draw_Circle_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short R);
void Draw_Ellipse(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Ellipse_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Left_Up_Curve(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Left_Up_Curve_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Right_Down_Curve(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Right_Down_Curve_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Right_Up_Curve(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Right_Up_Curve_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Left_Down_Curve(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Left_Down_Curve_Fill(unsigned long ForegroundColor,unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R);
void Draw_Square(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2);
void Draw_Square_Fill(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2);
void Draw_Circle_Square(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short R,unsigned short Y_R);
void Draw_Circle_Square_Fill(unsigned long ForegroundColor,unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short R,unsigned short Y_R);
void BTE_Memory_Copy(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H);
void BTE_Memory_Copy_Chroma_key(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H);
void BTE_MCU_Write_MCU_8bit(unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H,const unsigned char *data_array);
void BTE_MCU_Write_MCU_16bit(unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H,const unsigned short *data_array);
void BTE_MCU_Write_Chroma_key_MCU_8bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H,const unsigned char *data_array);
void BTE_MCU_Write_Chroma_key_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H,const unsigned short *data_array);
void BTE_Memory_Copy_ColorExpansion(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,unsigned long Background_color);
void BTE_Memory_Copy_ColorExpansion_Chroma_key(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color);
void BTE_MCU_Write_ColorExpansion_MCU_8bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,unsigned long Background_color,const unsigned char *data_array);
void BTE_MCU_Write_ColorExpansion_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,unsigned long Background_color,const unsigned short *data_array);
void BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_8bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,const unsigned char *data_array);
void BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned long Foreground_color,const unsigned short *data_array);
void BTE_Pattern_Fill(unsigned char P_8x8_or_16x16, unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H);
void BTE_Pattern_Fill_With_Chroma_key(unsigned char P_8x8_or_16x16 ,unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned long Background_color,unsigned short X_W,unsigned short Y_H);
void BTE_Solid_Fill(unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned long Foreground_color,unsigned short X_W,unsigned short Y_H);
void BTE_Alpha_Blending_Picture_Mode(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W, unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned char alpha);
void DMA_24bit(unsigned char Clk ,unsigned short X1,unsigned short Y1,unsigned short X_W,unsigned short Y_H ,unsigned short P_W ,unsigned long Addr);
void DMA_32bit(unsigned char Clk ,unsigned short X1,unsigned short Y1,unsigned short X_W,unsigned short Y_H ,unsigned short P_W,unsigned long Addr);
void JPG_NOR (unsigned long addr,unsigned long JPGsize,unsigned long IDEC_canvas_width,unsigned short x,unsigned short y);
void AVI_NOR(unsigned long addr,unsigned long videosize,unsigned long shadow_buffer_addr,unsigned long PIP_buffer_addr,unsigned long x,unsigned long y,unsigned long height,unsigned long width,unsigned long PIP_width);
四、彩蛋
我们已经开发好一款新的RA8889开发板,简单易用,使用您的单片机,通过并口或者串口直接连接即可,外接一片AT043TN25或者AT070TN92,只要接口兼容,通通都能点!
RA8889精简版:RA6809,该芯片仅提供SPI接口与MCU通信,但
功能上和RA8889完全一样!更详细信息请关注我们的产品开发进展!
以下效果使用51单片机STC8H8K64U+RA6809开发板+1024x600/800x480彩屏进行演示: