|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-10-14 21:28:54
|
显示全部楼层
#include"system.h"
#include <io.h>
#include<stdio.h>
#include <unistd.h>
#include <altera_avalon_pio_regs.h>
#include <alt_types.h>
void Lcd_Write_Data(alt_u16 dat);
void Draw_Point(alt_u16 x,alt_u16 y,alt_u16 color); //画点
void Lcd_Write_Com(alt_u16 index);
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 Draw_Point(alt_u16 x,alt_u16 y,alt_u16 color) //画点
{
//IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 0);
Lcd_Write_Com(0x0020);
Lcd_Write_Data(x); //设置X坐标位置
Lcd_Write_Com(0x0021);
Lcd_Write_Data(y); //设置Y坐标位置
Lcd_Write_Com(0x0022);
Lcd_Write_Data(color);
//IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1);
}
alt_u16 Get_Point(alt_u16 x,alt_u16 y)
{
alt_u16 i;
Lcd_Write_Com(0x0020);
Lcd_Write_Data(x); //设置X坐标位置
Lcd_Write_Com(0x0021);
Lcd_Write_Data(y); //设置Y坐标位置
Lcd_Write_Com(0x0022);
IOWR_ALTERA_AVALON_PIO_DIRECTION(DATA_BASE, 0x0000);
IOWR_ALTERA_AVALON_PIO_DATA(RS_BASE, 1);//rs=1
IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE, 0);
//i=IORD_ALTERA_AVALON_PIO_DATA(DATA_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE, 0);
i=IORD_ALTERA_AVALON_PIO_DATA(DATA_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(RD_BASE, 1);
return i;
}
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);
Draw_Point(j,i,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
Address_set(0,0,240,320);
//IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1); //关闭片选使能
}
int main(void)
{
//int i,j;
Lcd_Init();
Pant(0x0000);
while(1){
Pant(0xf800); //红色
Draw_Point(120,100,0xf800);
Draw_Point(120,120,0x001f);
Draw_Point(120,140,0xfff0);
Draw_Point(120,160,0xffff);
Draw_Point(220,100,Get_Point(120,100));
Draw_Point(220,120,Get_Point(120,120));
Draw_Point(220,140,Get_Point(120,140));
Draw_Point(220,160,Get_Point(120,160));
delayms(2000);
Pant(0X07E0); //绿色
Draw_Point(120,100,0xf800);
Draw_Point(120,120,0x001f);
Draw_Point(120,140,0xfff0);
Draw_Point(120,160,0xffff);
Draw_Point(220,100,Get_Point(120,100));
Draw_Point(220,120,Get_Point(120,120));
Draw_Point(220,140,Get_Point(120,140));
Draw_Point(220,160,Get_Point(120,160));
delayms(2000);
Pant(0x001f); //蓝色
Draw_Point(120,100,0xf800);
Draw_Point(120,120,0x001f);
Draw_Point(120,140,0xfff0);
Draw_Point(120,160,0xffff);
Draw_Point(220,100,Get_Point(120,100));
Draw_Point(220,120,Get_Point(120,120));
Draw_Point(220,140,Get_Point(120,140));
Draw_Point(220,160,Get_Point(120,160));
delayms(2000);}
/*
Draw_Point(120,100,0xf800);
Draw_Point(120,120,0x001f);
Draw_Point(120,140,0xfff0);
Draw_Point(120,160,0xffff);
Draw_Point(220,100,Get_Point(120,100));
Draw_Point(220,120,Get_Point(120,120));
Draw_Point(220,140,Get_Point(120,140));
Draw_Point(220,160,Get_Point(120,160));
*/
return 0;
}
现在我这么写了,可以读出数据了。不知道代码能否简化(get_point函数是我胡乱写的),怎样能加快读写速度吗? |
|