TM320*240, controller is RA8806.
1. There are DDRAM1 and DDRAM2, which have double-layer display function.
2. The interface and operation are similar to LCD12864.
3. The controller needs to be configured with many register values. The basic operation methods are to write register address, write register content, write display data, read display data, and judge busy.
4. Steps for writing text characters: a. Set the display position. This is achieved by setting the values of registers 0x60[seg], 0x70[com]. b. Write instructions to the memory. c. Write data.
.c files
//================================Version information===================================//
//Ver:2011082301
//Author:XZQ
//Note: Display mode example: oscilloscope. Display background information, grid, coordinates, etc. in DDRAM2; display waveform and data in DDRAM1
//================================================================================//
#include "TM320X240_Driver.h"
/*******************************************
Function name: LCD_CmdWriteFunction
: Select register and write data to register
Parameters: unsigned char cmdaddr, unsigned char wrdata
cmdaddr register address to be written wrdata content to be written
Return value: None
********************************************/
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_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);
lcd_wr; //wr=1;
CtrlOUT |=lcd_cs1; //cs1=1;
delay_us(1);
}
/*******************************************
Function name: LCD_DataWriteFunction
: Write display data to LCD
Parameter: unsigned char wrdataReturn
value: None
********************************************/
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;
}
/*******************************************
Function name: LCD_RegWriteFunction
: Select register
Parameter: unsigned char reg. Register address
Return value: None
********************************************/
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);
}
/*******************************************
Function name: LCD_DataReadFunction
: Read display content data
Parameter: None
Return value: unsigned char data status value
********************************************/
unsigned char LCD_DataRead(void)
{
unsigned char data;
LCD_ChkBusy();
DataDIR|=0xFF; //Set to output directionDataOUT
=0xff; //lcd_data = 0xff
DataDIR&=~0xFF; //Set to input directionCtrlOUT
|=lcd_wr; //lcd_wr = 1 bWRZ = 1;
CtrlOUT&=~lcd_cs1; //lcd_cs1 =0,chINT enable bCSZ = 0;
CtrlOUT&=~lcd_rs; //lcd_rs = 0//data selection 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; //Set to output direction
DataOUT=0xff; //lcd_data = 0xff
return(data);
}
/*******************************************
Function name: lcd_data_readFunction
: Read data from DDRAM
Parameter: None
Return value :unsigned char data status value
********************************************/
unsigned char lcd_data_read(void) //Read data from DDRAM
{
unsigned char data;
LCD_RegWrite(0XB1);
data=LCD_DataRead();
return(data);
}
/*******************************************
Function name: LCD_StatusReadFunction
: Read status data
Parameter: None
Return value: unsigned char data status value
********************************************/
unsigned char LCD_StatusRead(void)
{
unsigned char data;
DataDIR|=0xFF; //Set to output directionDataOUT
=0xff; //lcd_data = 0xff
DataDIR&=~0xFF; //Set to input directionCtrlOUT
|=lcd_wr; //lcd_wr = 1 bWRZ = 1;
CtrlOUT&=~lcd_cs1; //lcd_cs1 =0,chINT enable bCSZ = 0;
CtrlOUT|=lcd_rs; //lcd_rs = 1//Command selection 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; //Set to output direction
DataOUT=0xff; //lcd_data = 0xff
return(data);
}
/********************************************
Function name: LCD_ChkBusyFunction
: Busy check
Parameter: None
Return value: None
********************************************/
void LCD_ChkBusy(void)
{
uchar temp;
do
{
temp = LCD_StatusRead();
}while((temp & 0xc0));
}
/*******************************************
Function name: LCD_RstFunction
: TM320X240 reset operation
Parameter: None
Return value: None
********************************************/
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
}
/*******************************************
Function name: lcd_initalFunction
: TM320X240 initialization operation
Parameter: None
Return value: None
********************************************/
void lcd_inital()
{
LCD_CmdWrite(WLCR,0x00); //[00H] , Default --> 0x00 Drawing mode, screen display off
LCD_CmdWrite(MISC,0x08); //[01H] , Default --> 0x00 Scan order seg 0-319 com 0-239
LCD_CmdWrite(ADSR,0x00); //[03H] , Default --> 0x00 Turn off scroll function
LCD_CmdWrite(INTR,0x00); //[0FH] , Default --> 0x10 Turn on touch interrupt. 0x00 Disable all types of interrupt
LCD_CmdWrite(WCCR,0x00); //[10H] , Default --> 0x00 When writing to DDRAM, the cursor automatically increases by 1, turns off cursor display, and turns off cursor flashing
LCD_CmdWrite(CHWI,0x00); //[11H] , Default --> 0x00 Set cursor size
LCD_CmdWrite(MAMR,0x33); //[12H] , Default --> 0x11 Dual layer display, access DDRAM1/DDRAM2 at the same time, the relationship between the two layers is 'OR'
LCD_CmdWrite(AWRR,0x27); //[20H] , Default --> 0x27 Working window boundary
LCD_CmdWrite(DWWR,0x27); //[21H] , Default --> 0x27 Working window boundary
LCD_CmdWrite(AWBR,0xEF); //[30H] , Default --> 0xEF Working window boundary
LCD_CmdWrite(DWHR,0xEF); //[31H] , Default --> 0xEF Working window boundary
LCD_CmdWrite(AWLR,0x00); //[40H] , Default --> 0x00 Working window boundary
LCD_CmdWrite(DWLR,0x00); //[41H] , Default --> 0x00 Working window boundary
LCD_CmdWrite(AWTR,0x00); //[50H] , Default --> 0x00 Working window boundary
LCD_CmdWrite(DWTR,0x00); //[51H] , Default --> 0x00 Working window boundary
LCD_CmdWrite(CURX,0x00); //[60H] , Default --> 0x00 Set segment position range [0-39]
LCD_CmdWrite(BGSG,0x00); //[61H] , Default --> 0x00 Set scroll mode seg starting point
LCD_CmdWrite(EDSG,0x00); //[62H] , Default --> 0x00 Set scroll mode seg starting point
LCD_CmdWrite(CURY,0x00); //[70H] , Default --> 0x00 Set common position range [0-239]
LCD_CmdWrite(BGCM,0x00); //[71H] , Default --> 0x00 Set scroll mode com starting point
LCD_CmdWrite(EDCM,0x00); //[72H] , Default --> 0x00 Set scroll mode com starting point
LCD_CmdWrite(BTMR,0x00); //[80H] , Default --> 0x00 Set cursor blinking and scrolling time
LCD_CmdWrite(ITCR,0x27); //[90H] , Default --> 0x00 Set idle time
LCD_CmdWrite(KSCR1,0x00); //[A0H] , Default --> 0x00 Set keyboard function
LCD_CmdWrite(KSCR2,0x00); //[A1H] , Default --> 0x00 Set keyboard function
LCD_CmdWrite(KSDR0,0x00); //[A2H] , Default --> 0x00 Set keyboard function
LCD_CmdWrite(KSDR1,0x00); //[A3H] , Default --> 0x00 Set keyboard function
LCD_CmdWrite(KSDR2,0x00); //[A3H] , Default --> 0x00 Set keyboard function
LCD_CmdWrite(PCR,0x40); //[D0H] , Default --> 0x00 PWM control
LCD_CmdWrite(PDCR,0x00); //[D1H] , Default --> 0x00 PWM control
LCD_CmdWrite(PNTR,0x00); //[E0H] , Default --> 0x00 Data to be written into DDRAM
LCD_CmdWrite(FNCR,0x00); //[F0H] , Default --> 0x00 ASCII table selection and other text display control
LCD_CmdWrite(FVHT,0x00); //[F1H] , Default --> 0x00 Set the character size to the original size
}
/*******************************************
Function name: DrawPicture
Function: TM320X240 display picture
Parameter: unsigned char const *m. Picture data first address
Return value: None
Description: Modulo method horizontal modulo, byte positive order. Data is written to DDRAM2
********************************************/
void DrawPicture(unsigned char const *m)
{
unsigned int y=0,x=0,c=0;
//LCD_CmdWrite(0xf0,0xa8);//ISO 8859 mode, open the memory clearing function, fill the working window with PNTR data
LCD_CmdWrite(FNCR,0xa8);//ISO 8859 mode, open the memory clearing function, fill the working window with PNTR data
LCD_CmdWrite(WLCR,0x04);//Set to text mode
LCD_CmdWrite(CURX,0x00);//Set seg address to 0
LCD_CmdWrite(CURY,0x00);//Set com address to 0
LCD_CmdWrite(CHWI,0x00);//Set cursor width to 8, height to 1, spacing to 1
LCD_CmdWrite(WCCR,0x00); //[10H] , Default --> 0x00 When writing to DDRAM, the cursor automatically increases by 1, turns off the cursor display, and turns off the cursor flashing
LCD_CmdWrite(MAMR,0x32);//Dual layer display mode, access DDRAM2
LCD_RegWrite(MWCR); //Memory write instruction
for(y=0;y<240;y++)
{
for(x=0;x<40;x++)
{
LCD_DataWrite(m[c++]);
LCD_CmdWrite(CHWI,0x00);//Set the cursor width to 8, height to 1, and spacing to 1
delay_us(10);
LCD_CmdWrite(MAMR,0x32);//Dual layer display, access DDRAM2
delay_us(10);
LCD_RegWrite(MWCR);//Memory write instruction
delay_us(10);
}
}
}
/********************************************
Function name: Clear_DDRAM1Function
: Clear display
Parameter: None
Return value: None
********************************************/
void Clear_DDRAM1(void)
{
LCD_CmdWrite(MAMR,0x31); //Access DDRAM1 and display DDRAM1/DDRAM2 at the same time
LCD_CmdWrite(0xE0,0x00); //Contents to be written to DDRAM. When register 0XF0 BIT3=1, this data
//will fill the window
LCD_CmdWrite(0xF0,0xA8); //Open the memory cleanup function and fill the window with 0XE0 data
delay_ms(50);
}
/*******************************************
Function name: Clear_AllFunction
: Parameter
: None
Return value: None
********************************************/
void Clear_All()
{
LCD_CmdWrite(MAMR,0x33); //Dual layer display mode, access DDRAM1/DDRAM2 at the same time
LCD_CmdWrite(0xE0,0x00); //Contents to be written to DDRAM. When register 0XF0 BIT3=1, this data
//will fill the window
LCD_CmdWrite(0xF0,0xA8); //Turn on the memory cleanup function and fill the window with 0XE0 data
delay_ms(30);
}
/*******************************************
Function name: LCD_show_strFunction
: Display string
Parameter: unsigned char *text. String first address
Return value: None
Description: Display position is not set, so the display position
is the address of AC value before calling this function
Description: Display in DDRAM1
********************************************/
void LCD_show_str(unsigned char *text)
{
LCD_CmdWrite(0x00,0x0c);//Text mode
LCD_CmdWrite(MAMR,0x31);//Access DDRAM1
while(*text != '\0')
{
LCD_RegWrite(0xb0);
LCD_DataWrite(*text);
++text;
delay_us(20);
}
}
/***********************************************
Function name: Disp_char
Function: Display Chinese characters
Parameters: uchar x, uchar y. Display position first address
unsigned char *text. String first address
Return value: None
Description: Can display Chinese and ASCII characters. Display
row position can be single-row stepping and column position can be 2-column stepping in DDRAM1
****************************************/
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);
}
/*******************************************
Function name: LCD_pointFunction
: Dot at coordinate (x,y)
Parameter: int x, int
yReturn value: None
Description: -----0---x---319----------
|0
|y
|239
Display in 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);//Access DDRAM1
LCD_RegWrite(0xb0);
LCD_DataWrite(x_bb);
}
/***************************************** ******
Function name: Draw_LineFunction
: TM320X240 initialization operation
Parameters: int x0, int y0, int x1, int y1Start
point (x0, y0), end point (x1, y1)
Return value: NoneDescription
: --- --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 file
//================================Version Information===================================//
//Ver:2011082301
//Author:XZQ
//================================================================================//
#ifndef _TM320X240_DRIVER_H
#define _TM320X240_DRIVER_H
#include <msp430f5438.h>
#include "MCU_Init.h"
#include "RA8806Reg.h"
/*********************TM320X240 pin interface********************************/
//Control line P7 port
#define CtrlDIR P7DIR
#define CtrlOUT P7OUT
#define lcd_rs BIT2 //RS-->L: access buffer, H: access DDRAM
#define lcd_wr BIT3 //WR--> L valid
#define lcd_rd BIT4 //RD--> L valid
#define lcd_cs1 BIT5 //CS1-->L valid
#define lcd_rst BIT6 //RST-->L valid
#define lcd_busy BIT7 //BUSY-->Detect busy signal
//LCD data pins DB0~DB7
#define DataDIR P3DIR
#define DataOUT P3OUT
#define DataIN P3IN
#define DataSEL P3SEL
//Bottom function
extern void
extern void LCD_DataWrite(unsigned char wrdata);
extern void LCD_RegWrite(unsigned char reg);
extern unsigned char LCD_DataRead(void); extern
unsigned char LCD_StatusRead(void);
extern
void LCD _ChkBusy(void);
//Basic function function
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); //Character display
extern void Disp_char(uchar x,uchar y,unsigned char *text);
extern void LCD_point(int x,int y);//Graphic display
extern void DrawPicture(unsigned char const *m);
//Advanced function
extern void Draw_Line(int x0, int y0, int x1, int y1);
#endif
RA8806 controller register macro definition file
//================================Version Information===================================//
//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 0 xD1 //new
#define PNTR 0xE0
#define FNCR 0xF0
#define FVHT 0xF1
|