/*********************************************************************
* *
* 3.2TFT液晶测试 *
* ( 普中科技 ) *
* *
*
*实验现象:彩屏中显示汉字、数字、字母! *
* *
***********************************************************************/
#include
//#include
#include "lcd.h"
uint colors[]=
{
0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff
};
/**********************************************************
主函数
**********************************************************/
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL2|=SELM_2+DIVM0;
P3SEL=0x00;
P4SEL=0x00;
unsigned char i,ii;
LCD_DataOut;
LCD_CMDOut;
LCD_init();
for(ii=0;ii<7;ii++)
LCD_clear(ii); //刷屏测试
LCD_clear(2);
for(i=0;i<8;i++)
{
ChineseChar(60,20+i*50,2,colors[5],colors[2],1); //普
ChineseChar(90,20+i*50,2,colors[5],colors[2],2); //中
ChineseChar(120,20+i*50,2,colors[5],colors[2],3); //科
ChineseChar(150,20+i*50,2,colors[5],colors[2],4); //技
}
while(1) ;
}
/**********************************************************
* *
* 彩屏驱动程序 *
* *
**********************************************************/
#include
#include "Lcd.h"
#include "char.h"
#include "chinese.h"
//#include
/**********************************************************
延时子函数
**********************************************************/
void delay_MS(uint ms)
{
unsigned int k;
while (ms--)
{
for (k = 0; k <150; k++) _NOP();
}
}
/**********************************************************
写命令与数据子函数
**********************************************************/
void LCD_Write(uchar type, uint value)
{
LCD_CS_L;
if(type==0x00)
LCD_RS_L;
else LCD_RS_H; // 0: command 1: data
LCD_WR_L;
LCD_DataOut;
MCU2LCD_Data= (uchar)(value>>8) ;
LCD_WR_H;
_NOP();
LCD_WR_L;
MCU2LCD_Data = (uchar)value;
LCD_WR_H;
_NOP();
LCD_CS_H;
}
/**********************************************************
写8位数据子函数
**********************************************************/
void LCD_Write_Data8(uchar value) // color data
{
LCD_CS_L;
LCD_RS_H;
LCD_WR_L;
LCD_DataOut;
MCU2LCD_Data= value;
LCD_WR_H;
LCD_CS_H;
}
/**********************************************************
写16位数据子函数
**********************************************************/
void LCD_Wirte_Data16(uint value) // color data
{
LCD_CS_L;
LCD_RS_H;
LCD_WR_L;
//DATA = (uchar)value;
LCD_DataOut;
MCU2LCD_Data= (uchar)(value>>8) ;
LCD_WR_H;
LCD_WR_L;
//DATA = (uchar)(value>>8) ;
MCU2LCD_Data= (uchar)value;
LCD_WR_H;
LCD_CS_H;
}
/* *********************************************************
// * ********************************************************
// 写寄存器子函数
// ********************************************************* */
void Reg_Write(uint reg,uint value)
{
LCD_Write(TYPE_LCD_COMMAND,reg);
LCD_Wirte_Data16(value);
}
/**********************************************************
设置显示窗口子函数
**********************************************************/
void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{
Reg_Write(0x200, xStart);
Reg_Write(0x201, yStart);
Reg_Write(0x0210, xStart);
Reg_Write(0x0212,yStart);
Reg_Write(0x211,xEnd);
Reg_Write(0x213,yEnd);
// LCD_Write(TYPE_LCD_COMMAND,0x022);
// LCD_Write(TYPE_LCD_COMMAND,0x0202); // 0x22
LCD_Write(TYPE_LCD_COMMAND,0x0202);
// delay_MS(500);
}
void LCD_init(void)
{
LCD_RST_H;
delay_MS(5);
LCD_RST_L;
delay_MS(5);
LCD_RST_H;
delay_MS(5);
LCD_CS_L; //打开片选使能
Reg_Write(0x000,0x0000); delay_MS(5);
Reg_Write(0x000,0x0000); delay_MS(5);
Reg_Write(0x000,0x0000);delay_MS(5);
Reg_Write(0x000,0x0000); delay_MS(5);
delay_MS(100);
LCD_Wirte_Data16(0x0000);delay_MS(5);
LCD_Wirte_Data16(0x0000);delay_MS(5);
LCD_Wirte_Data16(0x0000);delay_MS(5);
LCD_Wirte_Data16(0x0000); delay_MS(5);
delay_MS(100);
Reg_Write(0x400,0x6200);delay_MS(5);
Reg_Write(0x008,0x0808); delay_MS(5);
// Reg_Write(0x010,0x0010);
Reg_Write(0x300,0x0c0c);delay_MS(5);//GAMMA
Reg_Write(0x301,0xff13); delay_MS(5);
Reg_Write(0x302,0x0f0f); delay_MS(5);
Reg_Write(0x303,0x150b); delay_MS(5);
Reg_Write(0x304,0x1020); delay_MS(5);
Reg_Write(0x305,0x0a0b); delay_MS(5);
Reg_Write(0x306,0x0003);delay_MS(5);
Reg_Write(0x307,0x0d06); delay_MS(5);
Reg_Write(0x308,0x0504); delay_MS(5);
Reg_Write(0x309,0x1030); delay_MS(5);
Reg_Write(0x010,0x001b);delay_MS(5); //60Hz
Reg_Write(0x011,0x0101);delay_MS(5);
Reg_Write(0x012,0x0000);delay_MS(5);
Reg_Write(0x013,0x0001);delay_MS(5);
Reg_Write(0x100,0x0330);delay_MS(5);//BT,AP 0x0330
Reg_Write(0x101,0x0247);delay_MS(5);//DC0,DC1,VC
Reg_Write(0x103,0x1000);delay_MS(5);//VDV //0x0f00
Reg_Write(0x280,0xbf00);delay_MS(5);//VCM
Reg_Write(0x102,0xd1b0);delay_MS(5);//VRH,VCMR,PSON,PON
delay_MS(1220);
Reg_Write(0x001,0x0100);delay_MS(5);
Reg_Write(0x002,0x0100);delay_MS(5);
Reg_Write(0x003,0x1030); delay_MS(5);
Reg_Write(0x009,0x0001);delay_MS(5);
Reg_Write(0x0C,0x0000);delay_MS(5); //MCU interface
Reg_Write(0x090,0x8000);delay_MS(5);
Reg_Write(0x00f,0x0000);delay_MS(5);
Reg_Write(0x210,0x0000);delay_MS(5);
Reg_Write(0x211,0x00ef);delay_MS(5);
Reg_Write(0x212,0x0000);delay_MS(5);
Reg_Write(0x213,0x018f); delay_MS(5);
Reg_Write(0x500,0x0000); delay_MS(5);
Reg_Write(0x501,0x0000); delay_MS(5);
Reg_Write(0x502,0x005f); delay_MS(5);
Reg_Write(0x401,0x0001); delay_MS(5);
Reg_Write(0x404,0x0000); delay_MS(5);
delay_MS(500);
Reg_Write(0x0007,0x0100);delay_MS(5);
delay_MS(1000);
Reg_Write(0x200,0x0000);delay_MS(5);
Reg_Write(0x201,0x0000);delay_MS(5);
delay_MS(500);
LCD_Write(TYPE_LCD_COMMAND,0x0202);
delay_MS(500);
}
/**********************************************************
清屏子函数
**********************************************************/
void LCD_clear(unsigned char x)
{
unsigned int com,seg;
LCD_SetRamAddr(0,239, 0,399);
// delay_MS(100);
for(com=0;com<400;com++)
{
for(seg=0;seg<240;seg++)
{
LCD_Wirte_Data16(colors[x]);
}
}
}
/**********************************************************
字符显示子函数
**********************************************************/
void LCD_ShowChar(uchar x,uchar y,uint For_color,uint Bk_color, char ch)
{
uchar temp;
uchar pos,t;
uchar CHAR_W,CHAR_H;
CHAR_W = 8; //8*16
CHAR_H = 16;
if(x>(LCD_SIZE_X-CHAR_W)||y>(LCD_SIZE_Y-CHAR_H))
return;
LCD_SetRamAddr(x, x+CHAR_W-1, y,y+CHAR_H-1);
ch = ch-32; //按照ASCII编码顺序的到相应字母的编码
for(pos=0;pos
{
temp= Font8x16[ch][pos];
for(t=0;t
{
if(temp&0x80)
LCD_Wirte_Data16(For_color); //textcolor
else
LCD_Wirte_Data16(Bk_color); //backcolor
temp<<=1;
}
}
}
/**********************************************************
显示字符串子函数
x,y:起点坐标
*p:字符串起始地址
**********************************************************/
void LCD_ShowString(uchar x,uchar y,uint For_color,uint Bk_color,char *p)
{
while(*p!=' |