STC12C5A60S2 RA8875 {MOD}彩显示错误问题

2019-03-24 17:13发布

我的板子显示三基 {MOD}正常,但显示别的 {MOD}彩时显示错误。选用8位接口16 {MOD}彩。
东华4.3寸彩屏。
有空一起研究的请看下面代码如下:

RA8875驱动:
#include"STC12C5A60S2.H"
#include "RA8875.h"

/*************************** 延时子函数 ****************************/
void delay_ms(uint ms)
{
   uchar k;
   while (ms--)
   {
     for (k = 0; k <125; k++);      
   }
}
/********************* RA8875 写指令函数 **************************/
void LCD_CmdWrite(uchar Cmd)    //8080模式
{
   LCD_rd = 1;
   LCD_cs = 0;
   LCD_rs = 1;
   DATA_BUS = Cmd;
   LCD_wr = 0;
   LCD_wr = 1;
   LCD_cs= 1;
   DATA_BUS = 0xff;
   LCD_rs = 0;
/*
   LCD_rs = 1;
   LCD_cs = 0;
   LCD_wr = 0;
   LCD_rd = 1;
   DATA_BUS = Cmd;
   LCD_wr = 1;
   LCD_cs = 1;
   DATA_BUS = 0xff;
   LCD_rs = 0;
   */
}
/********************* RA8875 写数据函数 **************************/
void LCD_DataWrite(uchar Data)   //8080模式
{
   LCD_rd = 1;      
   LCD_cs = 0;
   LCD_rs = 0;
   DATA_BUS = Data;
   LCD_wr = 0;
   LCD_wr = 1;
   LCD_cs = 1;
   DATA_BUS = 0xff;
   LCD_rs = 1;
/*
   LCD_rs = 0;      
   LCD_cs = 0;
   LCD_wr = 0;
   LCD_rd = 1;
   DATA_BUS = Data;
   LCD_wr = 1;
   LCD_cs = 1;
   DATA_BUS = 0xff;
   LCD_rs = 1;
   */
}
/********************* RA8875 写指令和写数据函数 **************************/
void Write_Dir(uchar Cmd,uchar Data)
{
   LCD_CmdWrite(Cmd);
   LCD_DataWrite(Data);
}
/********************* RA8875 读状态函数 **************************/
uchar LCD_StatusRead(void)      //8080模式
{
   uchar Data;
   LCD_cs = 0;
   LCD_rs = 1;
   LCD_wr = 1;
   LCD_rd = 0;
   Data = DATA_BUS;
   LCD_rd = 1;
   LCD_cs = 1;
   DATA_BUS = 0xff;
   LCD_rs = 0;
   return Data;
}
/********************* RA8875 读数据函数 **************************/
uchar LCD_DataRead(void)      //8080模式
{
   uchar Data;
   LCD_wr = 1;
   LCD_cs = 0;
   LCD_rs = 0;
   LCD_rd = 0;
   Data = DATA_BUS;
   LCD_rd = 1;
   LCD_cs = 1;
   LCD_rs = 1;
   return Data;
}
/********************* RA8875 复位函数 **************************/
void LCD_Reset(void)
{
LCD_RST = 1;
delay_ms(5);
LCD_RST = 0;
delay_ms(5);
LCD_RST = 1;
delay_ms(5);
}
/********************* RA8875 倍频设置函数 **************************/
void PLL_ini(void)
{
     LCD_CmdWrite(0x88);      
     LCD_DataWrite(0x05);
     delay_ms(1);     
     LCD_CmdWrite(0x89);        
     LCD_DataWrite(0x02);  
     delay_ms(1);
}
/********************* RA8875 测忙函数组 **************************/
void Chk_Busy(void)
{
uchar temp;  
do
   {
      temp=LCD_StatusRead();
   }
     while((temp&0x80)==0x80);     
}
/*void Chk_BTE_Busy(void)
{
uchar temp;  
do
   {
   temp=LCD_StatusRead();
   }
while((temp&0x40)==0x40);     
}
void Chk_DMA_Busy(void)
{
uchar temp;  
do
   {
   LCD_CmdWrite(0xBF);
   temp =LCD_DataRead();
   }
while((temp&0x01)==0x01);   
}
/********************************* RA8875 初始化函数 *************************************/
void LCD_Initial(void)
{  
     PLL_ini();
LCD_CmdWrite(0x10);      //SYSR   bit[4:3]=00 256 color  bit[2:1]=  00 8bit MPU interface
LCD_DataWrite(0x0C);     //1x 64k color  1x 16bit        
delay_ms(1);
LCD_CmdWrite(0x04);      //PCLK
LCD_DataWrite(0x82);     //
delay_ms(1);

//Horizontal set
LCD_CmdWrite(0x14);  //HDWR//Horizontal Display Width Setting Bit[6:0]  
LCD_DataWrite(0x3b); //Horizontal display width(pixels) = (HDWR + 1)*8       0x27
LCD_CmdWrite(0x15);  //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
LCD_DataWrite(0x02); //(HNDR + 1)*8 +HNDFCR
LCD_CmdWrite(0x16);  //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
LCD_CmdWrite(0x17);  //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x01); //HSYNC Start Position(PCLK) = (HSTR + 1)*8
LCD_CmdWrite(0x18);  //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x03); //HSYNC Width [4:0]   HSYNC Pulse width(PCLK) = (HPWR + 1)*8
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0x0f); //Vertical pixels = VDHR + 1 0xef
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x01); //Vertical pixels = VDHR + 1  0x00
LCD_CmdWrite(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x0F); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1d); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x0e); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x06); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1f);  //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x01); //VSYNC Pulse Width(PCLK) = (VPWR + 1)

