本帖最后由 fredinand 于 2010-12-26 14:16 编辑
我用的是ILI9325,八位数据模式,开发板为EMSTM32V100,RS,CS,WR,RD分别接到PE0,PE1,PE2,PE3,八位数据口接到PD0-7;下面是C代码和H文件
#include "lcd_ILI9325.h"
extern void Delay(vu32 nTime);
void LCD_Init()
{
LCD_config();
//************* Start Initial Sequence **********//
LCD_WR_COM_DATA(0x0001, 0x0100); // set SS and SM bit
LCD_WR_COM_DATA(0x0002, 0x0700); // set 1 line inversion
LCD_WR_COM_DATA(0x0003, 0x1030); // set GRAM write direction and BGR=1.
LCD_WR_COM_DATA(0x0004, 0x0000); // Resize register
LCD_WR_COM_DATA(0x0008, 0x0202); // set the back porch and front porch
LCD_WR_COM_DATA(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
LCD_WR_COM_DATA(0x000A, 0x0000); // FMARK function
LCD_WR_COM_DATA(0x000C, 0x0000); // RGB interface setting
LCD_WR_COM_DATA(0x000D, 0x0000); // Frame marker Position
LCD_WR_COM_DATA(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ****************//
LCD_WR_COM_DATA(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_WR_COM_DATA(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
LCD_WR_COM_DATA(0x0012, 0x0000); // VREG1OUT voltage
LCD_WR_COM_DATA(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
LCD_WR_COM_DATA(0x0007, 0x0001);
Delay(60000); // Dis-charge capacitor power voltage
LCD_WR_COM_DATA(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_WR_COM_DATA(0x0011, 0x0227); // R11h=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0]
Delay(50000); // Delay 50ms
LCD_WR_COM_DATA(0x0012, 0x001A); // External reference voltage= Vci;
Delay(50000); // Delay 50ms
LCD_WR_COM_DATA(0x0013, 0x1400); // R13=1200 when R12=009D;VDV[4:0] for VCOM amplitude
LCD_WR_COM_DATA(0x0029, 0x0024); // R29=000C when R12=009D;VCM[5:0] for VCOMH
LCD_WR_COM_DATA(0x002B, 0x000C); // Frame Rate
Delay(50000); // Delay 50ms
LCD_WR_COM_DATA(0x0020, 0x0000); // GRAM horizontal Address
LCD_WR_COM_DATA(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
LCD_WR_COM_DATA(0x0030, 0x0007);
LCD_WR_COM_DATA(0x0031, 0x0604);
LCD_WR_COM_DATA(0x0032, 0x0007);
LCD_WR_COM_DATA(0x0035, 0x0504);
LCD_WR_COM_DATA(0x0036, 0x0808);
LCD_WR_COM_DATA(0x0037, 0x0007);
LCD_WR_COM_DATA(0x0038, 0x0301);
LCD_WR_COM_DATA(0x0039, 0x0007);
LCD_WR_COM_DATA(0x003C, 0x0302);
LCD_WR_COM_DATA(0x003D, 0x0808);
//------------------ Set GRAM area ---------------//
LCD_WR_COM_DATA(0x0050, 0x0000); // Horizontal GRAM Start Address
LCD_WR_COM_DATA(0x0051, 0x00EF); // Horizontal GRAM End Address
LCD_WR_COM_DATA(0x0052, 0x0000); // Vertical GRAM Start Address
LCD_WR_COM_DATA(0x0053, 0x013F); // Vertical GRAM Start Address
LCD_WR_COM_DATA(0x0060, 0xA700); // Gate Scan Line
LCD_WR_COM_DATA(0x0061, 0x0001); // NDL,VLE, REV
LCD_WR_COM_DATA(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
LCD_WR_COM_DATA(0x0080, 0x0000);
LCD_WR_COM_DATA(0x0081, 0x0000);
LCD_WR_COM_DATA(0x0082, 0x0000);
LCD_WR_COM_DATA(0x0083, 0x0000);
LCD_WR_COM_DATA(0x0084, 0x0000);
LCD_WR_COM_DATA(0x0085, 0x0000);
//-------------- Panel Control -------------------//
LCD_WR_COM_DATA(0x0090, 0x0010);
LCD_WR_COM_DATA(0x0092, 0x0600);
LCD_WR_COM_DATA(0x0007, 0x0133); // 262K color and display ON
}
//向端口输送数据
void data_trans(u8 data)
{
GPIO_Write(GPIOD, (u16)data);
}
//写数据
void lcd_wr_u16_data(u16 data)
{
RS_high;
CS_low;
data_trans(data>>8);
WR_low;
WR_high;
data_trans(data);
WR_low;
WR_high;
CS_high;
}
//写命令
void lcd_wr_u16_command(u16 command)
{
RS_low;
CS_low;
data_trans(command>>8);
WR_low;
WR_high;
data_trans(command);
WR_low;
WR_high;
CS_high;
}
//写寄存器
void LCD_WR_COM_DATA(u16 Command,u16 data)
{
lcd_wr_u16_command(Command);
lcd_wr_u16_data(data);
}
void LCD_SET_LOCATION(u16 i,u16 j)
{
LCD_WR_COM_DATA(0x0020,0);//设置X坐标位置
LCD_WR_COM_DATA(0x0021,0);//设置Y坐标位置
lcd_wr_u16_command(0x0022);//指向RAM寄存器,准备写数据到RAM
}
void LCD_WR_DATA_BYTE(u8 DataH,u8 DataL)
{
RS_high;
CS_low;
data_trans(DataH);
WR_low;
WR_high;
data_trans(DataL);
WR_low;
WR_high;
CS_high;
}
void test_lcd_mon(void)
{
unsigned char i,j,k;
LCD_SET_LOCATION(0,0); //设置X,Y坐标
for(i=0;i<8;i++) //显示单色数据到LCD
for(j=0;j<40;j++)
for(k=0;k<240;k++)
LCD_WR_DATA_BYTE(color[i*2],color[i*2+1]);
}
void LCD_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//dataio
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//ctrlio
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//启动时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOD, ENABLE);
}
H文件
#include "stm32f10x_lib.h"
/*---------------------------- LCD color ---------------------------------*/
#define white 0xFFFF
#define black 0x0000
#define grey 0xF7DE//灰白
#define blue 0x001F
#define blue2 0x051F
#define red 0xF800
#define magenta 0xF81F//红紫
#define green 0x07E0
#define cyan 0x7FFF//青
#define yellow 0xFFE0
#define line0 0
#define line1 1*16
#define line2 2*16
#define line3 3*16
#define line4 4*16
#define line5 5*16
#define line6 6*16
#define line7 7*16
#define line8 8*16
#define line9 9*16
#define line10 10*16
#define line11 11*16
#define line12 12*16
#define line13 13*16
#define line14 14*16
#define line15 15*16
#define line16 16*16
#define line17 17*16
#define line18 18*16
#define line19 19*16
#define RS_high GPIO_SetBits(GPIOE, GPIO_Pin_0)
#define RS_low GPIO_ResetBits(GPIOE, GPIO_Pin_0)
#define CS_high GPIO_SetBits(GPIOE, GPIO_Pin_1)
#define CS_low GPIO_ResetBits(GPIOE, GPIO_Pin_1)
#define WR_high GPIO_SetBits(GPIOE, GPIO_Pin_2)
#define WR_low GPIO_ResetBits(GPIOE, GPIO_Pin_2)
#define RD_high GPIO_SetBits(GPIOE, GPIO_Pin_3)
#define RD_low GPIO_ResetBits(GPIOE, GPIO_Pin_3)
/*LCD function*/
void LCD_Init(void);
void test_lcd_mon(void);//彩条测试
void LCD_SET_LOCATION(u16 i,u16 j);
void LCD_WR_COM_DATA(u16 Command,u16 data);
void LCD_config(void);
void data_trans(u8 data);
void LCD_WR_DATA_BYTE(u8 DataH,u8 DataL);
void lcd_wr_u16_data(u16 data);
void lcd_wr_u16_command(u16 data);
u16 color[]={0xf8,0x00,0x07,0xe0,0x00,0x1f,0xff,0xe0,0x00,0x00,0xff,0xff,0x07,0xff,0xf8,0x1f};
调试截图
|