我想这样配置
rs pa0
wr pa1
rd pa2
cs pa3
reset pa8
db0-pb0
db1-pb1
db2-pb2
......
db15-pb15
下面附原码
/*
[url=]\\\|///[/url]
\\ - - //
( @ @ )
+---------------------oOOo-(_)-oOOo-------------------------+
| Author :wang kai |
| Data :2010-04-29 |
| Version :V01 |
| QQ :447926737 |
| Function :drive for 240*320 lcd |
| |
| Discription: |
| drive ic: ILI9325 (9320) |
| IM3 = 0 : 8080 16bits paralle MPU interface |
| DB1--DB8 DB10--DB17 are used |
| History : |
| |
| Oooo |
+-----------------------oooO--( )-------------------------+
( ) ) /
\ ( (_/
\_)
*/
/*---------------------------------------------------------------------------
引脚:
DOTCLK --VCC DB1 --PD14 D0
VSYNC --VCC DB2 --PD15 D1
HSYNS --VCC DB3 --PD0 D2
DEN --VCC DB4 --PD1 D3
IM3 --GND DB5 --PE7 D4
DB9 --GND DB6 --PE8 D5
DB0 --GND DB7 --PE9 D6
DB8 --PE10 D7
BL_CN -- PA8 TIM1_CH1//背光灯 DB10 --PE11 D8
DB11 --PE12 D9
CS# --PG12 DB12 --PE13 D10
RS --PF0 DB13 --PE14 D11
WR# --PD5 DB14 --PE15 D12
RD# --PD4 DB15 --PD8 D13
RESET# -- DB16 --PD9 D14
DB17 --PD10 D15
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
* LCD MPU interface & RGB interface
MCU模式:目前最常用的连接模式,一般是80系统(68系统已经不存在了)。数据位
传输有8位,9位,16位和18位。连线分为:CS/,RS(寄存器选择),RD/,WR/,再就
是数据线了。
优点是:控制简单方便,无需时钟和同步信号。
缺点是:要耗费GRAM,所以难以做到大屏。
RGB模式:大屏采用较多的模式,数据位传输也有6位,16位和18位之分。连线一般有:VSYNC,HSYNC
,DOTCLK,VLD,ENABLE,剩下就是数据线。它的优缺点正好和MCU模式相反。
MCU接口: 由 timing generator 产生时序信号,驱动 COM 和SEG驱动器。
RGB接口: 在写LCD register setting时,和MPU没有区别,用于液晶的初始化,常用的
模式是串口(这个串口是模拟串口,因为SCL,CS,SDK是挂在I/O上)两者的区别只在于
图像的写入方式。
* 操作 ili9325 其实就是写其内部 register 和 GRAM
读写 GRAM之前要先写入 0x0022 (参考ILI9325DS_V0.25.pdf page 82)
* _____________ G320 G319 (0,0)
| | | | --------->>X
| | Y 320 | | |
| | / \ | | |
| | | | | |
| | | | | |
| | | | | |
| | | G2 G1 |
|____________| | S1------------S720 \/
(0,0) Y
X <------------
240
操作 时 x(column)方向减
y(row) 方向减
GRAM地址 在 X方向更新
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "lcd_ili9325.h"
#include "lcd_light.h"
/*-------------------------------------------------------------------------*/
#define pin_cs (1 << 12)//pg12
#define pin_rs (1 << 0)//pf0
#define pin_wr (1 << 5)//pd5
#define pin_rd (1 << 4)//pd4
#define lcd_cs(x) GPIOG->ODR = (GPIOG->ODR & ~pin_cs) | (x ? pin_cs : 0);
#define lcd_rs(x) GPIOF->ODR = (GPIOF->ODR & ~pin_rs) | (x ? pin_rs : 0);
#define lcd_wr(x) GPIOD->ODR = (GPIOD->ODR & ~pin_wr) | (x ? pin_wr : 0);
#define lcd_rd(x) GPIOD->ODR = (GPIOD->ODR & ~pin_rd) | (x ? pin_rd : 0);
static unsigned int text_color = red, back_color = white;
/*-------------------------------------------------------------------------*/
//延时函数
static
void delay(volatile unsigned long cnt)
{
volatile unsigned int i = 0;
while(cnt--)
{
for (i = 0; i < 2; i++)
{
__nop();
}
}
}
//数据总线输入 d0---d15
static
void lcd_dataline_in(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 |
GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
//数据总线输出方向 d0---d15
static
void lcd_dataline_out(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 |
GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
//从总线读数据
static
unsigned int bus_data_read(void)
{
unsigned int data = 0, i = 0, j = 0;
lcd_dataline_in();
delay(20);
i = GPIOD->IDR;
j = GPIOE->IDR;
data |= (i >> 14) & 0x0001;//pd14 d0
data |= (i >> 14) & 0x0002;//pd15 d1
data |= (i << 2) & 0x0004;//pd0 d2
data |= (i << 2) & 0x0008;//pd1 d3
data |= (j >> 3) & 0x1ff0;//pe7--15 d4--d12
data |= (i >> 5) & 0x0010;//pd8 d13
data |= (i >> 5) & 0x0020;//pd9 d14
data |= (i >> 5) & 0x0040;//pd10 d15
lcd_dataline_out();
return data;
}
//数据送入总线
static
void bus_data_write(unsigned int data)
{
//先清掉d0--d15
GPIO_ResetBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 \
| GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15);
GPIO_ResetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 \
| GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
//再把相应位置1
if (data & 0x0001) GPIO_SetBits(GPIOD, GPIO_Pin_14);//d0
if (data & 0x0002) GPIO_SetBits(GPIOD, GPIO_Pin_15);//d1
if (data & 0x0004) GPIO_SetBits(GPIOD, GPIO_Pin_0);//d2
if (data & 0x0008) GPIO_SetBits(GPIOD, GPIO_Pin_1);//d3
GPIO_SetBits(GPIOE, (data & 0x1ff0)<<3);//d4--d12
GPIO_SetBits(GPIOD, (data & 0xe000)>>5);//d3--d15
}
//与lcd的控制io口配置
static
void lcd_io_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//打开io口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
// cs rs wr rd 输出模式
//rd wr
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//rs
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOF, &GPIO_InitStructure);
//cs
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOG, &GPIO_InitStructure);
//BL_CN
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOA, &GPIO_InitStructure);
lcd_dataline_out();
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
功能: 写lcd内部寄存器
---------------------------------------------------------------------------*/
void lcd_write_reg(unsigned int reg_index, unsigned int data)
{
lcd_cs(0);
lcd_rs(0);//cmd
lcd_rd(1);
delay(1);
bus_data_write(reg_index);
lcd_wr(0);//上升沿写入
delay(1);
lcd_wr(1);
lcd_rs(1);//data
delay(1);
bus_data_write(data);
lcd_wr(0);//上升沿写入
delay(1);
lcd_wr(1);
lcd_cs(1);
}
/*---------------------------------------------------------------------------
功能: 写命令
---------------------------------------------------------------------------*/
void lcd_write_cmd(unsigned int cmd)
{
lcd_cs(0);
lcd_rs(0);//cmd
lcd_rd(1);
delay(1);
bus_data_write(cmd);
lcd_wr(0);//上升沿写入
delay(1);
lcd_wr(1);
lcd_cs(1);
}
/*---------------------------------------------------------------------------
功能: 写数据
---------------------------------------------------------------------------*/
void lcd_write_data(unsigned int data)
{
lcd_cs(0);
lcd_rs(1);//data
lcd_rd(1);
delay(1);
bus_data_write(data);
lcd_wr(0);//上升沿写入
delay(1);
lcd_wr(1);
lcd_cs(1);
}
/*---------------------------------------------------------------------------
功能: 读数据
---------------------------------------------------------------------------*/
unsigned int lcd_read_data(void)
{
unsigned int data = 0;
lcd_cs(0);
lcd_rs(1);//data
lcd_wr(1);
lcd_rd(0);
delay(1);
data = bus_data_read();
lcd_rd(1);
lcd_cs(1);
return data;
}
/*---------------------------------------------------------------------------
功能: lcd 初始化
---------------------------------------------------------------------------*/
void lcd_ili9325_init(void)
{
lcd_io_config();
delay(50);
//tim1_init();//pwm调节亮度
//用3225加上这三条
//lcd_write_reg(0x00e3, 0x3008);//Set internal timing
//lcd_write_reg(0x00e7, 0x0012);//Set internal timing
//lcd_write_reg(0x00ef, 0x1231);//Set internal timing
lcd_write_reg(0x0001, 0x0000);/* set SS=0 and SM=0 S1---S720 */
lcd_write_reg(0x0002, 0x0700);// set 1 line inversion
lcd_write_reg(0x0003, 0x1030);// set GRAM write direction and BGR=1.
lcd_write_reg(0x0004, 0x0000);// Resize register
lcd_write_reg(0x0008, 0x0207);// set the back porch and front porch
lcd_write_reg(0x0009, 0x0000);// set non-display area refresh cycle ISC[3:0]
lcd_write_reg(0x000a, 0x0000);// FMARK function
lcd_write_reg(0x000c, 0x0000);// RGB interface setting
lcd_write_reg(0x000d, 0x0000);// Frame marker Position
lcd_write_reg(0x000f, 0x0000);// RGB interface polarity
/*-------------power on sequence------------*/
lcd_write_reg(0x0010, 0x0000);// SAP, BT[3:0], AP, DSTB, SLP, STB
lcd_write_reg(0x0011, 0x0007);// DC1[2:0], DC0[2:0], VC[2:0]
lcd_write_reg(0x0012, 0x0000);// VREG1OUT voltage
lcd_write_reg(0x0013, 0x0000);// VDV[4:0] for VCOM amplitude
delay(400000); // Delay 200 MS , Dis-charge capacitor power voltage
lcd_write_reg(0x0010, 0x1690);// SAP, BT[3:0], AP, DSTB, SLP, STB
lcd_write_reg(0x0011, 0x0227);// R11H=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0]
delay(100000); // Delay 50ms
lcd_write_reg(0x0012, 0x001d);// External reference voltage= Vci;001d
delay(100000); // Delay 50ms
lcd_write_reg(0x0013, 0x0800);// R13H=1D00 when R12H=009D;VDV[4:0] for VCOM amplitude
lcd_write_reg(0x0029, 0x0014);// R29H=0013 when R12H=009D;VCM[5:0] for VCOMH
lcd_write_reg(0x002b, 0x000B);// Frame Rate = 96Hz
delay(100000); // Delay 50ms
lcd_write_reg(0x0020, 0x0000);// GRAM horizontal Address
lcd_write_reg(0x0021, 0x0000);// GRAM Vertical Address
/* ----------- Adjust the Gamma Curve ---------- */
lcd_write_reg(0x0030, 0x0007);
lcd_write_reg(0x0031, 0x0707);
lcd_write_reg(0x0032, 0x0006);
lcd_write_reg(0x0035, 0x0704);
lcd_write_reg(0x0036, 0x1F04);
lcd_write_reg(0x0037, 0x0004);
lcd_write_reg(0x0038, 0x0000);
lcd_write_reg(0x0039, 0x0706);
lcd_write_reg(0x003c, 0x0701);
lcd_write_reg(0x003d, 0x000F);
/* ------------------ Set GRAM area --------------- */
lcd_write_reg(0x0050, 0x0000);// Horizontal GRAM Start Address
lcd_write_reg(0x0051, 239);// Horizontal GRAM End Address
lcd_write_reg(0x0052, 0x0000);// Vertical GRAM Start Address
lcd_write_reg(0x0053, 319);// Vertical GRAM Start Address
lcd_write_reg(0x0060, 0x2700);/* GS=0 320 line */
lcd_write_reg(0x0061, 0x0001);// NDL,VLE(滚屏允许), REV(灰度翻转)
lcd_write_reg(0x006a, 0x0000);// set scrolling line
/* -------------- Partial Display Control --------- */
lcd_write_reg(0x0080, 0x0000);
lcd_write_reg(0x0081, 0x0000);
lcd_write_reg(0x0082, 0x0000);
lcd_write_reg(0x0083, 0x0000);
lcd_write_reg(0x0084, 0x0000);
lcd_write_reg(0x0085, 0x0000);
/* -------------- Panel Control ------------------- */
lcd_write_reg(0x0090, 0x0010);
lcd_write_reg(0x0092, 0x0000);
lcd_write_reg(0x0093, 0x0003);
lcd_write_reg(0x0095, 0x0110);
lcd_write_reg(0x0097, 0x0000);
lcd_write_reg(0x0098, 0x0000);
/* Set GRAM write direction and BGR = 1 */
/* I/D=11 (Horizontal : increment, Vertical : increment) */
/* AM=0 (address is updated in Horizontal writing direction) */
lcd_write_reg(0x0003, 0x1030);
lcd_write_reg(0x0007, 0x0173);// 262K color and display ON
} |
|