初中生
最后登录1970-1-1
在线时间 小时
注册时间2021-11-8
|
显示屏 使用ILI9325 驱动 数据输入口位 8位
一直驱动不起来 白屏状态。使用51可以正常显示。有大神帮忙看看
****************************************************************
LCD.h文件
#ifndef _LCD_DOFLY_H_
#define _LCD_DOFLY_H_
#include "stm32f10x.h"
//#define DB0_7_RCC RCC_APB2Periph_GPIOB
//#define DB_8_15_RCC RCC_APB2Periph_GPIOC
//-------------------------------------------
#define nCsPin_RCC RCC_APB2Periph_GPIOA
#define nCsPin_Port GPIOA
#define nCsPin GPIO_Pin_11
#define RsPin_RCC RCC_APB2Periph_GPIOA
#define RsPin_Port GPIOA
#define RsPin GPIO_Pin_15
#define nWrPin_RCC RCC_APB2Periph_GPIOA
#define nWrPin_Port GPIOA
#define nWrPin GPIO_Pin_12
#define nRdPin_RCC RCC_APB2Periph_GPIOA
#define nRdPin_Port GPIOA
#define nRdPin GPIO_Pin_1
#define nRstPin_RCC RCC_APB2Periph_GPIOB
#define nRstPin_Port GPIOB
#define nRstPin GPIO_Pin_1
//#define LightPin_RCC RCC_APB2Periph_GPIOB
//#define LightPin_Port GPIOB
//#define LightPin GPIO_Pin_0
//-----------------------------------------
#define Set_nWr GPIO_SetBits (nWrPin_Port, nWrPin)//nCsPin_Port->BSRR = nWrPin // GPIO_SetBits (nWrPin_Port, nWrPin)
#define Clr_nWr GPIO_ResetBits (nWrPin_Port, nWrPin)//nCsPin_Port->BRR = nWrPin // GPIO_ResetBits (nWrPin_Port, nWrPin)
#define Set_Cs GPIO_SetBits (nCsPin_Port, nCsPin)//nCsPin_Port->BSRR = nCsPin // GPIO_SetBits (nCsPin_Port, nCsPin)
#define Clr_Cs GPIO_ResetBits (nCsPin_Port, nCsPin)//nCsPin_Port->BRR = nCsPin// GPIO_ResetBits (nCsPin_Port, nCsPin)
#define Set_Rs GPIO_SetBits (RsPin_Port, RsPin) //RsPin_Port->BSRR = RsPin // GPIO_SetBits (RsPin_Port, RsPin)
#define Clr_Rs GPIO_ResetBits (RsPin_Port, RsPin)//RsPin_Port->BRR = RsPin // GPIO_ResetBits (RsPin_Port, RsPin)
#define Set_nRd GPIO_SetBits (nRdPin_Port, nRdPin)//nRdPin_Port->BSRR = nRdPin // GPIO_SetBits (nRdPin_Port, nRdPin)
#define Clr_nRd GPIO_ResetBits (nRdPin_Port, nRdPin)//nRdPin_Port->BRR = nRdPin // GPIO_ResetBits (nRdPin_Port, nRdPin)
#define Set_Rst GPIO_SetBits (nRstPin_Port, nRstPin)//nRstPin_Port->BSRR = nRstPin// GPIO_SetBits (nRstPin_Port, nRstPin)
#define Clr_Rst GPIO_ResetBits (nRstPin_Port, nRstPin)//nRstPin_Port->BRR = nRstPin // GPIO_ResetBits (nRstPin_Port, nRstPin)
#define Set_Light GPIO_SetBits (LightPin_Port, LightPin)//LightPin_Port->BSRR = LightPin// GPIO_SetBits (LightPin_Port, LightPin)
#define Clr_Light GPIO_ResetBits (LightPin_Port, LightPin)//LightPin_Port->BRR = LightPin // GPIO_ResetBits (LightPin_Port, LightPin)
//---------------------------------
#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
void Lcd_Configuration(void); //初始化GPIO
void LCD_ili9320_Initializtion(void); //初始化ILI9320---uCGUI需要使用--1
void LCD_ili9320_Reset(void);
void delayms(int count);
void LCD_ili9320_SetCursor(u16 x,u16 y); //设置坐标---uCGUI需要使用--2
void LCD_ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY); //设置窗体
void LCD_ili9320_Clear(u16 dat); //清屏
void LCD_ili9320_Test(void);
void LCD_ili9320_Write_Byte(uint8_t Byte); //写8位数据 因为是8个IO需要这个函数
void LCD_ili9320_WriteData(uint16_t data); //写数据
void LCD_ili9320_WriteCMD(uint16_t data); //写地址
void LCD_ili9320_WriteIndex(u16 idx); //写地址
void LCD_ili9320_WriteRegister(u16 index,u16 dat); //写寄存器
u16 LCD_ili9320_BGR2RGB(u16 c); //转换颜色格式
u16 LCD_ili9320_Color565(u32 RGB); // RGB颜色转为16位(565)
#endif
*********************************************************
LCD.C
#include "LCD_DOFLY.h"
#include "font.h"
void Lcd_Configuration(void)
{
GPIO_InitTypeDef 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_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
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_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/****************************************************************************
* 功 能:向 ili9320 写8位数据
* 入口参数:Byte 寄存器数据
* 说 明:LCD8位数据口输入先写高位
****************************************************************************/
void LCD_ili9320_Write_Byte(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));
}
/****************************************************************************
* 功 能:写 ili9320 寄存器数据
* 入口参数:dat 寄存器数据
* 说 明:向控制器指定地址写入数据,调用前需先写寄存器地址,内部函数
* 名字: GGM
****************************************************************************/
void LCD_ili9320_WriteData(uint16_t data)
{
uint8_t m,n;
m = ((data&0xFF00)>>8);
n = (data&0xFF);
Clr_Cs; //片选
Set_Rs; //选择数据 RS=1
delayms(1);
LCD_ili9320_Write_Byte( m );
Clr_nWr;
delayms(1);
Set_nWr; // 写入数据
LCD_ili9320_Write_Byte( n );
Clr_nWr;
delayms(1);
Set_nWr; // 写入数据
Set_Cs; //结束片选
// GPIOB->ODR = (GPIOB->ODR & 0x00ff) | (((data << 8) >> 8) << 8); // 低8位数据写入CPIOB高8位
// GPIOC->ODR = (GPIOC->ODR & 0xff00) | (((data >> 8) << 8) >> 8); // 高8位数据写入CPIOC低8位
}
/****************************************************************************
* 功 能:写 ili9320 寄存器数据
* 入口参数:data 寄存器数据
* 说 明:向控制器指定地址写入数据,调用前需先写寄存器地址,内部函数
* 名字: GGM
****************************************************************************/
void LCD_ili9320_WriteCMD(uint16_t data)
{
uint8_t m,n;
m = ((data&0xFF00)>>8);
n = (data&0xFF);
Clr_Cs; //片选 CS=0
Clr_Rs; //选择地址 RS=0
delayms(1);
LCD_ili9320_Write_Byte( m );
Clr_nWr; //WR=0
delayms(1);
Set_nWr; // 写入数据 WR=1
LCD_ili9320_Write_Byte( n );
Clr_nWr;
delayms(1);
Set_nWr; // 写入数据
Set_Cs; //结束片选
// GPIOB->ODR = (GPIOB->ODR & 0x00ff) | (((data << 8) >> 8) << 8); // 低8位数据写入CPIOB高8位
// GPIOC->ODR = (GPIOC->ODR & 0xff00) | (((data >> 8) << 8) >> 8); // 高8位数据写入CPIOC低8位
}
/****************************************************************************
* 功 能:写 ili9320 控制器寄存器地址
* 入口参数:idx 寄存器地址
****************************************************************************/
void LCD_ili9320_WriteIndex(u16 idx)
{
// Clr_Rs;
// Set_nRd;
LCD_ili9320_WriteCMD(idx);
// Clr_nWr;
// Set_nWr;
// Set_Rs;
}
/****************************************************************************
* 功 能:写指定地址寄存器的值
* 入口参数:index 寄存器地址
* :dat 寄存器值
****************************************************************************/
void LCD_ili9320_WriteRegister(u16 index,u16 dat)
{
/************************************************************************
** **
** nCS ----\__________________________________________/------- **
** RS ------\____________/----------------------------------- **
** nRD ------------------------------------------------------- **
** nWR --------\_______/--------\_____/----------------------- **
** DB[0:15] ---------[index]----------[data]----------------------- **
** **
************************************************************************/
// Clr_Cs;
// Clr_Rs;
// Set_nRd;
LCD_ili9320_WriteCMD(index);//地址
// Clr_nWr;
// Set_nWr;
// Set_Rs;
LCD_ili9320_WriteData(dat); //值
// Clr_nWr;
// Set_nWr;
// Set_Cs;
}
void delayms(int count) // X1ms
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1000;j++);
}
void LCD_ili9320_Initializtion (void) //--功 能:初始化 ILI9320 控制器
{
Lcd_Configuration();
Set_Rst;
delayms(200);
Clr_Rst;
delayms(1000);
LCD_ili9320_WriteRegister(0x0000,0x0001); // Start OCS
delayms(200);
LCD_ili9320_WriteRegister(0x00e7,0x0010);
LCD_ili9320_WriteRegister(0x0000,0x0001); //开启内部时钟
LCD_ili9320_WriteRegister(0x0001,0x0100);
LCD_ili9320_WriteRegister(0x0002,0x0700); //电源开启
LCD_ili9320_WriteRegister(0x0003,(1<<12)|(3<<4)|(0<<3) ); //65K
LCD_ili9320_WriteRegister(0x0004,0x0000);
LCD_ili9320_WriteRegister(0x0008,0x0207);
LCD_ili9320_WriteRegister(0x0009,0x0000);
LCD_ili9320_WriteRegister(0x000a,0x0000); //display setting
LCD_ili9320_WriteRegister(0x000c,0x0001); //display setting
LCD_ili9320_WriteRegister(0x000d,0x0000); //0f3c
LCD_ili9320_WriteRegister(0x000f,0x0000);
//电源配置
LCD_ili9320_WriteRegister(0x0010,0x0000);
LCD_ili9320_WriteRegister(0x0011,0x0007);
LCD_ili9320_WriteRegister(0x0012,0x0000);
LCD_ili9320_WriteRegister(0x0013,0x0000);
delayms(5);
LCD_ili9320_WriteRegister(0x0010,0x1590);
LCD_ili9320_WriteRegister(0x0011,0x0227);
delayms(5);
LCD_ili9320_WriteRegister(0x0012,0x009c);
delayms(5);
LCD_ili9320_WriteRegister(0x0013,0x1900);
LCD_ili9320_WriteRegister(0x0029,0x0023);
LCD_ili9320_WriteRegister(0x002b,0x000e);
delayms(5);
LCD_ili9320_WriteRegister(0x0020,0x0000);
LCD_ili9320_WriteRegister(0x0021,0x013f);
delayms(5);
//伽马校正
LCD_ili9320_WriteRegister(0x0030,0x0007);
LCD_ili9320_WriteRegister(0x0031,0x0707);
LCD_ili9320_WriteRegister(0x0032,0x0006);
LCD_ili9320_WriteRegister(0x0035,0x0704);
LCD_ili9320_WriteRegister(0x0036,0x1f04);
LCD_ili9320_WriteRegister(0x0037,0x0004);
LCD_ili9320_WriteRegister(0x0038,0x0000);
LCD_ili9320_WriteRegister(0x0039,0x0706);
LCD_ili9320_WriteRegister(0x003c,0x0701);
LCD_ili9320_WriteRegister(0x003d,0x000f);
delayms(5);
LCD_ili9320_WriteRegister(0x0050,0x0000); //水平GRAM起始位置
LCD_ili9320_WriteRegister(0x0051,0x00ef); //水平GRAM终止位置
LCD_ili9320_WriteRegister(0x0052,0x0000); //垂直GRAM起始位置
LCD_ili9320_WriteRegister(0x0053,0x013f); //垂直GRAM终止位置
LCD_ili9320_WriteRegister(0x0060,0xa700);
LCD_ili9320_WriteRegister(0x0061,0x0001);
LCD_ili9320_WriteRegister(0x006a,0x0000);
LCD_ili9320_WriteRegister(0x0080,0x0000);
LCD_ili9320_WriteRegister(0x0081,0x0000);
LCD_ili9320_WriteRegister(0x0082,0x0000);
LCD_ili9320_WriteRegister(0x0083,0x0000);
LCD_ili9320_WriteRegister(0x0084,0x0000);
LCD_ili9320_WriteRegister(0x0085,0x0000);
LCD_ili9320_WriteRegister(0x0090,0x0010);
LCD_ili9320_WriteRegister(0x0092,0x0000);
LCD_ili9320_WriteRegister(0x0093,0x0003);
LCD_ili9320_WriteRegister(0x0095,0x0110);
LCD_ili9320_WriteRegister(0x0097,0x0000);
LCD_ili9320_WriteRegister(0x0098,0x0000);
//开启显示设置
LCD_ili9320_WriteRegister(0x0007,0x0133);
LCD_ili9320_WriteRegister(0x0020,0x0000);
LCD_ili9320_WriteRegister(0x0021,0x013f);
delayms(200);
}
void LCD_ili9320_SetCursor(u16 x,u16 y) //--功 能:设置屏幕座标
{
LCD_ili9320_WriteRegister(0x0020,x); // 行
LCD_ili9320_WriteRegister(0x0021,y); // 列
}
/****************************************************************************
* 功 能:设置窗口区域
* 入口参数:StartX 行起始座标
* StartY 列起始座标
* EndX 行结束座标
* EndY 列结束座标
****************************************************************************/
void LCD_ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY)
{
LCD_ili9320_SetCursor(StartX,StartY);
LCD_ili9320_WriteRegister(0x0050, StartX);
LCD_ili9320_WriteRegister(0x0052, StartY);
LCD_ili9320_WriteRegister(0x0051, EndX);
LCD_ili9320_WriteRegister(0x0053, EndY);
}
/****************************************************************************
* 功 能:将屏幕填充成指定的颜色,如清屏,则填充 0xffff
* 入口参数:dat 填充值
****************************************************************************/
void LCD_ili9320_Clear(u16 dat)
{
u32 i;
LCD_ili9320_SetCursor(0x0000, 0x0000);
// Clr_Cs;
LCD_ili9320_WriteIndex(0x0022);
// Set_Rs;
for(i = 0; i < 768000; i++) //240*320=76800
{
LCD_ili9320_WriteData(dat);
// Clr_nWr;
// Set_nWr;
}
// Set_Cs;
}
/****************************************************************************
* 功 能:RRRRRGGGGGGBBBBB 改为 BBBBBGGGGGGRRRRR 格式
* 入口参数:c BRG 颜色值
* 出口参数:RGB 颜色值
****************************************************************************/
u16 LCD_ili9320_BGR2RGB(u16 c)
{
u16 r, g, b, rgb;
b = (c>>0) & 0x1f;
g = (c>>5) & 0x3f;
r = (c>>11) & 0x1f;
rgb = (b<<11) + (g<<5) + (r<<0);
return( rgb );
}
/****************************************************************************
* 功 能:复位 ili9320 控制器
* 说 明:复位控制器,内部函数
****************************************************************************/
void LCD_ili9320_Reset()
{
}
/****************************************************************************
* 功 能:将RGB颜色转换为16位颜色。
* 入口参数:RGB 颜色值
* 出口参数:返回16位RGB颜色值。
****************************************************************************/
u16 LCD_ili9320_Color565(u32 RGB)
{
u8 r, g, b;
b = ( RGB >> (0+3) ) & 0x1f; // 取B色的高5位
g = ( RGB >> (8+2) ) & 0x3f; // 取G色的高6位
r = ( RGB >> (16+3)) & 0x1f; // 取R色的高5位
return( (r<<11) + (g<<5) + (b<<0) );
}
*******************************************************************8
main 函数刷屏
#include "stm32f10x.h"
#include "BasicTime.h"
#include "led.h"
#include "Delay.h"
#include "usart.h"
#include "GT30L32S4W.h"
#include "SPI.H"
#include "LCD_DOFLY.h"
uint16_t tim;
/*
* 函数名:main
* 描述 :主函数
* 输入 :无
* 输出 :无
*/
int main(void)
{
BASIC_TIM_Init();
LED_Init();
LCD_ili9320_Initializtion();
// SPI_Driving();
/* 配置串口为:115200 8-N-1 */
// USART_Config();
// printf("\r\n 这是一个2.4寸德飞莱显示屏测试实验 \r\n");
LCD_ili9320_Clear(Blue);
while(1)
{
// LCD_ili9320_Write_Byte(0XFF);
// LCD_ili9320_Clear(Blue);
}
}
|
|