TM 320*240のMSP 430駆動

18497 ワード

TM 320*240、コントローラはRA 8806である.
1、DDRAM 1、DDRAM 2があり、二層表示機能を有する.
2.インタフェースおよび動作はLCD 12864と同様である.
3、コントローラに多くのレジスタの値を配置する必要があります.基本的な操作方法は、レジスタアドレスを書き、レジスタ内容を書き、表示データを書き、表示データを読み、忙しいと判断することです.
4、文字を書くステップ:a.表示位置を設定する.レジスタ0 x 60[seg]、0 x 70[com]の値を設定することにより実現される.b.メモリ書き込み命令.c.データを書く.
.cファイル
//=================================    ==================================//

//Ver:2011082301

//Author:XZQ

//Note:      :   。 DDRAM2      ,  ,   ; DDRAM1    、  

//===========================================================================//

#include "TM320X240_Driver.h"



/*******************************************

    :LCD_CmdWrite

      :              

      :unsigned char cmdaddr,unsigned char wrdata

          cmdaddr         wrdata      

     : 

********************************************/

void LCD_CmdWrite(unsigned char cmdaddr,unsigned char wrdata)//8080

{

      CtrlDIR |=0xff;

      DataDIR |=0xff;

      CtrlOUT &=~lcd_cs1;  //cs1=0;

      CtrlOUT |=lcd_rd;    //rd=1;

      CtrlOUT |=lcd_rs;    //rs=1;

      DataOUT  =cmdaddr;

      delay_us(1);

      CtrlOUT &=~lcd_wr;   //wr=0;

      delay_us(1);

      CtrlOUT |=lcd_wr;    //wr=1;

      CtrlOUT |=lcd_cs1;   //cs1=1;



      CtrlOUT &=~lcd_cs1;  //cs1=0;

      CtrlOUT |=lcd_rd;    //rd=1;

      CtrlOUT &=~lcd_rs;   //rs=0;

      delay_us(1);

      DataOUT=wrdata;

      delay_us(1);

      CtrlOUT &=~lcd_wr;   //wr=0;

      delay_us(1);

      CtrlOUT |=lcd_wr;    //wr=1;

      CtrlOUT |=lcd_cs1;   //cs1=1;

      delay_us(1);

}



/*******************************************

    :LCD_DataWrite

      :         

      :unsigned char wrdata

     : 

********************************************/

void LCD_DataWrite(unsigned char wrdata)

{  

      CtrlDIR |=0xff;

      DataDIR |=0xff;

      CtrlOUT &=~lcd_cs1;   //cs1=0;

      CtrlOUT |=lcd_rd;     //rd=1;

      CtrlOUT &=~lcd_rs;    //rs=0;

      DataOUT = wrdata;

      delay_us(1);

      CtrlOUT &=~lcd_wr;    //wr=0;

      delay_us(1);

      CtrlOUT |=lcd_wr;     //wr=1;

      CtrlOUT |=lcd_cs1;    //cs1=1;

}

/*******************************************

    :LCD_RegWrite

      :     

      :unsigned char reg。     

     : 

********************************************/

void LCD_RegWrite(unsigned char reg)

{  

      CtrlDIR |=0xff;

      DataDIR |=0xff; 

      CtrlOUT &=~lcd_cs1;  //cs1=0;

      CtrlOUT |=lcd_rd;    //rd=1;

      CtrlOUT |=lcd_rs;    //rs=1;

      DataOUT=reg;

      delay_us(1);

      CtrlOUT &=~lcd_wr;   //wr=0;

      delay_us(1);

      CtrlOUT |=lcd_wr;    //wr=1;

      CtrlOUT |=lcd_cs1;   //cs1=1;

      delay_us(1);

}

/*******************************************

    :LCD_DataRead

      :        

      : 

     :unsigned char data   

********************************************/

unsigned char LCD_DataRead(void)

