|
发表于 2011-2-23 16:45:19
|
显示全部楼层
我就用的9325的屏 但是现在就是一直白屏不知道是什么原因,程序如下:请高手帮我看看我的问题出在什么地方 了
#include <iom128v.h>
#include <macros.h>
//CS:PG4 /RS:PG3 /WR:PG0 /RD:PG1 /RST:PG2 /8位模式PG
#define LCD_nCS(x) if(x==1) PORTG|=BIT(PG4);else PORTG&=~BIT(PG4)
#define LCD_nRD(x) if(x==1) PORTG|=BIT(PG1);else PORTG&=~BIT(PG1)
#define LCD_nWR(x) if(x==1) PORTG|=BIT(PG0);else PORTG&=~BIT(PG0)
#define LCD_RS(x) if(x==1) PORTG|=BIT(PG3);else PORTG&=~BIT(PG3)
#define LCD_nRST(x) if(x==1) PORTG|=BIT(PG2);else PORTG&=~BIT(PG2)
#define RED 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define WHITE 0xffff
#define BLACK 0x0000
#define YELLOW 0xFFE0
void delay_ms(unsigned char i)
{
unsigned char a, b;
for (a = 1; a < i; a++)
{
for (b = 1; b; b++);
}
}
void writecom(unsigned int ch)//写指令
{
LCD_nCS(0);//CS低
LCD_RS(0);//RS低
//delay_ms(5);
LCD_nRD(1);
PORTA=(unsigned char)(ch>>8);//赋值高八位
LCD_nWR(0);//WR低
//delay_ms(5);
asm("nop");//这个有没有都可以,仿真的时候用的
//PORTA=ch>>8;//赋值高八位
LCD_nWR(1);//WR高
PORTA=(unsigned char)(ch&0x00ff);//赋值低八位
LCD_nWR(0);//WR低
asm("nop");
//PORTA=ch&0x00ff;//赋值低八位
LCD_nWR(1);//WR高
LCD_nCS(1);//CS高
}
void writedata(unsigned int dh)//写数据
{
LCD_nCS(0);//CS低
LCD_RS(1);//RS高
LCD_nRD(1);
PORTA=(unsigned char)(dh>>8);
LCD_nWR(0);//WR低
asm("nop");
//PORTA=dh>>8;
LCD_nWR(1);//WR高
PORTA=(unsigned char)(dh&0x00ff);
LCD_nWR(0);//WR低
asm("nop");
//PORTA=dh&0x00ff;
LCD_nWR(1);//WR高
LCD_nCS(1);//CS高
}
void main_w_c_d(unsigned int com1, unsigned int data)//写指令&数据
{
writecom(com1);
writedata(data);
}
void addset(unsigned int x1,unsigned int y1,unsigned x2,unsigned y2)
{
main_w_c_d(0x0020,x1);//设置X坐标位置
main_w_c_d(0x0021,y1);//设置Y坐标位置
main_w_c_d(0x0050,x1); //开始X
main_w_c_d(0x0052,y1);//开始Y
main_w_c_d(0x0051,x2); //结束X
main_w_c_d(0x0053,y2); //结束Y
writecom(0x0022);
}
void LCD9325_Init()
{
LCD_nRST(1);
delay_ms(1);
LCD_nRST(0); //RST复位
delay_ms(10);
LCD_nRST(1);
delay_ms(50);
//LCD_nCS(0);//CS低
main_w_c_d(0x00E3, 0x3008); // Set internal timing
main_w_c_d(0x00E7, 0x0012); // Set internal timing
main_w_c_d(0x00EF, 0x1231); // Set internal timing
main_w_c_d(0x0001, 0x0100); // set SS and SM bit
main_w_c_d(0x0002, 0x0700); // set 1 line inversion
main_w_c_d(0x0003, 0x1000); // set GRAM write direction and BGR=1.
main_w_c_d(0x0004, 0x0000); // Resize register
main_w_c_d(0x0008, 0x0207); // set the back porch and front porch
main_w_c_d(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
main_w_c_d(0x000A, 0x0000); // FMARK function
main_w_c_d(0x000C, 0x0000); // RGB interface setting
main_w_c_d(0x000D, 0x0000); // Frame marker Position
main_w_c_d(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
main_w_c_d(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
main_w_c_d(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
main_w_c_d(0x0012, 0x0000); // VREG1OUT voltage
main_w_c_d(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delay_ms(50); // Dis-charge capacitor power voltage
main_w_c_d(0x0010, 0x1490); // SAP, BT[3:0], AP, DSTB, SLP, STB
main_w_c_d(0x0011, 0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
delay_ms(50); // delay_ms 50ms
main_w_c_d(0x0012, 0x001D); // Internal reference voltage= Vci;
delay_ms(50); // delay_ms 50ms
main_w_c_d(0x0013, 0x1000); // Set VDV[4:0] for VCOM amplitude
main_w_c_d(0x0029, 0x0026); // Set VCM[5:0] for VCOMH
main_w_c_d(0x002B, 0x000D); // Set Frame Rate
delay_ms(50); // delay_ms 50ms
main_w_c_d(0x0020, 239); // GRAM horizontal Address
main_w_c_d(0x0021, 219); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
main_w_c_d(0x0030, 0x0007);
main_w_c_d(0x0031, 0x0707);
main_w_c_d(0x0032, 0x0006);
main_w_c_d(0x0035, 0x0704);
main_w_c_d(0x0036, 0x1F04);
main_w_c_d(0x0037, 0x0004);
main_w_c_d(0x0038, 0x0000);
main_w_c_d(0x0039, 0x0706);
main_w_c_d(0x003C, 0x0701);
main_w_c_d(0x003D, 0x000F);
//------------------ Set GRAM area ---------------//
main_w_c_d(0x0050, 0x0000); // Horizontal GRAM Start Address
main_w_c_d(0x0051, 0x00EF); // Horizontal GRAM End Address
main_w_c_d(0x0052, 0x0000); // Vertical GRAM Start Address
main_w_c_d(0x0053, 0x013F); // Vertical GRAM Start Address
main_w_c_d(0x0060, 0xA700); // Gate Scan Line
main_w_c_d(0x0061, 0x0001); // NDL,VLE, REV
main_w_c_d(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
main_w_c_d(0x0080, 0x0000);
main_w_c_d(0x0081, 0x0000);
main_w_c_d(0x0082, 0x0000);
main_w_c_d(0x0083, 0x0000);
main_w_c_d(0x0084, 0x0000);
main_w_c_d(0x0085, 0x0000);
//-------------- Panel Control -------------------//
main_w_c_d(0x0090, 0x0010);
main_w_c_d(0x0092, 0x0600);
main_w_c_d(0x0093, 0x0003);
main_w_c_d(0x0095, 0x0110);
main_w_c_d(0x0097, 0x0000);
main_w_c_d(0x0098, 0x0000);
main_w_c_d(0x0007, 0x0133); // 262K color and display ON
delay_ms(50);
//LCD_nCS(1);//CS高
}
void pant(unsigned int color)//单一颜色刷屏
{
int i,j;
//LCD_nCS(0);//CS高
addset(0,0,239,319);
for(i=0;i<319;i++)
{
for(j=0;j<239;j++)
writedata(color);
}
LCD_nCS(1);//CS高
}
/*IO口初始化函数*/
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0x20;
DDRB = 0x20;
PORTC = 0xFF; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x1F;
DDRG = 0x1F;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices(); /*初始化IO口*/
//disp_init(); /*初始显示部*/
LCD9325_Init();
pant(0xf800);
delay_ms(1000);
PORTB = 0x00;
while (1)
{
//PORTB = 0x00;
// delay_ms(200);
// PORTB = 0x20;
// delay_ms(200);
pant(0xf800); //红
// pant(0xf800);//黑
}
} |
|