打印

用RA8875芯片,利用fsmc总线,驱动4.3寸液晶,液晶不亮

[复制链接]
7776|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
墨如风0205|  楼主 | 2013-8-6 20:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*
* FILE                                        : ra8875.c
* DESCRIPTION        : This file is PLAM ra8875 driver demo.
* Author                                : momo
* Copyright                :
*
* History
* --------------------
* Rev                                        : 0.00
* Date                                        : 07/17/2013
*
* create.
* --------------------
*/

//---------------- Include files ------------------------//

#include "..\include\hardware.h"
#include "..\include\ra8875.h"
#include "..\include\fpga.h"
#include "stm32f4xx.h"

//---------------- Function Prototype -------------------//

static int LCD_Initial(void);
static int LCD_CmdWrite(int Cmd);
static int LCD_DataWrite(int Data);
static int Write_Dir(int Cmd,int Data);
static int LCD_StatusRead(void);
static int LCD_DataRead(void);
static int LCD_Reset(void);
static int Chk_Busy(void);
static int Chk_BTE_Busy(void);
static int Chk_DMA_Busy(void);
static int Active_Window(int XL,int XR ,int YT ,int YB);
static int Text_Background_Color1(unsigned int b_color);
static int Text_Foreground_Color1(unsigned int b_color);
static int Draw_Circle(int X,int Y,int R);
static int Draw_Ellipse(int X,int Y,int R1,int R2);
static int Draw_Line(int XS,int XE ,int YS,int YE);
static int Text_Background_Color(unsigned int setR,unsigned int setG,unsigned int setB);
static int Text_Foreground_Color(unsigned int setR,unsigned int setG,unsigned int setB);

#define color_brown   0x40c0
#define color_black   0x0000
#define color_white   0xffff
#define color_red     0xf800
#define color_green   0x07e0
#define color_blue    0x001f
#define color_yellow  color_red|color_green
#define color_cyan    color_green|color_blue
#define color_purple  color_red|color_blue

//---------------- Variable -----------------------------//


SYS_RA8875_T ra8875 = {
        .LCD_Initial = LCD_Initial,
        .LCD_CmdWrite = LCD_CmdWrite,
        .LCD_DataWrite = LCD_DataWrite,
        .Write_Dir = Write_Dir,
        .LCD_StatusRead = LCD_StatusRead,
        .LCD_DataRead = LCD_DataRead,
        .LCD_Reset = LCD_Reset,
        .Chk_Busy = Chk_Busy,       
        .Chk_BTE_Busy = Chk_BTE_Busy,
        .Chk_DMA_Busy = Chk_DMA_Busy,
        .Active_Window = Active_Window,
        .Text_Background_Color1 = Text_Background_Color1,
        .Text_Foreground_Color1 = Text_Foreground_Color1,
        .Write_Dir = Write_Dir,
        .Draw_Circle = Draw_Circle,
        .Draw_Ellipse = Draw_Ellipse,
        .Draw_Line = Draw_Line,
        .Text_Background_Color = Text_Background_Color,
  .Text_Foreground_Color = Text_Foreground_Color
};

//-----------------Function------------------------------//
/*
* Name                                        : LCD_CmdWrite
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 写指令函数
*/
static int LCD_CmdWrite(int Cmd)
{
       
        tft_write(1, Cmd);

        return 0;
}

/*
* Name                                        : LCD_DataWrite
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 写数据函数
*/
static int LCD_DataWrite(int Data)
{

        tft_write(0, Data);

       
        return 0;
}

/*
* Name                                        : Write_Dir
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 写指令和写数据函数
*/
static int Write_Dir(int Cmd,int Data)        //写指令
{
        LCD_CmdWrite(Cmd);
  LCD_DataWrite(Data);
       
        return 0;
}
// /*
//  * Name                                        : read
//  * Description        : ---
//  * Author                                : momo.
//  *
//  * History
//  * ----------------------
//  * Rev                                        : 0.00
//  * Date                                        : 07/19/2013
//  *
//  * create.
//  * ----------------------
//  * 读tft数据
//  */
// static int read(int offset)
// {
//         tft_write(1,offset);
//        
//         return tft_read(0);
// }

/*
* Name                                        : LCD_StatusRead
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 读寄存器的状态
*/
static int LCD_StatusRead(void)         //读状态
{
        unsigned char Data;

        Data = tft_read(1);
       
        return Data;
}

