📄 s6a0074.c
字号:
// Functions for S6A0078
// Send a byte to LCD Controller
void SendByte(bit DatCmd, uint8 dByte)
{
#ifdef LCD_4BIT
LCD_DataPort = 0x0F;
LCD_RS = DatCmd;
LCD_RW = 0;
LCD_E = 1;
LCD_DataPort = dByte & 0xF0; //Higher 4-bit
// DelayUs(100);
LCD_E = 0;
LCD_E = 1;
LCD_DataPort = dByte << 4; //Lower 4-bit
// DelayUs(100);
LCD_E = 0;
#elif defined(LCD_8BIT)
LCD_DataPort = 0x00;
LCD_RS = DatCmd;
LCD_RW = 0;
LCD_E = 1;
LCD_DataPort = dByte;
DelayUs(50);
LCD_E = 0;
#endif
DelayUs(500);
}
// Read a byte from DDRAM/CGRAM/SEGRAM
uint8 ReadByte(void)
{
uint8 Result;
#ifdef LCD_4BIT
LCD_DataPort = 0xF0;
LCD_RS = iDat;
LCD_RW = 1;
LCD_E = 1;
LCD_E = 0;
DelayUs(50);
Result = LCD_DataPort & 0xF0; //Higher 4-bit
LCD_E = 1;
LCD_E = 0;
DelayUs(50);
Result |= LCD_DataPort >> 4; //Lower 4-bit
#elif defined(LCD_8BIT)
LCD_DataPort = 0xFF;
LCD_RS = iDat;
LCD_RW = 1;
LCD_E = 1;
LCD_E = 0;
DelayUs(50);
Result = LCD_DataPort;
#endif
return Result;
}
// Move Cursor or display
void Move(uint8 dir)
{
SendByte(iCmd, dir);
}
// Goto specific location
void Gotoxy(uint8 Row, uint8 Col)
{
#if defined(LCD_L2)
switch (Row)
{
case 2:
SendByte(iCmd, LCD_L2 + Col); break;
#if defined(LCD_L3)
case 3:
SendByte(iCmd, LCD_L3 + Col); break;
#endif
#if defined(LCD_L4)
case 4:
SendByte(iCmd, LCD_L4 + Col); break;
#endif
default:
SendByte(iCmd, LCD_L1 + Col); break;
}
#endif
}
// Send a string to LCD Screen
void SendStr(uint8 code *ptString)
{
while((*ptString) != '\0')
{
SendByte(iDat, *ptString++);
}
}
// Fill CGRAM with array CGRAM[]
void FillCGRAM(void)
{
uint8 i;
// SendByte(iCmd, 0x08);//display off
SendByte(iCmd, LCD_CGRAM_ADDR);
for (i = 0; i < LCD_CGMAX; i++)
{
SendByte(iDat, CGRAM[i]); // (& 0x3F) will disable blink
}
// SendByte(iCmd, 0x0c);//display on
}
// Show All patterns in CGRAM
void ShowCGRAM(void)
{
uint8 i,k;
for (i = 0; i < 8; i++)
{
SendByte(iCmd, LCD_L1);
for (k = 0; k < LCD_CHAR; k++)
{
#if defined(LCD_L2)
switch (k)
{
case LCD_COL:
SendByte(iCmd, LCD_L2); break;
#if defined(LCD_L3)
case LCD_COL*2:
SendByte(iCmd, LCD_L3); break;
#endif
#if defined(LCD_L4)
case LCD_COL*3:
SendByte(iCmd, LCD_L4); break;
#endif
default:
break;
}
#endif
SendByte(iDat, i);
}
WAC();
}
}
// Turn ON/OFF the specific ICONs
void SetICON(uint8 SAddr, uint8 State)
{
SendByte(iCmd, 0x24);
SendByte(iCmd, 0x40 + SAddr);
SendByte(iDat, State);
SendByte(iCmd, 0x28);
}
// Call built-in Charactors
void CallBuiltinChar(void)
{
uint8 i, k;
for (i = 0; i < LCD_COL/4; i += LCD_ROW)
{
SendByte(iCmd, LCD_L1);
for (k = 0; k < LCD_CHAR; k++)
{
#if defined(LCD_L2)
switch (k)
{
case LCD_COL:
SendByte(iCmd, LCD_L2); break;
/*
#if defined(LCD_L3)
case LCD_COL*2:
SendByte(iCmd, LCD_L3); break;
#endif
#if defined(LCD_L4)
case LCD_COL*3:
SendByte(iCmd, LCD_L4); break;
#endif
*/
default:
break;
}
#endif
SendByte(iDat, k + LCD_COL*i+32);
}
WAC();
}
}
// Clear Entire Screen
void LCD_CLS(void)
{
SendByte(iCmd, 0x01);
DelayMs(5);
// 2ms delay is Necessary after sending LCD_CLS command !!!
}
// Wait some time then clear the screen
void WAC(void)
{
DelayMs(800);
LCD_CLS();
}
// LCD initialize procedure
void LCD_Initial(void)
{
DelayMs(200); // Wait for internal initialization
#ifdef LCD_4BIT
SendByte(iCmd, 0x20); // Function Set
SendByte(iCmd, 0x28); // Function Set(4-bit/1-line)
#elif LCD_8BIT
SendByte(iCmd, 0x38); // Function Set(4-bit/2-line)
#endif
SendByte(iCmd, 0x24); // Extended function set
SendByte(iCmd, 0x08); // Set font(5 dots)
SendByte(iCmd, 0x20); // Basic function set
// SendByte(iCmd, 0x0C); // Enable Display
// LCD_CLS();
SendByte(iCmd, 0x06); // Entry Mode Set
SendByte(iCmd, 0x0c); //display off
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -