|
求教,使用液晶的问题。控制器9325.
打开电源,液晶为背光灯的颜色(白色)。
在主函数里面初始化过后,液晶变为灰色,然后再怎么写程序,也始终是这个样子。我把代码贴上来,就一个LCD.c文件。
#include"system.h"
#include <io.h>
#include<stdio.h>
#include <unistd.h>
#include <altera_avalon_pio_regs.h>
#include <alt_types.h>
void delayms(unsigned int time)
{
int i;
for(i=0;i<time;i++){
usleep(1011);
}
}
void LCD_Writ_Bus(alt_u16 dat) //并行数据写入
{
IOWR_ALTERA_AVALON_PIO_DIRECTION(DATA_BASE, 0xffff);//cmd out
IOWR_ALTERA_AVALON_PIO_DATA(DATA_BASE, dat);//dat
IOWR_ALTERA_AVALON_PIO_DATA(WR_BASE, 0);
IOWR_ALTERA_AVALON_PIO_DATA(WR_BASE, 1);
}
void Lcd_Write_Com(alt_u16 index) //发送命令
{
IOWR_ALTERA_AVALON_PIO_DATA(RS_BASE, 0);//rs=0
LCD_Writ_Bus(index);
}
void Lcd_Write_Data(alt_u16 dat) //发送数据
{
IOWR_ALTERA_AVALON_PIO_DATA(RS_BASE, 1);//rs=1
LCD_Writ_Bus(dat);
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
Lcd_Write_Com(0x20);Lcd_Write_Data(x1); //设置X坐标位置
Lcd_Write_Com(0x21);Lcd_Write_Data(y1); //设置Y坐标位置
Lcd_Write_Com(0x50);Lcd_Write_Data(x1); //开始X
Lcd_Write_Com(0x52);Lcd_Write_Data(y1); //开始Y
Lcd_Write_Com(0x51);Lcd_Write_Data(x2); //结束X
Lcd_Write_Com(0x53);Lcd_Write_Data(y2); //结束Y
Lcd_Write_Com(0x22);
}
void Pant(alt_u16 dat)
{
int i,j;
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 0);//打开片选使能
Address_set(0,0,240,320);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
Lcd_Write_Data(dat);
}
}
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1);//关闭片选使能
}
void Lcd_Init(void)
{
IOWR_ALTERA_AVALON_PIO_DATA(RESET_BASE, 1);
delayms(5);
IOWR_ALTERA_AVALON_PIO_DATA(RESET_BASE,0);
delayms(5);
IOWR_ALTERA_AVALON_PIO_DATA(RESET_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(WR_BASE, 1);
delayms(5);
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 0); //打开片选使能
//************* Start Initial Sequence **********//
Lcd_Write_Com(0xE5); Lcd_Write_Data((0x78<<8)+0xF0); // set SRAM internal timing
Lcd_Write_Com(0x01); Lcd_Write_Data((0x01<<8)+0x00); // set SS and SM bit
Lcd_Write_Com(0x02); Lcd_Write_Data((0x07<<8)+0x00); // set 1 line inversion
Lcd_Write_Com(0x03); Lcd_Write_Data((0x10<<8)+0x30); // set GRAM write direction and BGR=1.
Lcd_Write_Com(0x04); Lcd_Write_Data(0x0000); // Resize register
Lcd_Write_Com(0x08); Lcd_Write_Data((0x02<<8)+0x07); // set the back porch and front porch
Lcd_Write_Com(0x09); Lcd_Write_Data(0x0000); // set non-display area refresh cycle ISC[3:0]
Lcd_Write_Com(0x0A); Lcd_Write_Data(0x0000); // FMARK function
Lcd_Write_Com(0x0C); Lcd_Write_Data(0x0000); // RGB interface setting
Lcd_Write_Com(0x0D); Lcd_Write_Data(0x0000); // Frame marker Position
Lcd_Write_Com(0x0F); Lcd_Write_Data(0x0000); // RGB interface polarity
//*************Power On sequence ****************//
Lcd_Write_Com(0x10); Lcd_Write_Data(0x00); // SAP, BT[3:0], AP, DSTB, SLP, STB
Lcd_Write_Com(0x11); Lcd_Write_Data(0x07); // DC1[2:0], DC0[2:0], VC[2:0]
Lcd_Write_Com(0x12); Lcd_Write_Data(0x00); // VREG1OUT voltage
Lcd_Write_Com(0x13); Lcd_Write_Data(0x00); // VDV[4:0] for VCOM amplitude
Lcd_Write_Com(0x07); Lcd_Write_Data(0x01);
delayms(50); // Dis-charge capacitor power voltage
Lcd_Write_Com(0x0010); Lcd_Write_Data((0x10<<8)+0x90); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
Lcd_Write_Com(0x0011); Lcd_Write_Data((0x02<<8)+0x27); // DC1[2:0], DC0[2:0], VC[2:0]
delayms(50); // Delay 50ms
Lcd_Write_Com(0x0012); Lcd_Write_Data(0x001F); //001C// Internal reference voltage= Vci;
delayms(50); // Delay 50ms
Lcd_Write_Com(0x0013); Lcd_Write_Data((0x15<<8)+0x00); //0x1000//1400 Set VDV[4:0] for VCOM amplitude 1A00
Lcd_Write_Com(0x0029); Lcd_Write_Data(0x0027); //0x0012 //001a Set VCM[5:0] for VCOMH //0x0025 0034
Lcd_Write_Com(0x002B); Lcd_Write_Data(0x000D); // Set Frame Rate 000C
delayms(50); // Delay 50ms
Lcd_Write_Com(0x0020); Lcd_Write_Data(0x0000); // GRAM horizontal Address
Lcd_Write_Com(0x0021); Lcd_Write_Data(0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
Lcd_Write_Com(0x0030); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0031); Lcd_Write_Data((0x07<<8)+0x07);
Lcd_Write_Com(0x0032); Lcd_Write_Data((0x03<<8)+0x07);
Lcd_Write_Com(0x0035); Lcd_Write_Data((0x02<<8)+0x00);
Lcd_Write_Com(0x0036); Lcd_Write_Data(0x0008);//0207
Lcd_Write_Com(0x0037); Lcd_Write_Data(0x0004);//0306
Lcd_Write_Com(0x0038); Lcd_Write_Data(0x0000);//0102
Lcd_Write_Com(0x0039); Lcd_Write_Data((0x07<<8)+0x07);//0707
Lcd_Write_Com(0x003C); Lcd_Write_Data(0x0002);//0702
Lcd_Write_Com(0x003D); Lcd_Write_Data((0x1D<<8)+0x04);//1604
//------------------ Set GRAM area ---------------//
Lcd_Write_Com(0x0050); Lcd_Write_Data(0x0000); // Horizontal GRAM Start Address
Lcd_Write_Com(0x0051); Lcd_Write_Data(0x00EF); // Horizontal GRAM End Address
Lcd_Write_Com(0x0052); Lcd_Write_Data(0x0000); // Vertical GRAM Start Address
Lcd_Write_Com(0x0053); Lcd_Write_Data((0x01<<8)+0x3F); // Vertical GRAM Start Address
Lcd_Write_Com(0x0060); Lcd_Write_Data((0xA7<<8)+0x00); // Gate Scan Line
Lcd_Write_Com(0x0061); Lcd_Write_Data(0x0001); // NDL,VLE, REV
Lcd_Write_Com(0x006A); Lcd_Write_Data(0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
Lcd_Write_Com(0x0080); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0081); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0082); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0083); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0084); Lcd_Write_Data(0x0000);
Lcd_Write_Com(0x0085); Lcd_Write_Data(0x0000);
//-------------- Panel Control -------------------//
Lcd_Write_Com(0x0090); Lcd_Write_Data(0x0010);
Lcd_Write_Com(0x0092); Lcd_Write_Data((0x06<<8)+0x00);
Lcd_Write_Com(0x0007); Lcd_Write_Data((0x01<<8)+0x33); // 262K color and display ON
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1); //关闭片选使能
}
int main(void)
{
int i,j;
Lcd_Init(); //TFT初始化
/*IOWR_ALTERA_AVALON_PIO_DATA(RS_BASE, 1);//rs=1
IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DIRECTION(DATA_BASE, 0xffff);//cmd out
for(i=0;i<240;i++){
for(j=0;j<320;j++){
IOWR_ALTERA_AVALON_PIO_DATA(DATA_BASE, 0xf8);//dat
IOWR_ALTERA_AVALON_PIO_DATA(WR_BASE, 0);
IOWR_ALTERA_AVALON_PIO_DATA(WR_BASE, 1);
}
}*/
// Pant(0xf800); //红色
//delayms(2000);
//Pant(0X07E0); //绿色
//delayms(2000);
//Pant(0x001f); //蓝色
//delayms(2000);
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|