{

   unsigned char data;

   LCD_ChkBusy();

   DataDIR|=0xFF;      //       

   DataOUT=0xff;       //lcd_data = 0xff

   DataDIR&=~0xFF;     //       

   

   CtrlOUT|=lcd_wr;    //lcd_wr = 1 bWRZ = 1;

   CtrlOUT&=~lcd_cs1;  //lcd_cs1 =0,chINT enable  bCSZ = 0;

   CtrlOUT&=~lcd_rs;   //lcd_rs = 0//       bA0  = 0;

   CtrlOUT&=~lcd_rd;   //lcd_rd = 0  bRDZ = 0;

   

   data = DataIN;

   CtrlOUT|=lcd_rd;    //lcd_rd = 1   bRDZ = 1;

   CtrlOUT|=lcd_cs1;   //lcd_cs1 =1,chINT disable   bCSZ = 1;

   CtrlOUT|=lcd_rs;    //lcd_rs = 1

   

   DataDIR|=0xFF;      //       

   DataOUT=0xff;       //lcd_data = 0xff

   return(data);

}

/*******************************************

    :lcd_data_read

      : DDRAM    

      : 

     :unsigned char data   

********************************************/

unsigned char lcd_data_read(void)      // DDRAM    

{

  unsigned char data;

  LCD_RegWrite(0XB1);

  data=LCD_DataRead();   

  return(data);

}

/*******************************************

    :LCD_StatusRead

      :      

      : 

     :unsigned char data   

********************************************/

unsigned char LCD_StatusRead(void)

{

   unsigned char data;

   

   DataDIR|=0xFF;      //       

   DataOUT=0xff;       //lcd_data = 0xff

   DataDIR&=~0xFF;     //       

   

   

   CtrlOUT|=lcd_wr;    //lcd_wr = 1 bWRZ = 1;

   CtrlOUT&=~lcd_cs1;  //lcd_cs1 =0,chINT enable  bCSZ = 0;

   

   CtrlOUT|=lcd_rs;    //lcd_rs = 1//     bA0  = 1;

   CtrlOUT&=~lcd_rd;   //lcd_rd = 0  bRDZ = 0;

   

   data = DataIN;

   CtrlOUT|=lcd_rd;    //lcd_rd = 1   bRDZ = 1;

   CtrlOUT|=lcd_cs1;   //lcd_cs1 =1,chINT disable   bCSZ = 1;

   CtrlOUT|=lcd_rs;    //lcd_rs = 1

  

   DataDIR|=0xFF;      //       

   DataOUT=0xff;       //lcd_data = 0xff

   return(data);

}

/*******************************************

    :LCD_ChkBusy

      :  

      : 

     : 

********************************************/

void LCD_ChkBusy(void)

{

   uchar temp;

   do

    {

      temp = LCD_StatusRead();

    }while((temp & 0xc0));

}





/*******************************************

    :LCD_Rst

      :TM320X240    

      : 

     : 

********************************************/

void LCD_Rst()

{   

     CtrlDIR |=0xff;

     CtrlOUT &=~lcd_cs1;  //cs1=0;

     CtrlOUT |=lcd_rd;    //rd = 1;

     CtrlOUT &=~lcd_rst;  //rst=0;

     delay_ms(300);//300ms

     CtrlOUT |=lcd_rst;   //rst=1;

     delay_ms(100);//100ms

}

/*******************************************

    :lcd_inital

      :TM320X240     

      : 

     : 

********************************************/

void lcd_inital()