/*
* Name                                        : LCD_DataRead
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 读寄存器的数据
*/
static int LCD_DataRead(void) //读数据
{
        unsigned Data;

        Data = tft_read(0);
       
        return Data;
}

/*
* Name                                        : LCD_Reset
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* LCD复位函数
*/
static int LCD_Reset(void)        //LCD复位
{
        int i = 0;
        RA8875_RST_OUTPUT;       
       
        RA8875_RST_OFF;
        for(i=0;i<1000000;i++);
        RA8875_RST_ON;
        for(i=0;i<1000000;i++);
       
        return 0;
}


/*
* Name                                        : Chk_Busy
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 测忙函数组
*/

static int Chk_Busy(void)
{
        char temp;
        do
        {
                temp = LCD_StatusRead();
                }while((temp&0x80) == 0x80);
       
                return 0;
       
}
/*
* Name                                        : Chk_BTE_Busy
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 测忙函数组
*/
static int Chk_BTE_Busy(void)
{
        char temp;
        do
        {
                temp = LCD_StatusRead();
                }while((temp&0x40) == 0x40);
               
        return 0;
}
/*
* Name                                        : Chk_DMA_Busy
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 测忙函数组
*/
static int Chk_DMA_Busy(void)
{
  char temp;
        do
        {
                LCD_CmdWrite(0xBF);
                temp = LCD_DataRead();
                }while((temp&0x01) == 0x01);
               
        return 0;
}
/*
* Name                                        : PLL_ini
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 倍频设置
*/
static int PLL_ini(void)
{
        int i = 0;
       
        LCD_CmdWrite(0x88);
        for(i = 0; i < 1000; i ++);
        LCD_DataWrite(0x08);
        for(i=0;i<10000;i++);       
        LCD_CmdWrite(0x89);
  for(i = 0; i < 1000; i ++);       
        LCD_DataWrite(0x04);
        for(i=0;i<10000;i++);       
       
        return 0;
}       

/*
* Name                                        : LCD_Initial
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 初始化设置
*/
static int LCD_Initial(void)
{
        int i = 0;
       
        for(int k = 0; k < 10000000; k ++);
       
        LCD_Reset();               
        PLL_ini();
       
        LCD_CmdWrite(0x10);                //SYSR   bit[4:3]=00 256 color  bit[2:1]=  00 8bit MPU interface
       
        LCD_DataWrite(0x0f);        //                                                                1x 64k color                                                        1x        16bit                                                  
       
        LCD_CmdWrite(0x04);                //PCLK
        LCD_DataWrite(0x00);        //PCLK频率周期 = 1*系统频率周期
        for(i = 0; i<100000;i++);
       
        //水平设置
        LCD_CmdWrite(0x14);         //HDWR//Horizontal Display Width Setting Bit[6:0]  
        LCD_DataWrite(0x3b); //Horizontal display width(pixels) = (HDWR + 1)*8 = (59+1)*8 = 480      0x27
        LCD_CmdWrite(0x15);         //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
        LCD_DataWrite(0x00); //(HNDR + 1)*8 +HNDFCR
        LCD_CmdWrite(0x16);         //HNDR//Horizontal Non-Display Period Bit[4:0]
        LCD_DataWrite(0x01); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
        LCD_CmdWrite(0x17);         //HSTR//HSYNC Start Position[4:0]
        LCD_DataWrite(0x00); //HSYNC Start Position(PCLK) = (HSTR + 1)*8
        LCD_CmdWrite(0x18);         //HPWR//HSYNC Polarity ,The period width of HSYNC.
        LCD_DataWrite(0x05); //HSYNC Width [4:0]   HSYNC Pulse width(PCLK) = (HPWR + 1)*8

        //垂直设置
        LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
        LCD_DataWrite(0x0f); //Vertical pixels = VDHR + 1         = 10f+1=272
        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(0x02); //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(0x07); //VSYNC Start Position(PCLK) = (VSTR + 1)
        LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
        LCD_DataWrite(0x00); //VSYNC Start Position(PCLK) = (VSTR + 1)
        LCD_CmdWrite(0x1f);         //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
        LCD_DataWrite(0x09); //VSYNC Pulse Width(PCLK) = (VPWR + 1)
       
        //Active window set
        //setting active window X
        Write_Dir(0x30,0x00);
        Write_Dir(0x31,0x00);
        Write_Dir(0x34,0xdf);
        Write_Dir(0x35,0x01);
       
        //setting active window Y
        Write_Dir(0x32,0x00);
        Write_Dir(0x33,0x00);
        Write_Dir(0x36,0x0f);
        Write_Dir(0x37,0x01);
        for(i = 0; i<10000;i++);
       
        LCD_CmdWrite(0x04);    //PCLK
        LCD_DataWrite(0x00);   //PCLK频率周期 = 系统频率周期

        LCD_CmdWrite(0x8a);//PWM控制设置
        LCD_DataWrite(0x80);//打开PWM
        LCD_CmdWrite(0x8a);//PWM控制设置
        LCD_DataWrite(0x81);//开启PWM
        LCD_CmdWrite(0x8b);//背光亮度
        LCD_DataWrite(0x7f);//亮度参数0xff-0x00
       
        Write_Dir(0x40,0x00);        //绘图模式 0为→↓,1为←↓,2为↑→,3为↓→
        Write_Dir(0x41,0x00);        //图形光标,图层选择
       
        //         ra8875.Write_Dir(0x8b,0x7f);//背光亮度调节 0x3f:25% ;ox7f:50% ;0xff:100%
//         for(i = 0; i<10000;i++);
       
        return 0;
       
}

