请教ILI9325的8位驱动,一直没有驱动起来.
网上买的屏:http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=5019585&bbs_page_no=1&search_mode=4&search_text=dongls&bbs_id=9999我用的是ATMEGA88
#include <avr/io.h>
#include <util/delay.h>
//定义液晶屏接口
#define CTRLP PORTB
#define CTRLDDR DDRB
#define DATAP PORTD
#define DATAIN PIND
#define DATADDR DDRD
#define CS PB1 //片选
#define RST PB0 //复位
#define RS PB2 //数据/命令选择
#define WR PB3 //写
#define RD PB4 //读
//液晶屏控制端口初始化
void TFT_PortInit(void)
{
DATADDR = 0xFF; //8位数据端口配置为输出
CTRLDDR|= _BV(RST) | _BV(CS) | _BV(RS) | _BV(WR) | _BV(RD); //控制端口配置为输出
CTRLP|= _BV(RST) | _BV(CS) | _BV(RS) | _BV(WR) | _BV(RD); //控制端口初始高电平1
}
//发送命令
void TFT_WriteReg(unsigned int index)
{
CTRLP |= (1 << RD);
CTRLP &= ~(1 << RS);
CTRLP &= ~(1 << CS);
CTRLP &= ~(1 << WR);
DATAP = (index >> 8);
CTRLP |= (1 << WR);
CTRLP &= ~(1 << WR);
DATAP = (index & 0xFF);
CTRLP |= (1 << WR);
CTRLP |= (1 << CS);
}
//发送数据
void TFT_WriteData(unsigned int Data)
{
CTRLP |= (1 << RD);
CTRLP |= (1 << RS);
CTRLP &= ~(1 << CS);
CTRLP &= ~(1 << WR);
DATAP = (Data >> 8);
CTRLP |= (1 << WR);
CTRLP &= ~(1 << WR);
DATAP = (Data & 0xFF);
CTRLP |= (1 << WR);
CTRLP |= (1 << CS);
}
//写命令数据
void TFT_Write(unsigned int index, unsigned int Data)
{
TFT_WriteReg(index);
TFT_WriteData(Data);
}
//定义坐标
static void TFT_SetPos(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1)
{
TFT_Write(0x0050,x0);
TFT_Write(0x0051,x1);
TFT_Write(0x0052,y0);
TFT_Write(0x0053,y1);
TFT_Write(0x0020,x0);
TFT_Write(0x0021,y0);
TFT_WriteReg(0x0022);//LCD_WriteCMD(GRAMWR);
}
//清屏
void TFT_ClearScreen(unsigned int bColor)
{
unsigned int i,j;
TFT_SetPos(0,240,0,320);//320x240
for (i=0;i<320;i++)
{
for (j=0;j<240;j++)
TFT_WriteData(bColor);
}
}
//TFT屏初始化
void TFT_Init(void)
{
TFT_PortInit();
CTRLP &= ~(1 << RST);
_delay_ms(100);
CTRLP |= (1 << RST);
_delay_ms(50);//根据不同晶振速度可以调整延时,保障稳定显示
TFT_Write(0x0001, 0x0100); //SS = 1; SM = 0;输出转变方向:S720到S1
TFT_Write(0x0002, 0x0700); //EOR = 1; B/C = 0; 行反转
TFT_Write(0x0003, 0x1030);//水平写入方向得以更新,BGR = 1(转换RGB数据到BGR) ??
TFT_Write(0x0004, 0x0000); //不调整大小 RSZ = 00; RCH = 00; RCV = 00
TFT_Write(0x0008, 0x0207); //设定正面和背面门廓期的行号:BP = 7; FP = 2
TFT_Write(0x0009, 0x0000);//set non-display area refresh cycle ISC
TFT_Write(0x000A, 0x0000);//FMARK function : 1 frame
TFT_Write(0x000C, 0x0000);//RGB 显示接口控制(18位RGB接口,DB17~DB0, 内部系统时钟,系统接口访问GRAM,读写周期为 1 FRAME)
TFT_Write(0x000D, 0x0000);//FRAME marker position
TFT_Write(0x000F, 0x0000);//RGB interface polarity
//power on sequence VGHVGL
TFT_Write(0x0010, 0x0000); //SAP(得先禁用,后启用) BT AP SLP STB
TFT_Write(0x0011, 0x0007);//DC1, DC0, VC
TFT_Write(0x0012, 0x0000);//VREGOUT voltage
TFT_Write(0x0013, 0x1300);//VDV for VCOM amplitude (0.7) 0x1300 - 1.0
// TFT_InitData(0x0007,0x0001);
_delay_ms(300); // Dis-charge capacitor power voltage
//vgh
TFT_Write(0x0010, 0x1290);//1690//SAP, BT, AP, DSTB, SLP, STB
TFT_Write(0x0011, 0x0527);//227 //DC1, DC0, VC
// _delay_ms(50);
//vregiout
TFT_Write(0x0012, 0x0018); //1D//Internal reference voltage= Vci;
// _delay_ms(50);
TFT_Write(0x0013, 0x0800); //1500//Set VDV for VCOM amplitude
TFT_Write(0x0029, 0x0014); //10// Set VCM for VCOMH
TFT_Write(0x002B, 0x000B); //D// Set Frame Rate
_delay_ms(50);
TFT_Write(0x0020, 0x0000);
TFT_Write(0x0021, 0x0000);
//gamma
//**************************************
// TFT_Write(0x0030, 0x0007);
//***************************************
TFT_Write(0x0031, 0x0007);
TFT_Write(0x0032, 0x0002);// 0006
TFT_Write(0x0035, 0x0206);
TFT_Write(0x0036, 0x0408);
TFT_Write(0x0037, 0x0507);
TFT_Write(0x0038, 0x0200);//0200
TFT_Write(0x0039, 0x0707);
TFT_Write(0x003C, 0x0504);// 0504
TFT_Write(0x003D, 0x0F02); //0F02
//ram
TFT_Write(0x0050, 0x0000); // Horizontal GRAM Start Address
TFT_Write(0x0051, 0x00EF); // Horizontal GRAM End Address
TFT_Write(0x0052, 0x0000); // Vertical GRAM Start Address
TFT_Write(0x0053, 0x013F); // Vertical GRAM Start Address
TFT_Write(0x0060, 0x2700); // Gate Scan Line
TFT_Write(0x0061, 0x0001); // NDL,VLE, REV
TFT_Write(0x006A, 0x0000); // set scrolling line
//Partial Display Control
TFT_Write(0x0080, 0x0000);
TFT_Write(0x0081, 0x0000);
TFT_Write(0x0082, 0x0000);
TFT_Write(0x0083, 0x0000);
TFT_Write(0x0084, 0x0000);
TFT_Write(0x0085, 0x0000);
//panel control
TFT_Write(0x0090, 0x0010);
TFT_Write(0x0092, 0x0000); //0900 //6 clocks
TFT_Write(0x0093, 0x0003);
TFT_Write(0x0095, 0x0110);
TFT_Write(0x0097, 0x0000);
TFT_Write(0x0098, 0x0000);
TFT_Write(0x0007, 0x0133); // 262K color and display ON 0133
_delay_ms(200);
//TFT_SetPos(0, 240, 0, 320);
TFT_ClearScreen(0xF800);
}
初始化时:如果加TFT_Write(0x0030, 0x0007);这一句的话是白屏(只背光亮),如果不加这一句的话是花屏.
请教各位,如何修改?先谢谢回贴的各位. CTRLP &= ~(1 << WR);
DATAP = (index >> 8);
CTRLP |= (1 << WR);
CTRLP &= ~(1 << WR);
DATAP = (index & 0xFF);
CTRLP |= (1 << WR);
木有用过,不过感觉应先送数据,然后wr=0,wr=1 回复【1楼】xiaodao35
-----------------------------------------------------------------------
调整了一下,还是不行.没写0x30寄存器花屏,写的话白屏(只背光亮). 搞了一下午没搞定,哪位高手支个招. 今天换成MEGA8的芯片,驱动成功了。看起来没有什么差别,不知为什么MEGA88不能驱动?先发个成功的测试代码。
#include <avr/io.h>
#include <util/delay.h>
//定义液晶屏接口
#define DATAP PORTD
#define CS_L() PORTC &= ~(1 << PC2)//片选
#define CS_H() PORTC |=(1 << PC2)
#define WR_L() PORTC &= ~(1 << PC1)//写
#define WR_H() PORTC |=(1 << PC1)
#define RST_L() PORTC &= ~(1 << PC0)//复位
#define RST_H() PORTC |=(1 << PC0)
#define RS_L() PORTB &= ~(1 << PB0)
#define RS_H() PORTB |=(1 << PB0)//数据/命令选择
#define RD_L() PORTB &= ~(1 << PB1)//读(此处不用,接高电位)
#define RD_H() PORTB |=(1 << PB1)
//液晶屏控制端口初始化
void TFT_PortInit(void)
{
DDRD = 0xFF; //8位数据端口配置为输出
DDRC |= (1 << PC2) | (1 << PC1) | (1 << PC0); //控制端口配置为输出
DDRB |= (1 << PB1) | (1 << PB0);
PORTC |= (1 << PC2) | (1 << PC1) | (1 << PC0);//控制端口初始高电平
PORTB |= (1 << PB1) | (1 << PB0);
}
//////////////////////////////////////////////////
//写命令
void TFT_WriteCmdU16(unsigned int Cmd)
{
RS_L();
CS_L();
DATAP = Cmd << 8;
WR_L();
WR_H();
DATAP = Cmd & 0xFF;
WR_L();
WR_H();
CS_H();
}
//写数据
void TFT_WriteDataU16(unsigned int Data)
{
RS_H();
CS_L();
DATAP = Data >> 8;
WR_L();
WR_H();
DATAP = Data & 0xFF;
WR_L();
WR_H();
CS_H();
}
//写命令数据
void TFT_InitData(unsigned int Cmd, unsigned int Data)
{
TFT_WriteCmdU16(Cmd);
TFT_WriteDataU16(Data);
}
//液晶初始化
void TFT_Init(void)
{
TFT_PortInit();
_delay_ms(100);
RST_L();
_delay_ms(100);
RST_H();
_delay_ms(500);//根据不同晶振速度可以调整延时,保障稳定显示
TFT_InitData(0x00E5,0x78F0); // set SRAM internal timing
TFT_InitData(0x0001,0x0100); // set SS and SM bit
TFT_InitData(0x0002,0x0700); // set 1 line inversion
TFT_InitData(0x0003,0x1030); // set GRAM write direction and BGR=1.
TFT_InitData(0x0004,0x0000); // Resize register
TFT_InitData(0x0008,0x0207); // set the back porch and front porch
TFT_InitData(0x0009,0x0000); // set non-display area refresh cycle ISC
TFT_InitData(0x000A,0x0000); // FMARK function
TFT_InitData(0x000C,0x0000); // RGB interface setting
TFT_InitData(0x000D,0x0000); // Frame marker Position
TFT_InitData(0x000F,0x0000); // RGB interface polarity
//power on sequence VGHVGL
TFT_InitData(0x0010,0x0000); // SAP, BT, AP, DSTB, SLP, STB
TFT_InitData(0x0011,0x0007); // DC1, DC0, VC
TFT_InitData(0x0012,0x0000); // VREG1OUT voltage
TFT_InitData(0x0013,0x1300); // VDV for VCOM amplitude
// TFT_InitData(0x0007,0x0001);
_delay_ms(500); // Dis-charge capacitor power voltage
//vgh
TFT_InitData(0x0010,0x1290); // 1490//SAP, BT, AP, DSTB, SLP, STB
TFT_InitData(0x0011,0x0527); // DC1, DC0, VC
// _delay_ms(50);
//vregiout
TFT_InitData(0x0012,0x0018); //001C// Internal reference voltage= Vci;
//DelayMs(50);
//vom amplitude
TFT_InitData(0x0013,0x1300); //0x1000//1400 Set VDV for VCOM amplitude1A00
TFT_InitData(0x0029,0x001E); //0x0012 //001aSet VCM for VCOMH//0x00250034
TFT_InitData(0x002B,0x000B); // Set Frame Rate 000C
_delay_ms(50);
TFT_InitData(0x0020,0x0000); // GRAM horizontal Address
TFT_InitData(0x0021,0x0000); // GRAM Vertical Address
//gamma
TFT_InitData(0x0030,0x0004);
TFT_InitData(0x0031,0x0307);
TFT_InitData(0x0032,0x0002);// 0006
TFT_InitData(0x0035,0x0206);
TFT_InitData(0x0036,0x0408);
TFT_InitData(0x0037,0x0507);
TFT_InitData(0x0038,0x0204);//0200
TFT_InitData(0x0039,0x0707);
TFT_InitData(0x003C,0x0405);// 0504
TFT_InitData(0x003D,0x0F02);
//ram
TFT_InitData(0x0050,0x0000); // Horizontal GRAM Start Address
TFT_InitData(0x0051,0x00EF); // Horizontal GRAM End Address
TFT_InitData(0x0052,0x0000); // Vertical GRAM Start Address
TFT_InitData(0x0053,0x013F); // Vertical GRAM Start Address
TFT_InitData(0x0060,0xA700); // Gate Scan Line
TFT_InitData(0x0061,0x0001); // NDL,VLE, REV
TFT_InitData(0x006A,0x0000); // set scrolling line
//
TFT_InitData(0x0080,0x0000);
TFT_InitData(0x0081,0x0000);
TFT_InitData(0x0082,0x0000);
TFT_InitData(0x0083,0x0000);
TFT_InitData(0x0084,0x0000);
TFT_InitData(0x0085,0x0000);
//
TFT_InitData(0x0090,0x0010);
TFT_InitData(0x0092,0x0600);
TFT_InitData(0x0093,0x0003);
TFT_InitData(0x0095,0x0110);
TFT_InitData(0x0097,0x0000);
TFT_InitData(0x0098,0x0000);
TFT_InitData(0x0007,0x0173); // 262K color and display ON
_delay_ms(500);
}
//定义坐标
static void TFT_SetPos(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1)
{
TFT_InitData(0x0050,x0);
TFT_InitData(0x0051,x1);
TFT_InitData(0x0052,y0);
TFT_InitData(0x0053,y1);
TFT_InitData(0x0020,x0);
TFT_InitData(0x0021,y0);
TFT_WriteCmdU16(0x0022);//LCD_WriteCMD(GRAMWR);
}
//清屏
void TFT_ClearScreen(unsigned int bColor)
{
unsigned int i,j;
TFT_SetPos(0,240,0,320);//320x240
for (i=0;i<320;i++)
{
for (j=0;j<240;j++)
TFT_WriteDataU16(bColor);
}
} 8位模式时,IM0管脚要拉高。16位模式时IM0管脚拉低。 proteldxp 发表于 2012-1-3 19:47 static/image/common/back.gif
8位模式时,IM0管脚要拉高。16位模式时IM0管脚拉低。
您好请问io口的速度对读写有影响么?我现在用k60主频超到200m还是无法正常读取产品id
页:
[1]