{ 

      LCD_CmdWrite(WLCR,0x00);		//[00H] , Default --> 0x00     ,      

      LCD_CmdWrite(MISC,0x08);		//[01H] , Default --> 0x00      seg 0-319 com 0-239

      LCD_CmdWrite(ADSR,0x00);		//[03H] , Default --> 0x00       

      LCD_CmdWrite(INTR,0x00);          //[0FH] , Default --> 0x10      .0x00        

      LCD_CmdWrite(WCCR,0x00);		//[10H] , Default --> 0x00   DDRAM      1,     ,     

      LCD_CmdWrite(CHWI,0x00);		//[11H] , Default --> 0x00        

      LCD_CmdWrite(MAMR,0x33);		//[12H] , Default --> 0x11      ,    DDRAM1/DDRAM2,      'OR'

      LCD_CmdWrite(AWRR,0x27);		//[20H] , Default --> 0x27       

      LCD_CmdWrite(DWWR,0x27);		//[21H] , Default --> 0x27        

      LCD_CmdWrite(AWBR,0xEF);		//[30H] , Default --> 0xEF       	

      LCD_CmdWrite(DWHR,0xEF);		//[31H] , Default --> 0xEF       

      LCD_CmdWrite(AWLR,0x00);		//[40H] , Default --> 0x00       

      LCD_CmdWrite(DWLR,0x00);		//[41H] , Default --> 0x00       

      LCD_CmdWrite(AWTR,0x00);		//[50H] , Default --> 0x00       

      LCD_CmdWrite(DWTR,0x00);		//[51H] , Default --> 0x00       

      LCD_CmdWrite(CURX,0x00);		//[60H] , Default --> 0x00   segment     [0-39]

      LCD_CmdWrite(BGSG,0x00);		//[61H] , Default --> 0x00       seg  

      LCD_CmdWrite(EDSG,0x00);		//[62H] , Default --> 0x00       seg  

      LCD_CmdWrite(CURY,0x00);		//[70H] , Default --> 0x00   common     [0-239]

      LCD_CmdWrite(BGCM,0x00);		//[71H] , Default --> 0x00       com   

      LCD_CmdWrite(EDCM,0x00);		//[72H] , Default --> 0x00       com  

      LCD_CmdWrite(BTMR,0x00);		//[80H] , Default --> 0x00            

      LCD_CmdWrite(ITCR,0x27);		//[90H] , Default --> 0x00       

      LCD_CmdWrite(KSCR1,0x00);	        //[A0H] , Default --> 0x00       

      LCD_CmdWrite(KSCR2,0x00);	        //[A1H] , Default --> 0x00       

      LCD_CmdWrite(KSDR0,0x00);	        //[A2H] , Default --> 0x00       

      LCD_CmdWrite(KSDR1,0x00);	        //[A3H] , Default --> 0x00       

      LCD_CmdWrite(KSDR2,0x00);	        //[A3H] , Default --> 0x00       

      LCD_CmdWrite(PCR,0x40);		//[D0H] , Default --> 0x00 PWM  

      LCD_CmdWrite(PDCR,0x00);		//[D1H] , Default --> 0x00 PWM  

      LCD_CmdWrite(PNTR,0x00);		//[E0H] , Default --> 0x00    DDRAM    

      LCD_CmdWrite(FNCR,0x00);		//[F0H] , Default --> 0x00 ASCII          

      LCD_CmdWrite(FVHT,0x00);		//[F1H] , Default --> 0x00            	

}

/*******************************************

    :DrawPicture

      :TM320X240    

      :unsigned char const *m。       

     : 

      :         、    。    DDRAM2

********************************************/

void DrawPicture(unsigned char const *m)

{

      unsigned int y=0,x=0,c=0; 

      //LCD_CmdWrite(0xf0,0xa8);//ISO 8859  ,        , PNTR        

      LCD_CmdWrite(FNCR,0xa8);//ISO 8859  ,        , PNTR        

      LCD_CmdWrite(WLCR,0x04);//       

      LCD_CmdWrite(CURX,0x00);//  seg    0

      LCD_CmdWrite(CURY,0x00);//  com    0

      LCD_CmdWrite(CHWI,0x00);//       8,   1,   1

      LCD_CmdWrite(WCCR,0x00);	//[10H] , Default --> 0x00   DDRAM      1,     ,     

      LCD_CmdWrite(MAMR,0x32);//       ,  DDRAM2 

      LCD_RegWrite(MWCR);     //       

      for(y=0;y<240;y++)

      {

          for(x=0;x<40;x++)

          {

            LCD_DataWrite(m[c++]); 

            LCD_CmdWrite(CHWI,0x00);//       8,   1,   1

            delay_us(10);

            LCD_CmdWrite(MAMR,0x32);//     ,  DDRAM2 

            delay_us(10);

            LCD_RegWrite(MWCR);//        

            delay_us(10);

          }   

      }   

}

/*******************************************

    :Clear_DDRAM1

      :    

      : 

     : 

********************************************/

void Clear_DDRAM1(void)

{

      LCD_CmdWrite(MAMR,0x31);	//  DDRAM1,    DDRAM1/DDRAM2

      LCD_CmdWrite(0xE0,0x00);//   DDRAM   。    0XF0 BIT3=1 ,   

                              //     

      LCD_CmdWrite(0xF0,0xA8);//        , 0XE0      

      delay_ms(50);

}

/*******************************************

    :Clear_All

      :

      : 

     : 

********************************************/

void Clear_All()

{

      LCD_CmdWrite(MAMR,0x33);	//       ,    DDRAM1/DDRAM2

      LCD_CmdWrite(0xE0,0x00);  //   DDRAM   。    0XF0 BIT3=1 ,   

                              //     

      LCD_CmdWrite(0xF0,0xA8);//        , 0XE0      

      delay_ms(30);

} 