/*
* Name                                        : Active_Window
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 设置工作窗口区域
*/

static int Active_Window(int XL,int XR ,int YT ,int YB)
{
       
        int temp;
        //setting active window X
        temp=XL;   
        LCD_CmdWrite(0x30);//HSAW0  设置开始X
        LCD_DataWrite(temp);
        temp=XL>>8;   
        LCD_CmdWrite(0x31);//HSAW1          
        LCD_DataWrite(temp);

        temp=XR;   
        LCD_CmdWrite(0x34);//HEAW0  设置结束Y
        LCD_DataWrite(temp);
        temp=XR>>8;   
        LCD_CmdWrite(0x35);//HEAW1          
        LCD_DataWrite(temp);

        //setting active window Y
        temp=YT;   
        LCD_CmdWrite(0x32);//VSAW0  设置开始Y
        LCD_DataWrite(temp);
        temp=YT>>8;   
        LCD_CmdWrite(0x33);//VSAW1          
        LCD_DataWrite(temp);

        temp=YB;   
        LCD_CmdWrite(0x36);//VEAW0  设置结束Y
        LCD_DataWrite(temp);
        temp=YB>>8;   
        LCD_CmdWrite(0x37);//VEAW1          
        LCD_DataWrite(temp);
       
        return 0;
}

/*
* Name                                        : Text_Background_Color1
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 背景颜色设置
*/
static int Text_Background_Color1(unsigned int b_color)
{       
        LCD_CmdWrite(0x60);//BGCR0
        LCD_DataWrite((int)((b_color & 0xf800 )>>11));
       
        LCD_CmdWrite(0x61);//BGCR0
        LCD_DataWrite((int)((b_color & 0x07e0 )>>5));
       
        LCD_CmdWrite(0x62);//BGCR0
        LCD_DataWrite((int)((b_color & 0x001f)));
       
        return 0;
}

static int Text_Background_Color(unsigned int setR,unsigned int setG,unsigned int setB)
{
        LCD_CmdWrite(0x60);//BGCR0
        LCD_DataWrite(setR);
   
        LCD_CmdWrite(0x61);//BGCR0
        LCD_DataWrite(setG);

        LCD_CmdWrite(0x62);//BGCR0
        LCD_DataWrite(setB);
       
        return 0;
}


/*
* Name                                        : Text_Foreground_Color1
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 前景颜色设置
*/
static int Text_Foreground_Color1(unsigned int b_color)
{
               
        LCD_CmdWrite(0x63);//BGCR0
        LCD_DataWrite((int)((b_color & 0xf800 )>>11));
       
        LCD_CmdWrite(0x64);//BGCR0
        LCD_DataWrite((int)((b_color & 0x07e0 )>>5));
       
        LCD_CmdWrite(0x65);//BGCR0
        LCD_DataWrite((int)((b_color & 0x001f)));
       
        return 0;
}


static int Text_Foreground_Color(unsigned int setR,unsigned int setG,unsigned int setB)
{            
    LCD_CmdWrite(0x63);//BGCR0
        LCD_DataWrite(setR);
   
    LCD_CmdWrite(0x64);//BGCR0
        LCD_DataWrite(setG);

    LCD_CmdWrite(0x65);//BGCR0
        LCD_DataWrite(setB);
       
        return 0;
}


