本篇介绍软件设计,相关代码查阅本人以往文章贴子获取,已上传多种参考代码,大同小异。
一、老样子,先上一张软件代码导图:
代码三步曲:
- 设定通信方式(已写好各种通信方式的参考代码了);
- 初始化RA8889,如上图所示,看似很多,代码都是直接调用API函数;
- 调用API函数进行界面设计,对于工业上所使用的UI,这些API足够用,也十分简洁!
二、代码要点:
1. 一些宏定义请先修改,在userdef.h
(1)显存规划:
/* RA8889显存和显示配置 */
#define canvas_image_width 1600 //画布宽度,设定为屏宽的n倍
#define main_image_width 1600 //图像宽度,设定为屏宽的n倍
#define LCD_Width 800
#define LCD_Height 480
(2)主频配置,一般只修改SCAN_FREQ即可
/* RA8889频率配置 */
#define OSC_FREQ 10 //晶振频率,外接晶振请使用10MHz
#define DRAM_FREQ 133 //SDRAM刷新频率,最高166MHz
#define CORE_FREQ 120 //RA8889核心频率,最高133MHz
#define SCAN_FREQ 30 //PCLK液晶扫描频率,最高100MHz
(3)液晶屏型号定义,最终是在初始化中Set_LCD_Panel();执行,不同液晶屏配置不同,许多RD还不熟悉彩屏,这里先卖个关子,待后续文章另起新篇针对该项专门介绍。
下方为AT070TN92的液晶屏参数配置:
#ifdef L80480R70
//**[10h]**//
Select_LCD_Sync_Mode(); // Enable XVSYNC, XHSYNC, XDE.
// Select_LCD_DE_Mode(); // XVSYNC & XHSYNC in idle state.
PCLK_Falling();
// PCLK_Rising();
VSCAN_T_to_B();
PDATA_Set_RGB();
HSYNC_Low_Active();
VSYNC_Low_Active();
DE_High_Active();
// DE_Low_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
//**[10h]**//
//Select_LCD_Sync_Mode(); // Enable XVSYNC, XHSYNC, XDE.
Select_LCD_DE_Mode(); // XVSYNC & XHSYNC in idle state.
// PCLK_Rising();
PCLK_Falling();
VSCAN_T_to_B();
PDATA_Set_RGB();
//**[13h]**//
HSYNC_Low_Active();
VSYNC_Low_Active();
DE_High_Active();
// DE_Low_Active();
//------------------------------------
//**[14h][15h][1Ah][1Bh]**//
LCD_HorizontalWidth_VerticalHeight(480, 272); // LCD Resolution 480x272。
//**[16h][17h]**//
LCD_Horizontal_Non_Display(38); // 480x272,HSYNC Back Porch=38。
//**[18h]**//
LCD_HSYNC_Start_Position(20); // 480x272 HSYNC Front Porch = 20。
//**[19h]**//
LCD_HSYNC_Pulse_Width(20); // 480x272,HSYNC Pulse Width=5~30,set 20。
//**[1Ch][1Dh]**//
LCD_Vertical_Non_Display(4); // 480x272,VSYNC Back Porch =4。
//**[1Eh]**//
LCD_VSYNC_Start_Position(15); // 480x272,VSYNC Front Porch =15。
//**[1Fh]**//
LCD_VSYNC_Pulse_Width(3); // 480x272,VSYNC Pulse Width =3。
#endif
参考演示程序已经预设各种分辨率的液晶屏参数配置,可以直接代入测试,再进行微调。使用上非常简单!
(4)MCU通信方式和显示色深定义:
/*==== MCU接口通信位数和显示色深定义 ====*/
//#define MCU_8bit_ColorDepth_8bpp
//#define MCU_8bit_ColorDepth_16bpp
#define MCU_8bit_ColorDepth_24bpp
//#define MCU_16bit_ColorDepth_16bpp
//#define MCU_16bit_ColorDepth_24bpp_Mode_1
//#define MCU_16bit_ColorDepth_24bpp_Mode_2
2. 延时函数
使用毫秒即可,请依照自己的MCU主频调整延时长度:
void delay_ms(unsigned int n);
三、进行UI界面设计
底层封装好API函数了,存放在RA8889_API.c(51单片机请改用RA8889_API_51.c),每个函数头均有用法说明,不明白请进函数查阅详细参数说明。并且所有代码透明,感兴趣的话请进入函数查看底层寄存器的设定。
UI界面基础三要素为 绘图、显示文字、显示图片, 这些都是RA8889硬件支持的功能,显示速度很快!如下列举主要的显示函数:
/* MCU直接写点,基础函数 */
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);
/* DMA功能,快速显示图片(JPG,BMP),播放AVI影片 */
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彩屏进行演示:
|