📄 ra8835.c
字号:
//------------------------------------------------------------------------------
// File name : lcd.c
// Description : RA8835AP3N driver
// History :
// 1. Date : Feb 23, 2009
// Author : Chandrakant Bhor
// Description : Create
//Connection to GLCD are as follows:
//
//------------------------------------------------------------------------------
#include "ra8835.h"
//------------------------------------------------------------------------------
//Variables
unsigned short CurrScreen = 0, PrevScreen = 0;
unsigned char P9Val = 0,P4Val = 0;
float Temp;
unsigned int Menu=0;
unsigned int Flash = 0;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Strings
char *Posn[] = { "1","2","3","4"};
char *Day[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
char *DetType[] = {"NONE","FID ","TCD ","ECD ","NPD "};
char *Polarity[] = {"+","-"};
char *InjType[] = {"NONE","SSL ","PTV ","PKD "};
char *GcStatus[]={"READY ","WAITING ","COOLING ","RUNNING ","PRE-RDY ","TESTOVEN","RDY-INH "};
char *Status[]={"OFF","ON "};
char *AmPm[]={"AM","PM"};
char *SplitMode[]={"SPL","S/L"};
char *Units[]={"Bar","Psi","Kpa"};
char *Gas[]={"N2 ","H2 ","He ","Ar ","Air"};
char *InjCntrl[]={"PRESSURE"," FLOW "," TEMP "};
char Buffer[20];
char TxBuffer[60] = "UART1 - 1,8,N,1@115.2k communication without flow control\n\r";
char RxBuffer[60];
//------------------------------------------------------------------------------
// Function Name: LCDIOInit
// Parameters: none
// Return: none
// Description: Init IO ports directions and level
//------------------------------------------------------------------------------
void Delay (unsigned int dly)
{
unsigned int x;
for(x=dly;x>0;x--);
}
//------------------------------------------------------------------------------
// Function Name: LCDIOInit
// Parameters: none
// Return: none
// Description: Init IO ports directions and level
//------------------------------------------------------------------------------
void LCDIOInit (void)
{
#ifndef TFT
GPIO_InitTypeDef GPIO_InitStructure;
// Enable GPIO clocks
SCU_APBPeriphClockConfig(__GPIO8 | __GPIO9, ENABLE);
// Release GPIO reset
SCU_APBPeriphReset(__GPIO8 | __GPIO9, DISABLE);
// IO configure
SCU->GPIOEMI &= 0;
SCU->GPIOTYPE[9] &= ~(LCD_WR | LCD_A0 | LCD_CS);
GPIO9->DDR |= LCD_WR | LCD_A0 | LCD_CS;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
P9Val |= LCD_WR | LCD_A0 | LCD_CS;
GPIO_Write(GPIO9,P9Val);
#else
GPIO_InitTypeDef GPIO_InitStructure;
// Enable GPIO clocks
SCU_APBPeriphClockConfig(__GPIO8 | __GPIO4, ENABLE);
// Release GPIO reset
SCU_APBPeriphReset(__GPIO8 | __GPIO4, DISABLE);
// IO configure
SCU->GPIOEMI &= 0;
// SCU->GPIOTYPE[4] &= ~(LCD_RS | LCD_WR | LCD_RD | LCD_CS | LCD_RST | LCD_UD | LCD_LR);
// GPIO4->DDR |= LCD_RS | LCD_WR | LCD_RD | LCD_CS | LCD_RST | LCD_UD | LCD_LR;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_RS | LCD_WR | LCD_RD | LCD_CS | LCD_RST | LCD_UD | LCD_LR;
GPIO_Init(GPIO4, &GPIO_InitStructure);
P4Val |= LCD_RS | LCD_WR | LCD_RD | LCD_CS | LCD_RST | LCD_UD | LCD_LR;
GPIO_Write(GPIO4,P4Val);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
#endif
}
//------------------------------------------------------------------------------
// Function Name: LCD_Cmd_Write (unsigned char Cmd)
// Parameters: unsigned char Data
// Return: none
// Description: Write cmd to LCD
//------------------------------------------------------------------------------
void LCDCmdWrite (unsigned char Cmd)
{
#ifndef TFT
GPIO_Write(GPIO8,Cmd); //Data on Datalines.
Delay(100);
P9Val |= LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - High
Delay(100);
P9Val &= ~LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - Low
Delay(100);
P9Val &= ~LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - Low
Delay(100);
P9Val |= LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - High
Delay(100);
P9Val |= LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - High
Delay(100);
#else
P4Val |= LCD_RD;
GPIO_Write(GPIO4,P4Val); // RD Output - High
// Delay(100);
P4Val &= ~LCD_RS;
GPIO_Write(GPIO4,P4Val); // RS Output - Low
// Delay(100);
P4Val &= ~LCD_WR;
GPIO_Write(GPIO4,P4Val); // WR Output - Low
// Delay(100);
P4Val &= ~LCD_CS;
GPIO_Write(GPIO4,P4Val); // CS Output - Low
// Delay(100);
GPIO_Write(GPIO8,Cmd); //Data on Datalines.
// Delay(100);
P4Val |= LCD_CS;
GPIO_Write(GPIO4,P4Val); // CS Output - High
// Delay(100);
P4Val |= LCD_WR;
GPIO_Write(GPIO4,P4Val); // WR Output - High
// Delay(100);
#endif
}
//------------------------------------------------------------------------------
// Function Name: LCDDataWrite (unsigned char Data);
// Parameters: unsigned char Data
// Return: none
// Description: Write cmd to LCD
//------------------------------------------------------------------------------
void LCDDataWrite (unsigned char Data)
{
#ifndef TFT
P9Val &= ~LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - Low
Delay(100);
GPIO_Write(GPIO8,Data); //Data on Datalines.
Delay(100);
P9Val &= ~LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - Low
Delay(100);
P9Val &= ~LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - Low
Delay(100);
P9Val |= LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - High
Delay(100);
P9Val |= LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - High
Delay(100);
P9Val |= LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - High
Delay(100);
#else
P4Val |= LCD_RD;
GPIO_Write(GPIO4,P4Val); // RD Output - High
// Delay(100);
P4Val |= LCD_RS;
GPIO_Write(GPIO4,P4Val); // RS Output - High
// Delay(100);
P4Val &= ~LCD_WR;
GPIO_Write(GPIO4,P4Val); // WR Output - Low
// Delay(100);
P4Val &= ~LCD_CS;
GPIO_Write(GPIO4,P4Val); // CS Output - Low
// Delay(100);
GPIO_Write(GPIO8,Data); //Data on Datalines.
// Delay(100);
P4Val |= LCD_CS;
GPIO_Write(GPIO4,P4Val); // CS Output - High
// Delay(100);
P4Val |= LCD_WR;
GPIO_Write(GPIO4,P4Val); // WR Output - High
// Delay(100);
#endif
}
//------------------------------------------------------------------------------
// Function Name: LCDStsRead
// Parameters: none
// Return: unsigned char Data
// Description: Read LCD status
//------------------------------------------------------------------------------
unsigned char LCDStsRead (void)
{
unsigned char status=0;
GPIO_InitTypeDef GPIO_InitStructure;
#ifndef TFT
// Set Direction
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
P9Val |= LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - High
Delay(100);
P9Val &= ~LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - Low
Delay(100);
P9Val |= LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - High
Delay(100);
status = GPIO_Read(GPIO8);
Delay(100);
P9Val &= ~LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - Low
Delay(100);
P9Val |= LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - High
Delay(100);
P9Val &= ~LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - Low
Delay(100);
// Set Direction
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
#else
#endif
return(status);
}
//------------------------------------------------------------------------------
// Function Name: LCDDataRead
// Parameters: none
// Return: unsigned char
// Description: Write cmd to LCD
//------------------------------------------------------------------------------
unsigned char LCDDataRead (void)
{
unsigned char data=0;
GPIO_InitTypeDef GPIO_InitStructure;
#ifndef TFT
// LCDCmdWrite(0x47); //Read mem cmd.
// Set Direction
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
P9Val &= ~LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - Low
Delay(100);
P9Val &= ~LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - Low
Delay(100);
P9Val |= LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - High
Delay(100);
data = GPIO_Read(GPIO8);
Delay(100);
P9Val &= ~LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - Low
Delay(100);
P9Val |= LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - High
Delay(100);
P9Val |= LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - High
Delay(100);
// Set Direction
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_InitStructure.GPIO_Pin = LCD_DATA;
GPIO_Init(GPIO8, &GPIO_InitStructure);
#else
#endif
return(data);
}
//------------------------------------------------------------------------------
// Function Name: ResetDisplay
// Parameters: none
// Return: none
// Description: function to reset the graphics display
//------------------------------------------------------------------------------
void ResetDisplay(void)
{
#ifndef TFT
P9Val &= ~LCD_A0;
GPIO_Write(GPIO9,P9Val); // A0 Output - Low
Delay(1000);
P9Val |= LCD_WR;
GPIO_Write(GPIO9,P9Val); // WR Output - High
Delay(100);
P9Val |= LCD_CS;
GPIO_Write(GPIO9,P9Val); // CS Output - High
Delay(100);
#else
P4Val &= ~LCD_UD;
GPIO_Write(GPIO4,P4Val); //UD Output - Low
// Delay(100);
P4Val |= LCD_LR;
GPIO_Write(GPIO4,P4Val); //LR Output - High
// Delay(100);
P4Val &= ~LCD_RST;
GPIO_Write(GPIO4,P4Val); //RST Output - Low
Delay(100);
P4Val |= LCD_RST;
GPIO_Write(GPIO4,P4Val); //RST Output - High
Delay(100);
LCDCmdWrite(0x01); //Software reset
LCDCmdWrite(0x01);
LCDCmdWrite(0x01);
Delay(100);
LCDCmdWrite(0xE0);
LCDDataWrite(0x01); //Enable PLL
Delay(100);
// LCDCmdWrite(0xE0); //Lock PLL
LCDDataWrite(0x03);
#endif
}
//------------------------------------------------------------------------------
// Function Name: ClearGraphics
// Parameters: none
// Return: none
// Description: function to clear the graphic screen
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -