使用了拉普兰德的底层库
TFTlcd.c
#include "TFTlcd.h"
#include "8X16.h"
#define White 0xFFFF
#define Black 0x0000
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
void CLR_Screen(unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<240;i++)
{
for (j=0;j<320;j++)
Write_Data_U16(bColor);
}
}
void Write_Data_U16(unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Data(m,n);
}
void Write_Cmd_Data (unsigned char x,unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Cmd(0x00,x);
Write_Data(m,n);
}
void Write_Cmd(uint32_t DH,uint32_t DL)
{
TFT_CS_L;
TFT_RS_L;
DataPort=(DH<<6)&0x00003fc0;
TFT_RW_L;
TFT_RW_H;
DataPort=(DL<<6)&0x00003fc0;
TFT_RW_L;
TFT_RW_H;
TFT_CS_H;
}
void Write_Data(uint32_t DH,uint32_t DL)//д???? ?8λ
{
TFT_CS_L;
TFT_RS_H;
DataPort=(DH<<6)&0x00003fc0;
TFT_RW_L;
TFT_RW_H;
DataPort=(DL<<6)&0x00003fc0;
TFT_RW_L;
TFT_RW_H;
TFT_CS_H;
}
void ILI9325_Initial(void)
{
LPLD_GPIO_Init(PTD, 8, DIR_OUTPUT, OUTPUT_L, IRQC_DIS); //SCL
LPLD_GPIO_Init(PTD, 10, DIR_OUTPUT, OUTPUT_L, IRQC_DIS); //SDA
LPLD_GPIO_Init(PTD, 12, DIR_OUTPUT, OUTPUT_L, IRQC_DIS); //RST
LPLD_GPIO_Init(PTD, 14, DIR_OUTPUT, OUTPUT_L, IRQC_DIS); //DC
LPLD_GPIO_Init(PTC, 6, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 7, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 8, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 9, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 10, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 11, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 12, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
LPLD_GPIO_Init(PTC, 13, DIR_OUTPUT, OUTPUT_L, IRQC_DIS);
TFT_CS_H;
delay_ms(5);
TFT_RES_L;
delay_ms(5);
TFT_RES_H;
delay_ms(50);
Write_Cmd_Data(0x0001,0x0100);
Write_Cmd_Data(0x0002,0x0700);
Write_Cmd_Data(0x0003,0x1030); //??跽??
Write_Cmd_Data(0x0004,0x0000);
Write_Cmd_Data(0x0008,0x0207);
Write_Cmd_Data(0x0009,0x0000);
Write_Cmd_Data(0x000A,0x0000);
Write_Cmd_Data(0x000C,0x0000);
Write_Cmd_Data(0x000D,0x0000);
Write_Cmd_Data(0x000F,0x0000);
//power on sequence VGHVGL
Write_Cmd_Data(0x0010,0x0000);
Write_Cmd_Data(0x0011,0x0007);
Write_Cmd_Data(0x0012,0x0000);
Write_Cmd_Data(0x0013,0x0000);
//vgh
Write_Cmd_Data(0x0010,0x1290);
Write_Cmd_Data(0x0011,0x0227);
//delay_ms(100);
//vregiout
Write_Cmd_Data(0x0012,0x001d); //0x001b
//delay_ms(100);
//vom amplitude
Write_Cmd_Data(0x0013,0x1500);
//delay_ms(100);
//vom H
Write_Cmd_Data(0x0029,0x0018);
Write_Cmd_Data(0x002B,0x000D);
//gamma
Write_Cmd_Data(0x0030,0x0004);
Write_Cmd_Data(0x0031,0x0307);
Write_Cmd_Data(0x0032,0x0002);// 0006
Write_Cmd_Data(0x0035,0x0206);
Write_Cmd_Data(0x0036,0x0408);
Write_Cmd_Data(0x0037,0x0507);
Write_Cmd_Data(0x0038,0x0204);//0200
Write_Cmd_Data(0x0039,0x0707);
Write_Cmd_Data(0x003C,0x0405);// 0504
Write_Cmd_Data(0x003D,0x0F02);
//ram
Write_Cmd_Data(0x0050,0x0000);
Write_Cmd_Data(0x0051,0x00EF);
Write_Cmd_Data(0x0052,0x0000);
Write_Cmd_Data(0x0053,0x013F);
Write_Cmd_Data(0x0060,0xA700);
Write_Cmd_Data(0x0061,0x0001);
Write_Cmd_Data(0x006A,0x0000);
//
Write_Cmd_Data(0x0080,0x0000);
Write_Cmd_Data(0x0081,0x0000);
Write_Cmd_Data(0x0082,0x0000);
Write_Cmd_Data(0x0083,0x0000);
Write_Cmd_Data(0x0084,0x0000);
Write_Cmd_Data(0x0085,0x0000);
//
Write_Cmd_Data(0x0090,0x0010);
Write_Cmd_Data(0x0092,0x0600);
Write_Cmd_Data(0x0093,0x0003);
Write_Cmd_Data(0x0095,0x0110);
Write_Cmd_Data(0x0097,0x0000);
Write_Cmd_Data(0x0098,0x0000);
Write_Cmd_Data(0x0007,0x0133);
// Write_Cmd_Data(0x0022);//
}
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 Put_pixel(uint8_t x,uint8_t y,unsigned int color)
{
LCD_SetPos(x,x,y,y);
Write_Data_U16(color);
}
void dis_num(unsigned short x,unsigned short y,unsigned int num) //显示5位数字
{
unsigned char TempData[5]={0};
TempData[0]='0'+num/10000;
TempData[1]='0'+num/1000%10;
TempData[2]='0'+num/100%10;
TempData[3]='0'+num/10%10;
TempData[4]='0'+num%10;
LCD_PutString(x,y,TempData,Green,White);
}
/*----------------------------------------------------------------
显示字符串
可以中英文同时显示
输入参数:x 横坐标
y 纵坐标
*s 需要显示的字符串
fColor 字符颜色
bColor 字符背景颜色
----------------------------------------------------------------*/
void LCD_PutString(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor)
{
unsigned char l=0;
while(*s) {
if( *s < 0x80)
{
LCD_PutChar(x+l*8,y,*s,fColor,bColor);
s++;l++;
}
else
{
// PutGB1616(x+l*8,y,(unsigned char*)s,fColor,bColor);
s+=2;l+=2;
}
}
}
/*----------------------------------------------------------------
显示英文字符
输入参数:x 横坐标
y 纵坐标
c 需要显示的字符
fColor 字符颜色
bColor 字符背景颜色
----------------------------------------------------------------*/
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
LCD_PutChar8x16( x, y, c, fColor, bColor );
}
/*----------------------------------------------------------------
显示英文字符
输入参数:x 横坐标
y 纵坐标
c 需要显示的字符
fColor 字符颜色
bColor 字符背景颜色
---------------------------------------------------------------- */
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(x,x+8-1,y,y+16-1);
for(i=0; i<16;i++)
{
unsigned char m=Font8x16[c*16+i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
Write_Data_U16(fColor);
}
else
{
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
TFTlcd.h
#ifndef __TFTLCD_H__
#define __TFTLCD_H_
#include "HAL_GPIO.h"
#define DataPort (PTC_BASE_PTR->PDOR) //数据口C
#define TFT_CS_H LPLD_GPIO_Set_b(PTD, 8, OUTPUT_H)
#define TFT_CS_L LPLD_GPIO_Set_b(PTD, 8, OUTPUT_L)
#define TFT_RES_H LPLD_GPIO_Set_b(PTD, 10, OUTPUT_H)
#define TFT_RES_L LPLD_GPIO_Set_b(PTD, 10, OUTPUT_L)
#define TFT_RS_H LPLD_GPIO_Set_b(PTD, 14, OUTPUT_H)
#define TFT_RS_L LPLD_GPIO_Set_b(PTD, 14, OUTPUT_L)
#define TFT_RW_H LPLD_GPIO_Set_b(PTD, 12, OUTPUT_H)
#define TFT_RW_L LPLD_GPIO_Set_b(PTD, 12, OUTPUT_L)
/*----------------------------------------------------------------
全局变量
----------------------------------------------------------------*/
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START 0x0052 // Vertical;// Start Address Set
#define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
#define GRAMWR 0x0022 // memory write
void ILI9325_Initial(void);
void Write_Data_U16(unsigned int y);
void Write_Cmd_Data(unsigned char x, unsigned int y);
void Write_Cmd(uint32_t DH,uint32_t DL);
void Write_Data(uint32_t DH,uint32_t DL);
void CLR_Screen(unsigned int bColor);
void DRAWTFT(void);
void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);
void Put_pixel(uint8_t x,uint8_t y,unsigned int color);
void DrawPhoto(uint8_t Image[PHOTO_SIZE]);
void dis_num(unsigned short x,unsigned short y,unsigned int num);
void LCD_PutString(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor);
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor);
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor);
extern uint8_t MidLine[V];
#endif
8x16.h
/* XPM */
#define s ((((((((0
#define X )*2+1
#define _ )*2
unsigned char Font8x16[] = {
/* pixels */
/* 0x00 */
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ 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_ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
/* 0x04 */
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _ _ _ _ ,
s _ _ _ _ _

本文介绍了如何在K60平台上利用拉普兰德的底层库来驱动ILI9325彩屏,展示了TFTlcd.c文件在驱动过程中的关键作用。
最低0.47元/天 解锁文章
4575

被折叠的 条评论
为什么被折叠?