LCD_CmdWrite(0x8C);    //PWM2 控制设置
LCD_DataWrite(0x80);   //开启PWM2
LCD_CmdWrite(0x8C);    //PWM2 控制设置
LCD_DataWrite(0x81);   //开启PWM2
LCD_CmdWrite(0x8D);    //背光亮度
LCD_DataWrite(0x00);   //亮度参数0xff-0x00
}

/********************************* 设置工作窗口区域 *************************************/
void Active_Window(uint XL,uint XR ,uint YT ,uint YB)
{
uchar temp;
     //setting active window X
temp=XL;   
     LCD_CmdWrite(0x30);//HSAW0
LCD_DataWrite(temp);
temp=XL>>8;   
     LCD_CmdWrite(0x31);//HSAW1   
LCD_DataWrite(temp);
temp=XR;   
     LCD_CmdWrite(0x34);//HEAW0
LCD_DataWrite(temp);
temp=XR>>8;   
     LCD_CmdWrite(0x35);//HEAW1   
LCD_DataWrite(temp);
     //setting active window Y
temp=YT;   
     LCD_CmdWrite(0x32);//VSAW0
LCD_DataWrite(temp);
temp=YT>>8;   
     LCD_CmdWrite(0x33);//VSAW1   
LCD_DataWrite(temp);
temp=YB;   
     LCD_CmdWrite(0x36);//VEAW0
LCD_DataWrite(temp);
temp=YB>>8;   
     LCD_CmdWrite(0x37);//VEAW1   
LCD_DataWrite(temp);
}
/********************************* 前景颜 {MOD}设置 *************************************/
void Text_Foreground_Color1(uint b_color)
{

LCD_CmdWrite(0x63);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));

LCD_CmdWrite(0x64);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));

LCD_CmdWrite(0x65);//BGCR0
LCD_DataWrite((uchar)(b_color));
}
/********************************* 背景颜 {MOD}设置 *************************************/
void Text_Background_Color1(uint b_color)
{

LCD_CmdWrite(0x60);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));

LCD_CmdWrite(0x61);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));

LCD_CmdWrite(0x62);//BGCR0
LCD_DataWrite((uchar)(b_color));
}




#include"STC12C5A60S2.H"
#include"RA8875.h"
uint tmp;
uint RGB(uchar R,uchar G,uchar B)
{
return((uint)(R&0XF8)<<8|(uint)(G&0XFC)<<3|(uint)(B&0XF8)>>3);
}
/**************************** 主函数 *******************************/
void main(void)
{
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
P4 = 0xff;
P4SW = 0xff;
LCD_Reset();      //复位RA8875
LCD_Initial();      //初始化RA8875
Write_Dir(0x01,0x80);            //开启显示
Active_Window(0,479,0,271);      //设置工作窗口大小
Text_Foreground_Color1(White);   //前景颜 {MOD}设定
Text_Background_Color1(Blue);     //背景颜 {MOD}设定
Write_Dir(0x8E,0x80);            //开始清屏(显示窗口)

   while(1)
     {
delay_ms(5000);
LCD_CmdWrite(0x8D);    //背光亮度
LCD_DataWrite(0xff);   //亮度参数0xff-0x00
delay_ms(5000);

Active_Window(0,479,0,271);//设置工作窗口大小
    Text_Background_Color1(White);//背景颜 {MOD}设定
    Write_Dir(0X8E,0X40);//设定清屏性质(工作窗口)
     Write_Dir(0X8E,0XC0);//开始清屏
    Chk_Busy();
     
     delay_ms(5000);

     tmp = RGB(128,128,255);    //分别输入888的R,G,B分量,转换成565的R,G,B分量.
     Active_Window(0,479,0,271);//设置工作窗口大小
    Text_Background_Color1(tmp);//背景颜 {MOD}设定
    Write_Dir(0X8E,0X40);//设定清屏性质(工作窗口)
     Write_Dir(0X8E,0XC0);//开始清屏
    Chk_Busy();

     }   
} 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
lgr
1楼-- · 2019-03-24 23:26
问题解决了!是RGB各高位和低高线路接反了!造成当三基 {MOD}之一全为高时红 {MOD}或绿 {MOD}或蓝 {MOD}都能正常显示,一但不是三基 {MOD}时TFT接收到的信号就不是正确的信号了。
董栋栋
2楼-- · 2019-03-25 03:49
我现在遇到用51来驱动这个芯片的问题  一直都没有反应  快要炸了
rudyhuang
3楼-- · 2019-03-25 04:37
 精彩回答 2  元偷偷看……

一周热门 更多>