/*******************************************

    :LCD_show_str

      :     

      :unsigned char *text。      

     : 

      :        ,           

           ,AC     

      : DDRAM1   

********************************************/

void LCD_show_str(unsigned char *text)

{ 

      LCD_CmdWrite(0x00,0x0c);//    

      LCD_CmdWrite(MAMR,0x31);//  DDRAM1

      while(*text != '\0')          

	{

          LCD_RegWrite(0xb0);

    	  LCD_DataWrite(*text);

    	  ++text; 

          delay_us(20);

        }

}

/*******************************************

    :Disp_char

      :       

      :uchar x,uchar y.       

          unsigned char *text。      

     : 

      :       ASCII  , DDRAM1   

                      ,        2   

********************************************/

void Disp_char(uchar x,uchar y,unsigned char *text)

{ 

    LCD_CmdWrite(0x60,x);//segment address 

    LCD_CmdWrite(0x70,y);//common address

    LCD_show_str(text); 

}

/*******************************************

    :LCD_point

      :   (x,y)  

      :int x,int y

     : 

      : -----0---x---319----------

          |0

          |y

          |239

           DDRAM1   

********************************************/

void LCD_point(int x,int y)

{

    uchar x_d,x_b,x_bb,r_d;

    x_d=x/8;

    x_b=x%8;

    switch(x_b)

    {

    case 0x00:x_bb=0x80;break;

    case 0x01:x_bb=0x40;break;

    case 0x02:x_bb=0x20;break;

    case 0x03:x_bb=0x10;break;

    case 0x04:x_bb=0x08;break;

    case 0x05:x_bb=0x04;break;

    case 0x06:x_bb=0x02;break;

    case 0x07:x_bb=0x01;break;

    }

    LCD_CmdWrite(0x00,0x04);

    LCD_CmdWrite(0x60,x_d); 

    LCD_CmdWrite(0x70,y); 

    r_d=lcd_data_read();

    x_bb |=r_d;

    LCD_CmdWrite(0x60,x_d); 

    LCD_CmdWrite(0x70,y);

    LCD_CmdWrite(MAMR,0x31);//  DDRAM1

    LCD_RegWrite(0xb0);

    LCD_DataWrite(x_bb);

}

/*******************************************

    :Draw_Line

      :TM320X240     

      :int x0, int y0, int x1, int y1

             (x0,y0),  (x1,y1)

     : 

      : -----0---x---319----------

          |0

          |y

          |239

********************************************/

void Draw_Line(int x0, int y0, int x1, int y1)

{

    unsigned int  x,y;

    unsigned int  dx; // = abs(x1 - x0);

    unsigned int  dy; // = abs(y1 - y0);



    if(y0==y1)

    {

      if(x0<=x1)

      {

         x=x0;

      }

      else

      {

         x=x1;

         x1=x0;

      }

      while(x <= x1)

      {

         LCD_point(x,y0);

         x++;

      }

      return;

    }

    else if(y0>y1)

    {

        dy=y0-y1;

    }

    else

    {

        dy=y1-y0;

    }



    if(x0==x1)

    {

        if(y0<=y1)

        {

          y=y0;

        }

        else

        {

          y=y1;

          y1=y0;

        }

        while(y <= y1)

        {

          LCD_point(x0,y);

          y++;

        }

        return;

    }

    else if(x0 > x1)

    {

      dx=x0-x1;

      x = x1;

      x1 = x0;

      y = y1;

      y1 = y0;

    }

    else

    {

      dx=x1-x0;

      x = x0;

      y = y0;

    }



    if(dx == dy)

    {

      while(x <= x1)

      {

        x++;

        if(y>y1)

        {

           y--;

        }

        else

        {

           y++;

        }

        LCD_point(x,y);

      }

    }

    else

    {

      LCD_point(x, y);

      if(y < y1)

      {

          if(dx > dy)

          {

          int p = dy * 2 - dx;

          int twoDy = 2 * dy;

          int twoDyMinusDx = 2 * (dy - dx);

              while(x < x1)

              {

                  x++;

                  if(p < 0)

                  {

                    p += twoDy;

                  }

                  else

                  {

                    y++;

                    p += twoDyMinusDx;

                  }

                  LCD_point(x, y);

              }

          }

          else

          {

          int p = dx * 2 - dy;

          int twoDx = 2 * dx;

          int twoDxMinusDy = 2 * (dx - dy);

              while(y < y1)

              {

                  y++;

                  if(p < 0)

                  {

                     p += twoDx;

                  }

                  else

                  {

                    x++;

                    p+= twoDxMinusDy;

                  }

                  LCD_point(x, y);

              }

          }

      }

      else

      {

        if(dx > dy)

        {

            int p = dy * 2 - dx;

            int twoDy = 2 * dy;

            int twoDyMinusDx = 2 * (dy - dx);

            while(x < x1)

            {

              x++;

              if(p < 0)

              {

                p += twoDy;

              }

              else

              {

                y--;

                p += twoDyMinusDx;

              }

              LCD_point(x, y);

            }

        }

        else

        {

          int p = dx * 2 - dy;

          int twoDx = 2 * dx;

          int twoDxMinusDy = 2 * (dx - dy);

          while(y1 < y)

          {

              y--;

              if(p < 0)

              {

                  p += twoDx;

              }

              else

              {

                   x++;

                   p+= twoDxMinusDy;

              }

              LCD_point(x, y);

          }

        }

      }

    }

}


