📄 780._c
字号:
// Functions for SPLC780X 16com/40seg LCD Controller and Driver
//#include "idelay.h"
//#include "convert.h"
//#include "780.h"
// PORT initialization
/*void port_ini(void)
{
LCD_CTRL_DDR = 0x07;
LCD_DATA_DDR = 0xFF;
}*/
//Busy check
void CheckBusy()
{
//uint8 readByte;
LCD_DATA_DDR = 0x00;
CLR_RS;
SET_RW;
#ifdef LCD_4BIT
SET_E;
LCD_DO = dByte & 0xF0; //Higher 4-bit
//DelayUs(50);
CLR_E;
//DelayUs(50);
SET_E;
LCD_DO = dByte << 4; //Lower 4-bit
//DelayUs(50);
CLR_E;
#elif defined(LCD_8BIT)
SET_E;
while((LCD_DI&0x80)==0x80);
//DelayUs(50);
CLR_E;
#endif
}
// Write a Data or Command to LCD
void SendByte(uint8 DatCmd, uint8 dByte)
{
CheckBusy();
LCD_DATA_DDR = 0xFF;
if (DatCmd == 0)
CLR_RS;
else
SET_RS;
CLR_RW;
#ifdef LCD_4BIT
SET_E;
LCD_DO = dByte & 0xF0; //Higher 4-bit
//DelayUs(50);
CLR_E;
//DelayUs(50);
SET_E;
LCD_DO = dByte << 4; //Lower 4-bit
//DelayUs(50);
CLR_E;
#elif defined(LCD_8BIT)
SET_E;
LCD_DO = dByte;
//DelayUs(50);
CLR_E;
#endif
}
// Write a string to LCD
void SendStr(uint8 *ptString)
{
while((*ptString)!='\0')
{
SendByte(iDat, *ptString++);
}
}
// Send a Number less than 255
void SendNbr(uint8 Number)
{
uint8 *temp;
temp = NumberToChar(Number);
SendByte(iDat, *temp++);
SendByte(iDat, *temp++);
SendByte(iDat, *temp);
}
// Move Cursor or display
void Move(uint8 dir)
{
SendByte(iCmd, dir);
}
// Goto specific location
void Gotoxy(uint8 Row, uint8 Col)
{
switch (Row)
{
#if defined(LCD_L2)
case 2:
SendByte(iCmd, LCD_L2 + Col); break;
#endif
#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;
}
}
// Clear LCD Screen
void Clear(void)
{
SendByte(iCmd, LCD_CLS);
//DelayMs(3);
// 2ms delay is Necessary after sending LCD_CLS command !!!
}
// Wait some time and clear screen
void wait_and_clear(void)
{
DelayMs(1000);
Clear();
}
// Fill CGRAM with array CGRAM[]
void FillCGRAM(void)
{
uint8 i;
SendByte(iCmd, LCD_CGRAM_ADDR);
for (i = 0; i < LCD_CGMAX; i++)
{
SendByte(iDat, CGRAM[i]);
}
}
// 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);
}
wait_and_clear();
}
}
// Call built-in Charactors
void CallBultinChar(void)
{
uint8 i, k;
for (i = 0; i < LCD_COL; 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);
}
wait_and_clear();
}
}
// LCD initialize procedure
void LCD_Initial(void)
{
delay100ms(); // Wait for internal initialization
//port_ini();
LCD_CTRL_DDR = 0x07;
#ifdef LCD_4BIT
CLR_RS;
CLR_RW;
SET_E;
LCD_DO = 0x20; // Set Interface to 4-bit
//DelayUs(50);
CLR_E;
#endif
SendByte(iCmd, LCD_FUNCTION); // Function Set
//DelayUs(50);
SendByte(iCmd, LCD_ON);
//DelayUs(50);
Clear();
SendByte(iCmd, LCD_ENTRY); // Entry Mode Set
/*
// Display system Info
#ifdef LCD_4BIT
Gotoxy(1, 4);
SendStr("LCD_4BIT");
#else
Gotoxy(1, 4);
SendStr("LCD_8BIT");
#endif
Gotoxy(2,1);
SendStr("LCD_COLS: ");
SendNbr(LCD_COL);
Gotoxy(3,1);
SendStr("LCD_ROWS: ");
SendNbr(LCD_ROW);
Gotoxy(4,1);
SendStr("LCD_CHAR: ");
SendNbr(LCD_CHAR);
wait_and_clear();
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -