|
发表于 2010-8-12 14:36:27
|
显示全部楼层
最近在整一块驱动芯片是HX8347的3.2的屏,就是点不亮呀,不知道这里有没有人高人弄过,代码贴出来
#include <avr/io.h>
#include <util/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#define NOP() asm("nop")
#define U8 unsigned char
#define U16 unsigned int
#define U32 unsigned long
#define DATA_LO_DDR DDRA
#define DATA_LO_PORT PORTA
#define DATA_LO_PIN PINA
#define DATA_HI_DDR DDRC
#define DATA_HI_PORT PORTC
#define DATA_HI_PIN PINC
#define LCD_CS_DDR DDRB
#define LCD_CS_PORT PORTB
#define LCD_CS_BIT 0
#define LCD_RS_DDR DDRB
#define LCD_RS_PORT PORTB
#define LCD_RS_BIT 1
#define LCD_WR_DDR DDRB
#define LCD_WR_PORT PORTB
#define LCD_WR_BIT 2
#define LCD_RST_DDR DDRB
#define LCD_RST_PORT PORTB
#define LCD_RST_BIT 3
#define LCD_CS_H() LCD_CS_PORT |= 1<<LCD_CS_BIT
#define LCD_CS_L() LCD_CS_PORT &= ~(1<<LCD_CS_BIT)
#define LCD_RS_H() LCD_RS_PORT |= 1<<LCD_RS_BIT
#define LCD_RS_L() LCD_RS_PORT &= ~(1<<LCD_RS_BIT)
#define LCD_WR_H() LCD_WR_PORT |= 1<<LCD_WR_BIT
#define LCD_WR_L() LCD_WR_PORT &= ~(1<<LCD_WR_BIT)
#define LCD_RST_H() LCD_RST_PORT |= 1<<LCD_RST_BIT
#define LCD_RST_L() LCD_RST_PORT &= ~(1<<LCD_RST_BIT)
static void Delay_nus(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
asm("nop");
}
}
static void Delay_nms(unsigned int Time)
{
unsigned int TimeCounter = 0;
for (TimeCounter = 0;TimeCounter < Time;TimeCounter ++)
{
Delay_nus(1300);
}
}
void WriteI(U16 c)
{
// LCD_CS_H();
// LCD_WR_H();//CS=WR=1;
// LCD_RS_L();//RS=0;
DATA_LO_PORT = (unsigned char)c;
DATA_HI_PORT = (unsigned char)(c>>8);//DB=c;
LCD_RS_L();//RS=1;
LCD_CS_L();//CS=0;
LCD_WR_L();//WR=0;
NOP();
NOP();
LCD_WR_H();//WR=1;
LCD_CS_H();//CS=1;
}
void WriteD(U16 d)
{
//LCD_CS_H();
//LCD_WR_H();//CS=WR=1;
//LCD_RS_H();//RS=1;
DATA_LO_PORT = (unsigned char)d;
DATA_HI_PORT = (unsigned char)(d>>8);//DB=d;
LCD_RS_H();//RS=1;
LCD_CS_L();//CS=0;
LCD_WR_L();//WR=0;
NOP();
NOP();
LCD_WR_H();//WR=1;
LCD_CS_H();//CS=1;
}
void Init_Data(U16 c,U16 d)
{
WriteI(c);
WriteD(d);
}
void LCD_Write_Start(void)
{
LCD_CS_H();
LCD_WR_H();
LCD_RS_L();
DATA_LO_PORT = 0x22;
DATA_HI_PORT = 0x00;
LCD_CS_L();
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_RS_H();
}
void LCD_Write_Data(unsigned int val)
{
DATA_LO_PORT = (unsigned char)val;
DATA_HI_PORT = (unsigned char)(val>>8);
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
}
void LCD_Write_End(void)
{
LCD_CS_H();
}
void Initial(void)
{
//=========Initial HX8347 for INL2.8"QVGA Panel======//
LCD_RST_H();
Delay_nms(1); // Delay 1ms
LCD_RST_L();
Delay_nms(1); // Delay 10ms
LCD_RST_H();
Delay_nms(150); // Delay 150 ms
Init_Data(0x0042,0x0008);
//Gamma setting
Init_Data(0x0046,0x00B4);
Init_Data(0x0047,0x0043);
Init_Data(0x0048,0x0013);
Init_Data(0x0049,0x0047);
Init_Data(0x004A,0x0014);
Init_Data(0x004B,0x0036);
Init_Data(0x004C,0x0003);
Init_Data(0x004D,0x0046);
Init_Data(0x004E,0x0005);
Init_Data(0x004F,0x0010);
Init_Data(0x0050,0x0008);
Init_Data(0x0051,0x000a);
//Window Setting
Init_Data(0x0002,0x0000);
Init_Data(0x0003,0x0000);
Init_Data(0x0004,0x0000);
Init_Data(0x0005,0x00EF);
Init_Data(0x0006,0x0000);
Init_Data(0x0007,0x0000);
Init_Data(0x0008,0x0001);
Init_Data(0x0009,0x003F);
Delay_nms(10);
Init_Data(0x0001,0x0006);
Init_Data(0x0016,0x00C8);
Init_Data(0x0023,0x0095);
Init_Data(0x0024,0x0095);
Init_Data(0x0025,0x00FF);
Init_Data(0x0027,0x0002);
Init_Data(0x0028,0x0002);
Init_Data(0x0029,0x0002);
Init_Data(0x002A,0x0002);
Init_Data(0x002C,0x0002);
Init_Data(0x002D,0x0002);
Init_Data(0x003A,0x0001);
Init_Data(0x003B,0x0001);
Init_Data(0x003C,0x00F0);
Init_Data(0x003D,0x0000);
Delay_nms(20);
Init_Data(0x0035,0x0038);
Init_Data(0x0036,0x0078);
Init_Data(0x003E,0x0038);
Init_Data(0x0040,0x000F);
Init_Data(0x0041,0x00F0);
Init_Data(0x0038,0x0000);
// Power Setting
Init_Data(0x0019,0x0049);
Init_Data(0x0093,0x000A);
Delay_nms(10);
Init_Data(0x0020,0x0020);
Init_Data(0x001D,0x0003);
Init_Data(0x001E,0x0000);
Init_Data(0x001F,0x0009);
Init_Data(0x0044,0x0053);
Init_Data(0x0045,0x0010);
Delay_nms(10);
Init_Data(0x001C,0x0004);
Delay_nms(20);
Init_Data(0x0043,0x0080);
Delay_nms(5);
Init_Data(0x001B,0x000a);
Delay_nms(40);
Init_Data(0x001B,0x0012);
Delay_nms(40);
//Display On Setting
Init_Data(0x0090,0x007F);
Init_Data(0x0026,0x0004);
Delay_nms(40);
Init_Data(0x0026,0x0024);
Init_Data(0x0026,0x002C);
Delay_nms(40);
Init_Data(0x0070,0x0008);
Init_Data(0x0026,0x003C);
Init_Data(0x0057,0x0002);
Init_Data(0x0055,0x0000);
Init_Data(0x0057,0x0000);
WriteI(0x0022);
}
void WriteColor(U32 color)
{
LCD_RS_H();//RS=1;
DATA_LO_PORT = (unsigned char)color;
DATA_HI_PORT = (unsigned char)(color>>8);//DB= color;
LCD_CS_L();//CS=0;
LCD_WR_L();//WR=0;
LCD_WR_H();//WR=1;
LCD_CS_H();//CS=1;
}
void Ramset(U16 startx,U16 starty,U16 endx,U16 endy)
{
Init_Data(0x0002,startx/256);
Init_Data(0x0003,startx);
Init_Data(0x0004,endx/256);
Init_Data(0x0005,endx);
Init_Data(0x0006,starty/256);
Init_Data(0x0007,starty);
Init_Data(0x0008,endy/256);
Init_Data(0x0009,endy);
Init_Data(0x0016,0x00C8);
WriteI(0x0022);
}
void DrawBlock (U16 startx,U16 starty,U16 endx,U16 endy,U32 color)
{
U16 i,j;
Init_Data(0x0002,startx/256);
Init_Data(0x0003,startx);
Init_Data(0x0004,endx/256);
Init_Data(0x0005,endx);
Init_Data(0x0006,starty/256);
Init_Data(0x0007,starty);
Init_Data(0x0008,endy/256);
Init_Data(0x0009,endy);
Init_Data(0x0016,0x00C8);
WriteI(0x0022);
for(i=starty;i<=endy;i++)
{
for(j=startx;j<=endx;j++)
{
WriteColor(color);
}
}
}
void LCD_test(void)
{
unsigned int i,j;
LCD_Write_Start();
for(i=0;i<320;i++)
for(j=0;j<240;j++)
{
if(i>279)LCD_Write_Data(0x0000); //
else if(i>239)LCD_Write_Data(0x001f); //蓝色
else if(i>199)LCD_Write_Data(0x07e0); //绿色
else if(i>159)LCD_Write_Data(0x07ff); //青色
else if(i>119)LCD_Write_Data(0xf800); //红色
else if(i>79)LCD_Write_Data(0xf81f); //紫色
else if(i>39)LCD_Write_Data(0xffe0); //黄色
else LCD_Write_Data(0xffff); //
}
LCD_Write_End();
}
int main(void)
{
DATA_LO_DDR=0XFF;
DATA_HI_DDR=0XFF;
DDRB=0XFF;
Initial();
LCD_test();
while(1);
return 0;
} |
|