LPC1788的LCD接口驱动真彩屏
扫描二维码
随时随地手机看文章
#ifndef __LCD_H_
#define __LCD_H_
#include "common.h"
#include "debugserial.h"
#include "delay.h"
#include "sdram.h"
#define White 0xFFFFFF
#define Black 0x000000
#define Blue 0xFF0000
#define Red 0x0000FF
#define Green 0x00FF00
#define Yellow 0x00FFFF
#define purple 0xff00ff
#define pixel_clock 9000000 //像素时钟设置为9M
#define lcd_h_size 480 //根据数据手册典型值设置
#define lcd_h_pulse 2
#define lcd_h_back_proch 43
#define lcd_h_front_porch 8
#define lcd_v_size 272
#define lcd_v_pulse 10
#define lcd_v_back_proch 12
#define lcd_v_front_porch 4
#define lcd_show_delay 10000
#define LCD_VRAM_BASE_ADDR ((unsigned long)SDRAM_BASE_ADDR + 0x00010000)//显示基地址
#define LCD_CURSOR_BASE_ADDR ((unsigned long)0x20088800)
void lcd_init(u32 defaultColor);
void lcd_clear(u32 color);
void lcd_set_backlight(u8 enable);
void lcd_draw_point(u32 x,u32 y,u32 color);
u32 lcd_read_point(u32 x,u32 y);
void lcd_draw_line(u16 x1,u16 y1,u16 x2,u16 y2,u32 color);
void lcd_draw_rect(u16 x1,u16 y1,u16 x2,u16 y2,u32 color);
void lcd_draw_cicle(u16 x0,u16 y0,u8 r,u32 color);
void lcd_test(u32 color);
#endif
#include "lcd.h"
//lcd io初始化
static void lcd_in_init(void)
{
LPC_SC->PCONP|=(1<<15);//打开时钟
/* R */
LPC_IOCON->P0_4=0x27; // LCD_VD_0
LPC_IOCON->P0_5=0x27; // LCD_VD_1
LPC_IOCON->P4_28=0x27; // LCD_VD_2
LPC_IOCON->P4_29=0x27; // LCD_VD_3
LPC_IOCON->P2_6=0x27; // LCD_VD_4
LPC_IOCON->P2_7=0x27; // LCD_VD_5
LPC_IOCON->P2_8=0x27; // LCD_VD_6
LPC_IOCON->P2_9=0x27; // LCD_VD_7
/* G */
LPC_IOCON->P0_6=0x27; // LCD_VD_8
LPC_IOCON->P0_7=0x27; // LCD_VD_9
LPC_IOCON->P1_20=0x27; // LCD_VD_10
LPC_IOCON->P1_21=0x27; // LCD_VD_11
LPC_IOCON->P1_22=0x27; // LCD_VD_12
LPC_IOCON->P1_23=0x27; // LCD_VD_13
LPC_IOCON->P1_24=0x27; // LCD_VD_14
LPC_IOCON->P1_25=0x27; // LCD_VD_15
/* B */
LPC_IOCON->P0_8=0x27; // LCD_VD_16
LPC_IOCON->P0_9=0x27; // LCD_VD_17
LPC_IOCON->P2_12=0x27; // LCD_VD_18
LPC_IOCON->P2_13=0x27; // LCD_VD_19
LPC_IOCON->P1_26=0x27; // LCD_VD_20
LPC_IOCON->P1_27=0x27; // LCD_VD_21
LPC_IOCON->P1_28=0x27; // LCD_VD_22
LPC_IOCON->P1_29=0x27; // LCD_VD_23
LPC_IOCON->P2_2=0x27; // LCD_DCLK
LPC_IOCON->P2_5=0x27; // LCD_LP -- HSYNC
LPC_IOCON->P2_3=0x27; // LCD_FP -- VSYNC
LPC_IOCON->P2_4=0x27; // LCD_ENAB_M -- LCDDEN
LPC_IOCON->P2_0=0x27; // LCD_PWR
}
void lcd_init(u32 defaultColor)
{
u32*pDst=(u32*)LCD_VRAM_BASE_ADDR;//显示数据基地址
u32 i=0;
//打开LCD时钟
LPC_SC->PCONP|=1<<0;
lcd_in_init();//初始化IO
//初始化背光引脚
LPC_IOCON->P2_1=0x00;
LPC_IOCON->P2_1|=(2<<3);//控制背光
P2dir(1)=1;
P2high(1)=1;
LPC_LCD->CRSR_CTRL&=~(1<<0);//禁止光标
LPC_LCD->CTRL=0;//禁止并清零LCD
LPC_LCD->CTRL&=~(7<<1);//清零面板设置
LPC_LCD->CTRL|=(5<<1);//设置面板tft 24bpp
LPC_LCD->CTRL|=(1<<5);//tft模式
LPC_LCD->CTRL&=~(1<<7);//单面板
LPC_LCD->CTRL&=~(1<<8);//RGB颜色
LPC_LCD->CTRL&=~(1<<9);//小端数据存储
LPC_LCD->CTRL&=~(1<<10);//像素排序小端
LPC_LCD->CTRL&=~(1<<11);//信号先维持低电平
LPC_SC->LCD_CFG=ApbClock/pixel_clock;//设置像素时钟 根据数据手册来
LPC_LCD->POL|=(1<<26);//像素时钟分频旁路
LPC_LCD->POL&=~(1<<5);//模块选择cclk时钟
LPC_LCD->POL|=(1<<11);//FB管脚低电平有效
LPC_LCD->POL|=(1<<12);//LP管脚低电平有效
LPC_LCD->POL&=~(1<<13);//像素信号于时钟上升沿驱动
LPC_LCD->POL&=~(1<<14);//高电平输出使能
LPC_LCD->POL&=~(0x3FF<<16);//清除h_szie
LPC_LCD->POL|=(lcd_h_size-1)<<16;//设置h_size
//设置水平时序控制
LPC_LCD->TIMH=0;
LPC_LCD->TIMH|=(lcd_h_back_proch-1)<<24;//水平后延
LPC_LCD->TIMH|=(lcd_h_front_porch-1)<<16;//水平前沿
LPC_LCD->TIMH|=(lcd_h_pulse-1)<<8; //水平同步脉冲宽度
LPC_LCD->TIMH|=((lcd_h_size/16)-1)<<2;//每一行的像素点
//设置竖直时序控制
LPC_LCD->TIMV=0;
LPC_LCD->TIMV|=(lcd_v_back_proch)<<24;//竖直后延
LPC_LCD->TIMV|=(lcd_v_front_porch)<<16;//竖直前沿
LPC_LCD->TIMV|=(lcd_v_pulse-1)<<10;//竖直脉冲宽度
LPC_LCD->TIMV|=lcd_v_size-1; //像素
// 设置显示缓冲区地址
LPC_LCD->UPBASE=LCD_VRAM_BASE_ADDR&(~(7<<0));
LPC_LCD->LPBASE=LCD_VRAM_BASE_ADDR&(~(7<<0));
for(i=0;(lcd_h_size*lcd_v_size)>i;i++)
{
*pDst++=defaultColor;//初始化颜色
}
i=lcd_show_delay;
while(i--);
LPC_LCD->CTRL|=(1<<0);//使能lcd
LPC_LCD->CTRL|=(1<<11);//使能lcd功率
}
void lcd_clear(u32 color)
{
u32*pDst=(u32*)LCD_VRAM_BASE_ADDR;//显示数据基地址
u32 i=0;
for(i=0;(lcd_h_size*lcd_v_size)>i;i++)
{
*pDst++=color;//初始化颜色
}
}
void lcd_set_backlight(u8 enable)
{
if(enable)P2high(1)=1;
elseP2low(1)=1;
}
void lcd_draw_point(u32 x,u32 y,u32 color)
{
u32*pDst=(u32*)LCD_VRAM_BASE_ADDR;//显示数据基地址
if(x { pDst=pDst+x+(y*lcd_h_size);