📄 ra8815.c
字号:
// --------------------- Functions for RA8815 ----------------------------------
// LCD Busy Check
void LCD_CheckBusy(void)
{
while((ReadCmd(0x0F) & 0x80) == 0x80);
}
// Write a command to the register specified by index
void WriteCmd(uint8 index, uint8 dByte)
{
#ifdef LCD_4SPI
SPI_CS = 0;
SPI_A0 = 0;
spi_sendbit(0); // RW = 0 for writing action
spi_sendbyte(index);
spi_sendbyte(dByte);
SPI_CS = 1;
#elif defined(LCD_3SPI)
SPI_CS = 0;
spi_sendbit(0); // RW = 0 for writing action
spi_sendbit(0); // A0 = 0 for command
spi_sendbyte(index);
spi_sendbyte(dByte);
SPI_CS = 1;
#else
SendByte(iCmd, index);
DelayUs(4);
SendByte(iCmd, dByte);
#endif
DelayUs(200);
}
// Write a data to DDRAM
void WriteData(uint8 dByte)
{
#ifdef LCD_4SPI
SPI_CS = 0;
SPI_A0 = 1;
spi_sendbit(0); // RW = 0 for writing action
spi_sendbyte(dByte);
SPI_CS = 1;
#elif defined(LCD_3SPI)
SPI_CS = 0;
spi_sendbit(0); // RW = 0 for writing action
spi_sendbit(1); // A0 = 1 for data
spi_sendbyte(dByte);
SPI_CS = 1;
#endif
LCD_CheckBusy();
SendByte(iDat, dByte);
//DelayMs(1);
DelayUs(250);
DelayUs(250);
}
// Read a Commamd from index register
uint8 ReadCmd(uint8 index)
{
uint8 Result;
#ifdef MCU_6800
SendByte(iCmd, index);
LCD_DataPort = 0xFF;
LCD_CS = 0;
LCD_A0 = 0;
LCD_RW = 1;
LCD_E = 1;
DelayUs(4);
Result = LCD_DataPort;
LCD_E = 0;
LCD_A0 = 1;
LCD_RW = 1;
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(MCU_8080)
SendByte(iCmd, index);
DelayUs(4);
LCD_DataPort = 0xFF;
LCD_CS = 0;
LCD_A0 = 0;
LCD_WR = 1;
LCD_RD = 0;
DelayUs(4);
Result = LCD_DataPort;
LCD_RD = 1;
LCD_A0 = 1;
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(LCD_4SPI)
SPI_CS = 0;
SPI_A0 = 0; // Command
spi_sendbit(1); // RW = 1 for Read
spi_sendbyte(index);
Result = spi_readbyte();
SPI_CS = 1;
#elif defined(LCD_3SPI)
SPI_CS = 0;
spi_sendbit(1); // RW = 1 for Reading Action
spi_sendbit(0); // A0 = 0 for Command
spi_sendbyte(index);
Result = spi_readbyte();
SPI_CS = 1;
#endif
return Result;
}
// Read a data from DDRAM
uint8 ReadData(uint8 xUnit, yBit)
{
uint8 Result;
Gotoxy(xUnit, yBit);
#ifdef MCU_6800
LCD_DataPort = 0xFF; // Set the port as Input
LCD_CS = 0;
LCD_A0 = 1; // Data
LCD_RW = 1;
LCD_E = 1;
Result = LCD_DataPort;
LCD_E = 0;
DelayUs(100);
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(MCU_8080)
LCD_DataPort = 0xFF; // Set the port as Input
LCD_CS = 0;
LCD_A0 = 1; // Data
LCD_WR = 1;
LCD_RD = 0;
DelayUs(4);
Result = LCD_DataPort;
LCD_RD = 1;
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(LCD_4SPI)
SPI_CS = 0;
SPI_A0 = 1; // A0 = 1 for Data
spi_sendbit(1); // RW = 1 for Reading Action
Result = spi_readbyte();
SPI_CS = 1;
#elif defined(LCD_3SPI)
SPI_CS = 0;
spi_sendbit(1); // RW = 1 for Reading Action
spi_sendbit(1); // A0 = 1 for Data
Result = spi_readbyte();
SPI_CS = 1;
#endif
return Result;
}
// Set LCD Drawing Mode
void SetMode(uint8 iMode)
{
uint8 temp;
temp = ReadCmd(0x03);
switch (iMode)
{
case 0:
temp &= 0xFC; break;
case 1:
temp |= 0x01;
temp &= 0xFD; break;
case 2:
temp &= 0xFE;
temp |= 0x02; break;
case 3:
temp |= 0x03; break;
default:
temp &= 0xFC; break;
}
WriteCmd(0x03, temp);
}
// Goto a specific position
void Gotoxy(uint8 xUnit, uint8 yBit)
{
WriteCmd(0x05, xUnit); // xUnit < X_MAX/8
WriteCmd(0x06, yBit); // yBit < Y_MAX
}
// Display a string of Ascii chars on the screen
void SendStr(uint8 *ptrString, uint16 tDelay)
{
while(*ptrString != '\0')
{
WriteData(*ptrString++);
DelayMs(tDelay); // Display a letter each tDelay Ms.
}
}
// Clear LCD Screen
void LCD_CLS(void)
{
uint8 temp;
temp = ReadCmd(0x01);
temp |= 0x40;
WriteCmd(0x01, temp);
}
// wait and clear
void wait_and_clear(void)
{
DelayMs(1000);
LCD_CLS();
}
// Turn On LCD display
void LCD_ON(void)
{
uint8 temp;
temp = ReadCmd(0x01);
temp |= 0x02;
WriteCmd(0x01, temp);
}
// Turn Off LCD display
void LCD_OFF(void)
{
uint8 temp;
temp = ReadCmd(0x01);
temp &= 0xFD;
WriteCmd(0x01, temp);
}
// LCD Initialization
void LCD_Initial(void)
{
LCD_Reset();
WriteCmd(0x02, 0x71); // System setting(BIG5, 128s*32c)
WriteCmd(0x03, 0x00); // Memory Writting Mode(Normal, Small Ascii)
WriteCmd(0x10, 0x80); // Bias and Contrast Setting(1/6Bias)
WriteCmd(0x11, 0xF2); // Driving Control(Internal Power, Normal Dir.)
WriteCmd(0x12, 0xE2); // Driving Control
WriteCmd(0x13, 0x00); // Blink Control
WriteCmd(0x04, 0x00); // Cursor setting(show a blink cursor with 1pix)
LCD_CLS();
LCD_ON();
}
// LCD Graphic Testing
void LCD_Test(void)
{
uint8 k;
uint16 i;
uint8 code TestData[][2] =
{
{0xFF,0xFF}, // 1. All
{0x00,0x00}, // 2. None
{0xAA,0xAA}, // 3. Virtical 1
{0x55,0x55}, // 4. Virtical 2
{0xFF,0x00}, // 5. Horizontal 1
{0x00,0xFF}, // 6. Horizontal 2
{0xAA,0x55}, // 7. Stars 2
{0x55,0xAA}, // 8. Stars 2
};
SetMode(GRAPHIC);
for(k = 0; k < 8; k++)
{
Gotoxy(0,0);
for(i = 0; i < Screen_Size; i++)
{
if ((i/(X_MAX/8))%2 != 0)
WriteData(TestData[k][1]);
else
WriteData(TestData[k][0]);
}
wait_and_clear();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -