我寫了一个EP2C8Q208C8 推ILI9327 3.2 " 400x240 TFT LCD 的程序 ,100MHz cpu clk, 想出全屏克色 , 可是全屏克色不成功 ,RUN AS HARDWARE "Hello from Nios II" 出到 , 硬體檢查沒有問題 !!! 請各位看看程序有沒有問題 !!!
#include "sys/alt_stdio.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
void LCD_Writ_Bus(char VH,char VL);
void Lcd_Write_Com(char VH,char VL);
void Lcd_Write_Data(char VH,char VL);
void Address_set( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);
void Pant1(char VH,char VL);
void delay_ms(unsigned short i);
void LCD_Writ_Bus(char VH,char VL)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAH_BASE,VH);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAL_BASE,VL);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE ,0); //write
IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE ,1);//write
}
void Lcd_Write_Com(char VH,char VL)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_RS_BASE ,0);// rs
LCD_Writ_Bus(VH,VL);
}
void Lcd_Write_Data(char VH,char VL)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_RS_BASE ,1);//rs
LCD_Writ_Bus(VH,VL);
}
void Address_set( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
{
Lcd_Write_Com(0x00,0x2a);
Lcd_Write_Data(0x00,x1>>8);
Lcd_Write_Data(0x00,x1);
Lcd_Write_Data(0x00,x2>>8);
Lcd_Write_Data(0x00,x2);
Lcd_Write_Com(0x00,0x2b);
Lcd_Write_Data(0x00,y1>>8);
Lcd_Write_Data(0x00,y1);
Lcd_Write_Data(0x00,y2>>8);
Lcd_Write_Data(0x00,y2);
Lcd_Write_Com(0x00,0x2c);
}
void Lcd_Init(void)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_RESET_BASE ,1); //output_high(pin_a5);
delay_ms(100);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_RESET_BASE ,0); //output_low(pin_a5);
delay_ms(100);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_RESET_BASE ,1);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE ,1); //chip select
IOWR_ALTERA_AVALON_PIO_DATA(PIO_RD_BASE ,1); //read
IOWR_ALTERA_AVALON_PIO_DATA(PIO_WR_BASE ,1); //write
//output_high(pin_a1);
delay_ms(100);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE ,0);
//output_low(pin_a3);
Lcd_Write_Com(0x00,0xE9);
Lcd_Write_Data(0x00,0x20);
Lcd_Write_Com(0x00,0x11); //Exit Sleep
delay_ms(100);
Lcd_Write_Com(0x00,0xD1);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x71);
Lcd_Write_Data(0x00,0x19);
Lcd_Write_Com(0x00,0xD0);
Lcd_Write_Data(0x00,0x07);
Lcd_Write_Data(0x00,0x01);
Lcd_Write_Data(0x00,0x08);
Lcd_Write_Com(0x00,0x36);
Lcd_Write_Data(0x00,0x68);
Lcd_Write_Com(0x00,0x3A);
Lcd_Write_Data(0x00,0x05);
Lcd_Write_Com(0x00,0xC1);
Lcd_Write_Data(0x00,0x10);
Lcd_Write_Data(0x00,0x10);
Lcd_Write_Data(0x00,0x02);
Lcd_Write_Data(0x00,0x02);
Lcd_Write_Com(0x00,0xC0); //Set Default Gamma
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x35);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x01);
Lcd_Write_Data(0x00,0x02);
Lcd_Write_Com(0x00,0xC5); //Set frame rate
Lcd_Write_Data(0x00,0x04);
Lcd_Write_Com(0x00,0xD2); //power setting
Lcd_Write_Data(0x00,0x01);
Lcd_Write_Data(0x00,0x44);
Lcd_Write_Com(0x00,0xC8); //Set Gamma
Lcd_Write_Data(0x00,0x04);
Lcd_Write_Data(0x00,0x67);
Lcd_Write_Data(0x00,0x35);
Lcd_Write_Data(0x00,0x04);
Lcd_Write_Data(0x00,0x08);
Lcd_Write_Data(0x00,0x06);
Lcd_Write_Data(0x00,0x24);
Lcd_Write_Data(0x00,0x01);
Lcd_Write_Data(0x00,0x37);
Lcd_Write_Data(0x00,0x40);
Lcd_Write_Data(0x00,0x03);
Lcd_Write_Data(0x00,0x10);
Lcd_Write_Data(0x00,0x08);
Lcd_Write_Data(0x00,0x80);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Com(0x00,0x2A);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0xc7);
Lcd_Write_Com(0x00,0x2B);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0x00);
Lcd_Write_Data(0x00,0xeF);
Lcd_Write_Com(0x00,0x29); //display on
Lcd_Write_Com(0x00,0x2C); //display on
IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE ,1);
}
void Pant1(char VH,char VL)
{
unsigned short i,j;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE ,0);
Address_set(0,0,399,239);
for(i=0;i<240;i++)
{
for (j=0;j<400;j++)
{
Lcd_Write_Data(VH,VL);
}
}
IOWR_ALTERA_AVALON_PIO_DATA(PIO_CS_BASE,1);
}
void delay_ms(unsigned short i)
{
unsigned short j,k;
for(j=0;j<i;j++)
{
for(k=0;k<1000;k++);
}
}
int main()
{
alt_putstr("Hello from Nios II!\n");
/* Event loop never exits. */
Lcd_Init();
Pant1(0,0);
while (1);
return 0;
} |
|