初中生
最后登录1970-1-1
在线时间 小时
注册时间2021-11-8
|
显示屏资料上写着使用ILI9325驱动的8位数据口,因为是为51单片机设计的,现在想在STM32上使用,移植代码没有驱动成功,显示屏处于白屏状态。希望有大神给看看。8位数据口DB7--DB0分别对应 GPIOB9.B8.B7.B6.B5.B13.B12.B0
CS------GPIOA11
REST----GPIOB1
WR-----GPIOA12
RS----GPIOA15
VCC----5V
GND
第一部分是是LCD.H#ifndef __LCD_DOFLY_H
#define __LCD_DOFLY_H
#include "stm32f10x.h"
#include "Delay.h"
#define WINDOW_XADDR_START 0x0050 //水平起始地址集
#define WINDOW_XADDR_END 0x0051 // 水平结束地址集
#define WINDOW_YADDR_START 0x0052 // 垂直起始地址集
#define WINDOW_YADDR_END 0x0053 // 垂直结束地址集
#define GRAM_XADDR 0x0020 // GRAM水平地址集
#define GRAM_YADDR 0x0021 // GRAM垂直地址集
#define GRAMWR 0x0022 // 存储器写入
/*LCD_DOFLY接口定义-开头****************************/
//片选GPIO
#define LCD_DOFLY_CS_APBxClock_FUN RCC_APB2PeriphClockCmd
#define LCD_DOFLY_CS_CLK RCC_APB2Periph_GPIOA
#define LCD_DOFLY_CS_PORT GPIOA
#define LCD_DOFLY_CS_PIN GPIO_Pin_11
//读数据 仅做显示不使用
#define LCD_DOFLY_RD_APBxClock_FUN RCC_APB2PeriphClockCmd
#define LCD_DOFLY_RD_CLK RCC_APB2Periph_GPIOB
#define LCD_DOFLY_RD_PORT GPIOB
#define LCD_DOFLY_RD_PIN GPIO_Pin_3
//WR写入数据
#define LCD_DOFLY_WR_APBxClock_FUN RCC_APB2PeriphClockCmd
#define LCD_DOFLY_WR_CLK RCC_APB2Periph_GPIOA
#define LCD_DOFLY_WR_PORT GPIOA
#define LCD_DOFLY_WR_PIN GPIO_Pin_12
//数据/命令选择
#define LCD_DOFLY_RS_APBxClock_FUN RCC_APB2PeriphClockCmd
#define LCD_DOFLY_RS_CLK RCC_APB2Periph_GPIOA
#define LCD_DOFLY_RS_PORT GPIOA
#define LCD_DOFLY_RS_PIN GPIO_Pin_15
//画笔颜色
#define WHITE 0xFFFF //白色
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
//GUI颜色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
#define LIGHTGREEN 0X841F //浅绿色
#define LIGHTGRAY 0XEF5B //浅灰色(PANNEL)
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
#define LCD_DOFLY_CS(x) GPIO_WriteBit(GPIOA, GPIO_Pin_11, (BitAction)(x))
#define LCD_DOFLY_RS(x) GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(x))
//#define LCD_DOFLY_RD(x) GPIO_WriteBit(GPIOA, GPIO_Pin_1, (BitAction)(x))
#define LCD_DOFLY_WR(x) GPIO_WriteBit(GPIOA, GPIO_Pin_12, (BitAction)(x))
#define LCD_DOFLY_REST(x) GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)(x))
void Lcd_Configuration(void);
void LCD_DOFLY_Write_16Byte(uint16_t data);
void Write_Cmd_Data (unsigned int x,unsigned int y);
void Write_Data_U16(unsigned int y);
void Write_Cmd(unsigned char DH,unsigned char DL);
void Write_Data(unsigned char DH,unsigned char DL);
void delayms(unsigned int count);
void ILI9325_Initial(void);
void show_colour_bar (void);
void ClearScreen(unsigned int bColor);
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color);
/**********************************************/
#endif //LCD_DOFLY
第二部分是LCD.C
#include "LCD_51.h"
void Lcd_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*开启相应时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/*所有Lcd引脚配置为推挽输出*/
/*8位数据*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5 | GPIO_Pin_6
| GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/*控制脚*/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*****************************************************************************************************
***结束***
**********************************************************************************************************/
/**********************************************
函数名: LCD_DOFLY_WriteByte(uint8_t data)
功能:向Lcd写8位数据
入口参数:无
返回值:无
***********************************************/
static void LCD_DOFLY_WriteByte(uint8_t Byte)
{
GPIO_WriteBit(GPIOB, GPIO_Pin_9,(Byte & 0x80) >> 7 );
GPIO_WriteBit(GPIOB, GPIO_Pin_8,(Byte & 0x40) >> 6 );
GPIO_WriteBit(GPIOB, GPIO_Pin_7,(Byte & 0x20) >> 5 );
GPIO_WriteBit(GPIOB, GPIO_Pin_6,(Byte & 0x10) >> 4 );
GPIO_WriteBit(GPIOB, GPIO_Pin_5,(Byte & 0x08) >> 3 );
GPIO_WriteBit(GPIOB, GPIO_Pin_13,(Byte & 0x04) >> 2 );
GPIO_WriteBit(GPIOB, GPIO_Pin_12,(Byte & 0x02) >> 1 );
GPIO_WriteBit(GPIOB, GPIO_Pin_0,(Byte & 0x01) );
}
//void LCD_DOFLY_Write_16Byte(uint16_t data)
//{
// uint8_t MSB,MLB;
//
// MSB = ((data&0xFF00)<<8);
// MLB = (data&0xFF);
//
// Write_Data(MSB,MLB);
//}
void Write_Cmd_Data (unsigned int x,unsigned int y)
{
unsigned char m,n,MAX,MIN;
m = ((y & 0xFF00 )>> 8);
n = (y & 0xFF);
MAX = ((x & 0xFF00) >> 8);
MIN = (x & 0xFF);
Write_Cmd(MAX,MIN);
delayms(1);
Write_Data(m,n);
}
void Write_Data_U16(unsigned int y)
{
unsigned char m,n;
// LCD_DOFLY_CS(0);
// LCD_DOFLY_RS(1);
m = ((y & 0xFF00 )>> 8);
n = (y & 0xFF);
Write_Data(m,n);
// LCD_DOFLY_WR(0);
// LCD_DOFLY_WR(1);
// LCD_DOFLY_CS(1);
}
//====================== 写命令 ==========================//
void Write_Cmd(unsigned char DH,unsigned char DL)
{
LCD_DOFLY_CS(0);
LCD_DOFLY_RS(0);
LCD_DOFLY_WriteByte(DH);
LCD_DOFLY_WR(0);
LCD_DOFLY_WR(1);
LCD_DOFLY_WriteByte(DL);
LCD_DOFLY_WR(0);
LCD_DOFLY_WR(1);
LCD_DOFLY_CS(1);
}
//===================== 写数据 ===========================//
void Write_Data(unsigned char DH,unsigned char DL)
{
LCD_DOFLY_CS(0);
LCD_DOFLY_RS(1);
LCD_DOFLY_WriteByte(DH);
LCD_DOFLY_WR(0);
LCD_DOFLY_WR(1);
LCD_DOFLY_WriteByte(DL);
LCD_DOFLY_WR(0);
LCD_DOFLY_WR(1);
LCD_DOFLY_CS(1);
}
//=======================================================
void delayms(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<260;j++);
}
}
/*************************************************************
函数名称CD_DefineDispWindow
功 能:定义显示窗体
参 数:x0: 窗体中X坐标中较小者
x1: 窗体中X坐标中较大者
y0: 窗体中Y坐标中较小者
y1: 窗体中Y坐标中较大者
返 回 值:无
*************************************************************/
static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
Write_Cmd_Data(WINDOW_XADDR_START,x0);
Write_Cmd_Data(WINDOW_XADDR_END,x1);
Write_Cmd_Data(WINDOW_YADDR_START,y0);
Write_Cmd_Data(WINDOW_YADDR_END,y1);
Write_Cmd_Data(GRAM_XADDR,x0);
Write_Cmd_Data(GRAM_YADDR,y0);
Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR);
}
void ClearScreen(unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<320;i++)
{
for (j=0;j<240;j++)
Write_Data_U16(bColor);
}
}
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color)
{
unsigned int i,j;
//address_set();
LCD_SetPos(x0,x1,y0,y1);
for (i=y0;i<=y1;i++)
{
for (j=x0;j<=x1;j++)
Write_Data_U16(Color);
}
}
//====================== 显示彩条 ======================//
void show_colour_bar (void)
{
int V,H;
LCD_SetPos(0,240,0,320);//320x240
for(H=0;H<240;H++)
{
for(V=0;V<40;V++)
Write_Data(0xf8,0x00);
}
for(H=0;H<240;H++)
{
for(V=40;V<80;V++)
Write_Data(0x07,0xe0);
}
for(H=0;H<240;H++)
{
for(V=80;V<120;V++)
Write_Data(0x00,0x1f);
}
for(H=0;H<240;H++)
{
for(V=120;V<160;V++)
Write_Data(0xff,0xe0);
}
for(H=0;H<240;H++)
{
for(V=160;V<200;V++)
Write_Data(0xf8,0x1f);
}
for(H=0;H<240;H++)
{
for(V=200;V<240;V++)
Write_Data(0x07,0xff);
}
for(H=0;H<240;H++)
{
for(V=240;V<280;V++)
Write_Data(0xff,0xff);
}
for(H=0;H<240;H++)
{
for(V=280;V<320;V++)
Write_Data(0x00,0x00);
}
}
/************************************************
函数名:Lcd写开始函数
功能:控制Lcd控制引脚 执行写操作
入口参数:无
返回值:无
************************************************/
void Lcd_WR_Start(void)
{
LCD_DOFLY_CS(0);
LCD_DOFLY_RS(0);
Write_Data_U16(0x0022);
LCD_DOFLY_WR(0);
//Delay_nus(1);
LCD_DOFLY_WR(1);
LCD_DOFLY_RS(1);
}
//===================== 初始化代码 =======================//
void ILI9325_Initial(void)
{
Lcd_Configuration();
LCD_DOFLY_CS(1);
LCD_DOFLY_REST(0);
delayms(5000);
LCD_DOFLY_REST(1);
delayms(5000);
// LCD_DOFLY_CS(1);
// delayms(50);
// LCD_DOFLY_REST(0);
// delayms(50);
// LCD_DOFLY_REST(1);
// delayms(5000);
// Write_Cmd_Data(0x0000,0x0001);
Write_Cmd_Data(0x0001,0x0100); //驱动器输出控制
Write_Cmd_Data(0x0002,0x0700); //LCD驱动波形控制-反转
Write_Cmd_Data(0x0003,0x1030); //进入模式--F-
Write_Cmd_Data(0x0004,0x0000); //重新调整控制寄存器大小---缩放
Write_Cmd_Data(0x0008,0x0207); //Display Contral 2.(0x0207)
Write_Cmd_Data(0x0009,0x0000); //Display Contral 3.(0x0000)
Write_Cmd_Data(0x000A,0x0000); //Frame信号输出间隔
Write_Cmd_Data(0x000C,0x0000); //此处配置接口类型 8位 system接口//RGB显示接口控制1--16位
Write_Cmd_Data(0x000D,0x0000); //帧标记的位置
Write_Cmd_Data(0x000F,0x0000); //RGB显示接口控制1
// delayms(5);
// Write_Cmd_Data(0x07,0x0101); //Display Contral.
//delayms(5);
//power on sequence VGHVGL
Write_Cmd_Data(0x0010,0x0000); //Power Control 1.(0x16b0)
Write_Cmd_Data(0x0011,0x0007); //Power Control 2.(0x0001)
Write_Cmd_Data(0x0012,0x0000); //Power Control 3.(0x0138)
Write_Cmd_Data(0x0013,0x0000); //Power Control 4.
// Write_Cmd_Data(0x29,0x0000); //Power Control 7.
//vgh
Write_Cmd_Data(0x0010,0x1290); //1690
Write_Cmd_Data(0x0011,0x0227);
delayms(1);
//vregiout
Write_Cmd_Data(0x0012,0x001d); //0x001b 009D
delayms(1);
//vom amplitude
Write_Cmd_Data(0x0013,0x1500); //1900
delayms(1);
//vom H
Write_Cmd_Data(0x0029,0x0018); //25
Write_Cmd_Data(0x002B,0x000D); //帧速率和色彩控制---70
//gamma
Write_Cmd_Data(0x0030,0x0004); //0007
Write_Cmd_Data(0x0031,0x0307); //0303
Write_Cmd_Data(0x0032,0x0002);// 0006
Write_Cmd_Data(0x0035,0x0206);
Write_Cmd_Data(0x0036,0x0408); //0008
Write_Cmd_Data(0x0037,0x0507); //0406
Write_Cmd_Data(0x0038,0x0204);//0200
Write_Cmd_Data(0x0039,0x0707); //0007
Write_Cmd_Data(0x003C,0x0405);// 0504 //0602
Write_Cmd_Data(0x003D,0x0F02); //0008
//ram
Write_Cmd_Data(0x0050,0x0000); //水平GRAM起始位置
Write_Cmd_Data(0x0051,0x00EF); //水平GRAM终止位置
Write_Cmd_Data(0x0052,0x0000); //垂直GRAM起始位置
Write_Cmd_Data(0x0053,0x013F); //垂直GRAM终止位置
Write_Cmd_Data(0x0060,0xA700); //门扫描控制器
Write_Cmd_Data(0x0061,0x0001); //Driver Output Control.
Write_Cmd_Data(0x006A,0x0000); //Vertical Srcoll Control.
//
Write_Cmd_Data(0x0080,0x0000); //局部影像控制器1
Write_Cmd_Data(0x0081,0x0000); //局部影像控制器1--起始地址
Write_Cmd_Data(0x0082,0x0000); //局部影像控制器1--终止地址
Write_Cmd_Data(0x0083,0x0000); //Displsy Position? Partial Display 2.
Write_Cmd_Data(0x0084,0x0000); //RAM Address Start? Partial Display 2.
Write_Cmd_Data(0x0085,0x0000); //RAM Address End? Partial Display 2.
//
Write_Cmd_Data(0x0090,0x0010); //平板接口控制器1(0x0013
Write_Cmd_Data(0x0092,0x0600); //Panel Interface Contral 2.(0x0000)
Write_Cmd_Data(0x0093,0x0003); //Panel Interface Contral 3.
Write_Cmd_Data(0x0095,0x0110); //Frame Cycle Contral.(0x0110)
Write_Cmd_Data(0x0097,0x0000);
Write_Cmd_Data(0x0098,0x0000); //Frame Cycle Contral.
Write_Cmd_Data(0x0007,0x0133);
// Write_Cmd_Data(0x00,Ox22);//
}
/*===========================================================*/
MAIN函数是一个刷屏函数
#include "stm32f10x.h"
#include "BasicTime.h"
#include "led.h"
#include "Delay.h"
#include "usart.h"
#include "GT30L32S4W.h"
#include "SPI.H"
#include "LCD_51.h"
int main(void)
{
ILI9325_Initial();
BASIC_TIM_Init();
LED_Init();
SPI_Driving();
/* 配置串口为:115200 8-N-1 */
// USART_Config();
// printf("\r\n 这是一个2.4寸德飞莱显示屏测试实验 \r\n");
ClearScreen(RED);
while(1)
{
}
}
|
|