#include"tftlcd.h"
#define CSH GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define CSL GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define WRH GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define WRL GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define RSH GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define RSL GPIO_ResetBits(GPIOA,GPIO_Pin_3)
#define RDH GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define RDL GPIO_ResetBits(GPIOA,GPIO_Pin_4)
#define RESTH GPIO_SetBits(GPIOA,GPIO_Pin_5)
#define RESTL GPIO_ResetBits(GPIOA,GPIO_Pin_5)
void delayms( u16 x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<72000;j++);
}
void RCC_config(void)
{
RCC->APB2ENR|=1<<2;
RCC->APB2ENR|=1<<3;
GPIOA->CRL&=0xff00000f;
GPIOA->CRL|=0x00333330;
GPIOA->ODR|=0x003e;
GPIOB->CRL&=0x00000000;
GPIOB->CRL|=0x33333333;
GPIOB->CRH&=0x00000000;
GPIOB->CRH|=0x33333333;
GPIOB->ODR|=0xffff;
}
void Write_Cmd(u16 address)
{
CSL;
RSL;
GPIOB->ODR=address;
WRL;
WRH;
CSH;
}
void Write_Dat(u16 date)
{
RSH;
CSL;
GPIOB->ODR=date;
WRL;
WRH;
CSH;
}
void Write_Cmd_Dat(u16 address,u16 date)
{
Write_Cmd(address);
Write_Dat(date);
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
Write_Cmd_Dat(0x0044,(x2<<8)+x1);
Write_Cmd_Dat(0x0045,y1);
Write_Cmd_Dat(0x0046,y2);
Write_Cmd_Dat(0x004e,x1);
Write_Cmd_Dat(0x004f,y1);
Write_Cmd(0x0022);
}
void Pant(unsigned int color)
{
int i,j;
Address_set(0,0,239,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
Write_Dat(color);
}
}
}
void LCD_Init()
{
RESTH;
delayms(5);
RESTL;
delayms(5);
RESTH;
delayms(5);
CSH;
RDH;
WRH;
delayms(5);
Write_Cmd_Dat(0x0000,0x0001); delayms(1); //打开晶振
Write_Cmd_Dat(0x0003,0xA8A4); delayms(1); //0xA8A4
Write_Cmd_Dat(0x000C,0x0000); delayms(1);
Write_Cmd_Dat(0x000D,0x080C); delayms(1);
Write_Cmd_Dat(0x000E,0x2B00); delayms(1);
Write_Cmd_Dat(0x001E,0x00B7); delayms(1);
Write_Cmd_Dat(0x0001,0x2B3F); delayms(1); //驱动输出控制320*240 0x6B3F
Write_Cmd_Dat(0x0002,0x0600); delayms(1);
Write_Cmd_Dat(0x0010,0x0000); delayms(1);
Write_Cmd_Dat(0x0011,0x6070); delayms(1); //0x4030 //定义数据格式 16位色
Write_Cmd_Dat(0x0005,0x0000); delayms(1);
Write_Cmd_Dat(0x0006,0x0000); delayms(1);
Write_Cmd_Dat(0x0016,0xEF1C); delayms(1);
Write_Cmd_Dat(0x0017,0x0003); delayms(1);
Write_Cmd_Dat(0x0007,0x0233); delayms(1); //0x0233
Write_Cmd_Dat(0x000B,0x0000); delayms(1);
Write_Cmd_Dat(0x000F,0x0000); delayms(1); //扫描开始地址
Write_Cmd_Dat(0x0041,0x0000); delayms(1);
Write_Cmd_Dat(0x0042,0x0000); delayms(1);
Write_Cmd_Dat(0x0048,0x0000); delayms(1);
Write_Cmd_Dat(0x0049,0x013F); delayms(1);
Write_Cmd_Dat(0x004A,0x0000); delayms(1);
Write_Cmd_Dat(0x004B,0x0000); delayms(1);
Write_Cmd_Dat(0x0044,0xEF00); delayms(1);
Write_Cmd_Dat(0x0045,0x0000); delayms(1);
Write_Cmd_Dat(0x0046,0x013F); delayms(1);
Write_Cmd_Dat(0x0030,0x0707); delayms(1);
Write_Cmd_Dat(0x0031,0x0204); delayms(1);
Write_Cmd_Dat(0x0032,0x0204); delayms(1);
Write_Cmd_Dat(0x0033,0x0502); delayms(1);
Write_Cmd_Dat(0x0034,0x0507); delayms(1);
Write_Cmd_Dat(0x0035,0x0204); delayms(1);
Write_Cmd_Dat(0x0036,0x0204); delayms(1);
Write_Cmd_Dat(0x0037,0x0502); delayms(1);
Write_Cmd_Dat(0x003A,0x0302); delayms(1);
Write_Cmd_Dat(0x003B,0x0302); delayms(1);
Write_Cmd_Dat(0x0023,0x0000); delayms(1);
Write_Cmd_Dat(0x0024,0x0000); delayms(1);
Write_Cmd_Dat(0x0025,0x8000); delayms(1);
Write_Cmd_Dat(0x004f,0); //行首址0
Write_Cmd_Dat(0x004e,0); //列首址0
Write_Cmd(0x0022);
}
#ifndef __TFTLCD_H
#define _TFTLCD_H
#include"stm32f10x.h"
#define u16 unsigned int
#define u8 unsigned char
void RCC_config(void);
void Write_Cmd(u16 address);
void Write_Cmd_dat(u16 date);
void Write_Cmd_Dat(u16 address,u16 date);
void LCD_Init(void);
void Pant(unsigned int color);
#endif
求解决 |
|