.hファイル
//=================================    ==================================//

//Ver:2011082301

//Author:XZQ

//===========================================================================//

#ifndef _TM320X240_DRIVER_H

#define _TM320X240_DRIVER_H



#include <msp430f5438.h>

#include "MCU_Init.h"

#include "RA8806Reg.h"

/*********************TM320X240    *****************************/

//    P7    

#define CtrlDIR   P7DIR

#define CtrlOUT   P7OUT

#define lcd_rs    BIT2//RS-->L:     ,H:  DDRAM

#define lcd_wr    BIT3//WR--> L  

#define lcd_rd    BIT4//RD--> L  

#define lcd_cs1   BIT5//CS1-->L  

#define lcd_rst   BIT6//RST-->L  

#define lcd_busy  BIT7 //BUSY-->     

//       DB0~DB7

#define DataDIR P3DIR

#define DataOUT P3OUT

#define DataIN  P3IN

#define DataSEL P3SEL



//    

extern void LCD_CmdWrite(unsigned char cmdaddr,unsigned char wrdata);

extern void LCD_DataWrite(unsigned char wrdata);

extern void LCD_RegWrite(unsigned char reg);

extern unsigned char LCD_DataRead(void);

extern unsigned char lcd_data_read(void);

extern unsigned char LCD_StatusRead(void);

extern void LCD_ChkBusy(void);



//      

extern void lcd_inital(void);

extern void LCD_Rst(void);

extern void Clear_DDRAM1(void);

extern void Clear_All(void);



extern void LCD_show_str(unsigned char *text);//    

extern void Disp_char(uchar x,uchar y,unsigned char *text);



extern void LCD_point(int x,int y);//    

extern void DrawPicture(unsigned char const *m);

//      

extern void Draw_Line(int x0, int y0, int x1, int y1);



#endif 


RA 8806コントローラレジスタマクロ定義ファイル
//=================================    ==================================//

//Ver:20110822

//Author:XZQ

//===========================================================================//

#define WLCR	0x00

#define MISC	0x01

#define ADSR	0x03

#define INTR	0x0F

#define WCCR	0x10

#define CHWI    0x11						//new(have change)

#define MAMR	0x12

#define AWRR	0x20

#define DWWR	0x21

#define AWBR	0x30

#define DWHR	0x31						//new(have change)

#define AWLR	0x40

#define DWLR	0x41

#define AWTR	0x50

#define DWTR	0x51

#define CURX	0x60						//new(have change)

#define BGSG	0x61

#define EDSG    0x62						//new

#define CURY	0x70						//new(have change)	

#define BGCM	0x71

#define EDCM	0x72

#define	BTMR	0x80

#define ITCR	0x90						//new(have change)

#define KSCR1	0xA0

#define KSCR2	0xA1

#define KSDR0  	0xA2						//new(have change)

#define KSDR1  	0xA3

#define KSDR2  	0xA4

#define MWCR	0xB0						//new(have change)

#define MRCR	0xB1						//new

#define TPCR	0xC0

#define TPXR	0xC1

#define TPYR	0xC2

#define TPZR	0xC3

#define PCR     0xD0						//new(have change)

#define PDCR    0xD1						//new

#define PNTR	0xE0

#define FNCR	0xF0

#define FVHT	0xF1