由于真彩屏管脚比较多,故选用SPI驱动的真彩屏。我手头上有智林的真彩屏。今天晚上回来点了下居然亮了。
保险起见我也用了模似SPI驱动,其管脚定义如下:
#define clr_RST GpioDataRegs.GPADAT.bit.GPIO4 = 0
#define set_RST GpioDataRegs.GPADAT.bit.GPIO4 = 1
#define clr_CS GpioDataRegs.GPADAT.bit.GPIO5 = 0
#define set_CS GpioDataRegs.GPADAT.bit.GPIO5 = 1
#define clr_SDO GpioDataRegs.GPADAT.bit.GPIO6 = 0 //PORTB &= ~0x02
#define set_SDO GpioDataRegs.GPADAT.bit.GPIO6 = 1 // PORTB |= 0x02
#define clr_CLK GpioDataRegs.GPADAT.bit.GPIO7 = 0
#define set_CLK GpioDataRegs.GPADAT.bit.GPIO7 = 1
也就是说这款TFT真彩屏我只用了四根线就驱动起来了。当然再加上地和3.3V电源共六根线。
工程也很简单:我把同TFT所有文件都放在TFT子录中。
以下是LCD的主要函数:
/******************************************
//测试系统
//芯片:F28027
//电压:3.3V
*/
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include"LCD.h"
/* LCD Registers */
volatile unsigned char Font=0;
/***************************************************
//颜色数值
//红色,绿色,蓝色,黄色,黑色,白色,天蓝色,紫色
****************************************************/
uint color[]={0xF800,0x07E0,0x001F,0xFFE0,0x0000,0xFFFF,0x07FF,0xF81F};
void _delay_ms(unsigned char x)
{
unsigned char i;
for(i=0;i
;
}
/*********************
I/O口初始化
**********************/
void LCD_IO_Init()
{
clr_RST;
_delay_ms(100); // _delay_ms 50ms
set_RST;
}
//===================================================
void SPI_OutB(unsigned char dat)
{
clr_SDO;
if(dat & 0x80)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x40)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x20)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x10)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x8)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x4)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x2)set_SDO;
clr_CLK ;
set_CLK ;
clr_SDO;
if(dat & 0x1)set_SDO;
clr_CLK ;
set_CLK ;
}
//发送命令给液晶
void send_comand(unsigned char cmd)
{
clr_CS;
SPI_OutB(0x70);
SPI_OutB(0x00);
SPI_OutB(cmd);
set_CS;
}
//发送字数据给液晶
void send_data(uint16 dat)
{
clr_CS;
SPI_OutB(0x72);
SPI_OutB(dat>>8);
SPI_OutB(dat);
set_CS;
}
//发送命令和数据
void send_com(unsigned char cmd,unsigned int dat)
{
send_comand(cmd);
send_data(dat);
}
//===================================================
void LCD_Init_ZL(void)
{
//************* Start Initial Sequence **********//
send_com(0x00E7, 0x0010); // Set internal timing
send_com(0x0000, 0x0001); // Start Oscillation
//send_com(0x0001, 0x0100); // set SS and SM bit
send_com(0x0001, 0x0000); // set SS and SM bit
send_com(0x0002, 0x0700); // set 1 line inversion
send_com(0x0003, (1<<12)|(1<<5)|(1<<4)|(1<<3) ); // 65K
send_com(0x0004, 0x0000); // Resize register
send_com(0x0008, 0x0207); // set the back porch and front porch
send_com(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
send_com(0x000A, 0x0000); // FMARK function
send_com(0x000C, 0x0001); // RGB interface setting: 16 bit
send_com(0x000D, 0x0000); // Frame marker Position
send_com(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
send_com(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
send_com(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
send_com(0x0012, 0x0000); // VREG1OUT voltage
_delay_ms(50); // _delay_ms 50ms
send_com(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
_delay_ms(200); // _delay_ms 50ms
send_com(0x0010, 0x1590); // SAP, BT[3:0], AP, DSTB, SLP, STB
send_com(0x0011, 0x0227); // R11h=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0]
_delay_ms(50); // _delay_ms 50ms
send_com(0x0012, 0x009C); // External reference voltage= Vci;
_delay_ms(50); // _delay_ms 50ms
send_com(0x0013, 0x1900); // VDV[4:0] for VCOM amplitude
send_com(0x0029, 0x0023); // VCM[5:0] for VCOMH
send_com(0x002B, 0x000E); // Frame Rate = 40Hz
_delay_ms(50); // _delay_ms 50ms
send_com(0x0020, 0x0000); // GRAM horizontal Address
send_com(0x0021, 0x0000); // GRAM Vertical Address
_delay_ms(50); // _delay_ms 50ms
// ----------- Adjust the Gamma Curve ----------//
send_com(0x0030, 0x0007);
send_com(0x0031, 0x0707);
send_com(0x0032, 0x0006);
send_com(0x0035, 0x0704);
send_com(0x0036, 0x1F04);
send_com(0x0037, 0x0004);
send_com(0x0038, 0x0000);
send_com(0x0039, 0x0706);
send_com(0x003C, 0x0701);
send_com(0x003D, 0x000F);
_delay_ms(50); // _delay_ms 50ms
//------------------ Set GRAM area ---------------//
send_com(0x0050, 0x0000); // Horizontal GRAM Start Address
send_com(0x0051, 0x00EF); // Horizontal GRAM End Address
send_com(0x0052, 0x0000); // Vertical GRAM Start Address
send_com(0x0053, 0x013F); // Vertical GRAM Start Address
send_com(0x0060, 0xA700); // Gate Scan Line
//send_com(0x0060, 0x2700); // Gate Scan Line
send_com(0x0061, 0x0001); // NDL,VLE, REV
send_com(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
send_com(0x0080, 0x0000);
send_com(0x0081, 0x0000);
send_com(0x0082, 0x0000);
send_com(0x0083, 0x0000);
send_com(0x0084, 0x0000);
send_com(0x0085, 0x0000);
//-------------- Panel Control -------------------//
send_com(0x0090, 0x0010);
send_com(0x0092, 0x0000);
send_com(0x0093, 0x0003);
send_com(0x0095, 0x0110);
send_com(0x0097, 0x0000);
send_com(0x0098, 0x0000);
//----------------- display ON -------------------//
send_com(0x0007, 0x0133); // 262K color and display ON
send_com(0x0020, 0x0000);
send_com(0x0021, 0x0000);
}
/**********************
LCD初始化函数
***********************/
void LCD_Init()
{
LCD_IO_Init();
//************* Start Initial Sequence **********//
send_com(0x00E3, 0x3008); // Set internal timing
send_com(0x00E7, 0x0012); // Set internal timing
send_com(0x00EF, 0x1231); // Set internal timing
send_com(0x0001, 0x0100); // set SS and SM bit
send_com(0x0002, 0x0700); // set 1 line inversion
//send_com(0x0003, 0x1030); // set GRAM write direction and BGR=1.
send_com(0x0003, 0x1038); // set GRAM write direction and BGR=1.
send_com(0x0004, 0x0000); // Resize register
send_com(0x0008, 0x0202); // set the back porch and front porch
send_com(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
send_com(0x000A, 0x0000); // FMARK function
send_com(0x000C, 0x0000); // RGB interface setting
send_com(0x000D, 0x0000); // Frame marker Position
send_com(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
send_com(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
send_com(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
send_com(0x0012, 0x0000); // VREG1OUT voltage
send_com(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
_delay_ms(100); // Dis-charge capacitor power voltage
send_com(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB
send_com(0x0011, 0x0227); // R11h=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0]
_delay_ms(10); // _delay_ms 50ms
send_com(0x0012, 0x001C); // External reference voltage= Vci;
_delay_ms(100); // _delay_ms 50ms
send_com(0x0013, 0x1800); // R13=1200 when R12=009D;VDV[4:0] for VCOM amplitude
send_com(0x0029, 0x001C); // R29=000C when R12=009D;VCM[5:0] for VCOMH
send_com(0x002B, 0x000D); // Frame Rate = 91Hz
_delay_ms(100); // _delay_ms 50ms
// send_com(0x0020, 0x0000); // GRAM horizontal Address
// send_com(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
send_com(0x0030, 0x0204);
send_com(0x0031, 0x0507);
send_com(0x0032, 0x0204);
send_com(0x0035, 0x0107);
send_com(0x0036, 0x0207);
send_com(0x0037, 0x0305);
send_com(0x0038, 0x0002);
send_com(0x0039, 0x0305);
send_com(0x003C, 0x0701);
send_com(0x003D, 0x060A);
//------------------ Set GRAM area ---------------//
send_com(0x0050, 0x0000); // Horizontal GRAM Start Address
send_com(0x0051, 0x00EF); // Horizontal GRAM End Address
send_com(0x0052, 0x0000); // Vertical GRAM Start Address
send_com(0x0053, 0x013F); // Vertical GRAM Start Address
send_com(0x0060, 0xA700); // Gate Scan Line
send_com(0x0061, 0x0001); // NDL,VLE, REV
send_com(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
send_com(0x0080, 0x0000);
send_com(0x0081, 0x0000);
send_com(0x0082, 0x0000);
send_com(0x0083, 0x0000);
send_com(0x0084, 0x0000);
send_com(0x0085, 0x0000);
//-------------- Panel Control -------------------//
send_com(0x0090, 0x0010);
send_com(0x0092, 0x0000);
send_com(0x0093, 0x0003);
send_com(0x0095, 0x0110);
send_com(0x0097, 0x0000);
send_com(0x0098, 0x0000);
send_com(0x0007, 0x0133); // 262K color and display ON
// set_CS;
}
//设置液晶显示位置
void ram_addr(unsigned int x,unsigned int y)
{
send_com(0x0020,x); //行地址
send_com(0x0021,y); //列地址
send_comand(0x22);
}
//全屏幕显示一种颜色
void Full_display(unsigned int color)
{
uint j;
uint8 i;
// clr_CS;
ram_addr(0,0);
//send_comand(0x22);
for(j=0;j<320;j++)
for(i=0;i<240;i++)
send_data(color);
// _delay_ms(10);
// set_CS;
}
/******************************
//测试程序
//彩色测试
*******************************/
void LCD_test()
{
}
/*-----------------------------------------------------------------------------*\
| LCD_SetCursor : Sets the cursor position. |
| Input : - Xpos: specifies the X position. |
| - Ypos: specifies the Y position. |
\*-----------------------------------------------------------------------------*/
void LCD_SetCursor(unsigned short Xpos, unsigned short Ypos)
{
send_com(R33, Xpos);
send_com(R32, Ypos);
}
/*-----------------------------------------------------------------------------*\
| LCD_SetArea : Sets a display window |
\*-----------------------------------------------------------------------------*/
void LCD_SetArea( unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1 ) {
LCD_SetCursor(x0, y0);
/* Horizontal GRAM Start Address */
send_com(R80, y0);
/* Horizontal GRAM End Address */
send_com(R81, y1);
/* Vertical GRAM Start Address */
send_com(R82, x0);
/* Vertical GRAM End Address */
send_com(R83, x1);
}
/*-----------------------------------------------------------------------------*\
| LCD_RectangleFill : Displays a rectangle filled |
\*-----------------------------------------------------------------------------*/
void LCD_RectangleFill( unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short Color ) {
int x,y;
LCD_SetArea(x0,y0,x1,y1);
send_comand( R34 ); /* Prepare to write GRAM */
for(x=0;x<=x1-x0;x++)
for(y=0;y<=y1-y0;y++)
send_data( Color );
}
/*-----------------------------------------------------------------------------*\
| LCD_Clear : Clears the hole LCD. |
\*-----------------------------------------------------------------------------*/
void LCD_Clear_Screen( unsigned short Color ) {
LCD_RectangleFill( 0,0, 319,239, Color );
}
/*-----------------------------------------------------------------------------*\
| LCD_SetPixel : Displays a pixel. |
\*-----------------------------------------------------------------------------*/
void LCD_SetPixel( unsigned short x, unsigned short y, unsigned short Color ) {
LCD_SetArea(x,y,x,y);
send_comand( R34 ); /* Prepare to write GRAM */
send_data( Color );
}
/*-----------------------------------------------------------------------------*\
| LCD_PutChar8x16 : Displays a 8x16 pixel charactor |
\*-----------------------------------------------------------------------------*/
/*
#include "8X16.h"
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
register unsigned int i,j;
LCD_SetArea(x,y,x+8-1,y+16-1);
send_comand( R34 );
for(i=0; i<16;i++) {
unsigned char m=Font8x16[c*16+i];
for(j=0;j<8;j++) {
if((m&0x80))
send_data( f );
else
send_data( b );
m<<=1;
}
}
}
*/
/*-----------------------------------------------------------------------------*\
| LCD_PutChar8x8 : Displays a 8x8 pixel charactor |
\*-----------------------------------------------------------------------------*/
#include "8X8h.h"
void LCD_PutChar8x8(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
register unsigned int i,j;
LCD_SetArea(x,y,x+8-1,y+8-1);
send_comand( R34 ); /* Prepare to write GRAM */
for(i=0; i<8;i++) {
unsigned char m=Font8x8[c]
;
for(j=0;j<8;j++) {
if((m&0x80))
send_data( f );
else
send_data( b );
m<<=1;
}
}
}
/*-----------------------------------------------------------------------------*\
| LCD_PutGB1616 : Displays a Chinese charactor use small libary |
\*-----------------------------------------------------------------------------*/
/*
#include "GB1616.h" //16*16汉字字模
void LCD_PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int f,unsigned int b){
unsigned int i,j,k;
LCD_SetArea(x, y, x+16-1, y+16-1);
send_comand( R34 );
for (k=0;k<70;k++) {
if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])){
for(i=0;i<32;i++) {
unsigned short m=codeGB_16[k].Msk;
for(j=0;j<8;j++) {
if((m&0x80)==0x80)
send_data( f );
else
send_data( b );
m<<=1;
}
}
}
}
}
*/
/*-----------------------------------------------------------------------------*\
| LCD_PutChar : Displays a charactor on Font |
\*-----------------------------------------------------------------------------*/
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int f, unsigned int b) {
if( Font )
LCD_PutChar8x8( x, y, c, f, b );
//else
//LCD_PutChar8x16( x, y, c, f, b );
}
/*-----------------------------------------------------------------------------*\
| LCD_PutString : Displays a string |
\*-----------------------------------------------------------------------------*/
void LCD_PutString(unsigned short x, unsigned short y, char *s, unsigned int f, unsigned int b) {
register unsigned char l=0;
while(*s) {
if( *s < 0x80 ) {
LCD_PutChar(x+l*8,y,*s,f,b);
s++;l++;
}
//else {
//LCD_PutGB1616(x+l*8,y,(unsigned char *)s,f,b);
//s+=2;l+=2;
//}
}
}
/*----------------------------------------------------------*\
| END OF FILE |
\*----------------------------------------------------------*/
我这次显示8*8的小字,下次想显示汉字。
以下是视频及照片:
上工程,这个工程可以在FLASH中执行
[
本帖最后由 ddllxxrr 于 2013-1-11 21:07 编辑 ]