/*
* Name                                        : Draw_Circle
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 画圆
*/
static int Draw_Circle(int X,int Y,int R)
{
       
        int temp;
   
        temp=X;   
        LCD_CmdWrite(0x99);
        LCD_DataWrite(temp);
        temp=X>>8;   
        LCD_CmdWrite(0x9a);          
        LCD_DataWrite(temp);  
          
        temp=Y;   
        LCD_CmdWrite(0x9b);
        LCD_DataWrite(temp);
        temp=Y>>8;   
        LCD_CmdWrite(0x9c);          
        LCD_DataWrite(temp);

        temp=R;   
        LCD_CmdWrite(0x9d);
        LCD_DataWrite(temp);
       
       
        return 0;
}
/*
* Name                                        : BTE_Size
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 椭圆
*/
static int Draw_Ellipse(int X,int Y,int R1,int R2)
{
        LCD_CmdWrite(0xA5);
        LCD_DataWrite(X);

        LCD_CmdWrite(0xA7);
        LCD_DataWrite(Y);

        LCD_CmdWrite(0xA1);
        LCD_DataWrite(R1);
   
        LCD_CmdWrite(0xA3);
        LCD_DataWrite(R2);
       
        return 0;

}

/*
* Name                                        : BTE_Size
* Description        : ---
* Author                                : momo.
*
* History
* ----------------------
* Rev                                        : 0.00
* Date                                        : 07/19/2013
*
* create.
* ----------------------
* 画线、矩形、三角形
*/
static int Draw_Line(int XS,int XE ,int YS,int YE)
{       
       
         int temp;   
        temp=XS;   
    LCD_CmdWrite(0x91);
        LCD_DataWrite(temp);
        temp=XS>>8;   
    LCD_CmdWrite(0x92);          
        LCD_DataWrite(temp);

        temp=XE;
    LCD_CmdWrite(0x95);
        LCD_DataWrite(temp);
        temp=XE>>8;   
    LCD_CmdWrite(0x96);          
        LCD_DataWrite(temp);

        temp=YS;   
    LCD_CmdWrite(0x93);
        LCD_DataWrite(temp);
        temp=YS>>8;   
    LCD_CmdWrite(0x94);          
        LCD_DataWrite(temp);

        temp=YE;   
    LCD_CmdWrite(0x97);
        LCD_DataWrite(temp);
        temp=YE>>8;   
    LCD_CmdWrite(0x98);          
        LCD_DataWrite(temp);
       
        return 0;

}

沙发
墨如风0205|  楼主 | 2013-8-6 20:25 | 只看该作者
然后在主程序里,打开显示,选择显示模式、图层,设置工作窗口,设置前景色和背景色,为什么液晶的PWM可调,液晶有一定的亮度,但是就是没有颜色,为什么呢?

使用特权

评论回复
板凳
墨如风0205|  楼主 | 2013-8-6 20:26 | 只看该作者
求指教啊,,,

使用特权

评论回复
地板
墨如风0205|  楼主 | 2013-8-7 09:21 | 只看该作者
问题解决了,是DISP没有拉高,液晶终于点亮了

使用特权

评论回复
5
王紫豪| | 2013-8-7 10:43 | 只看该作者
:lol

使用特权

评论回复
6
墨如风0205|  楼主 | 2013-8-9 14:57 | 只看该作者
王紫豪 发表于 2013-8-7 10:43

:)

使用特权

评论回复
7
chuangpu| | 2013-8-9 20:13 | 只看该作者
尼玛  调程序时   真的是折磨啊   终于出来了   恭喜楼主  

使用特权

评论回复
8
墨如风0205|  楼主 | 2013-8-14 20:54 | 只看该作者
chuangpu 发表于 2013-8-9 20:13
尼玛  调程序时   真的是折磨啊   终于出来了   恭喜楼主

谢谢,写代码真是件耐心活,哎

使用特权

评论回复
9
夜神荣| | 2015-4-25 17:31 | 只看该作者
求楼主发个例程共享啊,造福一下大家:)

使用特权

评论回复
10
Serge_Ding| | 2015-4-25 19:49 | 只看该作者
查找问题,分析原因,是件很痛苦的事

使用特权

评论回复
11
598330983| | 2015-4-25 22:23 | 只看该作者
static int LCD_Reset(void);

使用特权

评论回复
12
598330983| | 2015-4-25 22:25 | 只看该作者
查找问题,分析原因,是件很痛苦的事

使用特权

评论回复
13
周董| | 2015-4-26 12:30 | 只看该作者
提示: 该帖被管理员或版主屏蔽
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:不畏将来,不念过往。如此,安好!

4

主题

111

帖子

0

粉丝