|
2#
楼主 |
发表于 2014-12-4 14:36:48
|
只看该作者
//#define DC PTE24_OUT
//#define RS PTE24_OUT
#define DC(x) __Pin_Set_(PTE_BASE_PTR->PDOR,24,x)
//#define CS PTE25_OUT
#define CS(x) __Pin_Set_(PTE_BASE_PTR->PDOR,25,x)
//#define RD PTE26_OUT
#define RD(x) __Pin_Set_(PTE_BASE_PTR->PDOR,26,x)
//#define WR PTE27_OUT
#define WR(x) __Pin_Set_(PTE_BASE_PTR->PDOR,27,x)
//#define RESET PTE28_OUT
#define RESET(x) __Pin_Set_(PTE_BASE_PTR->PDOR,28,x)
//#define X_MAX 320
//#define Y_MAX 240
void LCD_PinInit(uint8 RW)
{
// 输出端初始化
PORTD_BASE_PTR->PCR[0] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[1] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[2] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[3] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[4] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[5] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[6] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[7] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[8] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[9] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[10] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[11] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[12] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[13] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[14] = PORT_PCR_MUX(1);
PORTD_BASE_PTR->PCR[15] = PORT_PCR_MUX(1);
if(0 == RW)
{
PTD_BASE_PTR->PDDR |= 0x0000FFFFu; // 后十六位置为输出
}
else // Pin_READ == RW
{
PTD_BASE_PTR->PDDR &= ~0x0000FFFFu; // 后十六位置为输入
}
// 芯片控制端初始化
PORTE_BASE_PTR->PCR[24] = PORT_PCR_MUX(1); // DC/RS
PORTE_BASE_PTR->PCR[25] = PORT_PCR_MUX(1); // CS
PORTE_BASE_PTR->PCR[26] = PORT_PCR_MUX(1); // RD
PORTE_BASE_PTR->PCR[27] = PORT_PCR_MUX(1); // WR
PORTE_BASE_PTR->PCR[28] = PORT_PCR_MUX(1); // RESET
PTE_BASE_PTR->PDDR |= 0x1F000000u; //
}
void LCD_writeIndex(uint16 Index_Input)
{
DC(0);CS(0);
vint32 Index = PTD_BASE_PTR->PDOR;
Index &= ~0x0000FFFFu;
Index |= Index_Input;
PTD_BASE_PTR->PDOR = Index;
WR(0);WR(1);CS(1);
}
void LCD_writeData(uint16 Data_Input)
{
DC(1);CS(0);
vint32 Data = PTD_BASE_PTR->PDOR;
Data &= ~0x0000FFFFu;
Data |= Data_Input;
PTD_BASE_PTR->PDOR = Data;
WR(0);WR(1);CS(1);
}
void LCD_writeReg(uint16 Index,uint16 Data)
{
CS(0);
LCD_writeIndex(Index);
LCD_writeData(Data);
CS(1);
}
unsigned short int LCD_readReg(uint16 Index_In)
{
// 读取的数据确实只有status colorsInPixels // By 0822
// reading the display data from GDDRAM or reading the status from the status register
PTD_BASE_PTR->PDDR |= 0x0000FFFFu; // 后十六位置为输出
LCD_writeIndex(Index_In); //写入要读的寄存器号
CS(1);DC(1);CS(0);WR(1);RD(0);
vint32 Index = PTD_BASE_PTR->PDOR;
Index &= ~0x0000FFFFu;
Index |= 0xFFFFu;
PTD_BASE_PTR->PDOR = Index;
PTD_BASE_PTR->PDDR &= ~0x0000FFFFu; // 后十六位置为输入
RD(1);
Index = PTD_BASE_PTR->PDIR & 0x0000FFFFu;
CS(1);
return Index;
}
uint8 LCD_Init() // 放置在PIT启动前
{
SIM_SCGC5 |= (SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK);
uint16 CodeDevice = 0;
uint16 timer = 0;
LCD_PinInit(0);
RESET(0);
vDelayMs(100);
RESET(1);
vDelayMs(100);
do
{
timer++;
LCD_PinInit(0);
RESET(0);
vDelayMs(100);
RESET(1);
vDelayMs(100);
CodeDevice = LCD_readReg(0x0000);
vDelayMs(50);
if(timer > 3){return 0xFA;}
}
while( 0x8989 != CodeDevice );
LCD_PinInit(0);
// 打开晶振
LCD_writeReg(R00_OSC,0x0001);
//
LCD_writeReg(R10_SleepMode,0x0000); // 退出休眠
vDelayMs(50);
LCD_writeReg(R01_DriverOutC,0x693F); // 横屏 // TB=0 RL=1 SM=0
// LCD_Reversal(0x693F,1,1); // 切换为竖屏
LCD_writeReg(R07_DisplayC,0x0033); //
LCD_writeReg(R11_EntryMode,0x6030); // 左手坐标系
// LCD_writeReg(R11_EntryMode,0x6030);
LCD_writeReg(R02_LCDdriveAC,0x0600);
// Power supply setting
LCD_writeReg(R03_PowerC_1,0xA8A4); // 0xA8A4
LCD_writeReg(R0C_PowerC_2,0x0000);
LCD_writeReg(R0D_PowerC_3,0x080C);
LCD_writeReg(R0E_PowerC_4,0x2B00);
LCD_writeReg(R1E_PowerC_5,0x00B0);
// 开窗设置
///LCD_writeReg(0x0044,0xEF00); //水平RAM的起始-结束地址位置 (00~EF)
///LCD_writeReg(0x0045,0x0000); //垂直RAM的起始地址 00
///LCD_writeReg(0x0046,0x013F); //垂直RAM的结束地址 13F
// Gama控制
LCD_writeReg(0x0030,0x0101);
LCD_writeReg(0x0031,0x0101);
LCD_writeReg(0x0032,0x0101);
LCD_writeReg(0x0033,0x0101);
LCD_writeReg(0x0034,0x0101);
LCD_writeReg(0x0035,0x0101);
LCD_writeReg(0x0036,0x0101);
LCD_writeReg(0x0037,0x0101);
LCD_writeReg(0x003A,0x0101);
LCD_writeReg(0x003B,0x0101);
return 0;
} |
|